[Rd] Friday question: negative zero
Duncan Murdoch
murdoch at stats.uwo.ca
Sat Sep 1 02:39:02 CEST 2007
The IEEE floating point standard allows for negative zero, but it's hard
to know that you have one in R. One reliable test is to take the
reciprocal. For example,
> y <- 0
> 1/y
[1] Inf
> y <- -y
> 1/y
[1] -Inf
The other day I came across one in complex numbers, and it took me a
while to figure out that negative zero was what was happening:
> x <- complex(real = -1)
> x
[1] -1+0i
> 1/x
[1] -1+0i
> x^(1/3)
[1] 0.5+0.8660254i
> (1/x)^(1/3)
[1] 0.5-0.8660254i
(The imaginary part of 1/x is negative zero.)
As a Friday question: are there other ways to create and detect
negative zero in R?
And another somewhat more serious question: is the behaviour of
negative zero consistent across platforms? (The calculations above were
done in Windows in R-devel.)
Duncan Murdoch
More information about the R-devel
mailing list