Re: FastCode RoundToEx




Claim Number 3
"The result of RoundToEx(InpVal,-2) will be
RoundToEX_Ref = + 0.04999 99999 99999 99999 72894 94568 78623 89149
81367 99782 51457 21435 54687 5
which is actually further away from the rational 5/100 value than the InpVal
is away from the rational value."

Claim3 was made in the context that the input InpVal was a an extended type and had been assigned the value "5/100" in code or as the result of a division of 5 by 100.

In such situation: (It helps to use Courier font.)

InpVal (5/100) = + 0.05000 00000 00000 00000 06776 26357 80344 02712 54658 00054 37135 69641 11328 125

RoundTo_JFH() = + 0.05000 00000 00000 00000 06776 26357 80344 02712 54658 00054 37135 69641 11328 125

RoundToEX_Ref()= + 0.04999 99999 99999 99999 72894 94568 78623 89149 81367 99782 51457 21435 54687 5

Here is how I determine which value is closer to 0.05: (It helps to use Courier font.)

By observation, I do the arithmetic to calc the abs value of the difference between the numbers and 0.05 (=5/100):

Abs(RoundTo_JFH - 5/100) = 0.00000 00000 00000 00000 06776 26357 80344 02712 54658 00054 37135 69641 11328 125

Abs(RoundToEX_Ref - 5/100) = 0.00000 00000 00000 00000 27105 05431 21376 10850 18632 00217 48542 78564 45312 5

Here you can see that the RoundToEX_Ref result is about three times farther away from the 5/100 target than the RoundTo_JH result.

RoundTo_JFH uses (the equivalent of)
LFactor := IntPower(10, -ADigit);
Result := Round(aValue*LFactor)/LFactor;

RoundToEx_Ref uses
LFactor := IntPower(10, ADigit);
Result := Round(AValue / LFactor) * LFactor;

Regards to all, JohnH

--
Support the movement to add floating and fixed
decimal fraction numbers to Delphi.
http://qc.borland.com/wc/qcmain.aspx?d=28022
DecimalRounding (JH1)
http://cc.codegear.com/Item.aspx?id=21909
IEEE Number Analyzer (project code)
http://cc.codegear.com/item.aspx?id=23631
ExactFloatToStr
http://cc.codegear.com/Item.aspx?id=19421
.



Relevant Pages

  • Re: LOGFONT and Courier font to a printer
    ... Given that the font can change based on the report, the pitch FIXED_PITCH ... Or FF_MODERN will work for 'Courier New', will it also work for Arial or do I ...
    (microsoft.public.win32.programmer.gdi)
  • Re: LOGFONT and Courier font to a printer
    ... If you get the FontType for Courier, it will be RASTER_FONTTYPE and if you ... The font mapper made your font the same as you expected except that it is ... Is there a method to know if a font is a Raster Font verses a true type ... You are not zero-filling your LOGFONT structure, ...
    (microsoft.public.win32.programmer.gdi)
  • Re: LOGFONT and Courier font to a printer
    ... I am not sure I follow what you're saying. ... Courier font. ... customer chooses Courier, the font mapper chooses Arial with his driver. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: LOGFONT and Courier font to a printer
    ... If you MUST use Courier, the only solution I can think of is to output the ... over TrueType scalable font _if_ one is available for the given typeface. ... Is there a method to know if a font is a Raster Font verses a true type ... You are not zero-filling your LOGFONT structure, ...
    (microsoft.public.win32.programmer.gdi)
  • Re: LOGFONT and Courier font to a printer
    ... I am not sure how we ended up assuming it was using the "Courier New" ... like Courier as it is a variable width font whereas ... to your LOGFONT structure as this is what the font mapper is using. ... Is there a method to know if a font is a Raster Font verses a true ...
    (microsoft.public.win32.programmer.gdi)