Const
Returns the absolute value of a given number
The value to get the absolute value of
The absolute value of the input
BigIntMath.abs(-1n) // 1n
BigIntMath.abs(1n) // 1n
BigIntMath.abs(-1) // 1n
BigIntMath.abs("-1") // 1n
Returns the number of bits required to represent a given number
The number to get the bit length of
The number of bits required to represent the input number
Returns the quotient of a division between two numbers, rounded up
The number to divide
The number to divide by
The quotient of the division, rounded up
BigIntMath.ceilDivide(5n, 2n) // 3n
BigIntMath.ceilDivide(4n, 2n) // 2n
Returns the quotient and remainder of a division between two numbers
The number to divide
The number to divide by
The quotient and remainder of the division
Returns the maximum of a list of numbers
Rest
...args: BigIntable[]The numbers to get the maximum of
The maximum of the input numbers transformed to a BigInt
BigIntMath.max(1n, 2n, 3n) // 3n
BigIntMath.max(1, 2n, "3") // 3n
Returns the minimum of a list of numbers
Rest
...args: BigIntable[]The numbers to get the minimum of
The minimum of the input numbers transformed to a BigInt
BigIntMath.min(1n, 2n, 3n) // 1n
BigIntMath.min(1, 2n, "3") // 1n
Returns a random number between 0 and a given maximum
The maximum value of the random number
A random number between 0 and the input maximum
This function uses a cryptographically secure random number generator
In Node.js, it uses crypto.randomBytes
In browsers, it uses crypto.getRandomValues
BigIntMath.rand(10n) // A random number between 0 and 10
Returns the quotient of a division between two numbers, rounded to the nearest integer
The number to divide
The number to divide by
The quotient of the division, rounded to the nearest integer
BigIntMath.roundDivide(7n, 3n) // 2n
BigIntMath.roundDivide(7n, 2n) // 4n (3.5 rounded to the nearest integer)
Returns the sign of a given number
The value to get the sign of
-1 if the value is negative, 0 if the value is 0, 1 if the value is positive
BigIntMath.sign(-1n) // -1
BigIntMath.sign(0n) // 0
BigIntMath.sign(1n) // 1
Generated using TypeDoc
A collection of functions to perform mathematical operations on BigInts