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
@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 version deleted
there 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?
Why does the expression (-8)^(1/3) return NaN
On Sun, Jul 19, 2009 at 7:33 PM, jim holtmanjholt...@gmail.com 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
On Sun, Jul 19, 2009 at 12:28 AM, jim holtmanjholt...@gmail.com 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?
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
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
snip
I was vaguely aware of this ... but it now triggers in my mind the
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 Turnerr.tur...@auckland.ac.nz 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
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]]
__
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:
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
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), but
12 matches
Mail list logo