ts-fortress
    Preparing search index...

    Variable PositiveSafeInt

    PositiveSafeInt: {
        add: (
            x: WithSmallInt<PositiveSafeInt, 40>,
            y: WithSmallInt<PositiveSafeInt, 40>,
        ) => PositiveSafeInt;
        div: (
            x: WithSmallInt<PositiveSafeInt, 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;
                        SafeInt: true;
                    } & Readonly<
                        {
                            "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                        },
                    >,
                >,
        ) => PositiveSafeInt;
        fromNumber: (x: number) => PositiveSafeInt;
        is: (a: number) => a is PositiveSafeInt;
        max: (
            ...values: readonly WithSmallInt<PositiveSafeInt, 40>[],
        ) => PositiveSafeInt;
        MAX_VALUE: SafeUint;
        min: (
            ...values: readonly WithSmallInt<PositiveSafeInt, 40>[],
        ) => PositiveSafeInt;
        MIN_VALUE: 1;
        mul: (
            x: WithSmallInt<PositiveSafeInt, 40>,
            y: WithSmallInt<PositiveSafeInt, 40>,
        ) => PositiveSafeInt;
        pow: (
            x: WithSmallInt<PositiveSafeInt, 40>,
            y: WithSmallInt<PositiveSafeInt, 40>,
        ) => PositiveSafeInt;
        random: (
            min?: WithSmallInt<PositiveSafeInt, 40>,
            max?: WithSmallInt<PositiveSafeInt, 40>,
        ) => PositiveSafeInt;
        sub: (
            x: WithSmallInt<PositiveSafeInt, 40>,
            y: WithSmallInt<PositiveSafeInt, 40>,
        ) => PositiveSafeInt;
    }

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

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

    Type Declaration

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

      Adds two positive safe integers, returning a + b as a PositiveSafeInt.

      const sum = PositiveSafeInt.add(
      asPositiveSafeInt(1000),
      asPositiveSafeInt(2048),
      );

      assert.isTrue(sum === 3048);

      assert.isTrue(PositiveSafeInt.is(sum));
    • Readonlydiv: (
          x: WithSmallInt<PositiveSafeInt, 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;
                      SafeInt: true;
                  } & Readonly<
                      {
                          "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                      },
                  >,
              >,
      ) => PositiveSafeInt

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

      const quotient = PositiveSafeInt.div(
      asPositiveSafeInt(25),
      asPositiveSafeInt(4),
      );

      const clamped = PositiveSafeInt.div(
      asPositiveSafeInt(5),
      asPositiveSafeInt(50),
      );

      assert.isTrue(quotient === 6);

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

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

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

      const belowRange = PositiveSafeInt.fromNumber(0);

      const withinRange = PositiveSafeInt.fromNumber(123);

      const aboveRange = PositiveSafeInt.fromNumber(Number.MAX_SAFE_INTEGER + 10);

      assert.isTrue(belowRange === 1);

      assert.isTrue(withinRange === 123);

      assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
    • Readonlyis: (a: number) => a is PositiveSafeInt

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

      assert.isTrue(isPositiveSafeInt(1));

      assert.isTrue(isPositiveSafeInt(Number.MAX_SAFE_INTEGER));

      assert.isFalse(isPositiveSafeInt(0));

      assert.isTrue(PositiveSafeInt.is(42));

      isPositiveSafeInt for usage examples

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

      Returns the largest of the given positive safe integers.

      const largest = PositiveSafeInt.max(
      asPositiveSafeInt(10),
      asPositiveSafeInt(5),
      );

      assert.isTrue(largest === 10);
    • ReadonlyMAX_VALUE: SafeUint

      The largest value representable as PositiveSafeInt (the upper saturation target of fromNumber).

    • Readonlymin: (...values: readonly WithSmallInt<PositiveSafeInt, 40>[]) => PositiveSafeInt

      Returns the smallest of the given positive safe integers.

      const smallest = PositiveSafeInt.min(
      asPositiveSafeInt(10),
      asPositiveSafeInt(5),
      );

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

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

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

      Multiplies two positive safe integers, returning a * b as a PositiveSafeInt.

      const product = PositiveSafeInt.mul(
      asPositiveSafeInt(50),
      asPositiveSafeInt(20),
      );

      assert.isTrue(product === 1000);

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

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

      const base = asPositiveSafeInt(3);

      const exponent = asPositiveSafeInt(3);

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

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

      Generates a random PositiveSafeInt within the given range.

      The range is inclusive on both ends.

      const min = asPositiveSafeInt(1);

      const max = asPositiveSafeInt(6);

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

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

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

      Subtracts two positive safe integers, returning a - b as a PositiveSafeInt.

      const difference = PositiveSafeInt.sub(
      asPositiveSafeInt(10),
      asPositiveSafeInt(20),
      );

      assert.isTrue(difference === 1);

      assert.isTrue(PositiveSafeInt.is(difference));