Re: [Rd] Friday question: negative zero

From: Tony Plate <tplate_at_acm.org>
Date: Sat, 01 Sep 2007 17:22:26 -0600

One place where I've been caught by -ve zeros is with unit tests. If identical(-0, 0) returns FALSE, and the object storage doesn't preserve -ve zeros, that can lead to test failures that are tricky to debug.

However, it doesn't look like that is too much a problem in the current incarnation of R, at least running under Linux:

The fact that identical(-0,0) is TRUE means that we have the situation where it is possible that identical(x, y) != identical(f(x), f(y)). I don't know if this is a real problem anywhere.

> x <- 0
> y <- -0
> 1/x
[1] Inf
> 1/y

[1] -Inf
> identical(x, y)
[1] TRUE
> ### there exists f,x,y such that identical(x, y) != identical(f(x), f(y))
> identical(1/x, 1/y)

[1] FALSE
> ### save/load preserves -ve zero
> save("y", file="y.rda")
> remove("y")
> load("y.rda")
> 1/y

[1] -Inf
> identical(x, y)
[1] TRUE
> ### dump does not preserve -ve zero
> dump("y", file="y.R")
> remove("y")
> source("y.R")
> y

[1] 0
> 1/y

[1] Inf
> version

               _
platform       x86_64-unknown-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
status
major          2
minor          5.1
year           2007
month          06
day            27
svn rev        42083
language       R

version.string R version 2.5.1 (2007-06-27)
>

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 01 Sep 2007 - 23:24:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 02 Sep 2007 - 08:40:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.