Skip to content
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

Closed
benlbroussard mannequin opened this issue Aug 25, 2009 · 3 comments
Closed

even exponentiation of negative numbers #51030

benlbroussard mannequin opened this issue Aug 25, 2009 · 3 comments

Comments

@benlbroussard
Copy link
Mannequin

benlbroussard mannequin commented Aug 25, 2009

BPO 6781
Nosy @mdickinson

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:

assignee = None
closed_at = <Date 2009-08-25.12:35:08.482>
created_at = <Date 2009-08-25.12:29:23.867>
labels = ['invalid']
title = 'even exponentiation of negative numbers'
updated_at = <Date 2009-08-25.13:03:52.914>
user = 'https://bugs.python.org/benlbroussard'

bugs.python.org fields:

activity = <Date 2009-08-25.13:03:52.914>
actor = 'mark.dickinson'
assignee = 'none'
closed = True
closed_date = <Date 2009-08-25.12:35:08.482>
closer = 'mark.dickinson'
components = ['None']
creation = <Date 2009-08-25.12:29:23.867>
creator = 'benlbroussard'
dependencies = []
files = []
hgrepos = []
issue_num = 6781
keywords = []
message_count = 3.0
messages = ['91951', '91952', '91953']
nosy_count = 2.0
nosy_names = ['mark.dickinson', 'benlbroussard']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue6781'
versions = ['Python 2.6']

@benlbroussard
Copy link
Mannequin Author

benlbroussard mannequin commented Aug 25, 2009

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

@mdickinson
Copy link
Member

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

@mdickinson
Copy link
Member

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?

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant