Questions about NCEG

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Jun 1 01:42:14 AEST 1990


In article <1990May30.205436.11534 at twinsun.com> eggert at twinsun.com (Paul Eggert) writes:
>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.

I sometimes wonder why I waste my time responding.
IEEE 754 does not apply to C source code!
The C standard says simply that the value of "-x" is the "negative of x";
in the case of integer operations on a ones' complement architecture,
which does have a representation for "negative zero" integers, one can
deduce from a combination of specifications in the standard that "-0"
must have the same representation as "0", not all-one-bits.  While I
doubt that there are tight enough constraints to deduce that the
analogous situation is mandated for floating-point, I'm sure that it is
allowed.  Since no special requirements are made for IEEE FP environments
in the C standard, it would then be allowed by the C standard for such
environments also.  Note that "-0.0" consists of the TWO tokens "-" and
"0.0"; it is NOT a single floating constant, and thus is covered by the
ordinary rules for negation in expressions, not treated as some special
code that must be represented by the IEEE bit pattern for "minus zero".

>IEEE 754 doesn't specify the output format, but it does require that
>+0 and -0 be output differently, ...

However, it does not require that writing "-0.0" in C source code be
a way of producing a "minus zero".  IF you are somehow able to cobble
up a minus zero result, perhaps through bitwise operations or by
dividing 1 by -infinity (produced as an overflow or something), THEN
printing that result would have to print something distinguishable from
(plus) zero in order to satisfy IEEE 754.

>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.

I would have sent a bug report to the former, since although the former
may technically be allowed it is not what I would expect for negation of
an expression that happened to have the value 0.  Mathematically it is
nonsense to say -0 is not identical to 0.  (Yes, I've heard all the
arguments for the IEEE 754 extended number system, but I don't buy it.
There are much more useful extensions that would also have been
mathematically valid, but the real number represented by -0 is
identically the real number represented by 0.)

>But I explicitly assumed conformance to both ANSI C and IEEE 754.

So did I.



More information about the Comp.std.c mailing list