Re: rfc: pow-operator

From: Date: Sun, 24 Nov 2013 00:58:36 +0000
Subject: Re: rfc: pow-operator
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-70337@lists.php.net to get a copy of this message
I don't see any benefit in using Python's unique behavior as a model. The model should conform to established mathematical laws, not some other arbitrarily chosen scripting language. According to Order of Operations, all operations of the same type within the same context (parentheses) must be processed in order from left to right. For example, -2 ** 3 ** 2 would be processed from left to right, like this: pow( pow( -2, 3 ), 2 ); We've introduced multiple options into RFCs before without encountering the problems you mention. The alternative would be to create a separate RFC that calls for behavior that conforms to established arithmetic standards. But it makes more sense to me to put that into one RFC rather than having two separate threads to discuss what should be one single issue. --Kris On Sat, Nov 23, 2013 at 4:51 PM, Andrea Faulds <ajf@ajf.me> wrote: > > > On 24/11/13 00:31, Kris Craig wrote: > >> We should be following standard Order of Operations here. As such, the >> option of no associativity should be included. Furthermore, there needs >> to >> be a voting option regarding how to deal with even exponents of negative >> bases; i.e. treat "-3 ^ 2" as "-3 ^ 2 == 9" or as "-(3 ^ 2) == >> -9". >> >> Without those options, my vote would be a firm No. >> >> > I am worried that adding so many options might cause problems. Is it fair > if it passes 3/4, but there is only a plurality for, say, > left-associativity or right-associativity? What if someone votes for it, > but would not have voted for it were it to be left-associative? > > I suggest that either Tjerk makes a decision for us and offers a straight > Yes/No choice, or he limits the choices to very few and combines them, so: > > * Yes, right-associative > > * Yes, left-associative > > * No > > Oh, and for my personal thoughts on the matter: I know ** from Python, and > I think (2 ** (3 ** 2)) is more useful than ((2 ** 3) ** 2), so I'd like > (-2 ** 3 ** 2) to be -(2 ** (3 ** 2)), just as Python does it. > > -- > Andrea Faulds > http://ajf.me/ >

« previous php.internals (#70337) next »