Re: Power function as operator
| From: | Tjerk Meesters | Date: | Sat, 23 Nov 2013 05:26:29 +0000 |
| Subject: | Re: Power function as operator | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70314@lists.php.net to get a copy of this message | ||
Hi Niel,
On Sat, Nov 23, 2013 at 6:27 AM, Niel Archer <spam-free@blueyonder.co.uk>wrote:
> > On 22 November 2013 17:08, Sherif Ramadan <theanomaly.is@gmail.com>
> wrote:
> > > I definitely like the idea of having pow as an operator. I've actually
> been
> > > wanting to copy that from Python for a while. I'm all for it.
> >
> > On 22 November 2013 19:56, Sherif Ramadan <theanomaly.is@gmail.com>
> wrote:
> > > That looks very wrong. pow(pow(2,3),2) == 64
> > >
> > > Exponent precedence should always be one higher than multiplication
> > > precedence.
> >
> > 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.
>
Children shouldn't be using power tools in the first place ;-)
Jokes aside, if you write down multiple exponents you would stack them up,
evaluating them from top to bottom (i.e. right associative).
> > Python 2.7.3 (default, Jan 2 2013, 13:56:14)
> > [GCC 4.7.2] on linux2
> > Type "help", "copyright", "credits" or "license"
> > for more information.
> > >>> 2 ** 3 ** 2
> > 512
>
>
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> --
> Niel Archer
> niel.archer (at) blueyonder.co.uk
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
--
Tjerk