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

** operator yielding wrong result for negative numbers #54270

Closed
eswars mannequin opened this issue Oct 10, 2010 · 3 comments
Closed

** operator yielding wrong result for negative numbers #54270

eswars mannequin opened this issue Oct 10, 2010 · 3 comments
Labels
build The build process and cross-build

Comments

@eswars
Copy link
Mannequin

eswars mannequin commented Oct 10, 2010

BPO 10061
Nosy @rhettinger, @orsenthil

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 2010-10-10.06:49:33.761>
created_at = <Date 2010-10-10.06:41:19.382>
labels = ['build', 'invalid']
title = '** operator yielding wrong result for negative numbers'
updated_at = <Date 2010-10-10.19:23:42.003>
user = 'https://bugs.python.org/eswars'

bugs.python.org fields:

activity = <Date 2010-10-10.19:23:42.003>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = <Date 2010-10-10.06:49:33.761>
closer = 'orsenthil'
components = ['None']
creation = <Date 2010-10-10.06:41:19.382>
creator = 'eswar.s'
dependencies = []
files = []
hgrepos = []
issue_num = 10061
keywords = []
message_count = 3.0
messages = ['118311', '118313', '118342']
nosy_count = 3.0
nosy_names = ['rhettinger', 'orsenthil', 'eswar.s']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue10061'
versions = ['Python 2.6']

@eswars
Copy link
Mannequin Author

eswars mannequin commented Oct 10, 2010

-5 ** 4 results as -625. It should be 625

@eswars eswars mannequin added the build The build process and cross-build label Oct 10, 2010
@orsenthil
Copy link
Member

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.

@rhettinger
Copy link
Contributor

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

@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
build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

2 participants