Re: rfc: pow-operator

From: Date: Sun, 24 Nov 2013 11:31:54 +0000
Subject: Re: rfc: pow-operator
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-70351@lists.php.net to get a copy of this message
On Sun, Nov 24, 2013 at 7:05 PM, Nikita Popov <nikita.ppv@gmail.com> wrote: > On Sun, Nov 24, 2013 at 7:58 AM, Tjerk Meesters <tjerk.meesters@gmail.com>wrote: > >> On Sun, Nov 24, 2013 at 8:31 AM, Kris Craig <kris.craig@gmail.com> 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". >> > >> >> To support the latter "-3 ** 2 == 9" we would require a unary minus that >> has a higher precedence than the exponent operator and as such falls >> outside of the scope of this RFC. >> >> That said, I'm not even sure whether we can support a unary minus with the >> current parser. >> > > Huh? We already support a unary minus with the current parser. It has the > same precedence and associativity as ++ (%prec). You can adjust the > relative precedence of ** and - by adjusting the relative precedence of ** > and T_INC (or making it completely independent if you like.) > Aha! I haven't yet learned all the Bison tricks :) With the unary minus in place (should we adjust the unary plus as well?), this would be the behaviour: -3 ** 2 == 9 1 -3 ** 2 == -8 I'll add this in the RFC. > > Nikita > -- -- Tjerk

« previous php.internals (#70351) next »