ts-fortress
    Preparing search index...

    Variable Uint

    Uint: {
        add: (
            x: WithSmallInt<NonNegativeInt, 40>,
            y: WithSmallInt<NonNegativeInt, 40>,
        ) => NonNegativeInt;
        div: (
            x: WithSmallInt<NonNegativeInt, 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;
                        "> -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;
                        },
                    >,
                >,
        ) => NonNegativeInt;
        fromNumber: (x: number) => NonNegativeInt;
        is: (a: number) => a is NonNegativeInt;
        max: (
            ...values: readonly WithSmallInt<NonNegativeInt, 40>[],
        ) => NonNegativeInt;
        min: (
            ...values: readonly WithSmallInt<NonNegativeInt, 40>[],
        ) => NonNegativeInt;
        MIN_VALUE: 0;
        mul: (
            x: WithSmallInt<NonNegativeInt, 40>,
            y: WithSmallInt<NonNegativeInt, 40>,
        ) => NonNegativeInt;
        pow: (
            x: WithSmallInt<NonNegativeInt, 40>,
            y: WithSmallInt<NonNegativeInt, 40>,
        ) => NonNegativeInt;
        random: (
            min?: WithSmallInt<NonNegativeInt, 40>,
            max?: WithSmallInt<NonNegativeInt, 40>,
        ) => NonNegativeInt;
        sub: (
            x: WithSmallInt<NonNegativeInt, 40>,
            y: WithSmallInt<NonNegativeInt, 40>,
        ) => NonNegativeInt;
    }

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

    The Uint type represents a non-negative integer. Division (div) uses floor division.

    Unlike SafeInt, Uint 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<NonNegativeInt, 40>,
          y: WithSmallInt<NonNegativeInt, 40>,
      ) => NonNegativeInt

      Adds two non-negative integers, returning a + b as an Uint.

      const sum = Uint.add(asUint(5), asUint(8));

      assert.isTrue(sum === 13);
    • Readonlydiv: (
          x: WithSmallInt<NonNegativeInt, 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;
                      "> -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;
                      },
                  >,
              >,
      ) => NonNegativeInt

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

      const quotient = Uint.div(asUint(10), asUint(4));

      assert.isTrue(quotient === 2);
    • ReadonlyfromNumber: (x: number) => NonNegativeInt

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

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

      const fromNegative = Uint.fromNumber(-5);

      const fromPositive = Uint.fromNumber(42);

      assert.isTrue(fromNegative === 0);

      assert.isTrue(fromPositive === 42);
    • Readonlyis: (a: number) => a is NonNegativeInt

      Type guard that checks if a value is a non-negative integer.

      assert.isTrue(isUint(4));

      assert.isFalse(isUint(-1));

      assert.isTrue(Uint.is(0));

      isUint for usage examples

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

      Returns the largest of the given non-negative integers.

      const largest = Uint.max(asUint(7), asUint(3));

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

      Returns the smallest of the given non-negative integers.

      const smallest = Uint.min(asUint(7), asUint(3));

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

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

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

      Multiplies two non-negative integers, returning a * b as an Uint.

      const product = Uint.mul(asUint(7), asUint(6));

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

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

      const base = asUint(2);

      const exponent = asUint(5);

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

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

      Generates a random Uint within the given range.

      The range is inclusive on both ends.

      const min = asUint(0);

      const max = asUint(3);

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

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

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

      Subtracts two non-negative integers, returning a - b as an Uint.

      const difference = Uint.sub(asUint(5), asUint(8));

      assert.isTrue(difference === 0);