Re: On writing negative zero - with or without sign
- From: "James Giles" <jamesgiles@xxxxxxxxxxxxxxxx>
- Date: Fri, 20 Jul 2007 10:21:08 GMT
tholen@xxxxxxxxxxxx wrote:
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.
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.
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.
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! Supressing it has no
advantages. It helps no one.
--
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
.
- Follow-Ups:
- Re: On writing negative zero - with or without sign
- From: tholen
- 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
- 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
|