Issue
This Content is from Stack Overflow. Question asked by Al-Baraa El-Hag
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).
Solution
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/952663/negative-number-raised-to-fractional-power
This Question was asked in StackOverflow by Al-Baraa El-Hag and Answered by Talha Tayyab It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.