[Rd] identical(0, -0)
savicky at cs.cas.cz
Mon Aug 10 19:31:49 CEST 2009
On Mon, Aug 10, 2009 at 05:47:57AM -0400, Duncan Murdoch wrote:
> I wouldn't mind a "strict" option. It would compare bit patterns, so
> would distinguish +0 from -0, and different NaN values.
I think that a logical option "strict" in the above meaning could be
useful for debugging. The default may be FALSE.
On Mon, Aug 10, 2009 at 10:20:39AM -0400, Duncan Murdoch wrote:
> +0 and -0 are exactly equal, which is what identical is documented to be
> testing. They are not indistinguishable, and not identical in the
> English meaning of the word, but they are identical in the sense of what
> the identical() function is documented to test.
> The cases where you want to distinguish between them are rare. They
> should not be distinguished in the default identical() test, any more
> than different values of NaN should be distinguished (and identical() is
> explicitly documented *not* to distinguish those).
The question, whether 0 and -0 are equal or not, is not clear, since
they have different reciprocals. However, i agree that distinguishing
the signs of zero is rarely useful. From this point of view, the
default FALSE seems to be acceptable.
For completeness, let me also add an argument that it would not be too
harmful, if the default is TRUE. I think that it is quite rare to have
two larger numerical structures, which match up to the last bits in all
numbers, but have a different sign of some zero. Matching all bits
almost requires that the two structures are obtained using the same
expressions for all components. Then, also the signs of zeros will
match. However, i may be wrong.
More information about the R-devel