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: even exponentiation of negative numbers
Type: Stage:
Components: None Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benlbroussard, mark.dickinson
Priority: normal Keywords:

Created on 2009-08-25 12:29 by benlbroussard, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg91951 - (view) Author: (benlbroussard) Date: 2009-08-25 12:29
Negative one squared should be one, but is negative one sometimes.

pow(-1, 2) = 1
-1 ** 2 = -1
-1 ^ 2 = -1

The ** and ^ operators aren't working like expected, and the pow()
documentation is incorrect since it says "The two-argument form pow(x,
y) is equivalent to using the power operator: x**y."
msg91952 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-08-25 12:35
This is not a bug:

-1 ** 2 is parsed as -(1 ** 2), not (-1) ** 2.  Take a look at:

http://docs.python.org/reference/expressions.html#the-power-operator

In -1 ^ 2, ^ is the bitwise exclusive-or operator, not the power operator.

pow(x, y) is indeed equivalent to x**y:

Python 2.6.2 (r262:71600, Aug 22 2009, 17:53:25) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = -1
>>> y = 2
>>> x ** y
1
>>> pow(x, y)
1
>>>
msg91953 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-08-25 13:03
By the way, I get -1 ^ 2 == -3, not -1:

>>> -1 ^ 2
-3

If you're getting -1 instead, then that *is* a bug!  Are you?
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51030
2009-08-25 13:03:52mark.dickinsonsetmessages: + msg91953
2009-08-25 12:35:08mark.dickinsonsetstatus: open -> closed

nosy: + mark.dickinson
messages: + msg91952

resolution: not a bug
2009-08-25 12:29:23benlbroussardcreate