Re: Re: power operator (again)

From: Date: Thu, 19 Dec 2013 22:19:32 +0000
Subject: Re: Re: power operator (again)
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70767@lists.php.net to get a copy of this message
Rasmus Lerdorf 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.
The only way to ensure you get what YOU expect is to add the missing brackets to any equation ... - (3**2) is simply not the same as (- 3)**2 but '-3' should always be (-3) the space has a significance in this case as far as I am concerned. All of this needs the proper inclusion of the brackets since you can't always remember which alternate is being used anyway ... -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

« previous php.internals (#70767) next »