[New-bugs-announce] [issue31519] Negative number raised to even power is negative (-1 ** even = negative)

Bob Hunkins report at bugs.python.org
Tue Sep 19 10:51:10 EDT 2017


New submission from Bob Hunkins:

Hello,
I'm only a novice with Python, so please take it easy on me if I have transgressed.

I am using Python 3.6.2 on a win10 64 bit machine, and entered this:

>>> a= [-1 ** x for x in range(1,10)]
>>> print(a)
[-1, -1, -1, -1, -1, -1, -1, -1, -1]
which is not correct.

however, entering this:

>>> b = [pow(-1, x) for x in range(1,10)]
>>> print(b)
[-1, 1, -1, 1, -1, 1, -1, 1, -1]

which is correct.
Any negative number entered and raised to an even power seems to not return a positive value, but the pow(x,y) function works.

I never have reported a bug on any programming language ever, and surprisingly I can't find a report of this (I did search, so if it's out there, I must not understand how to use the search. Forgive me. As I said, I'm very new to Python and I'm not a professional programmer.)

----------
messages: 302529
nosy: rdhunkins
priority: normal
severity: normal
status: open
title: Negative number raised to even power is negative (-1 ** even = negative)
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31519>
_______________________________________


More information about the New-bugs-announce mailing list