Zitat von Vojtěch Čihák <vojtech.ci...@atlas.cz>:
will not give any warning even if correct result is 2.5.
It is simply absurd because it is not about shooting your own foot. Compiler is not a crystal ball, it does what you tell him. If you need floating point, use floating point types and floating point division (my example) and if you need signed results, use

Really?

There are other source of loss of precision (in the trunk version) and the compiler does
not what I tell him. Example:

const
  d1: double = 1.0/3.0;
  d2: double = 1/3;
  x1: extended = 1.0/3.0;
  x2: extended = 1/3;
  s1: single   = 1.0/3.0;
  s2: single   = 1/3;
begin
  writeln(s1:30:10,  s2:30:10);
  writeln(d1:30:16,  d2:30:16);
  writeln(x1:30:16,  x2:30:16);
end.

and the result

                  0.3333333433                  0.3333333433
            0.3333333432674408            0.3333333333333333
            0.3333333432674408            0.3333333333333333

The single result is expected. But the double and extended constants d1, x1 are evaluated as single, even if I told the compiler to use the floating point quotient 1.0/3.0.

If I use the integer quotient the values are as expected. This is against intuition and gives no warning. And even if I can adapt to this and live with this quirk: Is there a definite
statement, that is will remain so. (Delphi works as expected).


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to