Re: Power function as operator

From: Date: Sat, 23 Nov 2013 06:19:16 +0000
Subject: Re: Power function as operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70318@lists.php.net to get a copy of this message
Niel Archer wrote: >> On 22 November 2013 17:08, Sherif Ramadan <theanomaly.is@gmail.com> wrote: >> Where Tjerk has placed it is exactly as python has it. I think right >> assoc is the correct choice here. If you imagine 2^3^2 written down, >> you would do 2^(3^2), not (2^3)^2 > > No, I would do the latter and get 64 as Sherif did. Basic math rule I > learned as a child, is to work left to right unless priority is > indicated by parentheses. In the basic rules you learn as a kid, the general precedence order is parentheses, exponents, multiplication, division, addition and subtraction (commonly called "PEMDAS", "BOMDAS", "BODMAS" or any similar acronym), then left-to-right within those groups. Those basic rules aren't exact (division and multiplication really have the same precedence, as do addition and subtraction, but it doesn't matter thankfully), but they're good for a quick guide. Exponents are never written as "2^3^2" on paper, so you never really have to think about the associativity. It's just a convenient notation for computers since we can't always do superscripts. That said, the convention with the "flattened" form is almost always right-to-left in my experience. Wikipedia also notes [1]: > The reason exponentiation is right-associative is that a repeated > left-associative exponentiation operation would be less useful. See also the discussion [2] on the D mailing list about this. [1]: <http://en.wikipedia.org/wiki/Associativity#Notation_for_non-associative_operations> [2]: <http://www.digitalmars.com/d/archives/digitalmars/D/Should_opPow_be_left-_or_right-associative_102999.html> -- Ryan McCue <http://ryanmccue.info/>

« previous php.internals (#70318) next »