Questions about NCEG

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Jun 1 03:52:13 AEST 1990


In article <1990May31.023244.12359 at twinsun.com> eggert at twinsun.com (Paul Eggert) 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.

Sorry, but your conclusion does not follow from the premises.

"Negation" of a number can (and should) be taken as an ordinary
English description of the mathematical process.  Mathematically,
the set of real numbers does not contain distinct members "plus
zero" and "minus zero", just as it does not include plus or minus
infinity.  (If you want to extend the real number system like that,
I suppose you are free to do so, but certainly that lies beyond
the meaning of the specification in the C standard.)  While the
standard does not specify in detail what objects having floating-
point types are good for, it does call them "arithmetic types",
and applies ordinary arithmetic and functional analysis terms to
operations involving them, implying that they somehow represent
the kind of entity that we are accustomed to using for ordinary
arithmetic etc., i.e. real numbers.  I know our schools are messed
up but I doubt if even they are teaching that negating zero does
not produce zero.  Indeed, most algebra classes seem to at some
point prove uniqueness of the additive (group) identity, and since
it is easy to show that the negative (group inverse) of 0 acts as
an additive identity, it must be identically 0.

I believe that you might be able to correctly argue that the C
standard wording about negation ALLOWS your interpretation but not
that it REQUIRES it, even on systems supporting IEEE 754 floating-
point.  As I stated in another posting, IEEE 754 does not
constrain the services that the C implementation provides to a
programmer, although it does control some aspects of what the C
implementation has to deal with.  (It also apparently conditions
programmers to expect to be able to access all the IEEE 754 warts.)

Anyone who really wants to play with distinct "minus zero" should
first learn a lesson from CDC's experience with such arithmetic
units:  Valid arithmetic operations on non-special values should
never result in a special value; the only way you should obtain a
special value is to have a special value as an operand or possibly
perform an invalid operation on (non-special) values.  Thus,
-1.0/(1.0e+300*1.0e+300) may very well produce an IEEE 754 "minus
zero" result, but as such overflow is explicitly specified in the
C standard as resulting in undefined behavior, it is not correct
to state that the C standard requires any particular result in
this case.



More information about the Comp.std.c mailing list