[fpc-pascal] fpc 32 / 64 bit / c++/ floating point question
Helmut Hartl
helmut.hartl at firmos.at
Sun Nov 21 18:54:13 CET 2010
While stabilizing my bullet physics port i saw some differences in
floating point behaviour between c++ and fpc32 and fpc 64 bit.
In question is a simple dot product.
The function :
result := a*d+b*e+c*f;
Gives "different" results( 6.3846106530 vs 6.3846111610 ) depending
on the usage of intermediate variables for the final result and the fpc
version
32 bit / 64 bit, while the C++ version does not show this behaviour and
always
gives the same result. (XCode 3.2.1/ GCC on OSX)
I only show the (extracted) compilable fpc exampe:
program fpc_floatmul;
var a,b,c,d,e,f : single;
i,j,k : single;
result_same_as_c : single;
begin
a:= 1;
b:= -5.65984446;
c:= -3.4953573;
d:= 8.48976051;
e:= 1.5;
f:= -1.82659933;
i := a * d;
j := b * e;
k := c * f;
result_same_as_c := i + j + k;
writeln(result_same_as_c:10:10);
writeln(a*d+b*e+c*f:10:10); // different result
end.
Running the above program gives
1) C++ / FPC 64 Bit
6.3846106530
6.3846106530
2) FPC32 Bit
6.3846106530
6.3846111610
Is this explainable or wrong behaviour ?
thanks,
helmut
More information about the fpc-pascal
mailing list