Issue 6781: even exponentiation of negative numbers (original) (raw)

Issue6781

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:52 admin set github: 51030
2009-08-25 13:03:52 mark.dickinson set messages: +
2009-08-25 12:35:08 mark.dickinson set status: open -> closednosy: + mark.dickinsonmessages: + resolution: not a bug
2009-08-25 12:29:23 benlbroussard create