[SOLVED] Python giving an incorrect answer for exponential multiplication


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).


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


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


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

(-8)** (1.1)

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:





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.

people found this article helpful. What about you?