http://www.perlmonks.org?node_id=740978


in reply to ** operator in perl

I'm going to be more verbose.

You seem to be thinking that unary minus binds more tightly than exponentiation under normal arithmetic rules. It doesn't. You're expecting it to parse as

(-2)4 - 1

this is a misconception I've had to deal with often when tutoring community college students. By the normal precedence rules of arithmetic, it will actually be evaluated

-(24) - 1.

Perl (and most other programming languages) try to replicate the normal arithmetic precedence rules as closely as possible.

Remember, under normal arithmetic rules, exponentiation (the ** operator in Perl) binds more closely than multiplication (there's an implied multiplication in -2; it's shorthand for (-1) * 2), which binds more tightly than addition.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc