Re: FastCode RoundToEx
- From: "John Herbster" <herb-sci1_AT_sbcglobal.net>
- Date: Sat, 29 Dec 2007 07:29:02 -0600
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
.
- Follow-Ups:
- Re: FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- References:
- FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- From: Dennis
- FastCode RoundToEx
- Prev by Date: Re: FastCode Reference Compilers
- Next by Date: Re: FastCode RoundToEx
- Previous by thread: Re: FastCode RoundToEx
- Next by thread: Re: FastCode RoundToEx
- Index(es):
Relevant Pages
|