This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Exponent operator(**) interpreter issue
Type: behavior Stage: resolved
Components: Interpreter Core Versions:
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: koala-lava, tim.peters
Priority: normal Keywords:

Created on 2022-02-02 22:33 by koala-lava, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg412402 - (view) Author: koala-lava (koala-lava) Date: 2022-02-02 22:33
If I put -2 ** 2 in the interpreter it outputs -4. Expected is 4.

If I create a variable and initialize it with -2 and then try the same then it's correct.
msg412404 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2022-02-02 22:43
Exponentiation has higher precedence (binds more tightly) than unary minus, so the expression groups as -(2**2).

Virtually all computer languages (those that _have_ an exponentiation operator) do the same. For example, here from wxMaxima:

(%i1) -2**2;
(%o1) -4

Closing as not-a-bug.
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90776
2022-02-02 22:43:50tim.peterssetstatus: open -> closed

versions: - Python 3.10
nosy: + tim.peters

messages: + msg412404
resolution: not a bug
stage: resolved
2022-02-02 22:33:12koala-lavacreate