Returns the absolute value of a safe integer.
The result is non-negative and keeps the SafeInt brand.
Adds two safe integers, returning a + b as a SafeInt.
Divides two safe integers using floor division (⌊a / b⌋): the result is
a / b rounded toward negative infinity, as a SafeInt.
Converts an arbitrary number into a SafeInt, rounding to the nearest
integer and saturating the result into the range [MIN_VALUE, MAX_VALUE].
Unlike asSafeInt, this is total: out-of-range inputs are clamped to the
nearest representable SafeInt instead of throwing.
Type guard that checks if a value is a safe integer.
assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));
assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));
assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
isSafeInt for usage examples
Readonlymax: (...values: readonly WithSmallInt<SafeInt>[]) => SafeIntReturns the largest of the given safe integers.
The largest value representable as SafeInt (the upper saturation target
of fromNumber).
Readonlymin: (...values: readonly WithSmallInt<SafeInt>[]) => SafeIntReturns the smallest of the given safe integers.
The smallest value representable as SafeInt (the lower saturation target
of fromNumber).
Multiplies two safe integers, returning a * b as a SafeInt.
Raises a to the power b, returning a ** b as a SafeInt (floored to
an integer).
Generates a random SafeInt within the given range.
The range is inclusive on both ends.
Subtracts two safe integers, returning a - b as a SafeInt.
Namespace providing type-safe operations for the
SafeIntbranded type.The
SafeInttype represents a safe integer. Division (div) uses floor division.