Python giving an incorrect answer for exponential multiplication

Question:

The equation in question is: (-8) ** (-1/3). Putting that into Python you get the following answer:

In [1]: (-8) ** (-1/3)                                                      
Out[1]: (0.25000000000000006-0.4330127018922193j) 

Which is incorrect, the answer should be -0.5. But if I take out the negative, it works fine.

In [2]: (8) ** (-1/3) * -1
Out[2]: -0.5

What’s going on? I tested this on two other calculators (Google’s search calculator and a scientific calculator on Android, CalcES) and I got the same mistake that Python is making when the input is (-8) ** (-1/3).

Asked By: Al-Baraa El-Hag

||

Answers:

Floating powers of a negative number will give you a complex number.

(-8)**(-1/3)
(0.25000000000000006-0.4330127018922193j)

Even if you remove the negative sign from the power you will get a complex number:

(-8)**(1/3)
(1.0000000000000002+1.7320508075688772j)

If I just do 1.1, then too it will be a complex number

(-8)** (1.1)
(-9.367103334496456-3.043556370026835j)

It does not matter if you take 8 or any other number, if the number is a negative number power raised to some floating number other than an integer, it will always yield a complex number.

Please seethe below links:

https://math.stackexchange.com/questions/317528/how-do-you-compute-negative-numbers-to-fractional-powers

https://math.stackexchange.com/questions/952663/negative-number-raised-to-fractional-power

https://math.stackexchange.com/questions/2174393/can-a-negative-number-be-raised-to-a-fractional-power-e-g-2-5

https://math.stackexchange.com/questions/4332039/why-cant-a-negative-base-be-raised-to-a-non-integer-exponent

Answered By: God Is One
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.