[R] (-8)^(1/3) == NaN?

David Winsemius dwinsemius at comcast.net
Sun Jul 19 00:43:30 CEST 2009


The correct mathematical "answer" is really one (or perhaps all  
three?) of three complex numbers that are the solutions to x^3+8=0.

Here is one of the others:

 > as.complex(-8)^(1/3)
[1] 1+1.732051i

I suspect there is a reason why R is willing to produce this  
particular solution and not the other two after being told to use the  
complex range, but I don't know the reason.

You can get all three with:
 > polyroot(c(8,0,0,1))
[1]  1+1.732051i -2+0.000000i  1-1.732051i

-- 
David.

On Jul 18, 2009, at 6:04 PM, Dave DeBarr wrote:

> Why does the expression "(-8)^(1/3)" return NaN, instead of -2?
>
> This is not answered by http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-are-powers-of-negative-numbers-wrong_003f
>
> Thanks,
> Dave

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list