Skip to content

Compiler no longer respects −0.0

This program:

const
	NegInfinity: single = -1.0 / 0.0;
begin
	writeln(-0.0);
	writeln(1.0 / (-1.0 / 0.0));
	writeln(1.0 / NegInfinity);
end.

fed to the trunk compiler prints

 0.000000000E+00
 0.000000000E+00
-0.000000000E+00

Third minus zero is thanks to the division not being folded; with true (untyped) const NegInfinity = -1.0 / 0.0 it is folded completely into a positive zero, as in the 1.0 / (-1.0 / 0.0) case.

There was a time when all of the three were giving minus zeros, see e.g. output with FPC 3.0.4: https://ideone.com/m17u8F.

Programming languages generally respect minus zeros: https://ideone.com/1H4ptw (C++), https://ideone.com/qZHdIg (Rust). Mainly because dividing 1.0 by +0.0 and by −0.0 gives two extremes, +∞ and −∞.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information