Re: Power function as operator
| From: | Niel Archer | Date: | Fri, 22 Nov 2013 22:27:03 +0000 |
| Subject: | Re: Power function as operator | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70299@lists.php.net to get a copy of this message | ||
> 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.
> 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