Readonlyabs: (x: WithSmallInt<SafeInt, 40>) => IntersectBrand<SafeInt, NonNegativeNumber>Returns the absolute value of a safe integer.
The result is non-negative and keeps the SafeInt brand.
Readonlyadd: (x: WithSmallInt<SafeInt, 40>, y: WithSmallInt<SafeInt, 40>) => SafeIntAdds two safe integers, returning a + b as a SafeInt.
Readonlydiv: (Divides two safe integers using floor division (⌊a / b⌋): the result is
a / b rounded toward negative infinity, as a SafeInt.
ReadonlyfromNumber: (x: number) => SafeIntConverts 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.
Readonlyis: (a: number) => a is SafeIntType 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, 40>[]) => SafeIntReturns the largest of the given safe integers.
ReadonlyMAX_VALUE: SafeUintThe largest value representable as SafeInt (the upper saturation target
of fromNumber).
Readonlymin: (...values: readonly WithSmallInt<SafeInt, 40>[]) => SafeIntReturns the smallest of the given safe integers.
ReadonlyMIN_VALUE: SafeIntThe smallest value representable as SafeInt (the lower saturation target
of fromNumber).
Readonlymul: (x: WithSmallInt<SafeInt, 40>, y: WithSmallInt<SafeInt, 40>) => SafeIntMultiplies two safe integers, returning a * b as a SafeInt.
Readonlypow: (x: WithSmallInt<SafeInt, 40>, y: WithSmallInt<SafeInt, 40>) => SafeIntRaises a to the power b, returning a ** b as a SafeInt (floored to
an integer).
Readonlyrandom: (min?: WithSmallInt<SafeInt, 40>, max?: WithSmallInt<SafeInt, 40>) => SafeIntGenerates a random SafeInt within the given range.
The range is inclusive on both ends.
Readonlysub: (x: WithSmallInt<SafeInt, 40>, y: WithSmallInt<SafeInt, 40>) => SafeIntSubtracts 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.