ts-fortress
    Preparing search index...

    Variable Int

    Int: {
        abs: (
            x: WithSmallInt<Int, 40>,
        ) => IntersectBrand<Int, NonNegativeNumber>;
        add: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
        div: (
            x: WithSmallInt<Int, 40>,
            y:
                | 20
                | 1
                | 2
                | 10
                | 3
                | 4
                | 5
                | 6
                | 7
                | 8
                | 9
                | 11
                | 30
                | 18
                | 28
                | 38
                | 12
                | 13
                | 14
                | 15
                | 16
                | 17
                | 19
                | 21
                | 22
                | 23
                | 24
                | 25
                | 26
                | 27
                | 29
                | 31
                | 32
                | 33
                | 34
                | 35
                | 36
                | 37
                | 39
                | -20
                | -1
                | -2
                | -10
                | -3
                | -4
                | -5
                | -6
                | -7
                | -8
                | -9
                | -11
                | -30
                | -40
                | -18
                | -28
                | -38
                | -12
                | -13
                | -14
                | -15
                | -16
                | -17
                | -19
                | -21
                | -22
                | -23
                | -24
                | -25
                | -26
                | -27
                | -29
                | -31
                | -32
                | -33
                | -34
                | -35
                | -36
                | -37
                | -39
                | NormalizeBrandUnion<
                    number & { "!=0": true; Finite: true; Int: true; NaNValue: false } & Readonly<
                        {
                            "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                        },
                    >,
                >,
        ) => Int;
        is: (a: number) => a is Int;
        max: (...values: readonly WithSmallInt<Int, 40>[]) => Int;
        min: (...values: readonly WithSmallInt<Int, 40>[]) => Int;
        mul: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
        pow: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
        random: (min?: WithSmallInt<Int, 40>, max?: WithSmallInt<Int, 40>) => Int;
        sub: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => 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

    • Readonlyabs: (x: WithSmallInt<Int, 40>) => IntersectBrand<Int, NonNegativeNumber>

      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));
    • Readonlyadd: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int

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

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

      assert.isTrue(sum === 20);
    • Readonlydiv: (
          x: WithSmallInt<Int, 40>,
          y:
              | 20
              | 1
              | 2
              | 10
              | 3
              | 4
              | 5
              | 6
              | 7
              | 8
              | 9
              | 11
              | 30
              | 18
              | 28
              | 38
              | 12
              | 13
              | 14
              | 15
              | 16
              | 17
              | 19
              | 21
              | 22
              | 23
              | 24
              | 25
              | 26
              | 27
              | 29
              | 31
              | 32
              | 33
              | 34
              | 35
              | 36
              | 37
              | 39
              | -20
              | -1
              | -2
              | -10
              | -3
              | -4
              | -5
              | -6
              | -7
              | -8
              | -9
              | -11
              | -30
              | -40
              | -18
              | -28
              | -38
              | -12
              | -13
              | -14
              | -15
              | -16
              | -17
              | -19
              | -21
              | -22
              | -23
              | -24
              | -25
              | -26
              | -27
              | -29
              | -31
              | -32
              | -33
              | -34
              | -35
              | -36
              | -37
              | -39
              | NormalizeBrandUnion<
                  number & { "!=0": true; Finite: true; Int: true; NaNValue: false } & Readonly<
                      {
                          "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                      },
                  >,
              >,
      ) => 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);
    • Readonlyis: (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, 40>[]) => 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, 40>[]) => Int

      Returns the smallest of the given integers.

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

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

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

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

      assert.isTrue(product === -24);
    • Readonlypow: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => 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);
    • Readonlyrandom: (min?: WithSmallInt<Int, 40>, max?: WithSmallInt<Int, 40>) => 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(1 <= randomValue && randomValue <= 6);
    • Readonlysub: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int

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

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

      assert.isTrue(difference === 4);