From 28bdf0798662bcb8efb11c4070f8a981a496ccc1 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 22 Jan 2016 12:15:28 -0500 Subject: [PATCH] Normative: Add Exponentiation Operator Fixes #318. --- spec.html | 327 +++++++++++++++++++++++++++++------------------------- 1 file changed, 173 insertions(+), 154 deletions(-) diff --git a/spec.html b/spec.html index e8c2ca704e..04584ef2a0 100644 --- a/spec.html +++ b/spec.html @@ -9448,7 +9448,7 @@

Punctuators

Syntax

Punctuator :: one of - `{` `(` `)` `[` `]` `.` `...` `;` `,` `<` `>` `<=` `>=` `==` `!=` `===` `!==` `+` `-` `*` `%` `++` `--` `<<` `>>` `>>>` `&` `|` `^` `!` `~` `&&` `||` `?` `:` `=` `+=` `-=` `*=` `%=` `<<=` `>>=` `>>>=` `&=` `|=` `^=` `=>` + `{` `(` `)` `[` `]` `.` `...` `;` `,` `<` `>` `<=` `>=` `==` `!=` `===` `!==` `+` `-` `*` `%` `++` `--` `<<` `>>` `>>>` `&` `|` `^` `!` `~` `&&` `||` `?` `:` `=` `+=` `-=` `*=` `%=` `<<=` `>>=` `>>>=` `&=` `|=` `^=` `=>` `**` `**=` DivPunctuator :: `/` @@ -10371,7 +10371,7 @@

Rules of Automatic Semicolon Insertion

The following are the only restricted productions in the grammar:

- PostfixExpression[Yield] : + UpdateExpression[Yield] : LeftHandSideExpression[?Yield] [no LineTerminator here] `++` LeftHandSideExpression[?Yield] [no LineTerminator here] `--` @@ -12121,21 +12121,23 @@

Runtime Semantics: Evaluation

- -

Postfix Expressions

+ +

Update Expressions

Syntax

- PostfixExpression[Yield] : + UpdateExpression[Yield] : LeftHandSideExpression[?Yield] LeftHandSideExpression[?Yield] [no LineTerminator here] `++` LeftHandSideExpression[?Yield] [no LineTerminator here] `--` + `++` UnaryExpression[?Yield] + `--` UnaryExpression[?Yield] - +

Static Semantics: Early Errors

- PostfixExpression : + UpdateExpression : LeftHandSideExpression `++` LeftHandSideExpression `--` @@ -12144,16 +12146,29 @@

Static Semantics: Early Errors

It is an early Reference Error if IsValidSimpleAssignmentTarget of |LeftHandSideExpression| is *false*. + + + UpdateExpression : + `++` UnaryExpression + `--` UnaryExpression + +
    +
  • + It is an early Reference Error if IsValidSimpleAssignmentTarget of |UnaryExpression| is *false*. +
  • +
- +

Static Semantics: IsFunctionDefinition

- PostfixExpression : + UpdateExpression : LeftHandSideExpression `++` LeftHandSideExpression `--` + `++` UnaryExpression + `--` UnaryExpression 1. Return *false*. @@ -12161,13 +12176,15 @@

Static Semantics: IsFunctionDefinition

- +

Static Semantics: IsValidSimpleAssignmentTarget

- PostfixExpression : + UpdateExpression : LeftHandSideExpression `++` LeftHandSideExpression `--` + `++` UnaryExpression + `--` UnaryExpression 1. Return *false*. @@ -12181,7 +12198,7 @@

Postfix Increment Operator

Runtime Semantics: Evaluation

- PostfixExpression : LeftHandSideExpression `++` + UpdateExpression : LeftHandSideExpression `++` 1. Let _lhs_ be the result of evaluating |LeftHandSideExpression|. 1. Let _oldValue_ be ? ToNumber(? GetValue(_lhs_)). @@ -12199,7 +12216,7 @@

Postfix Decrement Operator

Runtime Semantics: Evaluation

- PostfixExpression : LeftHandSideExpression `--` + UpdateExpression : LeftHandSideExpression `--` 1. Let _lhs_ be the result of evaluating |LeftHandSideExpression|. 1. Let _oldValue_ be ? ToNumber(? GetValue(_lhs_)). @@ -12209,6 +12226,93 @@

Runtime Semantics: Evaluation

+ + + +

Prefix Increment Operator

+ + + +

Runtime Semantics: Evaluation

+ UpdateExpression : `++` UnaryExpression + + 1. Let _expr_ be the result of evaluating |UnaryExpression|. + 1. Let _oldValue_ be ? ToNumber(? GetValue(_expr_)). + 1. Let _newValue_ be the result of adding the value `1` to _oldValue_, using the same rules as for the `+` operator (see ). + 1. Perform ? PutValue(_expr_, _newValue_). + 1. Return _newValue_. + +
+
+ + + +

Prefix Decrement Operator

+ + + +

Runtime Semantics: Evaluation

+ UpdateExpression : `--` UnaryExpression + + 1. Let _expr_ be the result of evaluating |UnaryExpression|. + 1. Let _oldValue_ be ? ToNumber(? GetValue(_expr_)). + 1. Let _newValue_ be the result of subtracting the value `1` from _oldValue_, using the same rules as for the `-` operator (see ). + 1. Perform ? PutValue(_expr_, _newValue_). + 1. Return _newValue_. + +
+
+
+ + +

Exponentiation Operator

+

Syntax

+ + + ExponentiationExpression[Yield] : + UnaryExpression[?Yield] + UpdateExpression[?Yield] `**` ExponentiationExpression[?Yield] + + + +

Static Semantics: IsFunctionDefinition

+ + + ExponentiationExpression : + UpdateExpression `**` ExponentiationExpression + + + 1. Return *false*. + +
+ + +

Static Semantics: IsValidSimpleAssignmentTarget

+ + + ExponentiationExpression : + UpdateExpression `**` ExponentiationExpression + + + 1. Return *false*. + +
+ + +

Runtime Semantics: Evaluation

+ + ExponentiationExpression : UpdateExpression `**` ExponentiationExpression + + + 1. Let _left_ be the result of evaluating _UpdateExpression_. + 1. Let _leftValue_ be ? GetValue(_left_). + 1. Let _right_ be the result of evaluating _ExponentiationExpression_. + 1. Let _rightValue_ be ? GetValue(_right_). + 1. Let _base_ be ? ToNumber(_leftValue_). + 1. Let _exponent_ be ? ToNumber(_rightValue_). + 1. Return the result of Applying the ** operator with _base_ and _exponent_ as specified in . + +
@@ -12217,44 +12321,26 @@

Unary Operators

Syntax

UnaryExpression[Yield] : - PostfixExpression[?Yield] + UpdateExpression[?Yield] `delete` UnaryExpression[?Yield] `void` UnaryExpression[?Yield] `typeof` UnaryExpression[?Yield] - `++` UnaryExpression[?Yield] - `--` UnaryExpression[?Yield] `+` UnaryExpression[?Yield] `-` UnaryExpression[?Yield] `~` UnaryExpression[?Yield] `!` UnaryExpression[?Yield] - - -

Static Semantics: Early Errors

- - UnaryExpression : - `++` UnaryExpression - `--` UnaryExpression - -
    -
  • - It is an early Reference Error if IsValidSimpleAssignmentTarget of |UnaryExpression| is *false*. -
  • -
-
-

Static Semantics: IsFunctionDefinition

UnaryExpression : + UpdateExpression `delete` UnaryExpression `void` UnaryExpression `typeof` UnaryExpression - `++` UnaryExpression - `--` UnaryExpression `+` UnaryExpression `-` UnaryExpression `~` UnaryExpression @@ -12271,11 +12357,10 @@

Static Semantics: IsValidSimpleAssignmentTarget

UnaryExpression : + UpdateExpression `delete` UnaryExpression `void` UnaryExpression `typeof` UnaryExpression - `++` UnaryExpression - `--` UnaryExpression `+` UnaryExpression `-` UnaryExpression `~` UnaryExpression @@ -12472,41 +12557,6 @@

Runtime Semantics: Evaluation

- - -

Prefix Increment Operator

- - - -

Runtime Semantics: Evaluation

- UnaryExpression : `++` UnaryExpression - - 1. Let _expr_ be the result of evaluating |UnaryExpression|. - 1. Let _oldValue_ be ? ToNumber(? GetValue(_expr_)). - 1. Let _newValue_ be the result of adding the value `1` to _oldValue_, using the same rules as for the `+` operator (see ). - 1. Perform ? PutValue(_expr_, _newValue_). - 1. Return _newValue_. - -
-
- - - -

Prefix Decrement Operator

- - - -

Runtime Semantics: Evaluation

- UnaryExpression : `--` UnaryExpression - - 1. Let _expr_ be the result of evaluating |UnaryExpression|. - 1. Let _oldValue_ be ? ToNumber(? GetValue(_expr_)). - 1. Let _newValue_ be the result of subtracting the value `1` from _oldValue_, using the same rules as for the `-` operator (see ). - 1. Perform ? PutValue(_expr_, _newValue_). - 1. Return _newValue_. - -
-
@@ -12719,6 +12769,40 @@

Applying the `%` Operator

+ +

Applying the `**` operator

+

+ Returns an implementation-dependent approximation of the result of raising _base_ to the power _exponent_. +

+
    +
  • If _exponent_ is *NaN*, the result is *NaN*.
  • +
  • If _exponent_ is +0, the result is 1, even if _base_ is *NaN*.
  • +
  • If _exponent_ is −0, the result is 1, even if _base_ is *NaN*.
  • +
  • If _base_ is *NaN* and _exponent_ is nonzero, the result is *NaN*.
  • +
  • If abs(_base_) > 1 and _exponent_ is +∞, the result is +∞.
  • +
  • If abs(_base_) > 1 and _exponent_ is −∞, the result is +0.
  • +
  • If abs(_base_) is 1 and _exponent_ is +∞, the result is *NaN*.
  • +
  • If abs(_base_) is 1 and _exponent_ is −∞, the result is *NaN*.
  • +
  • If abs(_base_) < 1 and _exponent_ is +∞, the result is +0.
  • +
  • If abs(_base_) < 1 and _exponent_ is −∞, the result is +∞.
  • +
  • If _base_ is +∞ and _exponent_ > 0, the result is +∞.
  • +
  • If _base_ is +∞ and _exponent_ < 0, the result is +0.
  • +
  • If _base_ is −∞ and _exponent_ > 0 and _exponent_ is an odd integer, the result is −∞.
  • +
  • If _base_ is −∞ and _exponent_ > 0 and _exponent_ is not an odd integer, the result is +∞.
  • +
  • If _base_ is −∞ and _exponent_ < 0 and _exponent_ is an odd integer, the result is −0.
  • +
  • If _base_ is −∞ and _exponent_ < 0 and _exponent_ is not an odd integer, the result is +0.
  • +
  • If _base_ is +0 and _exponent_ > 0, the result is +0.
  • +
  • If _base_ is +0 and _exponent_ < 0, the result is +∞.
  • +
  • If _base_ is −0 and _exponent_ > 0 and _exponent_ is an odd integer, the result is −0.
  • +
  • If _base_ is −0 and _exponent_ > 0 and _exponent_ is not an odd integer, the result is +0.
  • +
  • If _base_ is −0 and _exponent_ < 0 and _exponent_ is an odd integer, the result is −∞.
  • +
  • If _base_ is −0 and _exponent_ < 0 and _exponent_ is not an odd integer, the result is +∞.
  • +
  • If _base_ < 0 and _base_ is finite and _exponent_ is finite and _exponent_ is not an integer, the result is *NaN*.
  • +
+ +

The result of _base_ `**` _exponent_ when _base_ is *1* or *-1* and _exponent_ is *+Infinity* or *-Infinity* differs from IEEE 754-2008. The first edition of ECMAScript specified a result of *NaN* for this operation, whereas later versions of IEEE 754-2008 specified *1*. The historical ECMAScript behaviour is preserved for compatibility reasons.

+
+
@@ -13431,7 +13515,7 @@

Syntax

LeftHandSideExpression[?Yield] AssignmentOperator AssignmentExpression[?In, ?Yield] AssignmentOperator : one of - `*=` `/=` `%=` `+=` `-=` `<<=` `>>=` `>>>=` `&=` `^=` `|=` + `*=` `/=` `%=` `+=` `-=` `<<=` `>>=` `>>>=` `&=` `^=` `|=` `**=`
@@ -19237,21 +19321,26 @@

Expression Rules

MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator UnaryExpression + ExponentiationExpression : + UnaryExpression + UpdateExpression `**` ExponentiationExpression + + UpdateExpression : + LeftHandSideExpression `++` + LeftHandSideExpression `--` + `++` UnaryExpression + `--` UnaryExpression + UnaryExpression : + UpdateExpression `delete` UnaryExpression `void` UnaryExpression `typeof` UnaryExpression - `++` UnaryExpression - `--` UnaryExpression `+` UnaryExpression `-` UnaryExpression `~` UnaryExpression `!` UnaryExpression - PostfixExpression : - LeftHandSideExpression `++` - LeftHandSideExpression `--` - CallExpression : SuperCall CallExpression `[` Expression `]` @@ -24794,83 +24883,12 @@

Math.min ( _value1_, _value2_ , ..._values_ )

-

Math.pow ( _x_, _y_ )

-

Returns an implementation-dependent approximation to the result of raising _x_ to the power _y_.

-
    -
  • - If _y_ is NaN, the result is NaN. -
  • -
  • - If _y_ is +0, the result is 1, even if _x_ is NaN. -
  • -
  • - If _y_ is -0, the result is 1, even if _x_ is NaN. -
  • -
  • - If _x_ is NaN and _y_ is nonzero, the result is NaN. -
  • -
  • - If abs(_x_)>1 and _y_ is *+∞*, the result is *+∞*. -
  • -
  • - If abs(_x_)>1 and _y_ is *-∞*, the result is +0. -
  • -
  • - If abs(_x_) is 1 and _y_ is *+∞*, the result is NaN. -
  • -
  • - If abs(_x_) is 1 and _y_ is *-∞*, the result is NaN. -
  • -
  • - If abs(_x_)<1 and _y_ is *+∞*, the result is +0. -
  • -
  • - If abs(_x_)<1 and _y_ is *-∞*, the result is *+∞*. -
  • -
  • - If _x_ is *+∞* and _y_>0, the result is *+∞*. -
  • -
  • - If _x_ is *+∞* and _y_<0, the result is +0. -
  • -
  • - If _x_ is *-∞* and _y_>0 and _y_ is an odd integer, the result is *-∞*. -
  • -
  • - If _x_ is *-∞* and _y_>0 and _y_ is not an odd integer, the result is *+∞*. -
  • -
  • - If _x_ is *-∞* and _y_<0 and _y_ is an odd integer, the result is -0. -
  • -
  • - If _x_ is *-∞* and _y_<0 and _y_ is not an odd integer, the result is +0. -
  • -
  • - If _x_ is +0 and _y_>0, the result is +0. -
  • -
  • - If _x_ is +0 and _y_<0, the result is *+∞*. -
  • +

    Math.pow ( _base_, _exponent_ )

    +
    1. - If _x_ is -0 and _y_>0 and _y_ is an odd integer, the result is -0. + Return the result of Applying the ** operator with _base_ and _exponent_ as specified in .
    2. -
    3. - If _x_ is -0 and _y_>0 and _y_ is not an odd integer, the result is +0. -
    4. -
    5. - If _x_ is -0 and _y_<0 and _y_ is an odd integer, the result is *-∞*. -
    6. -
    7. - If _x_ is -0 and _y_<0 and _y_ is not an odd integer, the result is *+∞*. -
    8. -
    9. - If _x_<0 and _x_ is finite and _y_ is finite and _y_ is not an integer, the result is NaN. -
    10. -
- - -

The result of `Math.pow(x, y)` when _x_ is *1* or *-1* and _y_ is *+Infinity* or *-Infinity* differs from IEEE 754-2008. The first edition of ECMAScript specified a result of *NaN* for this operation, whereas later versions of IEEE 754-2008 specified *1*. The historical ECMAScript behaviour is preserved for compatibility reasons.

-
+
@@ -35418,8 +35436,9 @@

Expressions

- + + @@ -36723,7 +36742,7 @@

The Strict Mode of ECMAScript

Assignment to an undeclared identifier or otherwise unresolvable reference does not create a property in the global object. When a simple assignment occurs within strict mode code, its |LeftHandSideExpression| must not evaluate to an unresolvable Reference. If it does a *ReferenceError* exception is thrown (). The |LeftHandSideExpression| also may not be a reference to a data property with the attribute value {[[Writable]]:*false*}, to an accessor property with the attribute value {[[Set]]:*undefined*}, nor to a non-existent property of an object whose [[Extensible]] internal slot has the value *false*. In these cases a `TypeError` exception is thrown ().
  • - The identifier `eval` or `arguments` may not appear as the |LeftHandSideExpression| of an Assignment operator () or of a |PostfixExpression| () or as the |UnaryExpression| operated upon by a Prefix Increment () or a Prefix Decrement () operator. + The identifier `eval` or `arguments` may not appear as the |LeftHandSideExpression| of an Assignment operator () or of a |UpdateExpression| () or as the |UnaryExpression| operated upon by a Prefix Increment () or a Prefix Decrement () operator.
  • Arguments objects for strict mode functions define non-configurable accessor properties named `"caller"` and `"callee"` which throw a *TypeError* exception on access ().