Exponentiation operator precedence

Waldemar Horwat waldemar at google.com
Wed Aug 26 21:55:35 UTC 2015


On 08/26/2015 09:09, 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).

The grammar concerns have been resolved nicely upthread, so I'm not sure what your objection is.  The costs are no more significant than in the original proposal.  ** now has the same precedence as unary operators and weaker than the increment operators, which matches what most other languages that support exponentiation do.

There is precedence for unary operators not always binding tighter than binary.  yield 3+4 is yield(3+4), not (yield 3)+4.

     Waldemar



More information about the es-discuss mailing list