Class BigInt

A BigInt object is a wrapper for a primitive bigint value. bigint values can be numbers too large to be stored as number values.

A bigint literal in code is an integer number with an appended n.

Example:

1var hugeNumber = 1245678901234567890n;
2var hugeNumberObject = BigInt( hugeNumber );

API Version:

Available from version 22.7.

Note

Constructor Summary 

ConstructorDescription
BigInt()Constructs a BigInt with value 0.
BigInt(BigInt)Constructs a new BigInt using the specified BigInt.
BigInt(String)Constructs a BigInt using the specified value.

Method Summary 

MethodDescription
static asIntN(Number, BigInt)Clamps the given BigInt value to a signed integer with a given precision.
static asUintN(Number, BigInt)Clamps the given BigInt value to an unsigned integer with a given precision.
toLocaleString()Converts this BigInt to a String using local number formatting conventions.
toString()A String representation of this BigInt.
toString(Number)Converts the BigInt into a string using the specified radix (base).

Methods inherited from class Object 

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Constructor Details 

BigInt() 

BigInt()

Constructs a BigInt with value 0.


BigInt(BigInt) 

BigInt(value: BigInt)

Constructs a new BigInt using the specified BigInt.

Parameters:

  • value - the BigInt to use.

BigInt(String) 

BigInt(value: String)

Constructs a BigInt using the specified value.

Beside decimal numbers also binary, octal and hexadecimal numbers are supported:

1var decimal = BigInt( "12" );
2var binary  = BigInt( "0b1100" );
3var octal   = BigInt( "0o14" );
4var hex     = BigInt( "0xC" );

Parameters:

  • value - the value to use when creating the BigInt.

Method Details 

asIntN(Number, BigInt) 

static asIntN(bits: Number, value: BigInt): BigInt

Clamps the given BigInt value to a signed integer with a given precision.

Parameters:

  • bits - Number of bits required for resulting integer.
  • value - The value to be clamped to the given number of bits.

Returns:

  • The value modulo 2bits, as a signed integer.

asUintN(Number, BigInt) 

static asUintN(bits: Number, value: BigInt): BigInt

Clamps the given BigInt value to an unsigned integer with a given precision.

Parameters:

  • bits - Number of bits required for resulting integer.
  • value - The value to be clamped to the given number of bits.

Returns:

  • The value modulo 2bits, as an unsigned integer.

toLocaleString() 

toLocaleString(): String

Converts this BigInt to a String using local number formatting conventions.

The current implementation actually only returns the same as toString().

Returns:

  • a String using local number formatting conventions.

toString() 

toString(): String

A String representation of this BigInt.

Returns:

  • a String representation of this BigInt.

toString(Number) 

toString(radix: Number): String

Converts the BigInt into a string using the specified radix (base).

Parameters:

  • radix - the radix to use.

Returns:

  • a String representation of this BigInt.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!