[fpc-devel] Rounding inconsistent (critical)
Vincent Snijders
vsnijders at quicknet.nl
Mon Oct 2 13:30:00 CEST 2006
Chris Cheney schreef:
>
> Date sent: Mon, 2 Oct 2006 12:59:45 +0200
> From: "Graeme Geldenhuys" <graemeg.lists at gmail.com>
> To: "FPC developers' list" <fpc-devel at lists.freepascal.org>
> Subject: Re: [fpc-devel] Rounding inconsistent (critical)
> Send reply to: FPC developers' list <fpc-devel at lists.freepascal.org>
> <mailto:fpc-devel-request at lists.freepascal.org?subject=unsubscribe>
> <mailto:fpc-devel-request at lists.freepascal.org?subject=subscribe>
>
>> I also ran the exact example given on the Wikipedia site and I also got errors.
>>
>> AssertEquals('Failing on 1', '3.02', FormatFloat('0.00', 3.016));
>> AssertEquals('Failing on 2', '3.01', FormatFloat('0.00', 3.013));
>> AssertEquals('Failing on 3', '3.02', FormatFloat('0.00', 3.015));
>> AssertEquals('Failing on 4', '3.04', FormatFloat('0.00', 3.045));
>> AssertEquals('Failing on 5', '3.05', FormatFloat('0.00', 3.04501));
>>
>>
>> Test 1: Passed
>> Test 2: Passed
>> Test 3: Passed
>> Test 4: Failing on 4 expected: <3.04> but was: <3.05>
>> Test 5: Passed
>
> See, for example,
>
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;q42980
>
> (there are plenty of other web sites explaining this sort of thing)
>
> The short version is that very few numbers expressed as a decimal
> fraction are representable ACCURATELY on a computer.
But 0.125 and 0.375 are representable ACCURATELY on a computer, aren't they?
Vincent
More information about the fpc-devel
mailing list