Re: Re: power operator (again)

From: Date: Thu, 19 Dec 2013 21:50:48 +0000
Subject: Re: Re: power operator (again)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-70762@lists.php.net to get a copy of this message
On Thu, Dec 19, 2013 at 4:33 AM, Daniel Lowrey <rdlowrey@gmail.com> wrote: > > Thanks for all your effort! Unfortunately, since there's no option for > > negative numbers to intuitively square to positive outcomes, my vote is > > still No. I understand and respect your reasoning even though I do not > > agree with it. > > To me this is not a question of "intuitive" vs. "unintuitive" ... -3^2 = -9 > is how the preponderance of credible resources evaluate the expression. As > far as I can tell voting "no" on this basis is equivalent to me claiming > the earth is flat because it better fits my world-view. That's a faulty analogy. In mathematics, the square of any number, positive or negative, yields a positive result. Any scientific or graphing calculator will match that behavior. I did sqr(-3) in the Windows Calculator just now and it outputted 9, not -9. From http://en.wikipedia.org/wiki/Square_(algebra): "One of the important properties of squaring, for numbers as well as in many other mathematical systems, is that (for all numbers x), the square of x is the same as the square of its additive inverse -x. That is, the square function satisfies the identity x2 = (-x)2. This can also be expressed by saying that the squaring function is an even function." Now, I understand why some programming languages behave differently from the algebraic standard. I don't agree with it, but I understand their reasoning. Claiming that "the squaring function should always be an even function" is the equivalent of saying that the Earth is flat is faulty because it completely ignores the facts that support that argument, just as it would be faulty for me to ignore the facts that support yours. 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. You're free to disagree and you certainly have valid reasons for doing so, but please try to keep in mind that there is a valid argument on the other side of this, as well. --Kris

« previous php.internals (#70762) next »