[issue6781] even exponentiation of negative numbers

2009-08-25 Thread benlbroussard

New submission from benlbroussard :

Negative one squared should be one, but is negative one sometimes.

pow(-1, 2) = 1
-1 ** 2 = -1
-1 ^ 2 = -1

The ** and ^ operators aren't working like expected, and the pow()
documentation is incorrect since it says "The two-argument form pow(x,
y) is equivalent to using the power operator: x**y."

--
components: None
messages: 91951
nosy: benlbroussard
severity: normal
status: open
title: even exponentiation of negative numbers
versions: Python 2.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6781] even exponentiation of negative numbers

2009-08-25 Thread Mark Dickinson

Mark Dickinson  added the comment:

This is not a bug:

-1 ** 2 is parsed as -(1 ** 2), not (-1) ** 2.  Take a look at:

http://docs.python.org/reference/expressions.html#the-power-operator

In -1 ^ 2, ^ is the bitwise exclusive-or operator, not the power operator.

pow(x, y) is indeed equivalent to x**y:

Python 2.6.2 (r262:71600, Aug 22 2009, 17:53:25) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = -1
>>> y = 2
>>> x ** y
1
>>> pow(x, y)
1
>>>

--
nosy: +marketdickinson
resolution:  -> invalid
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6781] even exponentiation of negative numbers

2009-08-25 Thread Mark Dickinson

Mark Dickinson  added the comment:

By the way, I get -1 ^ 2 == -3, not -1:

>>> -1 ^ 2
-3

If you're getting -1 instead, then that *is* a bug!  Are you?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com