[fpc-devel] Rounding inconsistent (critical)
Graeme Geldenhuys
graemeg.lists at gmail.com
Mon Oct 2 14:32:56 CEST 2006
On 02/10/06, Vincent Snijders <vsnijders at quicknet.nl> wrote:
>
> But 0.125 and 0.375 are representable ACCURATELY on a computer, aren't they?
>
> Vincent
Yes they can, so FPC still has a bug in Banker's Rounding.
What is really interresting is that I never really thought about
irrational number and how they are represented in computers. From
that article in MSDN, here is a few basic calulations that don't work
on computers. Multiply is the only test that worked! All other tests
didn't. :-)
var
sumE: extended;
sumD: double;
sumS: single;
i: integer;
t1, t2, t3: single;
begin
write('multiply: ');
writeln(0.0001 * 10000);
writeln('=========');
// should be 1.0 in theory
sumE := 0;
for I := 1 to 10000 do
sumE := sumE + 0.0001;
write('sum E: ');
writeln(sumE);
writeln('=========');
// should be 1.0 in theory
sumD := 0;
for I := 1 to 10000 do
sumD := sumD + 0.0001;
write('sum D: ');
writeln(sumD);
writeln('=========');
// should be 1.0 in theory
sumS := 0;
for I := 1 to 10000 do
sumS := sumS + 0.0001;
write('sum S: ');
writeln(sumS);
writeln('=========');
writeln(' ');
writeln('testing the follow: 69.82 = 69.20 + 0.62 ');
t1 := 69.82;
t2 := 69.20;
t3 := 0.62;
writeln(t1);
writeln(t2);
writeln(t3);
if t1 = (t2 + t3) then
writeln('equality')
else
writeln('non equals'); <=== prints this!!!
writeln('=========');
Regards,
- Graeme -
More information about the fpc-devel
mailing list