Article View: comp.std.c
Article #1353Re: Questions about NCEG
From: Doug Gwyn
Date: Thu, 31 May 1990 15:42
Date: Thu, 31 May 1990 15:42
47 lines
3175 bytes
3175 bytes
In article <1990May30.205436.11534@twinsun.com> eggert@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.
Technical Details
Message-ID:
<13028@smoke.BRL.MIL>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!uwm.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwynReferences:
<1990May29.193451.6533@twinsun.com> <13016@smoke.BRL.MIL> <1990May30.205436.11534@twinsun.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!uwm.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c,comp.std.misc Subject: Re: Questions about NCEG Message-ID: <13028@smoke.BRL.MIL> Date: 31 May 90 15:42:14 GMT References: <1990May29.193451.6533@twinsun.com> <13016@smoke.BRL.MIL> <1990May30.205436.11534@twinsun.com> Followup-To: comp.std.c Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 47