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.

classification
Title: ** operating incorrectly for negative bases?
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: theller Nosy List: benjamin.peterson, martin.speleo, theller
Priority: normal Keywords:

Created on 2008-10-28 21:53 by martin.speleo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg75304 - (view) Author: Martin Green (martin.speleo) Date: 2008-10-28 21:53
I suspect that the following behavior is incorrect:

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
>>> -1**2
-1
>>> -2**2
-4
>>> -1**0.5
-1.0

The same happens when the base is a float.
I have not checked out the functionality of other versions of python

The function pow (which claims to be equivalent to **) works as I would
expect:

>>> pow(-1, 2)
1
>>> pow(-2, 2)
4
>>> pow(-1, 0.5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative number cannot be raised to a fractional power

I was not sure which components to select, please change them if I got
it wrong.
msg75305 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-28 21:57
This is because the negative sign is evaluated after the power. (-1)**2
works correctly.
History
Date User Action Args
2022-04-11 14:56:40adminsetgithub: 48474
2008-10-28 21:57:07benjamin.petersonsetstatus: open -> closed
resolution: not a bug
messages: + msg75305
components: + Interpreter Core, - Tests, ctypes
nosy: + benjamin.peterson
2008-10-28 21:53:13martin.speleocreate