[R] cube root of a negative number

Berwin A Turlach berwin at maths.uwa.edu.au
Wed Oct 27 02:15:57 CEST 2010


G'day Gregory,

On Tue, 26 Oct 2010 19:05:03 -0400
Gregory Ryslik <rsaber at comcast.net> wrote:

> Hi,
> 
> This might be me missing something painfully obvious but why does the
> cube root of the following produce an NaN?
> 
> > (-4)^(1/3)
> [1] NaN

1/3 is not exactly representable as a binary number.  My guess is that
the number that is closest to 1/3 and representable cannot be used as
the exponent for negative numbers, hence the NaN.

Essentially, don't expect finite precision arithmetic to behave like
infinite precision arithmetic, it just doesn't.  The resources
mentioned in FAQ 7.31 can probably shed more light on this issue.

Cheers,

	Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)            +61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin



More information about the R-help mailing list