Running the following snippet:
a = -1.0
show(a^(1/3))
Gives me the (unexpected) result:
0.500000000000000+0.866025403784439i
But, running the following:
show(-1.0^(1/3))
Gives me the expected result −1.00000000000000
.
Is this expected behavior? Am I misunderstanding what computation I'm asking for?
The first version calculates the principal cube root of -1, which is a complex number.
In the second version, the expression
-1.0^(1/3)
is equivalent to-(1.0^(1/3))
, because the unary negation operator has a lower precedence than exponentiation; so it calculates the cube root of 1, and then negates it.