ts-data-forge
    Preparing search index...
    Uint: {
        add: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt;
        clamp: (x: number) => NonNegativeInt;
        div: (
            x: WithSmallInt,
            y: ToNonZeroIntWithSmallInt<NonNegativeInt>,
        ) => NonNegativeInt;
        is: (a: number) => a is NonNegativeInt;
        max: (
            ...values: readonly WithSmallInt<NonNegativeInt, 40>[],
        ) => NonNegativeInt;
        min: (
            ...values: readonly WithSmallInt<NonNegativeInt, 40>[],
        ) => NonNegativeInt;
        MIN_VALUE: 0;
        mul: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt;
        pow: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt;
        random: (
            min?: WithSmallInt<NonNegativeInt, 40>,
            max?: WithSmallInt<NonNegativeInt, 40>,
        ) => NonNegativeInt;
        sub: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt;
    } = ...

    Namespace providing type-safe arithmetic operations for unsigned integers.

    All operations maintain the non-negative constraint by clamping negative results to 0. This ensures that all arithmetic preserves the unsigned integer property.

    Type Declaration

    • add: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt

      Adds two Uint values.

      const sum = Uint.add(asUint(5), asUint(8));

      assert(sum === 13);
    • clamp: (x: number) => NonNegativeInt

      Clamps a number to the Uint range (non-negative).

      const clampedNegative = Uint.clamp(-5);
      const clampedPositive = Uint.clamp(42);

      assert(clampedNegative === 0);
      assert(clampedPositive === 42);
    • div: (x: WithSmallInt, y: ToNonZeroIntWithSmallInt<NonNegativeInt>) => NonNegativeInt

      Divides one Uint by another using floor division.

      const quotient = Uint.div(asUint(10), asUint(4));

      assert(quotient === 2);
    • is: (a: number) => a is NonNegativeInt

      Type guard to check if a value is a Uint.

      assert.ok(isUint(4));
      assert.notOk(isUint(-1));
      assert.ok(Uint.is(0));

      isUint for usage examples

    • Readonlymax: (...values: readonly WithSmallInt<NonNegativeInt, 40>[]) => NonNegativeInt

      Returns the larger of two Uint values.

      const largest = Uint.max(asUint(7), asUint(3));

      assert(largest === 7);
    • Readonlymin: (...values: readonly WithSmallInt<NonNegativeInt, 40>[]) => NonNegativeInt

      Returns the smaller of two Uint values.

      const smallest = Uint.min(asUint(7), asUint(3));

      assert(smallest === 3);
    • ReadonlyMIN_VALUE: 0

      The minimum value for an unsigned integer.

    • mul: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt

      Multiplies two Uint values.

      const product = Uint.mul(asUint(7), asUint(6));

      assert(product === 42);
    • pow: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt

      Raises a Uint to the power of another Uint.

      const base = asUint(2);
      const exponent = asUint(5);
      const power = Uint.pow(base, exponent);

      assert(power === 32);
    • random: (
          min?: WithSmallInt<NonNegativeInt, 40>,
          max?: WithSmallInt<NonNegativeInt, 40>,
      ) => NonNegativeInt

      Generates a random Uint value.

      const min = asUint(0);
      const max = asUint(3);
      const randomValue = Uint.random(min, max);

      assert.ok(Uint.is(randomValue));
      assert.ok(randomValue >= 0 && randomValue <= 3);
    • sub: (x: WithSmallInt, y: WithSmallInt) => NonNegativeInt

      Subtracts one Uint from another.

      const difference = Uint.sub(asUint(5), asUint(8));

      assert(difference === 0);