BigNum
constBigNum:object
Defined in: Data/BigNum.ts:17
Safe conversion and arithmetic utilities for arbitrary-precision integers (bigint).
All functions are pure and data-last to compose cleanly with pipe.
Type Declaration
Section titled “Type Declaration”abs: (
value) =>bigint
Returns absolute value of a bigint.
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”bigint
Example
Section titled “Example”add: (
amount) => (value) =>bigint
Adds amount to value. Data-last curried signature: add(amount)(value) = value + amount.
Parameters
Section titled “Parameters”amount
Section titled “amount”bigint
Returns
Section titled “Returns”(value) => bigint
BigNum.subtract to subtract an amount from a bigint.
Example
Section titled “Example”between
Section titled “between”between: (
min,max) => (value) =>boolean
Returns true when the bigint is between min and max (both inclusive).
Parameters
Section titled “Parameters”bigint
bigint
Returns
Section titled “Returns”(value) => boolean
BigNum.inRange for half-open range checking [start, end).
Example
Section titled “Example”clamp: (
min,max) => (value) =>bigint
Clamps value between min and max (inclusive).
Parameters
Section titled “Parameters”bigint
bigint
Returns
Section titled “Returns”(value) => bigint
Example
Section titled “Example”divide
Section titled “divide”divide: (
divisor) => (dividend) =>Maybe<bigint>
Divides dividend by divisor. Returns None if divisor is 0n.
Parameters
Section titled “Parameters”divisor
Section titled “divisor”bigint
Returns
Section titled “Returns”(dividend) => Maybe<bigint>
- BigNum.multiply to multiply a bigint by a factor.
- BigNum.remainder to compute the division remainder.
Example
Section titled “Example”from:
object
Safe constructors and converters from raw primitives to BigInt.
from.number
Section titled “from.number”number: (
value) =>Maybe<bigint>
Safely converts a number into a bigint. Returns None for floats, NaN, or non-safe integers.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Maybe<bigint>
Example
Section titled “Example”from.string
Section titled “from.string”string: (
text) =>Maybe<bigint>
Safely parses a string into a bigint. Returns None if parsing fails.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Maybe<bigint>
Example
Section titled “Example”inRange
Section titled “inRange”inRange: (
start,end) => (value) =>boolean
Returns true if value is in the range [start, end) (inclusive start, exclusive end).
Parameters
Section titled “Parameters”bigint
bigint
Returns
Section titled “Returns”(value) => boolean
BigNum.between for fully closed range checking [min, max].
Example
Section titled “Example”is:
object
Predicates and type guards for BigInt values.
is.even
Section titled “is.even”even: (
value) =>boolean
Returns true when the bigint is an even integer.
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”boolean
BigNum.is.odd to check if a bigint is odd.
Example
Section titled “Example”is.negative
Section titled “is.negative”negative: (
value) =>boolean
Returns true when the bigint is strictly less than zero (0n).
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”boolean
BigNum.is.positive to check if a bigint is greater than zero.
Example
Section titled “Example”is.odd
Section titled “is.odd”odd: (
value) =>boolean
Returns true when the bigint is an odd integer.
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”boolean
BigNum.is.even to check if a bigint is even.
Example
Section titled “Example”is.positive
Section titled “is.positive”positive: (
value) =>boolean
Returns true when the bigint is strictly greater than zero (0n).
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”boolean
BigNum.is.negative to check if a bigint is less than zero.
Example
Section titled “Example”is.zero
Section titled “is.zero”zero: (
value) =>boolean
Returns true when the bigint is equal to zero (0n).
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”boolean
Example
Section titled “Example”max: (
values) =>Maybe<bigint>
Computes the maximum of a list of bigints. Returns None if the list is empty.
Parameters
Section titled “Parameters”values
Section titled “values”readonly bigint[]
Returns
Section titled “Returns”Maybe<bigint>
BigNum.min to compute the minimum value.
Example
Section titled “Example”min: (
values) =>Maybe<bigint>
Computes the minimum of a list of bigints. Returns None if the list is empty.
Parameters
Section titled “Parameters”values
Section titled “values”readonly bigint[]
Returns
Section titled “Returns”Maybe<bigint>
BigNum.max to compute the maximum value.
Example
Section titled “Example”multiply
Section titled “multiply”multiply: (
factor) => (value) =>bigint
Multiplies value by factor. Data-last curried signature: multiply(factor)(value) = value * factor.
Parameters
Section titled “Parameters”factor
Section titled “factor”bigint
Returns
Section titled “Returns”(value) => bigint
BigNum.divide to divide a bigint by a divisor.
Example
Section titled “Example”remainder
Section titled “remainder”remainder: (
divisor) => (dividend) =>Maybe<bigint>
Computes remainder of dividend / divisor. Returns None if divisor is 0n.
Parameters
Section titled “Parameters”divisor
Section titled “divisor”bigint
Returns
Section titled “Returns”(dividend) => Maybe<bigint>
BigNum.divide for full division.
Example
Section titled “Example”subtract
Section titled “subtract”subtract: (
amount) => (from) =>bigint
Subtracts amount from from. Data-last curried signature: subtract(amount)(from) = from - amount.
Parameters
Section titled “Parameters”amount
Section titled “amount”bigint
Returns
Section titled “Returns”(from) => bigint
BigNum.add to add an amount to a bigint.
Example
Section titled “Example”sum: (
values) =>bigint
Computes the sum of a list of bigints. Returns 0n if the list is empty.
Parameters
Section titled “Parameters”values
Section titled “values”readonly bigint[]
Returns
Section titled “Returns”bigint
Example
Section titled “Example”to:
object
Converters from BigInt to native types.
to.number
Section titled “to.number”number: (
value) =>Maybe<number>
Safely converts a bigint to a number. Returns None if the value is outside JavaScript’s safe integer range.
Parameters
Section titled “Parameters”bigint
Returns
Section titled “Returns”Maybe<number>