Re: On writing negative zero - with or without sign



tholen@xxxxxxxxxxxx wrote:
James Giles writes:
....
Maybe I've misunderstood the earlier discussion, but I thought that
minus zero applied only to cases where the actual numerical value
was in fact negative, but the chosen display format was insufficient
to show any significant digits, therefore the number would be
displayed as all zeros, with the question being whether to display
the minus sign or not. For example, should the value -1.2E-5, when
displayed with the format edit descriptor F4.1, be -0.0 or 0.0?

That's easy, the Fortran standard says that a negative value should
have a minus sign output. The earlier discussion was more concerned
over whether an internal value was negative or not, when its magnitude
was zero but it had a set sign bit. The rule should be more clearly
stated in the standard: if the sign bit is set the output should begin
(after any padding blanks) with a minus sign. That's independent of
the magnitude (infact, I think that should be the rule even if the
number turns out to be NaN).

As far as I am concerned, there is only one exact zero, not two, and
not three, and there should be no sign associated with an exact zero.

And, if you're simulating genuine real numbers with your floating
point REAL data type, you'll *never* see something you're sure
is an exact zero.

Suppose you have a record of temperatures recorded at some
observing site and you go through generating a first-difference
(an approximation to a derivative). Well, the thermometer reports
to a tenth of a degree. Suppose two consecutive times show a
value of 15 degrees. That means each value is actually somewhere
between 14.95 and 15.05 degrees and whatever true temp occurred
was rounded to just 15.0 degrees. The float difference of those two
measurements will have a magnitude of zero. But, it's pretty clear
that the temps at the two times were almost certainly more different
than the ~10^(-39) precision of floating point! That zero difference
is hardly *exact* (in fact, the correct answer is in the interval from
-0.1 through 0.1, somewhere). The sign printed with a zero arising
from such a calculation is meaningless, why do you care which is
printed?

In using float to simulate continuous real arithmetic, zeros
can arise a number of ways. They reduce to two categories:
1) underflow, where the sign bit still carries useful (maybe
decisive) information; 2) result of discrete approximation
(like the above difference) where the sign bit means nothing
and a good programmer knows it. There are no third cases,
that is, where it's actually *important* to supress the sign.

Now if you are using floating point to do some kind of discrete
arithmetic rather than as a surrogate for continuous reals, the
sign bit of zero may or may not be important (usually not).
However, I can still see no reason for the implementation
to supress it.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare


.



Relevant Pages

  • Re: On writing negative zero - with or without sign
    ... but the chosen display format was insufficient ... the minus sign or not. ... was zero but it had a set sign bit. ... and there should be no sign associated with an exact zero. ...
    (comp.lang.fortran)
  • REPRESENT revisited
    ... Forth-94 has few floating point display functions [none in the ... If u is greater than zero the character string shall consist ... If u is zero the string shall consist of one digit representing ...
    (comp.lang.forth)
  • Re: On writing negative zero - with or without sign
    ... but the chosen display format was insufficient ... the minus sign or not. ... was zero but it had a set sign bit. ... Extended reals are a valid mathematical system that you may not be familiar ...
    (comp.lang.fortran)
  • Re: Skipping parameters in a printf()
    ... I have a set of int variables: some variables can be negative and ... I want to display the ... zero and shows no minus sign. ...
    (comp.lang.c)
  • Re: Word XP - Strikethrough Font & More oops
    ... This will display a box with EQ in it. ... Between the parentheses, type 0,/ (zero, comma, slash). ... please post all follow-ups to the newsgroup so ... "Tony C" wrote in message ...
    (microsoft.public.word.printingfonts)