[Pythonmac-SIG] precedence bug?
Christopher Smith
csmith@blakeschool.org
Fri, 08 Feb 2002 17:36:29 -0600
Say, I noticed the following on the mac and wonder if others might try
this:
The python reference (ref/summary.html) it says that 'negation' and
'bitwise not' have higher precedence than exponentiation but this is not
born out by the interpreter (MacPython 2.2):
>>> ~0**2
-1
>>> (-1)**2 #~0 is -1 so if it were done first this is the equivalent
expression
1
>>> -2**2
-4
>>> (-2)**2 #if negation were done first then this would be the equivalent
4
Could someone try this on a Windows or other interpreter and compare
results.
Is this a bug? (If so, I suppose the easiest fix is to change the
documentation.) In terms of the programming world at large, I suppose one
should clear up any ambiguity with parenthesis. How is -2**2 handled by
other languages?
MacFortran returns -4 for -2**2
Chipmunk Basic gives +4
Python 2.2 (Mac) gives -4
/c