Precidence of unary plus/minus relative to exponentiation

Mikael Olofsson mikael at isy.liu.se
Wed Apr 2 02:45:15 EST 2003


On Tue, 1 Apr 2003 12:40:21 -0500
"Warnes, Gregory R" <gregory_r_warnes at groton.pfizer.com> wrote:
> The current operator precedence places unary plus and minus higher
> than exponentiation.  This leads the counterintuitive result:
> 
> 	>>> -2.0**2.0
> 	-4.0
> 	
> Python's operator predicence is causing this to be interpreted as:
> 
> 	>>> -(2.0**2.0)
> 
> rather than the normal mathematical precidence, which would give
> 
> 	>>> (-2.0)**2.0
> 
> Is there a good reason for the Python order of precedence?

I would say that the behaviour is what I expect. I would never expect
-2.0**2.0 to mean (-2.0)**2.0. Nobody I've met in a mathematical context
(engineers and mathematicians) have ever assumed your interpretation.
Where have you seen that interpretation?

/Mikael

-----------------------------------------------------------------------
E-Mail:  mikael at isy.liu.se
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael               
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339

         /"\
         \ /     ASCII Ribbon Campaign
          X      Against HTML Mail
         / \

This message was sent by Sylpheed.
-----------------------------------------------------------------------
Linköpings kammarkör: www.kammarkoren.com






More information about the Python-list mailing list