[R] cube root of a negative number
Dr. David Kirkby
david.kirkby at onetel.net
Wed Oct 27 18:42:57 CEST 2010
On 10/27/10 01:15 AM, Berwin A Turlach wrote:
> 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
All thee of these are solutions:
0.793701 + 1.37473 I
0.793701 - 1.37473 I
-1.5874
I must admit I consider it a bug that NaN is not returned.
Perhaps it's reasonable to not expect this from the statistics package R, but to
expect other software such as Maxima, Sage, Mathematica etc to do this.
Dave
More information about the R-help
mailing list