[fpc-pascal] Floating point discrepancy in x64 mode

OBones obones at free.fr
Fri Jul 20 11:59:53 CEST 2012


Hello all,

Let's consider the following test program:

program test;

function DirectCompute: Double;
var
   k: Integer;
begin
   k := 0;
   Result := (k+0.5)/12;
end;

function IntermediateCompute: Double;
var
   k: Integer;
begin
   k := 0;
   Result := k+0.5;
   Result := Result / 12;
end;

begin
   WriteLn(DirectCompute);
   WriteLn(IntermediateCompute);
end.

When I compile it with ppc386 and run it, I get the following output:

  4.16666666666667E-002
  4.16666666666667E-002

which is totally expected.
However, when I compile it with ppcrossx64 and run it, I get the 
following output:

  4.16666679084301E-002
  4.16666666666667E-002

The error is very significant here as in my real world program, it gets 
propagated through successive multiplications.
Looking at the bit values, I get this:

$3FA5555560000000 for the "bogus value"
$3FA5555555555555 for the expected value

I tried setting the optimization options ( O-, O1, O2, O3) but to no avail.
All this is with FPC 2.6.0 (2011/12/25) as it is the latest stable release.

Many thanks in advance for your help





More information about the fpc-pascal mailing list