21.2 BigInt Objects
21.2.1 The BigInt Constructor
The BigInt
- is %BigInt%.
- is the initial value of the
"BigInt" property of theglobal object . - performs a type conversion when called as a function rather than as a
constructor . - is not intended to be used with the
new
operator or to be subclassed. It may be used as the value of anextends
clause of a class definition but asuper
call to the BigIntconstructor will cause an exception.
21.2.1.1 BigInt ( value )
This function performs the following steps when called:
- If NewTarget is not
undefined , throw aTypeError exception. - Let prim be ?
ToPrimitive (value,number ). - If prim
is a Number , return ?NumberToBigInt (prim). - Otherwise, return ?
ToBigInt (prim).
21.2.1.1.1 NumberToBigInt ( number )
The abstract operation NumberToBigInt takes argument number (a Number) and returns either a
- If
IsIntegralNumber (number) isfalse , throw aRangeError exception. - Return
ℤ (ℝ (number)).
21.2.2 Properties of the BigInt Constructor
The BigInt
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
21.2.2.1 BigInt.asIntN ( bits, bigint )
This function performs the following steps when called:
21.2.2.2 BigInt.asUintN ( bits, bigint )
This function performs the following steps when called:
21.2.2.3 BigInt.prototype
The initial value of BigInt.prototype
is the
This property has the attributes { [[Writable]]:
21.2.3 Properties of the BigInt Prototype Object
The BigInt prototype object:
- is %BigInt.prototype%.
- is an
ordinary object . is not a BigInt object; it does not have a [[BigIntData]] internal slot.- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
The phrase “this BigInt value” within the specification of a method refers to the result returned by calling the abstract operation
21.2.3.1 BigInt.prototype.constructor
The initial value of BigInt.prototype.constructor
is
21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:
This method produces a String value that represents this BigInt value formatted according to the conventions of the 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.
21.2.3.3 BigInt.prototype.toString ( [ radix ] )
The optional radix should be an
This method performs the following steps when called:
- Let x be ?
ThisBigIntValue (this value). - If radix is
undefined , let radixMV be 10. - Else, let radixMV be ?
ToIntegerOrInfinity (radix). - If radixMV is not in the
inclusive interval from 2 to 36, throw aRangeError exception. - Return
BigInt::toString (x, radixMV).
This method is not generic; it throws a
21.2.3.4 BigInt.prototype.valueOf ( )
- Return ?
ThisBigIntValue (this value).
21.2.3.4.1 ThisBigIntValue ( value )
The abstract operation ThisBigIntValue takes argument value (an
- If value
is a BigInt , return value. - If value
is an Object and value has a [[BigIntData]] internal slot, thenAssert : value.[[BigIntData]]is a BigInt .- Return value.[[BigIntData]].
- Throw a
TypeError exception.
21.2.3.5 BigInt.prototype [ @@toStringTag ]
The initial value of the
This property has the attributes { [[Writable]]:
21.2.4 Properties of BigInt Instances
BigInt instances are