More Oyster Woes ...
In article id,
Dr J R Stockton wrote:
In uk.transport.london message
ernal-september.org, Mon, 25 Oct 2010 17:36:10, Sam Wilson
posted:
In article id,
Dr J R Stockton wrote:
In IEEE-754 floating-point "single" and "Double" number formats. there
is both a +zero and a -zero. They have the same value and compare
equal, ...
As do ones-complement integers (which I assume the IEEE-754 formats use
in some form)...
Never assume when you can Wiki ! They encode the unsigned part of
Numbers as mantissa and exponent, and put a sign bit in front.
Good point! Sign+magnitude[+exponent] rather than ones' complement.
... but they are distinguishable, even in languages that do not offer
access to the bit patterns as such.
... though I don't know of any higher-level languages that let you
distinguish between +0 and -0 integers even on hardware that supports
the distinction.
In JavaScript, where Numbers are Doubles, one does it by taking the
reciprocal. Plus infinity and minus infinity are easily told apart.
The internal sign of a Number X (that is not NaN) can be determined by
comparing X + 1/X with a zero. Min(Abs(X+1/X)) = 2, at least for real
numbers.
Yeah, but you can't say something like
if (result == +0)
{
...
}
else if (result == -0)
{
...
}
can you?
Sam
and have it operate differently from
|