BigIntMath: {
    abs(value): bigint;
    bitLength(bigint): number;
    ceilDivide(dividend, divisor): bigint;
    divide(dividend, divisor): {
        quotient: bigint;
        remainder: bigint;
    };
    max(...args): bigint;
    min(...args): bigint;
    rand(max): bigint;
    roundDivide(dividend, divisor): bigint;
    sign(value): -1 | 0 | 1;
} = ...

A collection of functions to perform mathematical operations on BigInts

Type declaration

  • abs:function
    • Returns the absolute value of a given number

      Parameters

      • value: BigIntable

        The value to get the absolute value of

      Returns bigint

      The absolute value of the input

      Example

      BigIntMath.abs(-1n) // 1n
      BigIntMath.abs(1n) // 1n
      BigIntMath.abs(-1) // 1n
      BigIntMath.abs("-1") // 1n
  • bitLength:function
    • Returns the number of bits required to represent a given number

      Parameters

      • bigint: BigIntable

        The number to get the bit length of

      Returns number

      The number of bits required to represent the input number

  • ceilDivide:function
    • Returns the quotient of a division between two numbers, rounded up

      Parameters

      Returns bigint

      The quotient of the division, rounded up

      Example

      BigIntMath.ceilDivide(5n, 2n) // 3n
      BigIntMath.ceilDivide(4n, 2n) // 2n
  • divide:function
    • Returns the quotient and remainder of a division between two numbers

      Parameters

      Returns {
          quotient: bigint;
          remainder: bigint;
      }

      The quotient and remainder of the division

      • quotient: bigint
      • remainder: bigint
  • max:function
    • Returns the maximum of a list of numbers

      Parameters

      • Rest ...args: BigIntable[]

        The numbers to get the maximum of

      Returns bigint

      The maximum of the input numbers transformed to a BigInt

      Example

      BigIntMath.max(1n, 2n, 3n) // 3n
      BigIntMath.max(1, 2n, "3") // 3n
  • min:function
    • Returns the minimum of a list of numbers

      Parameters

      • Rest ...args: BigIntable[]

        The numbers to get the minimum of

      Returns bigint

      The minimum of the input numbers transformed to a BigInt

      Example

      BigIntMath.min(1n, 2n, 3n) // 1n
      BigIntMath.min(1, 2n, "3") // 1n
  • rand:function
    • Returns a random number between 0 and a given maximum

      Parameters

      • max: bigint

        The maximum value of the random number

      Returns bigint

      A random number between 0 and the input maximum

      Remarks

      This function uses a cryptographically secure random number generator In Node.js, it uses crypto.randomBytes In browsers, it uses crypto.getRandomValues

      Example

      BigIntMath.rand(10n) // A random number between 0 and 10
      
  • roundDivide:function
    • Returns the quotient of a division between two numbers, rounded to the nearest integer

      Parameters

      Returns bigint

      The quotient of the division, rounded to the nearest integer

      Example

      BigIntMath.roundDivide(7n, 3n) // 2n
      BigIntMath.roundDivide(7n, 2n) // 4n (3.5 rounded to the nearest integer)
  • sign:function
    • Returns the sign of a given number

      Parameters

      Returns -1 | 0 | 1

      -1 if the value is negative, 0 if the value is 0, 1 if the value is positive

      Example

      BigIntMath.sign(-1n) // -1
      BigIntMath.sign(0n) // 0
      BigIntMath.sign(1n) // 1

Generated using TypeDoc