Re: Re: power operator (again)
| From: | George Wilson | Date: | Thu, 19 Dec 2013 22:11:03 +0000 |
| Subject: | Re: Re: power operator (again) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70764@lists.php.net to get a copy of this message | ||
Maybe this is because my educational background is in Mathematics but
personally, I would tend to assume first (with just about any
language- unless I had reason to believe otherwise) that - blah is
equivalent to - (blah). FWIW, - 3 ** 2 === (-3) ** 2 would seem very
counter intuitive to me and I would probably gripe to myself about an
odd choice of operation syntax. This particularly makes sense given
Rasmus's example. The function
function blah($argument){
return 3 - $blah ** 2
}
Should not by default reverse the sign of $blah as the suggested
syntax might suggest. Again, just my thought.
On Thu, Dec 19, 2013 at 1:58 PM, 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
> 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
>