Skip to content
Prev 33507 / 63424 Next

identical(0, -0)

Martin Maechler wrote:
I don't think that would be a good idea.  Other expressions besides "-0" 
calculate the zero with the negative sign bit, e.g. the following sequence:

pos <- 1
neg <- -1
zero <- 0
y <- zero*pos
z <- zero*neg
identical(y, z)

I think most R users would expect the last expression there to be TRUE 
based on the previous two lines, given that pos and neg both have finite 
values.  In a simple case like this y == z would be a better test to 
use, but if those were components of a larger structure, identical() is 
all we've got, and people would waste a lot of time tracking down why 
structures differing only in the sign of zero were not identical, even 
though every element tested equal.

Duncan Murdoch