bitwise-flag - v2.1.0
    Preparing search index...

    Class BigIntCombinatorInternal

    Implements Combinator for JavaScript's built-in bigint type using native arbitrary-precision bitwise operators.

    Every operation delegates directly to JavaScript's |, &, ^, ~ and << operators on bigint values. Unlike the number-based counterpart, bigint is not constrained to a fixed word size: the effective flag space is unbounded, and results are never truncated or sign-coerced by the engine.

    bigint uses two's complement with conceptually infinite precision: negative values represent an infinite sequence of leading 1 bits. This makes not always produce a negative result for any non-negative input, and makes popcount reject negative inputs rather than silently reinterpret them.

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    zero: 0n

    Neutral element for bitwise OR — a bigint with no bits set.

    Methods

    • Returns the bitwise AND of a and ~b. Same as combinator.and(a, combinator.not(b))

      Parameters

      • a: bigint

        First operand.

      • b: bigint

        Second operand.

      Returns bigint

      a & ~b as a bigint.

    • Counts the number of set bits (population count) in a.

      Unlike the number variant, negative bigint values cannot be reinterpreted as unsigned because bigint has no fixed width and a negative value conceptually has infinitely many set bits. Passing a negative value throws a RangeError with the offending value included in the message.

      Parameters

      • a: bigint

        Non-negative value whose set bits are counted.

      Returns number

      The count of bits set to 1 in a.

      If a is negative.

      c.popcount(0n)                // → 0
      c.popcount(0b0111n) // → 3
      c.popcount((1n << 128n) - 1n) // → 128
      c.popcount(-1n) // throws RangeError
    • Shifts value left by shift bit positions.

      The shift argument is a plain number and is converted to BigInt(shift) internally. Unlike the number variant, there is no 31-bit cap — values shifted beyond bit 31 or bit 63 remain exact and positive.

      Parameters

      • value: bigint

        Value to shift.

      • shift: number

        Number of positions to shift left (no upper bound enforced).

      Returns bigint

      value << BigInt(shift) as a bigint.

      c.shiftL(1n, 31)  // → 2147483648n  (not −2147483648 like number)
      c.shiftL(1n, 100) // → 2n ** 100n