[fpc-pascal] Strange floating-point result

Thomas Kurz fpc.2021 at t-net.ruhr
Fri Nov 11 11:49:17 CET 2022


by chance, I stumbled upon a strange behavior in floating-point calculation. Here's the example:

program Project1;

  f: double;
  n: integer = 1758;
  m: integer = 0;

  f := n * 1.2E6 + (2*m+1) * 50E3; // 2109650048
  f := Double(n) * 1.2E6 + Double(2*m+1) * 50E3; // 2109650000

Why do I have to explicitly cast Integer to Double here? I never did that before and am a bit worried whether I could get wrong results elsewhere, too, without having them noticed yet. And how does the first value come about?

FPC is 3.2.2 on Win64, targeting Win64.

Kind regards,

More information about the fpc-pascal mailing list