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

2009-07-20 Thread Thomas Lumley
On Sun, 19 Jul 2009, jim holtman wrote: If the power that a number is being raised to is integer, then is does evaluate honoring the unary minus. (-2) ^ 5 #integer power [1] -32 (-2) ^ 5.1 [1] NaN Yes. 3 is representable exactly as a whole number, so (-2)^3 exists, but (1/3) is repres

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

2009-07-19 Thread jim holtman
It also works for raising a number to a negative integer: > (-3)^(-3) [1] -0.03703704 > On Sun, Jul 19, 2009 at 6:23 PM, Rolf Turner wrote: > > On 20/07/2009, at 9:13 AM, jim holtman wrote: > >> If the power that a number is being raised to is integer, then is does >> evaluate honoring the unary

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

2009-07-19 Thread Rolf Turner
On 20/07/2009, at 9:13 AM, jim holtman wrote: If the power that a number is being raised to is integer, then is does evaluate honoring the unary minus. (-2) ^ 5 #integer power [1] -32 (-2) ^ 5.1 [1] NaN I was vaguely aware of this ... but it now triggers in my mind the questio

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

2009-07-19 Thread jim holtman
If the power that a number is being raised to is integer, then is does evaluate honoring the unary minus. > (-2) ^ 5 #integer power [1] -32 > (-2) ^ 5.1 [1] NaN > -8^(1/3) is parsed as -(8^(1/3)) according to operator precedence. On Sun, Jul 19, 2009 at 4:49 PM, Liviu Andronic wrote: > On Sun

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

2009-07-19 Thread Liviu Andronic
On Sun, Jul 19, 2009 at 12:28 AM, jim holtman wrote: > First of all, read FAQ 7.31 to understand that 1/3 is not > representable in floating point.  Also a^b is actually exp(log(a) * b) > and log(-8) is not valid (NaN). > If this is so, why would the following evaluate as expected? > (-8)^(3) [1]

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

2009-07-19 Thread Liviu Andronic
On Sun, Jul 19, 2009 at 7:33 PM, jim holtman wrote: > -8^1/3 is parsed as -(8^1)/3 = -2.6 > However the following is evaluated as one would expect: > 8^(1/3) [1] 2 > -8^(1/3) [1] -2 Perhaps it is parsed in this way: > -(8^(1/3)) [1] -2 Liviu __ R-

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

2009-07-19 Thread jim holtman
re are some rules about parenthesis... > > regards > > Víctor > > > > > De: r-help-boun...@r-project.org en nombre de Dave DeBarr > Enviado el: sáb 18/07/2009 05:04 > Para: r-help@r-project.org > Asunto: [R] (-8)^(1/3) == NaN? > >

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

2009-07-19 Thread Victor Manuel Garcia Guerrero
-help@r-project.org Asunto: [R] (-8)^(1/3) == NaN? 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 [[alternative HTML

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

2009-07-18 Thread Ted Harding
On 18-Jul-09 22:04:57, 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 Because R does not try to evaluate (-8)^(1/3)

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

2009-07-18 Thread David Winsemius
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

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

2009-07-18 Thread jim holtman
First of all, read FAQ 7.31 to understand that 1/3 is not representable in floating point. Also a^b is actually exp(log(a) * b) and log(-8) is not valid (NaN). You expression is not really taking the cube root; it is taking values to the 1/3 power. If you want to cube root function, then try: >

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

2009-07-18 Thread Dave DeBarr
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 [[alternative HTML version deleted]] __ R-help@r-