Re: [Rd] Friday question: negative zero

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri, 31 Aug 2007 21:25:10 -0400

On 8/31/07, Duncan Murdoch <murdoch_at_stats.uwo.ca> wrote:
> 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?

I think the only other way is the IEEE CopySign function but I don't think R has implemented it -- R probably should. Google CopySign .



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 01 Sep 2007 - 01:31:59 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 Sat 01 Sep 2007 - 05:40:12 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.