A class that represents a signed or unsigned integer of a specific bit size.

Constructors

Properties

Methods

Constructors

  • Creates a new CheckedBigInt. with custom boundaries

    Parameters

    • value: bigint

      initial value

    • bounds: Bounds

      the set boundaries for the instance

    Returns CheckedBigInt

    Example

    const a = new CheckedBigInt(1n, {min: 1n, max: 10n})
    
  • Creates a new CheckedBigInt. with a specific bit size and signedness

    Parameters

    • value: bigint

      initial value

    • bits: number

      the bit size of the integer

    • signed: boolean

      whether the integer is signed or not

    Returns CheckedBigInt

    Example

    const a = new CheckedBigInt(1n /* value */, 8 /*bits*/, false/*unsigned*/)
    

Properties

boundaries: Bounds
value: bigint

Methods

  • Add another integer to this integer, checking for overflow.

    Parameters

    • other: bigint

      The integer to add.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the addition.

    Throws

    RangeError If the result of the addition would exceed the bit size.

    Example

    const a = i8(1n).add(1n) // 2
    const b = i8(127n).add(1n) // throws RangeError
  • Divide this integer by another integer, checking for overflow.

    Parameters

    • other: bigint

      The integer to divide by.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the division.

    Throws

    RangeError If the result of the division would exceed the bit size.

    Throws

    RangeError If the divisor is zero.

  • Multiply this integer by another integer, checking for overflow.

    Parameters

    • other: bigint

      The integer to multiply by.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the multiplication.

    Throws

    RangeError If the result of the multiplication would exceed the bit size.

  • Power this integer to another integer, checking for overflow.

    Parameters

    • exponent: bigint

      The integer to power by.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the power.

    Throws

    RangeError If the result of the power would exceed the bit size.

  • Remainder of the division of this integer by another integer, checking for overflow.

    Parameters

    • other: bigint

      The integer to divide by.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the remainder.

    Throws

    RangeError If the result of the remainder would exceed the bit size.

    Throws

    RangeError If the divisor is zero.

  • Bitwise shift left this integer by another integer, checking for overflow.

    Parameters

    • bits: number | bigint

      The integer to shift by.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the shift.

    Throws

    RangeError If the number of bits is negative.

    Throws

    RangeError If the resulting number would exceed the bit size.

  • Bitwise shift right this integer by another integer, checking for overflow.

    Parameters

    • bits: number | bigint

      The integer to shift by.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the shift.

    Throws

    RangeError If the number of bits is negative.

    Throws

    RangeError If bits is greater than the bit size.

  • Subtract another integer from this integer, checking for overflow.

    Parameters

    • other: bigint

      The integer to subtract.

    Returns CheckedBigInt

    A new CheckedBigInt with the result of the subtraction.

    Throws

    RangeError If the result of the subtraction would exceed the bit size.

Generated using TypeDoc