Exponentiation operator precedence
thomasjamesfoster at bigpond.com
Wed Aug 26 18:03:36 UTC 2015
There's still the issue of exponentiation being right-associative. Unless ** becomes an operator which behaves differently as to how it would in a high school maths class, we're at an impasse.
That said, ^ is usually the operator used for exponentiation outside programming languages when you need to express an equation in text. It could be made explicit that ** is a variant on 'exponentiation', but then maybe things are deviating from being useful.
> On 27 Aug 2015, at 3:28 AM, Brendan Eich <brendan at mozilla.org> wrote:
> Yehuda Katz cited an acronym taught when he was a wee lad learning algebra: PEMDAS (Parentheses, Exponentiation, Multiplication/Dviistion, Addition/Subtraction). Who else learned this?
> There's nothing sacrosanct about binary precedence being generally lower than unary. Consider the property access operators in JS. But the precedent to which all cited languages bow is Math and that's what programmers (mostly) study. I think you are making too much out of the local -x ** y case in light of this global argument.
> Mark S. Miller wrote:
>> I don't get it. The conflict between
>> * the history of ** in other languages,
>> * the general pattern that unary binds tighter than binary
>> seems unresolvable. By the first bullet, -2 ** 2 would be -4. By the second, it would be 4. Either answer will surprise too many programmers. By contrast, no one is confused by either -Math.pow(2, 2) or Math.pow(-2, 2).
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss