Questions about NCEG
Paul Eggert
eggert at twinsun.com
Thu May 31 06:54:36 AEST 1990
I wrote:
There are ways to say the IEEE numbers in ANSI C + IEEE 754:
#define minus_0 (-0.0)
#define infinity (1e300*1e300)
...
Doug Gwyn replied:
These don't work. -0.0 is NOT a "minus zero"; it's identical to 0.0.
Surely ANSI C doesn't require this; it is inconsistent with IEEE 754.
For example, given the following strictly conforming ANSI C program
#include <stdio.h>
int main() { printf("%g\n", -0.0); return 0; }
an implementation that conforms to both ANSI C and IEEE 754 must print "-0",
not "0". IEEE 754 doesn't specify the output format, but it does require that
+0 and -0 be output differently, and "-0" is the only real choice here.
This is not purely academic. Of the two C compilers on my IEEE 754-based
machine, one prints "-0" and the other "0" when given the above program. I've
sent a bug report to the latter's implementer, and fully expect it to get fixed.
Finally, Gwyn wrote:
Assuming that 1.0e+300*1.0e+300 is not representable as a
(floating-point) number, the behavior is explicitly undefined...
(Steve Clamage made a similar point.)
True, if you assume only conformance to ANSI C.
But I explicitly assumed conformance to both ANSI C and IEEE 754.
More information about the Comp.std.c
mailing list