Re: On writing negative zero - with or without sign
- From: tholen@xxxxxxxxxxxx
- Date: 20 Jul 2007 18:04:14 GMT
James Giles writes:
....
Why should the sign bit be set if the magnitude is zero?
It's often decisive information. It's up to th euser to know if it
matters - it's *NOT* up to the implementation to arbitrarily decide
for the user. If it worries you, be content that I don't know any
implementations that set the sign bit for zeros that result from
sums or differences. The IEEE standard allows either sign
in such a case. For underflow the sign almost always carries
useful information. The implementation should never supress
it.
But
Z = (Y - X)/A
and
Z = Y/A - X/A
are algebraically equivalent. Suppose (Y - X)/A underflows, but
neither Y/A or X/A underflows, and the sign bit wouldn't be set
for the difference.
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.
Why not? Suppose I difference two real numbers that have the exact
same internal representation.
Then the *actual* difference is approximately the same magnitude
as the error in the least accurately calculated of the two operands.
For nearly all calculations that's a lots bigger than zero.
You're assuming that the numbers are calculated. I had previously
given an example in which the numbers being differenced were
assigned, not calculated (or manipulated, to use my previous term).
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?
You're assuming that I would want one or the other printed. In such
a case, I would be content to have no sign. It's up to the user to
properly interpret the results of a calculation.
And it's not up to the implementation to make that decision for
him(her). If it's up to the user, leave the sign there and let
the user decide. Never lie to the user.
Suppose in your temperature example, the first value was really
15.01 and the second value was 14.99, but the implementation
couldn't know that and used a plus sign, thus lying to the user.
Indeed, if forced to display a sign in that example, there's a
fifty percent chance of lying to the user.
If the sign bit carries decisive information, then it's important
for the correct sign to be displayed. In your temperature example
above, you noted that the correct answer could be either positive
or negative, so there is no way for the processor to know which is
the correct sign, thus I would argue it's important to suppress the
sign.
But, an absent sign *means* positive zero!
I disagree.
Supressing it has no advantages. It helps no one.
Again, I disagree. See above for an example.
.
- Follow-Ups:
- Re: On writing negative zero - with or without sign
- From: James Giles
- Re: On writing negative zero - with or without sign
- References:
- On writing negative zero - with or without sign
- From: Jerry DeLisle
- Re: On writing negative zero - with or without sign
- From: robert . corbett
- Re: On writing negative zero - with or without sign
- From: Richard Maine
- Re: On writing negative zero - with or without sign
- From: robert . corbett
- Re: On writing negative zero - with or without sign
- From: Richard Maine
- Re: On writing negative zero - with or without sign
- From: Terence
- Re: On writing negative zero - with or without sign
- From: Ron Shepard
- Re: On writing negative zero - with or without sign
- From: James Giles
- Re: On writing negative zero - with or without sign
- From: tholen
- Re: On writing negative zero - with or without sign
- From: James Giles
- Re: On writing negative zero - with or without sign
- From: tholen
- Re: On writing negative zero - with or without sign
- From: James Giles
- Re: On writing negative zero - with or without sign
- From: tholen
- Re: On writing negative zero - with or without sign
- From: James Giles
- Re: On writing negative zero - with or without sign
- From: tholen
- Re: On writing negative zero - with or without sign
- From: James Giles
- On writing negative zero - with or without sign
- Prev by Date: Re: On writing negative zero - with or without sign
- Next by Date: Re: On writing negative zero - with or without sign
- Previous by thread: Re: On writing negative zero - with or without sign
- Next by thread: Re: On writing negative zero - with or without sign
- Index(es):
Relevant Pages
|