ts-data-forge
    Preparing search index...
    SafeUint: {
        add: (x: WithSmallInt, y: WithSmallInt) => SafeUint;
        div: (x: WithSmallInt, y: ToNonZeroIntWithSmallInt<SafeUint>) => SafeUint;
        fromNumber: (x: number) => SafeUint;
        is: (a: number) => a is SafeUint;
        max: (...values: readonly WithSmallInt<SafeUint>[]) => SafeUint;
        MAX_VALUE: SafeUint;
        min: (...values: readonly WithSmallInt<SafeUint>[]) => SafeUint;
        MIN_VALUE: 0;
        mul: (x: WithSmallInt, y: WithSmallInt) => SafeUint;
        pow: (x: WithSmallInt, y: WithSmallInt) => SafeUint;
        random: (
            min?: WithSmallInt<SafeUint>,
            max?: WithSmallInt<SafeUint>,
        ) => SafeUint;
        sub: (x: WithSmallInt, y: WithSmallInt) => SafeUint;
    }

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

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

    Type Declaration

    • add: (x: WithSmallInt, y: WithSmallInt) => SafeUint

      Adds two non-negative safe integers, returning a + b as a SafeUint.

    • div: (x: WithSmallInt, y: ToNonZeroIntWithSmallInt<SafeUint>) => SafeUint

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

    • fromNumber: (x: number) => SafeUint

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

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

    • is: (a: number) => a is SafeUint

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

      isSafeUint for usage examples

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

      Returns the largest of the given non-negative safe integers.

    • MAX_VALUE: SafeUint

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

    • Readonlymin: (...values: readonly WithSmallInt<SafeUint>[]) => SafeUint

      Returns the smallest of the given non-negative safe integers.

    • MIN_VALUE: 0

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

    • mul: (x: WithSmallInt, y: WithSmallInt) => SafeUint

      Multiplies two non-negative safe integers, returning a * b as a SafeUint.

    • pow: (x: WithSmallInt, y: WithSmallInt) => SafeUint

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

    • random: (min?: WithSmallInt<SafeUint>, max?: WithSmallInt<SafeUint>) => SafeUint

      Generates a random SafeUint within the given range.

      The range is inclusive on both ends.

    • sub: (x: WithSmallInt, y: WithSmallInt) => SafeUint

      Subtracts two non-negative safe integers, returning a - b as a SafeUint.