[fpc-devel] Rounding inconsistent (critical)
Chris Cheney
C.J.Cheney at ucs.cam.ac.uk
Mon Oct 2 13:21:54 CEST 2006
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.
BTW Delphi uses Banker's Rounding by default.
More information about the fpc-devel
mailing list