Int64 strawman

Table of Contents

  1. Introduction
  2. 1 ECMAScript Data Types and Values (6)
    1. 1.1 ECMAScript language types (6.1)
      1. 1.1.1 Well-Known Intrinsic Objects (6.1.7.4)
    2. 1.2 The Int64 type
    3. 1.3 The Uint64 type
  3. 2 Abstract Operations (7)
    1. 2.1 Type Conversion (7.1)
      1. 2.1.1 ToPrimitive ( input [, PreferredType] ) (7.1.1)
      2. 2.1.2 ToBoolean ( argument ) (7.1.2)
      3. 2.1.3 ToNumber ( argument ) (7.1.3)
      4. 2.1.4 ToInt64 ( argument )
      5. 2.1.5 ToUint64 ( argument )
      6. 2.1.6 ToString ( argument ) (7.1.12)
      7. 2.1.7 ToObject ( argument ) (7.1.13)
    2. 2.2 RequireObjectCoercible ( argument ) (7.2.1)
    3. 2.3 SameValue(x, y) (7.2.9)
    4. 2.4 SameValueZero(x, y) (7.2.10)
    5. 2.5 Abstract Relational Comparison (7.2.11)
    6. 2.6 Abstract Equality Comparison (7.2.12)
    7. 2.7 Strict Equality Comparison (7.2.13)
  4. 3 Numeric Literals
    1. 3.1 Static Semantics: MV
  5. 4 The typeof Operator (12.5.6)
    1. 4.1 Runtime Semantics: Evaluation (12.5.6.1)
  6. 5 The Addition operator ( + ) (12.7.3)
    1. 5.1 Runtime Semantics: Evaluation (12.7.3.1)
  7. 6 Numbers and Dates (20)
    1. 6.1 Number Objects (20.1)
      1. 6.1.1 The Number Constructor (20.1.1)
        1. 6.1.1.1 Number ( [ value ] ) (20.1.1.1)
  8. 7 Int64 Objects
    1. 7.1 The Int64 constructor
      1. 7.1.1 Int64( [ value ] )
    2. 7.2 Properties of the Int64 constructor
      1. 7.2.1 Int64.MAX_VALUE
      2. 7.2.2 Int64.MIN_VALUE
      3. 7.2.3 Int64.add( a, b )
      4. 7.2.4 Int64.sub( a, b )
      5. 7.2.5 Int64.mul( a, b )
      6. 7.2.6 Int64.div( a, b )
      7. 7.2.7 Int64.mod( a, b )
      8. 7.2.8 Int64.neg( a )
      9. 7.2.9 Int64.not( a )
      10. 7.2.10 Int64.and( a, b )
      11. 7.2.11 Int64.or( a, b )
      12. 7.2.12 Int64.xor( a, b )
      13. 7.2.13 Int64.greaterThan( a, b )
      14. 7.2.14 Int64.lessThan( a, b )
      15. 7.2.15 Int64.greaterThanOrEqual( a, b )
      16. 7.2.16 Int64.lessThanOrEqual( a, b )
      17. 7.2.17 Int64.compare( a, b )
      18. 7.2.18 Int64.min( values... )
      19. 7.2.19 Int64.max( values... )
      20. 7.2.20 Int64.abs( a )
      21. 7.2.21 Int64.combine( lo, hi )
      22. 7.2.22 Int64.shiftLeft( value, shifter )
      23. 7.2.23 Int64.shiftRightArithmetic( value, shifter )
    3. 7.3 Properties of the Int64 Prototype Object
      1. 7.3.1 Int64.prototype.valueOf()
      2. 7.3.2 Int64.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ])
      3. 7.3.3 Int64.prototype.toString()
  9. 8 Uint64 Objects
    1. 8.1 The Uint64 constructor
      1. 8.1.1 Uint64( [ value ] )
    2. 8.2 Properties of the Uint64 constructor
      1. 8.2.1 Uint64.MAX_VALUE
      2. 8.2.2 Uint64.MIN_VALUE
      3. 8.2.3 Uint64.add( a, b )
      4. 8.2.4 Uint64.min( values... )
      5. 8.2.5 Uint64.max( values... )
      6. 8.2.6 Uint64.combine( lo, hi )
      7. 8.2.7 Uint64.shiftLeft( value, shifter )
      8. 8.2.8 Uint64.shiftRightLogical( value, shifter )
      9. 8.2.9 Uint64.clz( value )
    3. 8.3 Properties of the Uint64 Prototype Object
      1. 8.3.1 Uint64.prototype.valueOf()
      2. 8.3.2 Uint64.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ])
      3. 8.3.3 Uint64.prototype.toString()
  10. 9 TypedArray Objects (22.2)

Introduction

This proposal adds 64-bit integer arithmetic to ECMAScript. The main language features added are:

Specifically omitted features are: 64-bit integers are motivated by a number of use cases:

Specification-wise, the addition of more numerical types requires pervasive to ECMAScript's representation of numbers. The ES2015 specification identifies ECMAScript Numbers with mathematical numbers. With the addition of integers, and the fact that the set of double-precision floating point values intersects the sets of 64-bit signed and unsigned integers (which intersect each other), numbers in ECMAScript have to be formalized as tagged values. The complete change to the specification text is outside the scope of this strawman, but it will have to be dealt eventually. For the purposes of this strawman, interpret "untagged" numbers as Numbers by default when used as ECMAScript values.

Please file any issues here. The authoritative copy of this document is in the value-spec repo and a rendered, up-to-date copy is hosted here.

1ECMAScript Data Types and Values (6)

1.1ECMAScript language types (6.1)

1.1.1Well-Known Intrinsic Objects (6.1.7.4)

Intrinsic name: %Int64%
Global name: Int64
ECMAScript Language Association: The `Int64` object

Intrinsic name: %Int64Prototype%
Global name: Int64.prototype
ECMAScript Language Association: The initial value of the prototype data property of %Int64Constructor%

Intrinsic name: %Uint64%
Global name: Uint64
ECMAScript Language Association: The `Uint64` object

Intrinsic name: %Uint64Prototype%
Global name: Uint64.prototype
ECMAScript Language Association: The initial value of the prototype data property of %Uint64Constructor%

1.2The Int64 type

The Int64 type is the set of all integers [-9223372036854775808,9223372036854775807] tagged as Int64, that is, the numbers that can be expressed in a signed, 64-bit 2's complement integer.

1.3The Uint64 type

The Uint64 type is the set of all integers [0,18446744073709551615] tagged as Uint64, that is, the numbers that can be expressed in an unsigned, 64-bit 2's complement integer.

2Abstract Operations (7)

2.1Type Conversion (7.1)

2.1.1ToPrimitive ( input [, PreferredType] ) (7.1.1)

Argument type: Int64
Result: return input
Argument type: Uint64
Result: return input

2.1.2ToBoolean ( argument ) (7.1.2)

Argument type: Int64
Result: If argument is an Int64-tagged 0, return false; otherwise, return true. Argument type: Uint64
Result: If argument is a Uint64-tagged 0, return false; otherwise, return true. Note Another option would be to make all Int64 and Uint64 values be truthy, under the interpretation that it was a mistake to have anything be falsy but things like false, undefined, etc. However, this interpretation is consistent with Numbers, and it could make refactoring code using Numbers, or code written in C, easier to port.

2.1.3ToNumber ( argument ) (7.1.3)

Argument type: Int64
Result: throw a TypeError exception
Argument type: Uint64
Result: throw a TypeError exception
Note While it would be possible to provide a conversion to Numbers, the conversion would lose precision and lead operators like + to operate on less precise numbers. Throwing leaves the door open for future operator overloading while maintaining backwards compatibility.

2.1.4ToInt64 ( argument )

  1. If Type(argument) is Object,
    1. Let argument be ToPrimitive(argument, hint Number).
  2. If Type(argument) is Int64, return argument.
  3. If Type(argument) is Uint64,
    1. If argument > 9223372036854775807, return argument - 18446744073709551616 tagged as Int64.
    2. Else, return argument tagged as Int64.
  4. If Type(argument) is Number,
    1. If number is NaN, +0, −0, +∞, or −∞, return 0.
    2. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(argument)).
    3. Let int64bit be int modulo 264.
    4. If int64bit ≥ 263, return int64bit − 264 tagged as Int64, otherwise return int64bit tagged as Int64.
  5. If Type(argument) is String, parse the number as a string as described in the section "ToNumber Applied to the String Type", throwing a RangeError if the result is not representable exactly in a Int64, including on -0, NaN and Infinity.
  6. Otherwise, throw a TypeError.

2.1.5ToUint64 ( argument )

  1. If Type(argument) is Object,
    1. Let argument be ToPrimitive(argument, hint Number).
  2. If Type(argument) is Uint64, return argument.
  3. If Type(argument) is Int64,
    1. If argument < 0, return argument + 18446744073709551616 tagged as Uint64.
    2. Else, return argument tagged as Uint64.
  4. If Type(argument) is Number,
    1. If number is NaN, +0, −0, +∞, or −∞, return 0.
    2. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(argument)).
    3. Let int64bit be int modulo 264.
    4. Return int64bit tagged as Uint64.
  5. If Type(argument) is String, parse the number as a string as described in the section "ToNumber Applied to the String Type", throwing a RangeError if the result is not representable exactly in a Uint64, including on -0, NaN and Infinity.
  6. Otherwise, throw a TypeError.

2.1.6ToString ( argument ) (7.1.12)

Argument type: Int64
Result: Convert the value of the signed integer to a base-10 string in the normal way.
Argument type: Uint64
Result: Convert the value of the signed integer to a base-10 string in the normal way.

2.1.7ToObject ( argument ) (7.1.13)

Argument type: Int64
Result: Return a new %Int64% wrapper object whose [[Int64Data]] internal slot is set to argument.
Argument type: Uint64
Result: Return a new %Uint64% wrapper object whose [[Uint64Data]] internal slot is set to argument.

2.2RequireObjectCoercible ( argument ) (7.2.1)

Argument type: Int64
Result: return argument
Argument type: Uint64
Result: return argument

2.3SameValue(x, y) (7.2.9)

  1. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is different from Type(y), return false.
  4. If Type(x) is Undefined, return true.
  5. If Type(x) is Null, return true.
  6. If Type(x) is Number, then
    1. If x is NaN and y is NaN, return true.
    2. If x is +0 and y is -0, return false.
    3. If x is -0 and y is +0, return false.
    4. If x is the same Number value as y, return true.
    5. Return false.
  7. If Type(x) is String, then
    1. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices) return true; otherwise, return false.
  8. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true; otherwise, return false.
  9. If Type(x) is Symbol, then
    1. If x and y are both the same Symbol value, return true; otherwise, return false.
  10. If Type(x) is Int64, then
    1. Assert Type(y) is Int64.
    2. If x is the same Int64 value as y, return true.
    3. Return false.
  11. If Type(x) is Uint64, then
    1. Assert Type(y) is Uint64.
    2. If x is the same Uint64 value as y, return true.
    3. Return false.
  12. Return true if x and y are the same Object value. Otherwise, return false.

2.4SameValueZero(x, y) (7.2.10)

  1. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is different from Type(y), return false.
  4. If Type(x) is Undefined, return true.
  5. If Type(x) is Null, return true.
  6. If Type(x) is Number, then
    1. If x is NaN and y is NaN, return true.
    2. If x is +0 and y is -0, return true.
    3. If x is -0 and y is +0, return true.
    4. If x is the same Number value as y, return true.
    5. Return false.
  7. If Type(x) is String, then
    1. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices) return true; otherwise, return false.
  8. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true; otherwise, return false.
  9. If Type(x) is Symbol, then
    1. If x and y are both the same Symbol value, return true; otherwise, return false.
  10. If Type(x) is Int64, then
    1. Assert Type(y) is Int64.
    2. If x is the same Int64 value as y, return true.
    3. Return false.
  11. If Type(x) is Uint64, then
    1. Assert Type(y) is Uint64.
    2. If x is the same Uint64 value as y, return true.
    3. Return false.
  12. Return true if x and y are the same Object value. Otherwise, return false.

2.5Abstract Relational Comparison (7.2.11)

Note

No changes needed for Int64 or Uint64; it will throw a TypeError if either operand is a Int64 value because the algorithm will call ToNumber in step 6.a or 6.c, which throws on Int64 values.

It is important for Abstract Relational Comparison to throw on Int64 types because there is no clear scalar boolean interpretation, and allowing it to throw makes it possible overload the operator in the future.

2.6Abstract Equality Comparison (7.2.12)

  1. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is the same as Type(y), then
    1. Return the result of performing Strict Equality Comparison x === y.
  4. If x is null and y is undefined, return true.
  5. If x is undefined and y is null, return true.
  6. If Type(x) is Number and Type(y) is String,
    return the result of the comparison x == ToNumber(y).
  7. If Type(x) is String and Type(y) is Number,
    return the result of the comparison ToNumber(x) == y.
  8. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
  9. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
  10. If Type(x) is either String, Number, Int64, Uint64 or Symbol and Type(y) is Object, then
    return the result of the comparison x == ToPrimitive(y).
  11. If Type(x) is Object and Type(y) is either String, Number, Int64, Uint64 or Symbol, then
    return the result of the comparison ToPrimitive(x) == y.
  12. Return false.

2.7Strict Equality Comparison (7.2.13)

  1. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is different from Type(y), return false.
  4. If Type(x) is Undefined, return true.
  5. If Type(x) is Null, return true.
  6. If Type(x) is Number, then
    1. If x is NaN, return false.
    2. If y is NaN, return false.
    3. If x is the same Number value as y, return true.
    4. If x is +0 and y is −0, return true.
    5. If x is −0 and y is +0, return true.
    6. Return false.
  7. If Type(x) is String, then
    1. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices) return true; otherwise, return false.
  8. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true; otherwise, return false.
  9. If Type(x) is Symbol, then
    1. If x and y are both the same Symbol value, return true; otherwise, return false.
  10. If Type(x) is Int64, then
    1. Assert Type(y) is Int64.
    2. If x is the same Int64 value as y, return true.
    3. Return false.
  11. If Type(x) is Uint64, then
    1. Assert Type(y) is Uint64.
    2. If x is the same Uint64 value as y, return true.
    3. Return false.
  12. Return true if x and y are the same Object value. Otherwise, return false.

3Numeric Literals

In "12.2.4 Literals", where NumericLiteral is referred to, instead use TypedNumericLiteral, as defined below: TypedNumericLiteral:NumericLiteral NumericLiteralL NumericLiteralUL

3.1Static Semantics: MV

4The typeof Operator (12.5.6)

4.1Runtime Semantics: Evaluation (12.5.6.1)

Type of val: Int64
Result: "int64"
Type of val: Uint64
Result: "uint64"
NoteThis follows the pattern for Number ("number"), Boolean ("boolean"), etc.

5The Addition operator ( + ) (12.7.3)

5.1Runtime Semantics: Evaluation (12.7.3.1)

Note

No changes needed for Int64 or Uint64. With one Int64 argument and one argument which is a String after ToPrimitive is applied, this will coerce the Int64 value to a string. Otherwise, if either argument is an Int64 value, then ToNumber will be run on step 12. or 14., which would throw a TypeError.

It is important for + to throw when applied to Int64 types to allow the future definition of operator overloading on +.

6Numbers and Dates (20)

6.1Number Objects (20.1)

6.1.1The Number Constructor (20.1.1)

6.1.1.1Number ( [ value ] ) (20.1.1.1)

  1. If no arguments were passed to this function invocation, let n be +0.
  2. Else, if Type(n) is Int64, let n be the result of converting value to the nearest Number, with IEEE 754 round-to-nearest, ties-to-even semantics.
  3. Else, if Type(n) is Uint64, let n be the result of converting value to the nearest Number, with IEEE 754 round-to-nearest, ties-to-even semantics.
  4. Else, let n be ToNumber(value).
  5. ReturnIfAbrupt(n).
  6. If NewTarget is undefined, return n.
  7. Let O be OrdinaryCreateFromConstructor(NewTarget, "%NumberPrototype%", «[[NumberData]]» ).
  8. ReturnIfAbrupt(O).
  9. Set the value of O’s [[NumberData]] internal slot to n.
  10. Return O.

7Int64 Objects

7.1The Int64 constructor

The Int64 constructor is the %Int64% intrinsic object and the initial value of the Int64 property of the global object. When called as a constructor, it creates and initializes a new Int64 object. When Int64 is called as a function rather than as a constructor, it performs a type conversion. Int64 has a number of function properties for operating on Int64 values.

7.1.1Int64( [ value ] )

When Int64 is called with argument value, the following steps are taken:
  1. If no arguments were passed to this function invocation, let n be 0.
  2. Else, let n be ToInt64(value).
  3. ReturnIfAbrupt(n).
  4. If NewTarget is undefined, return n.
  5. Let O be OrdinaryCreateFromConstructor(NewTarget, "%Int64Prototype%", «[[Int64Data]]» ).
  6. ReturnIfAbrupt(O).
  7. Set the value of O’s [[NumberData]] internal slot to n.
  8. Return O.

7.2Properties of the Int64 constructor

The value of the [[Prototype]] internal slot of the Int64 constructor is the intrinsic object %FunctionPrototype% (19.2.3).

Besides the length property (whose value is 1), the Int64 constructor has the following properties:

7.2.1Int64.MAX_VALUE

The value of Int64.MAX_VALUE is the largest positive value of the Int64 type, which is 9223372036854775807, tagged as Int64.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

7.2.2Int64.MIN_VALUE

The value of Int64.MIN_VALUE is the smallest negative value of the Int64 type, which is -9223372036854775808, tagged as Int64.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

7.2.3Int64.add( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. Return the result of adding the values of a and b, with signed 2's complement 64-bit overflow, as an Int64 value.

7.2.4Int64.sub( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. Return the result of subtracting b from a, with signed 2's complement 64-bit overflow, as an Int64 value.

7.2.5Int64.mul( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. Return the result of multiplying a by b, with signed 2's complement 64-bit overflow, as an Int64 value.

7.2.6Int64.div( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If b is 0, throw a RangeError.
  3. If the b is -1 and a is the minimum Int64 value, throw a RangeError.
  4. Return the result of the signed integer division of a by b, as an Int64 value, with division rounding towards 0.
NoteThe RangeError occurs where division would result in an overflow. This is a sufficiently rare case that it is raised as an error, as opposed to overflow for +, -, *.

7.2.7Int64.mod( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If b is 0, throw a RangeError.
  3. Return the result of the signed integer remainder of a divided by b, as an Int64 value, with division rounding towards 0.

7.2.8Int64.neg( a )

  1. If Type(a) is not Int64, throw a TypeError.
  2. If a is -9223372036854775808, return a.
  3. Otherwise, return the additive inverse of a as an Int64 value.

7.2.9Int64.not( a )

  1. If Type(a) is not Int64, throw a TypeError.
  2. Return the bitwise negation of a, interpreted as a signed 2's complement 64-bit integer, as an Int64 value.

7.2.10Int64.and( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. Return the bitwise and of a with b interpreted as signed 2's complement 64-bit integers, as an Int64 value.

7.2.11Int64.or( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. Return the bitwise or of a with b interpreted as signed 2's complement 64-bit integers, as an Int64 value.

7.2.12Int64.xor( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. Return the bitwise xor of a with b interpreted as signed 2's complement 64-bit integers, as an Int64 value.

7.2.13Int64.greaterThan( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If a is greater than b, return true.
  3. Return false.

7.2.14Int64.lessThan( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If a is less than b, return true.
  3. Return false.

7.2.15Int64.greaterThanOrEqual( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If a is greater than or equal to b, return true.
  3. Return false.

7.2.16Int64.lessThanOrEqual( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If a is less than or equal to b, return true.
  3. Return false.

7.2.17Int64.compare( a, b )

  1. If Type(a) is not Int64 or Type(b) is not Int64, throw a TypeError.
  2. If a is less than b, return the Number -1.
  3. If a is equal to b, return the Number 0.
  4. Otherwise, a is greater than b; Return the Number 1.

7.2.18Int64.min( values... )

  1. If any of the values is not an Int64, throw a TypeError.
  2. If no arguments are given, then return the largest Int64 value, 9223372036854775807 tagged as Int64.
  3. Return the smallest Int64 argument among values.
The length of Int64.min is 2. NoteA separate min is needed because Math.min will throw on Int64 values when it tries to convert the to Numbers in the definition of Abstract Relational Comparison.

7.2.19Int64.max( values... )

  1. If any of the values is not an Int64, throw a TypeError.
  2. If no arguments are given, then return the smallest Int64 value, -9223372036854775808 tagged as Int64.
  3. Return the largest Int64 argument among values.
The length of Int64.max is 2. NoteA separate max is needed because Math.max will throw on Int64 values when it tries to convert the to Numbers in the definition of Abstract Relational Comparison.

7.2.20Int64.abs( a )

  1. If Type(a) is not Int64, throw a TypeError.
  2. If a is less than 0 and a does not equal -9223372036854775808, return the Int64 value -a.
  3. Return a.

7.2.21Int64.combine( lo, hi )

  1. Let loValue be ToUint32(lo).
  2. Let hiValue be ToUint32(lo).
  3. Let combined be the mathematical value (hiValue << 32) | loValue, tagged as Uint64.
  4. Return ToInt64(combined).

7.2.22Int64.shiftLeft( value, shifter )

  1. If Type(value) is not Int64, throw a TypeError.
  2. Let shiftValue be ToUint32(shifter).
  3. ReturnIfAbrupt(shiftValue).
  4. Let shiftCount be shiftValue mod 64.
  5. Return the result of shifting value left by shiftCount bits, masked to 64 bits, tagged as Int64.

7.2.23Int64.shiftRightArithmetic( value, shifter )

  1. If Type(value) is not Int64, throw a TypeError.
  2. Let shiftValue be ToUint32(shifter).
  3. ReturnIfAbrupt(shiftValue).
  4. Let shiftCount be shiftValue mod 64.
  5. Return the result of shifting value right by shiftCount bits, with the most significant bit propagated, tagged as Int64.

7.3Properties of the Int64 Prototype Object

7.3.1Int64.prototype.valueOf()

  1. If this does not have a [[Int64Data]] internal slot, throw a TypeError.
  2. Return this.[[Int64Data]].

7.3.2Int64.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ])

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the Int64.prototype.toLocaleString method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the toLocaleString method is used.

Produces a String value that represents this Int64 value formatted according to the conventions of the host environment’s current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.

The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.

The length property of the toLocaleString method is 0.

NoteECMA-402 will need an extension to define toLocaleString on Int64 values.

7.3.3Int64.prototype.toString()

  1. If this does not have a [[Int64Data]] internal slot, throw a TypeError.
  2. Return ToString(this.[[Int64Data]]).

8Uint64 Objects

8.1The Uint64 constructor

The Uint64 constructor is the %Uint64% intrinsic object and the initial value of the Uint64 property of the global object. When called as a constructor, it creates and initializes a new Uint64 object. When Uint64 is called as a function rather than as a constructor, it performs a type conversion. Uint64 has a number of function properties for operating on Uint64 values.

8.1.1Uint64( [ value ] )

When Uint64 is called with argument value, the following steps are taken:
  1. If no arguments were passed to this function invocation, let n be 0.
  2. Else, let n be ToUint64(value).
  3. ReturnIfAbrupt(n).
  4. If NewTarget is undefined, return n.
  5. Let O be OrdinaryCreateFromConstructor(NewTarget, "%Uint64Prototype%", «[[Uint64Data]]» ).
  6. ReturnIfAbrupt(O).
  7. Set the value of O’s [[NumberData]] internal slot to n.
  8. Return O.

8.2Properties of the Uint64 constructor

The value of the [[Prototype]] internal slot of the Uint64 constructor is the intrinsic object %FunctionPrototype% (19.2.3).

Besides the length property (whose value is 1), the Uint64 constructor has the following properties:

8.2.1Uint64.MAX_VALUE

The value of Uint64.MAX_VALUE is the largest positive value of the Uint64 type, which is 18446744073709551615, tagged as Uint64.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

8.2.2Uint64.MIN_VALUE

The value of Int64.MIN_VALUE is the smallest value of the Uint64 type, which is 0, tagged as Int64.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

8.2.3Uint64.add( a, b )

  1. If Type(a) is not Uint64 or Type(b) is not Uint64, throw a TypeError.
  2. Return the result of adding the values of a and b, with signed 2's complement 64-bit overflow, as an Int64 value.
Other function properties of Int64 are added analogously, through compare.

8.2.4Uint64.min( values... )

  1. If any of the values is not an Uint64, throw a TypeError.
  2. If no arguments are given, then return the largest Int64 value, 18446744073709551615 tagged as Uint64.
  3. Return the smallest Int64 argument among values.
The length of Uint64.min is 2. NoteA separate min is needed because Math.min will throw on Uint64 values when it tries to convert the to Numbers in the definition of Abstract Relational Comparison.

8.2.5Uint64.max( values... )

  1. If any of the values is not an Uint64, throw a TypeError.
  2. If no arguments are given, then return the smallest Int64 value, 0 tagged as Uint64.
  3. Return the largest Int64 argument among values.
The length of Uint64.max is 2. NoteA separate max is needed because Math.max will throw on Uint64 values when it tries to convert the to Numbers in the definition of Abstract Relational Comparison.

8.2.6Uint64.combine( lo, hi )

  1. Let loValue be ToUint32(lo).
  2. Let hiValue be ToUint32(lo).
  3. Return the mathematical value (hiValue << 32) | loValue, tagged as Uint64.

8.2.7Uint64.shiftLeft( value, shifter )

  1. If Type(value) is not Uint64, throw a TypeError.
  2. Let shiftValue be ToUint32(shifter).
  3. ReturnIfAbrupt(shiftValue).
  4. Let shiftCount be shiftValue mod 64.
  5. Return the result of shifting value left by shiftCount bits, masked to 64 bits, tagged as Uint64.

8.2.8Uint64.shiftRightLogical( value, shifter )

  1. If Type(value) is not Uint64, throw a TypeError.
  2. Let shiftValue be ToUint32(shifter).
  3. ReturnIfAbrupt(shiftValue).
  4. Let shiftCount be shiftValue mod 64.
  5. Return the result of shifting value right by shiftCount bits, with no propagation of the most significant bit, tagged as Uint64.

8.2.9Uint64.clz( value )

  1. Return the number of leading 0 bits in the 64-bit representation of value.

8.3Properties of the Uint64 Prototype Object

8.3.1Uint64.prototype.valueOf()

  1. If this does not have a [[Uint64Data]] internal slot, throw a TypeError.
  2. Return this.[[Uint64Data]].

8.3.2Uint64.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ])

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the Int64.prototype.toLocaleString method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the toLocaleString method is used.

Produces a String value that represents this Uint64 value formatted according to the conventions of the host environment’s current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.

The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.

The length property of the toLocaleString method is 0.

NoteECMA-402 will need an extension to define toLocaleString on Int64 values.

8.3.3Uint64.prototype.toString()

  1. If this does not have a [[Uint64Data]] internal slot, throw a TypeError.
  2. Return ToString(this.[[Uint64Data]]).

9TypedArray Objects (22.2)

TypedArrays are provided consisting of Int64 and Uint64 values. Unlike other TypedArrays, elements are 64-bit integers rather than Numbers. The definitions of SetValueInBuffer and GetValueFromBuffer must be modified to account for this difference. The conversion operation on Int64 and Uint64 is to check if the argument is of that particular type, throw a TypeError if not, and accept the value as is if so. DataView methods getInt64, setInt64, getUint64, and setUint64 are also provided analogously.