Re: Power function as operator

From: Date: Fri, 22 Nov 2013 21:37:32 +0000
Subject: Re: Power function as operator
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-70296@lists.php.net to get a copy of this message
On Fri, Nov 22, 2013 at 4:06 PM, Chris London <me@chrislondon.co> wrote: > > On Fri, Nov 22, 2013 at 12:56 PM, Sherif Ramadan <theanomaly.is@gmail.com>wrote: > >> On Fri, Nov 22, 2013 at 1:03 PM, Tjerk Meesters <tjerk.meesters@gmail.com >> >wrote: >> >> > >> > 2 ** 3 ** 2 == 512 >> > >> >> >> That looks very wrong. pow(pow(2,3),2) == 64 >> >> Exponent precedence should always be one higher than multiplication >> precedence. >> > > I don't know if we consider Google to be the authority but they also do > 512: > > 2 ^ 3 ^ 2 = 512 > > https://www.google.com/search?q=2+%5E+3+%5E+2 > > Well, it's correct in the sense that ** should be a right-associative operator (and as such Python will provide the same result). The get the same effect as pow(pow(2,3),2), one would have to do ((2**3)**2), in which case the result woudl be 64. I just didn't realize the patch made the operator right-associative until now.

« previous php.internals (#70296) next »