Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: ** operator in perl

by swampyankee (Parson)
on Feb 03, 2009 at 12:59 UTC ( #740978=note: print w/ replies, xml ) Need Help??

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

Comment on Re: ** operator in perl

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://740978]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2015-11-30 18:40 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (778 votes), past polls