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

    Namespace providing type-safe operations for Int branded types.

    The Int type represents any integer value (no fractional component) without range restrictions. All operations preserve the integer constraint, using floor division for division operations.

    Unlike SafeInt, Int allows values outside the safe integer range (±2^53 - 1), but be aware that very large integers may lose precision in JavaScript's number type.

    Type Declaration

    • abs: (x: WithSmallInt) => ToNonNegative<Int>

      Returns the absolute value of an integer.

      The result is always non-negative and maintains the Int brand. Note that Math.abs(Number.MIN_SAFE_INTEGER) exceeds Number.MAX_SAFE_INTEGER, so use SafeInt for guaranteed precision.

      const negative = asInt(-12);
      const absolute = Int.abs(negative);

      assert(absolute === 12);
      assert.ok(Int.is(absolute));
    • add: (x: WithSmallInt, y: WithSmallInt) => Int

      Adds two integers.

      const sum = Int.add(asInt(12), asInt(8));

      assert(sum === 20);
    • div: (x: WithSmallInt, y: ToNonZeroIntWithSmallInt<Int>) => Int

      Divides two integers using floor division.

      Performs mathematical floor division: ⌊a / b⌋. The result is always an integer, rounding toward negative infinity.

      const dividend = asInt(17);
      const divisor = asInt(5);
      const quotient = Int.div(dividend, divisor);

      assert(quotient === 3);
    • is: (a: number) => a is Int

      Type guard that checks if a value is an integer.

      assert.ok(isInt(5));
      assert.notOk(isInt(5.25));
      assert.ok(Int.is(-10));

      isInt for usage examples

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

      Returns the maximum value from a list of integers.

      const largest = Int.max(asInt(7), asInt(-3), asInt(2));

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

      Returns the minimum value from a list of integers.

      const smallest = Int.min(asInt(7), asInt(-3), asInt(2));

      assert(smallest === -3);
    • mul: (x: WithSmallInt, y: WithSmallInt) => Int

      Multiplies two integers.

      const product = Int.mul(asInt(-4), asInt(6));

      assert(product === -24);
    • pow: (x: WithSmallInt, y: WithSmallInt) => Int

      Raises an integer to a power.

      const base = asInt(2);
      const exponent = asInt(5);
      const power = Int.pow(base, exponent);

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

      Generates a random integer within the specified range (inclusive).

      The range is inclusive on both ends, so random(1, 6) can return any of: 1, 2, 3, 4, 5, or 6.

      const min = asInt(1);
      const max = asInt(6);
      const randomValue = Int.random(min, max);

      assert.ok(Int.is(randomValue));
      assert.ok(randomValue >= 1 && randomValue <= 6);
    • sub: (x: WithSmallInt, y: WithSmallInt) => Int

      Subtracts two integers.

      const difference = Int.sub(asInt(12), asInt(8));

      assert(difference === 4);