[Python-Dev] Order of operations
jason.orendorff at gmail.com
Thu Aug 30 13:02:13 CEST 2007
On 8/29/07, Dirkjan Ochtman <dirkjan at ochtman.nl> wrote:
> Alexandre Vassalotti wrote:
> > C doesn't have an exponentiation operator. You use the pow() function, instead:
> Wouldn't it make more sense, then, to have unary +/- have higher
> precedence than the ** operator, so that -3**2 == 9?
No, that would have been really bad. Anyone who's had high school
algebra expects -x**2 to be -(x**2) and not (-x)**2.
I think the weirdness comes from parsing -a/b as (-a)/b rather than
-(a/b). It should be the latter, if compatibility with math notation
is more important than compatibility with C. Oh well. Maybe in
Python 4. :)
More information about the Python-Dev