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

Inconsistent squaring behavior #86594

Closed
JohnSmith11132 mannequin opened this issue Nov 21, 2020 · 3 comments
Closed

Inconsistent squaring behavior #86594

JohnSmith11132 mannequin opened this issue Nov 21, 2020 · 3 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JohnSmith11132
Copy link
Mannequin

JohnSmith11132 mannequin commented Nov 21, 2020

BPO 42428
Nosy @mdickinson, @tiran

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 2020-11-21.20:12:48.549>
created_at = <Date 2020-11-21.19:56:52.287>
labels = ['interpreter-core', 'type-bug', 'invalid', '3.10']
title = 'Inconsistent squaring behavior'
updated_at = <Date 2020-11-21.20:12:48.547>
user = 'https://bugs.python.org/JohnSmith11132'

bugs.python.org fields:

activity = <Date 2020-11-21.20:12:48.547>
actor = 'christian.heimes'
assignee = 'none'
closed = True
closed_date = <Date 2020-11-21.20:12:48.549>
closer = 'christian.heimes'
components = ['Interpreter Core']
creation = <Date 2020-11-21.19:56:52.287>
creator = 'JohnSmith11132'
dependencies = []
files = []
hgrepos = []
issue_num = 42428
keywords = []
message_count = 3.0
messages = ['381573', '381574', '381575']
nosy_count = 3.0
nosy_names = ['mark.dickinson', 'christian.heimes', 'JohnSmith11132']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42428'
versions = ['Python 3.10']

@JohnSmith11132
Copy link
Mannequin Author

JohnSmith11132 mannequin commented Nov 21, 2020

Basically when squaring as a negative number, if it's a variable it acts like -3*-3 otherwise it acts like 3*-3.
For example:
>>> x = -3
>>> x ** 2
9
>>> -3 ** 2
-9

pow(-3, 2) seems to act like -3 * -3?
** 3 seems fine and both seems to act like -3*-3*-3.
>>> x = -3
>>> x ** 3
27
>>> -3 ** 3
-27

Will it be safe to use the ** 2 in Python? If I use a variable will it return the same value?

I only found this for the bug:
https://devforum.roblox.com/t/inconsistent-squaring-behavior/820028/

It looks like the exact same issue I'm having, but I still don't get it and it's not for Python.

@JohnSmith11132 JohnSmith11132 mannequin added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 21, 2020
@mdickinson
Copy link
Member

-3 ** 2 is parsed by Python as -(3 **2), not as (-3) ** 2.

@tiran
Copy link
Member

tiran commented Nov 21, 2020

Operator precedence and unary operator binding is explained in the language reference documentation, https://docs.python.org/3/reference/expressions.html#the-power-operator

@tiran tiran closed this as completed Nov 21, 2020
@tiran tiran added the invalid label Nov 21, 2020
@tiran tiran closed this as completed Nov 21, 2020
@tiran tiran added the invalid label Nov 21, 2020
@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
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants