This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ** operator yielding wrong result for negative numbers
Type: compile error Stage: resolved
Components: None Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eswar.s, orsenthil, rhettinger
Priority: normal Keywords:

Created on 2010-10-10 06:41 by eswar.s, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg118311 - (view) Author: eswar s (eswar.s) Date: 2010-10-10 06:41
-5 ** 4 results as -625. It should be 625
msg118313 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-10-10 06:49
It's to do with operator precedence.
** takes higher precedence than negative.

http://docs.python.org/reference/expressions.html#Summary


(-5) ** 4 will give what you are looking for.
msg118342 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-10-10 19:23
Python's order of operations runs the exponentation before the unary minus.  This convention makes the unary minus behave more like the subtraction operator so that:  -x**n == 0 - x**n.

This convention is somewhat common but there are exceptions such as MS Excel where the unary minus binds first.  See http://en.wikipedia.org/wiki/Order_of_operations#Examples
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54270
2010-10-10 19:23:42rhettingersetnosy: + rhettinger
messages: + msg118342
2010-10-10 06:49:33orsenthilsetstatus: open -> closed

nosy: + orsenthil
messages: + msg118313

resolution: not a bug
stage: resolved
2010-10-10 06:41:19eswar.screate