Stage 0 Draft / January 23, 2018

{BigInt,Number}.fromString

1BigInt.fromString ( string, radix )

The BigInt.fromString function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. If radix is undefined, it is assumed to be 10.

When the BigInt.fromString function is called, the following steps are taken:

  1. If Type(string) is not String, throw a TypeError exception.
  2. If string is empty, throw a SyntaxError exception.
  3. Let sign be 1.
  4. If the first code unit of string is the code unit 0x002D (HYPHEN-MINUS), then
    1. Let sign be -1.
    2. Remove the first code unit from string.
    3. If string is empty, throw a SyntaxError exception.
  5. If radix is not present, let R be 10.
  6. Else if radix is undefined, let R be 10.
  7. Else, let R be ? ToInteger(radix).
  8. If R < 2 or R > 36, throw a RangeError exception.
  9. If string represents a mathematical integer value in radix-R notation, using the characters 0-9 for digits with values 0 to 9, and the letters a-z for digits with values 10 through 35, then
    1. Let mathInt be that mathematical integer value.
  10. Else, throw a SyntaxError exception.
  11. Let number be sign × mathInt.
  12. Return the BigInt value for number.

2Number.fromString ( string, radix )

The Number.fromString function produces a numeric value dictated by interpretation of the contents of the string argument according to the specified radix. If radix is undefined, it is assumed to be 10.

When the Number.fromString function is called, the following steps are taken:

  1. If Type(string) is not String, throw a TypeError exception.
  2. If string is empty, throw a SyntaxError exception.
  3. Let sign be 1.
  4. If the first code unit of string is the code unit 0x002D (HYPHEN-MINUS), then
    1. Let sign be -1.
    2. Remove the first code unit from string.
    3. If string is empty, throw a SyntaxError exception.
  5. If radix is not present, let R be 10.
  6. Else if radix is undefined, let R be 10.
  7. Else, let R be ? ToInteger(radix).
  8. If R < 2 or R > 36, throw a RangeError exception.
  9. If string represents a mathematical number value in radix-R notation, using the characters 0-9 for digits with values 0 to 9, and the letters a-z for digits with values 10 through 35, then
    1. Let mathNum be that mathematical number value.
  10. Else, throw a SyntaxError exception.
  11. Let number be sign × mathNum.
  12. Return the Number value for number.