ts-fortress
    Preparing search index...

    Variable PositiveInt

    PositiveInt: {
        add: (
            x: WithSmallInt<PositiveInt, 40>,
            y: WithSmallInt<PositiveInt, 40>,
        ) => PositiveInt;
        div: (
            x: WithSmallInt<PositiveInt, 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
                | NormalizeBrandUnion<
                    number & {
                        "!=0": true;
                        "<=0": false;
                        "> -2^16": true;
                        "> -2^32": true;
                        ">= -2^15": true;
                        ">= -2^31": true;
                        ">=0": true;
                        Finite: true;
                        Int: true;
                        NaNValue: false;
                    } & Readonly<
                        {
                            "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                        },
                    >,
                >,
        ) => PositiveInt;
        fromNumber: (x: number) => PositiveInt;
        is: (a: number) => a is PositiveInt;
        max: (...values: readonly WithSmallInt<PositiveInt, 40>[]) => PositiveInt;
        min: (...values: readonly WithSmallInt<PositiveInt, 40>[]) => PositiveInt;
        MIN_VALUE: 1;
        mul: (
            x: WithSmallInt<PositiveInt, 40>,
            y: WithSmallInt<PositiveInt, 40>,
        ) => PositiveInt;
        pow: (
            x: WithSmallInt<PositiveInt, 40>,
            y: WithSmallInt<PositiveInt, 40>,
        ) => PositiveInt;
        random: (
            min?: WithSmallInt<PositiveInt, 40>,
            max?: WithSmallInt<PositiveInt, 40>,
        ) => PositiveInt;
        sub: (
            x: WithSmallInt<PositiveInt, 40>,
            y: WithSmallInt<PositiveInt, 40>,
        ) => PositiveInt;
    }

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

    The PositiveInt type represents a positive integer. Division (div) uses floor division.

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

    Type Declaration

    • Readonlyadd: (
          x: WithSmallInt<PositiveInt, 40>,
          y: WithSmallInt<PositiveInt, 40>,
      ) => PositiveInt

      Adds two positive integers, returning a + b as a PositiveInt.

      const sum = PositiveInt.add(asPositiveInt(4), asPositiveInt(5));

      assert.isTrue(sum === 9);
    • Readonlydiv: (
          x: WithSmallInt<PositiveInt, 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
              | NormalizeBrandUnion<
                  number & {
                      "!=0": true;
                      "<=0": false;
                      "> -2^16": true;
                      "> -2^32": true;
                      ">= -2^15": true;
                      ">= -2^31": true;
                      ">=0": true;
                      Finite: true;
                      Int: true;
                      NaNValue: false;
                  } & Readonly<
                      {
                          "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                      },
                  >,
              >,
      ) => PositiveInt

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

      const quotient = PositiveInt.div(asPositiveInt(9), asPositiveInt(2));

      const clamped = PositiveInt.div(asPositiveInt(3), asPositiveInt(10));

      assert.isTrue(quotient === 4);

      assert.isTrue(clamped === 1);
    • ReadonlyfromNumber: (x: number) => PositiveInt

      Converts an arbitrary number into a PositiveInt, rounding to the nearest integer and saturating the result into the range [MIN_VALUE, MAX_VALUE].

      Unlike asPositiveInt, this is total: out-of-range inputs are clamped to the nearest representable PositiveInt instead of throwing.

      const belowRange = PositiveInt.fromNumber(0);

      const withinRange = PositiveInt.fromNumber(10);

      assert.isTrue(belowRange === 1);

      assert.isTrue(withinRange === 10);
    • Readonlyis: (a: number) => a is PositiveInt

      Type guard that checks if a value is a positive integer.

      assert.isTrue(isPositiveInt(5));

      assert.isFalse(isPositiveInt(0));

      assert.isTrue(PositiveInt.is(10));

      isPositiveInt for usage examples

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

      Returns the largest of the given positive integers.

      const largest = PositiveInt.max(
      asPositiveInt(9),
      asPositiveInt(3),
      asPositiveInt(12),
      );

      assert.isTrue(largest === 12);
    • Readonlymin: (...values: readonly WithSmallInt<PositiveInt, 40>[]) => PositiveInt

      Returns the smallest of the given positive integers.

      const smallest = PositiveInt.min(
      asPositiveInt(9),
      asPositiveInt(3),
      asPositiveInt(12),
      );

      assert.isTrue(smallest === 3);
    • ReadonlyMIN_VALUE: 1

      The smallest value representable as PositiveInt (the lower saturation target of fromNumber).

    • Readonlymul: (
          x: WithSmallInt<PositiveInt, 40>,
          y: WithSmallInt<PositiveInt, 40>,
      ) => PositiveInt

      Multiplies two positive integers, returning a * b as a PositiveInt.

      const product = PositiveInt.mul(asPositiveInt(3), asPositiveInt(7));

      assert.isTrue(product === 21);
    • Readonlypow: (
          x: WithSmallInt<PositiveInt, 40>,
          y: WithSmallInt<PositiveInt, 40>,
      ) => PositiveInt

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

      const base = asPositiveInt(2);

      const exponent = asPositiveInt(4);

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

      assert.isTrue(power === 16);
    • Readonlyrandom: (
          min?: WithSmallInt<PositiveInt, 40>,
          max?: WithSmallInt<PositiveInt, 40>,
      ) => PositiveInt

      Generates a random PositiveInt within the given range.

      The range is inclusive on both ends.

      const min = asPositiveInt(3);

      const max = asPositiveInt(6);

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

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

      assert.isTrue(3 <= randomValue && randomValue <= 6);
    • Readonlysub: (
          x: WithSmallInt<PositiveInt, 40>,
          y: WithSmallInt<PositiveInt, 40>,
      ) => PositiveInt

      Subtracts two positive integers, returning a - b as a PositiveInt.

      const difference = PositiveInt.sub(asPositiveInt(5), asPositiveInt(7));

      assert.isTrue(difference === 1);