New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
even exponentiation of negative numbers #51030
Comments
Negative one squared should be one, but is negative one sometimes. pow(-1, 2) = 1 The ** and ^ operators aren't working like expected, and the pow() |
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
>>> |
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? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: