[fpc-pascal] Why the difference in the rounded results?

Guillermo gmartinez at burdjia.com
Fri Oct 15 20:28:23 CEST 2021


Hi,

Silly question: Were all compiled an executed in the same computer
and operating system?  Also, were all compilations done with same
optimization configuration?

It is well known that different CPUs have differences in some
operations, specially DIV ones that even introduced bugs in the past
(i.e. the infamous Pentium DIV).  Also different compilers may introduce
different configurations about math processing if you didn't set one
(i.e. using the "default" CPU).  Maybe some assume Pentium (so it should
workaround DIV operations) and other don't.

Also if it was compiled in a way that doesn't use the CPU math
operations different operating systems/library versions may have
different implementations for the same operation.

Regards,
Guillermo Martínez.


El Fri, 15 Oct 2021 11:49:59 +0200
Gabor Boros via fpc-pascal <fpc-pascal at lists.freepascal.org> escribió:
> Hi All,
> 
> I got different results with 32bit vs. 64bit, 3.2.2 vs. 3.3.1, FPC
> vs. Delphi. Why?
> 
> var
>    d1,d2:Double;
> 
> begin
>    d1:=20.5;
>    d2:=1.05;
>    Writeln(RoundTo(d1*d2,-2));
>    Writeln(SimpleRoundTo(d1*d2));
>    d1:=28.9;
>    Writeln;
>    Writeln(RoundTo(d1*d2,-2));
>    Writeln(SimpleRoundTo(d1*d2));
>    d1:=21.5;
>    Writeln;
>    Writeln(RoundTo(d1*d2,-2));
>    Writeln(SimpleRoundTo(d1*d2));
>    Readln;
> end.
> 
> - FPC 3.2.2 Win32
> 
>   2.1530000000000001E+001
>   2.1530000000000001E+001
> 
>   3.0340000000000000E+001
>   3.0340000000000000E+001
> 
>   2.2570000000000000E+001
>   2.2570000000000000E+001
> 
> - FPC 3.2.2 Win64
> 
>   2.1520000000000003E+001
>   2.1530000000000001E+001
> 
>   3.0340000000000007E+001
>   3.0350000000000001E+001
> 
>   2.2570000000000004E+001
>   2.2579999999999998E+001
> 
> - FPC 3.3.1 Win32
> 
>   2.1530000000000001E+001
>   2.1530000000000001E+001
> 
>   3.0340000000000000E+001
>   3.0340000000000000E+001
> 
>   2.2570000000000000E+001
>   2.2570000000000000E+001
> 
> - FPC 3.3.1 Win64
> 
>   2.1520000000000003E+001
>   2.1530000000000001E+001
> 
>   3.0340000000000007E+001
>   3.0350000000000001E+001
> 
>   2.2570000000000004E+001
>   2.2579999999999998E+001
> 
> - Delphi 10.4.2 Win32
> 
>   2.15300000000000E+0001
>   2.15300000000000E+0001
> 
>   3.03400000000000E+0001
>   3.03400000000000E+0001
> 
>   2.25800000000000E+0001
>   2.25800000000000E+0001
> 
> - Delphi 10.4.2 Win64
> 
>   2.15200000000000E+0001
>   2.15300000000000E+0001
> 
>   3.03400000000000E+0001
>   3.03500000000000E+0001
> 
>   2.25800000000000E+0001
>   2.25800000000000E+0001
> 
> Gabor
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list