ts-data-forge
    Preparing search index...
    Int: {
        abs: (x: WithSmallInt) => IntersectBrand<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>[]) => Int;
        min: (...values: readonly WithSmallInt<Int>[]) => Int;
        mul: (x: WithSmallInt, y: WithSmallInt) => Int;
        pow: (x: WithSmallInt, y: WithSmallInt) => Int;
        random: (min?: WithSmallInt<Int>, max?: WithSmallInt<Int>) => Int;
        sub: (x: WithSmallInt, y: WithSmallInt) => Int;
    }

    Namespace providing type-safe operations for the Int branded type.

    The Int type represents an integer. Division (div) uses floor division.

    Unlike SafeInt, Int allows values outside the safe integer range (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's number type.

    Type Declaration

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

      Returns the absolute value of an integer.

      The result is non-negative and keeps 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.isTrue(absolute === 12);

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

      Adds two integers, returning a + b as an Int.

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

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

      Divides two integers using floor division (⌊a / b⌋): the result is a / b rounded toward negative infinity, as an Int.

      const dividend = asInt(17);

      const divisor = asInt(5);

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

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

      Type guard that checks if a value is an integer.

      assert.isTrue(isInt(5));

      assert.isFalse(isInt(5.25));

      assert.isTrue(Int.is(-10));

      isInt for usage examples

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

      Returns the largest of the given integers.

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

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

      Returns the smallest of the given integers.

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

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

      Multiplies two integers, returning a * b as an Int.

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

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

      Raises a to the power b, returning a ** b as an Int (floored to an integer).

      const base = asInt(2);

      const exponent = asInt(5);

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

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

      Generates a random Int within the given range.

      The range is inclusive on both ends.

      const min = asInt(1);

      const max = asInt(6);

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

      assert.isTrue(Int.is(randomValue));

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

      Subtracts two integers, returning a - b as an Int.

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

      assert.isTrue(difference === 4);