[R] cube root of a negative number
Kjetil Halvorsen
kjetilbrinchmannhalvorsen at gmail.com
Wed Oct 27 01:16:52 CEST 2010
Look at this:
> x <- as.complex(-4)
> x
[1] -4+0i
> x^(1/3)
[1] 0.793701+1.37473i
> (-4)^(1/3)
[1] NaN
It seems that R gives you the principal root, which is complex, and
not the real root.
Kjetil
On Tue, Oct 26, 2010 at 8:05 PM, 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
>>
>
> As we can see:
>
>> (-1.587401)^3
> [1] -4
>
> Thanks!
>
> Greg
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list