Const
Adds two positive integers, ensuring the result is never less than 1.
Clamps a number to the positive integer range.
Since PositiveInt has a minimum value of 1, this function ensures that any input less than 1 is clamped to 1.
Divides two positive integers using floor division, clamping to remain positive.
Performs mathematical floor division: ⌊a / b⌋
. If the result would be 0
(when a < b), it is clamped to 1 to maintain the positive integer
constraint.
Type guard that checks if a value is a positive integer.
isPositiveInt for usage examples
Readonly
max: (...values: readonly WithSmallInt<PositiveInt, 40>[]) => PositiveIntReturns the maximum value from a list of positive integers.
Readonly
min: (...values: readonly WithSmallInt<PositiveInt, 40>[]) => PositiveIntReturns the minimum value from a list of positive integers.
Since all inputs are guaranteed to be >= 1, the result is also guaranteed to be a positive integer.
Readonly
MIN_VALUE: 1The minimum value for a PositiveInt.
Multiplies two positive integers, ensuring the result is never less than 1.
Raises a positive integer to a power, ensuring the result is never less than 1.
Generates a random positive integer within the specified range (inclusive).
Both bounds are inclusive, and both min and max must be positive integers. If min > max, they are automatically swapped.
Subtracts two positive integers, clamping the result to remain positive.
If the mathematical result would be <= 0, it is clamped to 1 to maintain the positive integer constraint.
Namespace providing type-safe operations for PositiveInt branded types.
PositiveInt represents integers that are strictly greater than zero (>= 1). All operations automatically clamp results to maintain the positive constraint, ensuring that arithmetic operations never produce zero or negative values.
This type is essential for: