Re: Re: power operator (again)
| From: | Daniel Macedo | Date: | Thu, 19 Dec 2013 22:16:10 +0000 |
| Subject: | Re: Re: power operator (again) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70766@lists.php.net to get a copy of this message | ||
On 19 Dec 2013 21:58, "Rasmus Lerdorf" <rasmus@lerdorf.com> wrote:
>
> On 12/19/2013 04:50 PM, Kris Craig wrote:
> > I believe that, especially for a KISS language like PHP, our top
priority
> > with math operators should be to match arithmetic laws as closely and as
> > intuitively as possible. The average PHP developer is going to do -3
** 2
> > and expect a result of 9, not -9, and rightly so I think.
>
> No, the average PHP developer is going to do $var ** 2 and it will
> behave exactly as they expect with negative values. Yes, in the very
I didn't quite understand if you're making the case for assuming a type
casting of $var and keep with the expected math or if operator precedence
would mean the result could be negative in some cases.
Example:
$str = '-3';
$res = 0 - $str ** 2;
PEMDAS would mean this results in $res having a value of 9 whatever the
case ($str positive or negative)!
Would this be different in regards to operator precedence?
> rare case that someone for some reason hardcodes a negative literal
> there, they are going to have to learn about operator precedence because
> we really can't have 0 - 3**2 be different from - 3**2.
>
> -Rasmus
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>