Questions about NCEG
Paul Eggert
eggert at twinsun.com
Thu May 31 12:32:44 AEST 1990
I wrote that IEEE 754 requires that -0.0 and 0.0 be distinguishable.
Tom Neff asks: ``Where does it say this?'' IEEE 754 section 5.6 says
When rounding to nearest, conversion from binary to decimal and back to
binary shall be the identity as long as the decimal string is carried
to the maximum precision specified in Table 2, namely 9 digits for
single and 17 digits for double.
In other words, print a binary floating-point number, then read it back in:
you'll get the original bit pattern, so long as you use enough digits and use
the default rounding mode. To satisfy this requirement, -0.0 and 0.0 must have
different external forms, since their internal forms differ.
Neff also writes:
ANSI C does require that the strings "-0.0" and "0.0" parse to the same
internal representation number (right Doug?).
On the contrary, the wording for strtod() (ANSI C 4.10.1.4) provides for the
distinction between 0.0 and -0.0:
If the subject sequence has the expected form, [it, minus any sign,]
... is interpreted as a floating constant.... If the subject
sequence begins with a minus sign, the value resulting from the
conversion is negated.
Thus on an IEEE 754 host, strtod("-0.0",NULL) computes 0.0 and then negates it,
yielding -0.0.
More information about the Comp.std.c
mailing list