Performs exponential calculation on operands. Same algorithm as Math.pow(x, y)
- Commonly used in albegra, geometry, physics and robotics.
- Nice to have "inline" operator
- Python
math.pow(x, y)
x ** y
- CoffeeScript
x ** y
- F#
x ** y
- Ruby
x ** y
- Perl
x ** y
- Lua, Basic, MATLAB, etc.
x ^ y
// x ** y
let squared = 2 ** 2;
// same as: 2 * 2
let cubed = 2 ** 3;
// same as: 2 * 2 * 2
// x **= y
let a = 2;
a **= 2;
// same as: a = a * a;
let b = 3;
b **= 3;
// same as: b = b * b * b;
ExponentiationExpression :
UnaryExpression
UnaryExpression ** ExponentiationExpression
MultiplicativeExpression :
ExponentiationExpression
MultiplicativeExpression * ExponentiationExpression
MultiplicativeExpression / ExponentiationExpression
MultiplicativeExpression % ExponentiationExpression
AssignmentOperator : one of
=
*=
/=
%=
+=
-=
<<=
>>=
>>>=
&=
^=
|=
**=
Implemented as option in Traceur
- Erik Arvidsson
- Dmitry Lomov
Is the right recursive version because of desired operator right associativity so "a ** b ** c" -> "(a ** (b ** c))"?
Most ECMAScript grammar productions are written as left recursive, but of course, that would make "a ** b ** c" -> "((a ** b) ** c)".