Adds two positive safe integers, returning a + b as a PositiveSafeInt.
Divides two positive safe integers using floor division (⌊a / b⌋): the
result is a / b rounded toward negative infinity, as a 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);
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>[]) => PositiveSafeIntReturns the largest of the given positive safe integers.
The largest value representable as PositiveSafeInt (the upper saturation
target of fromNumber).
Readonlymin: (...values: readonly WithSmallInt<PositiveSafeInt>[]) => PositiveSafeIntReturns the smallest of the given positive safe integers.
The smallest value representable as PositiveSafeInt (the lower saturation
target of fromNumber).
Multiplies two positive safe integers, returning a * b as a
PositiveSafeInt.
Raises a to the power b, returning a ** b as a PositiveSafeInt
(floored to an integer).
Generates a random PositiveSafeInt within the given range.
The range is inclusive on both ends.
Subtracts two positive safe integers, returning a - b as a
PositiveSafeInt.
Namespace providing type-safe operations for the
PositiveSafeIntbranded type.The
PositiveSafeInttype represents a positive safe integer. Division (div) uses floor division.