In this particular case it is part of the C99 stanadrd (7.12.7.4) for
the 'pow' function R uses.
On Wed, 27 Oct 2010, Berwin A Turlach wrote:
G'day Gregory,
On Tue, 26 Oct 2010 19:05:03 -0400
Gregory Ryslik wrote:
Hi,
This might be me missing something painfully obvious but why does the
cu
G'day Bill,
On Wed, 27 Oct 2010 10:34:27 +1100
wrote:
[...]
> It is no surprise that this does not work when working in the real
> domain, except "by fluke" with something like
>
> > -4^(1/3)
> [1] -1.587401
> >
>
> where the precedence of the operators is not what you might expect.
> Now th
Because it is implemented as
antilog((1/3)*log(-4))
most likely using base 2 for the log/antilog functions.
"Gregory Ryslik" 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 ca
what you might expect. Now that
could be considered a bug, since apparently
-4^(1/2)
[1] -2
which comes as rather a surprise!
Bill.
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Kjetil Halvorsen
Sent: Wednesday, 27 October
G'day Gregory,
On Tue, 26 Oct 2010 19:05:03 -0400
Gregory Ryslik 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 tha
AM
To: Gregory Ryslik
Cc: r-help Help
Subject: Re: [R] cube root of a negative number
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.
Kjet
hmm interesting. When I did -4^(1/3) got the correct answer, but then again
that's because it processes the negative later. i.e. -4^(1/2) gave me -2
instead of the 2i I expected. Also when I did (-4+0i)^(1/3) it gave me
0.793701+1.37473i. Possible bug?
Sachin
--- Please consider the environment b
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 wrote:
> Hi,
>
> This might be me missing somethi
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@r-project.org mailing list
https://stat.ethz.c
9 matches
Mail list logo