Stage 3 Draft / February 28, 2018

Numeric separators

The grammar listed in 11.8.3 is modified as follows.

1Numeric Literals

Syntax

NumericLiteralSeparator::_ NumericLiteral::DecimalLiteral BinaryIntegerLiteral OctalIntegerLiteral HexIntegerLiteral DecimalLiteral::DecimalIntegerLiteral.DecimalDigitsoptExponentPartopt .DecimalDigitsExponentPartopt DecimalIntegerLiteralExponentPartopt DecimalIntegerLiteral::0 NonZeroDigitDecimalDigitsopt NonZeroDigit NonZeroDigitNumericLiteralSeparatoroptDecimalDigits DecimalDigits::DecimalDigit DecimalDigitsDecimalDigit DecimalDigitsNumericLiteralSeparatoroptDecimalDigit DecimalDigit::one of0123456789 NonZeroDigit::one of123456789 ExponentPart::ExponentIndicatorSignedInteger ExponentIndicator::one ofeE SignedInteger::DecimalDigits +DecimalDigits -DecimalDigits BinaryIntegerLiteral::0bBinaryDigits 0BBinaryDigits BinaryDigits::BinaryDigit BinaryDigitsBinaryDigit BinaryDigitsNumericLiteralSeparatoroptBinaryDigit BinaryDigit::one of01 OctalIntegerLiteral::0oOctalDigits 0OOctalDigits OctalDigits::OctalDigit OctalDigitsOctalDigit OctalDigitsNumericLiteralSeparatoroptOctalDigit OctalDigit::one of01234567 HexIntegerLiteral::0xHexDigits 0XHexDigits HexDigits::HexDigit HexDigitsHexDigit HexDigitsNumericLiteralSeparatoroptHexDigit HexDigit::one of0123456789abcdefABCDEF

The SourceCharacter immediately following a NumericLiteral must not be an IdentifierStart or DecimalDigit.

Note

For example: 3in is an error and not the two input elements 3 and in.

A conforming implementation, when processing strict mode code, must not extend, as described in C.1.1, the syntax of NumericLiteral to include LegacyOctalIntegerLiteral, nor extend the syntax of DecimalIntegerLiteral to include NonOctalDecimalIntegerLiteral.

1.1Static Semantics: MV

A numeric literal stands for a value of the Number type. This value is determined in two steps: first, a mathematical value (MV) is derived from the literal; second, this mathematical value is rounded as described below.

Once the exact MV for a numeric literal has been determined, it is then rounded to a value of the Number type. If the MV is 0, then the rounded value is +0; otherwise, the rounded value must be the Number value for the MV (as specified in 6.1.6), unless the literal is a DecimalLiteral and the literal has more than 20 significant digits, in which case the Number value may be either the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit or the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit and then incrementing the literal at the 20th significant digit position. A digit is significant if it is not part of an ExponentPart and

  • it is not 0; or
  • there is a nonzero digit to its left and there is a nonzero digit, not in the ExponentPart, to its right.

2ToNumber Applied to the String Type

ToNumber applied to Strings applies the following grammar to the input String interpreted as a sequence of UTF-16 encoded code points (6.1.4). If the grammar cannot interpret the String as an expansion of StringNumericLiteral, then the result of ToNumber is NaN.

Note

The terminal symbols of this grammar are all composed of Unicode BMP code points so the result will be NaN if the string contains the UTF-16 encoding of any supplementary code points or any unpaired surrogate code points.

Syntax

StringNumericLiteral:::StrWhiteSpaceopt StrWhiteSpaceoptStrNumericLiteralStrWhiteSpaceopt StrWhiteSpace:::StrWhiteSpaceCharStrWhiteSpaceopt StrWhiteSpaceChar:::WhiteSpace LineTerminator StrNumericLiteral:::StrDecimalLiteral BinaryIntegerLiteral OctalIntegerLiteral HexIntegerLiteral StrBinaryLiteral StrOctalLiteral StrHexLiteral StrDecimalLiteral:::StrUnsignedDecimalLiteral +StrUnsignedDecimalLiteral -StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral:::Infinity DecimalDigits.DecimalDigitsoptExponentPartopt .DecimalDigitsExponentPartopt DecimalDigitsExponentPartopt StrDecimalDigits.StrDecimalDigitsoptStrExponentPartopt .StrDecimalDigitsStrExponentPartopt StrDecimalDigitsStrExponentPartopt StrDecimalDigits:::DecimalDigit StrDecimalDigitsDecimalDigit StrExponentPart:::ExponentIndicatorStrSignedInteger StrSignedInteger:::StrDecimalDigits +StrDecimalDigits -StrDecimalDigits StrBinaryLiteral:::0bStrBinaryDigits 0BStrBinaryDigits StrBinaryDigits:::BinaryDigit StrBinaryDigitsBinaryDigit StrOctalLiteral:::0oStrOctalDigits 0OStrOctalDigits StrOctalDigits:::OctalDigit StrOctalDigitsOctalDigit StrHexLiteral:::0xStrHexDigits 0XStrHexDigits StrHexDigits:::HexDigit StrHexDigitsHexDigit

2.1Runtime Semantics: MV

The conversion of a String to a Number value is similar overall to the determination of the Number value for a numeric literal (see 1), but some of the details are different, so the process for converting a String numeric literal to a value of Number type is given here. This value is determined in two steps: first, a mathematical value (MV) is derived from the String numeric literal; second, this mathematical value is rounded as described below. The MV on any grammar symbol, not provided below, is the MV for that symbol defined in 11.8.3.1.

Once the exact MV for a String numeric literal has been determined, it is then rounded to a value of the Number type. If the MV is 0, then the rounded value is +0 unless the first non white space code point in the String numeric literal is "-", in which case the rounded value is -0. Otherwise, the rounded value must be the Number value for the MV (in the sense defined in 6.1.6), unless the literal includes a StrUnsignedDecimalLiteral and the literal has more than 20 significant digits, in which case the Number value may be either the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit or the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit and then incrementing the literal at the 20th digit position. A digit is significant if it is not part of an ExponentPart and

  • it is not 0; or
  • there is a nonzero digit to its left and there is a nonzero digit, not in the ExponentPart, to its right.

ATemplate Literal Lexical Components

Syntax

CodePoint::HexDigitsbut only if MV of HexDigits ≤ 0x10FFFF CodePointDigitsbut only if MV of HexDigits ≤ 0x10FFFF CodePointDigits::HexDigit CodePointDigitsHexDigit

BGrammar Summary

Placeholder for Annex A

CAdditional ECMAScript Features for Web Browsers

...

C.1Additional Syntax

C.1.1Numeric Literals

The syntax and semantics of 1 is extended as follows except that this extension is not allowed for strict mode code:

Syntax

NumericLiteral::DecimalLiteral BinaryIntegerLiteral OctalIntegerLiteral HexIntegerLiteral LegacyOctalIntegerLiteral LegacyOctalIntegerLiteral::0OctalDigit LegacyOctalIntegerLiteralOctalDigit DecimalIntegerLiteral::0 NonZeroDigitDecimalDigitsopt NonZeroDigit NonZeroDigitNumericLiteralSeparatoroptDecimalDigits NonOctalDecimalIntegerLiteral NonOctalDecimalIntegerLiteral::0NonOctalDigit LegacyOctalLikeDecimalIntegerLiteralNonOctalDigit NonOctalDecimalIntegerLiteralDecimalDigit LegacyOctalLikeDecimalIntegerLiteral::0OctalDigit LegacyOctalLikeDecimalIntegerLiteralOctalDigit NonOctalDigit::one of89