diff --git a/spec.html b/spec.html index 39b77a9e28c..9801189d5c5 100644 --- a/spec.html +++ b/spec.html @@ -3637,7 +3637,7 @@

ToNumber ( _argument_ )

String - See grammar and conversion algorithm below. + Return StringToNumber(_argument_). @@ -3666,10 +3666,7 @@

ToNumber ( _argument_ )

ToNumber 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 (). If the grammar cannot interpret the String as an expansion of |StringNumericLiteral|, then the result of ToNumber is *NaN*.

- -

The terminal symbols of this grammar are all composed of characters in the Unicode Basic Multilingual Plane (BMP). Therefore, the result of ToNumber will be *NaN* if the string contains any or code units, whether paired or unpaired.

-
+

The abstract operation StringToNumber specifies how to convert a String value to a Number value. Overall, the process is similar to the determination of the NumericValue of a numeric literal (see ), but some of the details are different.

Syntax

StringNumericLiteral ::: @@ -3724,7 +3721,6 @@

Syntax

Runtime 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 ), 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 .

  • The MV of StringNumericLiteral ::: [empty] is 0. @@ -3784,7 +3780,30 @@

    Runtime Semantics: MV

    The MV of StrUnsignedDecimalLiteral ::: DecimalDigits ExponentPart is the MV of |DecimalDigits| times 10_e_, where _e_ is the MV of |ExponentPart|.
-

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 ), 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

+

For the MV of any production not shown above, see .

+
+ + +

StringToNumber ( _str_ )

+ + 1. Assert: Type(_str_) is String. + 1. Let _text_ be the sequence of Unicode code points that results from interpreting _str_ as UTF-16 encoded Unicode text as described in . + 1. Let _literal_ be the result of parsing _text_ using the goal symbol |StringNumericLiteral|. If _text_ does not conform to the grammar, or if any elements of _text_ were not matched by the parse, return *NaN*. + 1. NOTE: The terminal symbols of the |StringNumericLiteral| grammar are all code points in the Unicode Basic Multilingual Plane (BMP). Therefore, this operation will return *NaN* if _str_ contains any or code units, whether paired or unpaired. + 1. If _literal_ contains a |StrUnsignedDecimalLiteral| and _literal_ has more than 20 significant digits, then + 1. Let _lit_ be an implementation-dependent choice of: + * _literal_ + * a literal produced from _literal_ by replacing each significant digit after the 20th with a `0` digit + * a literal produced from _literal_ by replacing each significant digit after the 20th with a `0` digit and then incrementing the literal at the 20th significant digit position + 1. Else, + 1. Let _lit_ be _literal_. + 1. Let _mv_ be the MV of _lit_. + 1. If _mv_ is 0, then + 1. If the first non white space code point in _text_ is `"-"`, return *-0*; else return *+0*. + 1. Return the Number value for _mv_ (as specified in ). + + +

A digit is significant if it is not part of an |ExponentPart| and

  • it is not `0`; or @@ -10067,7 +10086,7 @@

    Syntax

    Static 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.

    +

    A numeric literal stands for a value of the Number type, as specified by the syntax-directed operation NumericValue. Determining this value involves deriving a mathematical value (MV) from the literal, according to the following rules.

    • The MV of NumericLiteral :: DecimalLiteral is the MV of |DecimalLiteral|. @@ -10217,7 +10236,37 @@

      Static Semantics: MV

      The MV of HexDigits :: HexDigits HexDigit is (the MV of |HexDigits| × 16) plus the MV of |HexDigit|.
    -

    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 ), 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

    +
    + + +

    Static Semantics: NumericValue

    + + NumericLiteral :: + BinaryIntegerLiteral + OctalIntegerLiteral + HexIntegerLiteral + + + 1. Let _mv_ be the MV of |NumericLiteral|. + 1. If _mv_ is 0, return *+0*. + 1. Return the Number value for _mv_ (as specified in ). + + + NumericLiteral :: DecimalLiteral + + 1. If |DecimalLiteral| has more than 20 significant digits, then + 1. Let _lit_ be an implementation-dependent choice of: + * |DecimalLiteral| + * a literal produced from |DecimalLiteral| by replacing each significant digit after the 20th with a `0` digit + * a literal produced from |DecimalLiteral| by replacing each significant digit after the 20th with a `0` digit and then incrementing the literal at the 20th significant digit position + 1. Else, + 1. Let _lit_ be |DecimalLiteral|. + 1. Let _mv_ be the MV of _lit_. + 1. If _mv_ is 0, return *+0*. + 1. Return the Number value for _mv_ (as specified in ). + + +

    A digit is significant if it is not part of an |ExponentPart| and

    • it is not `0`; or @@ -11456,7 +11505,7 @@

      Runtime Semantics: Evaluation

      Literal : NumericLiteral - 1. Return the number whose value is MV of |NumericLiteral| as defined in . + 1. Return NumericValue of |NumericLiteral| as defined in . Literal : StringLiteral @@ -11729,7 +11778,7 @@

      Static Semantics: PropName

      LiteralPropertyName : NumericLiteral - 1. Let _nbr_ be the result of forming the value of the |NumericLiteral|. + 1. Let _nbr_ be NumericValue of |NumericLiteral|. 1. Return ! ToString(_nbr_). ComputedPropertyName : `[` AssignmentExpression `]` @@ -11780,7 +11829,7 @@

      Runtime Semantics: Evaluation

      LiteralPropertyName : NumericLiteral - 1. Let _nbr_ be the result of forming the value of the |NumericLiteral|. + 1. Let _nbr_ be NumericValue of |NumericLiteral|. 1. Return ! ToString(_nbr_). ComputedPropertyName : `[` AssignmentExpression `]`