{{ message }}

Instantly share code, notes, and snippets.

# rwaldron/exponentiation.md

Last active Aug 29, 2015
Exponentiation Operator: **

# Exponentiation Operator

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

## Prior Art

• 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`

## Usage

```// 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
=
*=
/=
%=
+=
-=
<<=
>>=
>>>=
&=
^=
|=
**=
``````

## Status

Implemented as option in Traceur

## Reviewed By:

• Erik Arvidsson
• Dmitry Lomov

### liorean commented Mar 30, 2015

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)".

to join this conversation on GitHub. Already have an account? Sign in to comment