Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-10-22 02:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls