Ƭ T: bigint
Represents a very large integer.
Since
4.0.0
▸ guard(x
): x is bigint
Checks if a parameter x
is a BigInt
Example
import { BigInt } from 'tiinvo'
BigInt.guard(10) // false
BigInt.guard(10n) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
x |
unknown |
the parameter to check |
x is bigint
returns true if is a bigint, false otherwise
▸ cmp(a
, b
): ComparableResult
Compares two BigInt
a
and b
Example
import { BigInt } from 'tiinvo'
BigInt.cmp(1n, 0n) // 1
BigInt.cmp(0n, 0n) // 0
BigInt.cmp(0n, 1n) // -1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
b |
bigint |
- |
a
is less than b
a
is equal to b
a
is more than b
▸ cmp(a
): Unary
<T
, ComparableResult
>
Returns a unary function which compares two BigInt
b
and a
Example
import { BigInt } from 'tiinvo'
const cmp0 = BigInt.cmp(0n)
cmp0(0n) // 0
cmp0(1n) // -1
cmp0(-1n) // 1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
the unary function
▸ eq(a
, b
): boolean
Checks if a
and b
are equal
Example
import { BigInt } from 'tiinvo'
BigInt.eq(10n, 10n) // true
BigInt.eq(10n, 5n) // false
BigInt.eq(10n, 10 as any) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
b |
bigint |
the second bigint |
boolean
true if two bigints are equal
Returns a unary function which checks if b
and a
are equal
Example
import { BigInt } from 'tiinvo'
const is10n = BigInt.eq(10n)
is10n(10n) // true
is10n(5n) // false
is10n(10 as any) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
the unary function
▸ map<A
>(a
, m
): T
<A
>
Maps a bigint a
to a value Result.Ok<b>
if a is bigint
,
otherwise returns Result.Err
.
Example
import { BigInt } from 'tiinvo';
const toHex = BigInt.map(x => '0x' + x.toString(16))
BigInt.map(10n, x => '0x' + x.toString(16)) // "0xa"
BigInt.map("a", x => '0x' + x.toString(16)) // TypeError("a is not a bigint")
Since
4.0.0
Name | Description |
---|---|
A |
the mapped value |
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
m |
Mappable <bigint , A > |
the mappable functor |
T
<A
>
the mapped value or TypeError if a
is not a bigint
Returns a unary function which maps a bigint a
to
a value Result.Ok<b>
if a is bigint
, otherwise returns Result.Err
.
Example
import { BigInt } from 'tiinvo';
const toHex = BigInt.map(x => '0x' + x.toString(16))
toHex(10n) // "0xa"
toHex("a") // TypeError("a is not a bigint")
Since
4.0.0
Name | Description |
---|---|
A |
the mapped value |
Name | Type | Description |
---|---|---|
a |
Mappable <bigint , A > |
the mappable functor |
the unary function
▸ mapOr<A
>(a
, m
, b
): A
Maps a bigint a
to a value of type B
if a is bigint
, otherwise returns b
.
Example
import { BigInt } from 'tiinvo';
const toHex = BigInt.mapOr(x => '0x' + x.toString(16), "0x0")
toHex(10n) // "0xa"
toHex("a") // "0x0"
Since
4.0.0
Name | Description |
---|---|
A |
the mapped value type |
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
m |
Mappable <bigint , A > |
the mappable functor |
b |
A |
the fallback value |
A
Returns a unary function which maps a bigint b
to a value of type B
if a is bigint
, otherwise returns m
.
Example
import { BigInt } from 'tiinvo';
const toHex = BigInt.mapOr(x => '0x' + x.toString(16), "0x0")
toHex(10n) // "0xa"
toHex("a") // "0x0"
Since
4.0.0
Name | Description |
---|---|
A |
the mapped value type |
Name | Type | Description |
---|---|---|
a |
Mappable <bigint , A > |
the bigint |
m |
A |
the mappable functor |
the unary function
▸ add(a
, b
): T
Adds a
to b
Example
import { BigInt } from 'tiinvo';
BigInt.add(5n, -2n) // 3n
BigInt.add(5n, 12n) // 17n
const add5 = BigInt.add(5n)
add5(10n) // 15n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
b |
bigint |
the second bigint |
the result
Returns a unary function which adds a
to b
Example
import { BigInt } from 'tiinvo';
const add5 = BigInt.add(5n)
add5(10n) // 15n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
▸ div(a
, b
): T
Divides a
by b
.
Example
import { BigInt } from 'tiinvo';
BigInt.div(4n, 2n) // 2n
BigInt.div(12n, 3n) // 4n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
first value (top of division) |
b |
bigint |
second value (bottom of division) |
the result
Returns a unary function which divides a
by b
.
Example
import { BigInt } from 'tiinvo';
BigInt.div(4n, 2n) // 2n
BigInt.div(12n, 3n) // 4n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
second value (bottom of division) |
the unary function
▸ mod(a
, b
): T
Returns the remainder of the division of a
by b
Example
import { BigInt } from 'tiinvo';
BigInt.mod(2n, 2n) // 0n
BigInt.mod(3n, 2n) // 1n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the value |
b |
bigint |
the modulus |
the remainder
Returns a unary function which returns the remainder of the division of b
by a
Example
import { BigInt } from 'tiinvo';
const mod2 = BigInt.mod(2n)
mod2(10n) // 0n
mod2(15n) // 1n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the value |
the unary function
▸ mul(a
, b
): T
Multiplies a
to b
Example
import { BigInt } from 'tiinvo';
BigInt.mul(5n, -2n) // -10n
BigInt.mul(5n, 12n) // 60n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
b |
bigint |
the second bigint |
the result
Returns a Unary<T, T>
function which once called multiplies b
to a
Example
import { BigInt } from 'tiinvo';
const mul5 = BigInt.mul(5n)
mul5(10n) // 50n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
the unary function
▸ pow(a
, b
): T
Elevates a
by b
Example
import { BigInt } from 'tiinvo';
BigInt.pow(2n, 3n) // 8n
BigInt.pow(3n, 2n) // 9n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
b |
bigint |
the second bigint |
the result
Returns a Unary<T, T>
function which once called elevates b
by a
Example
import { BigInt } from 'tiinvo';
const pow5 = BigInt.pow(5n)
pow5(10n) // 100_000n
Since
4.0.0
Name | Type |
---|---|
a |
bigint |
▸ root(a
, b
): T
Root of a
under b
if both specified, otherwise returns a Unary<T, T>
function which once called returns the root of b
under a
Example
import { BigInt } from 'tiinvo';
BigInt.root(4n, 2n) // 2n
BigInt.root(9n, 2n) // 3n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
b |
bigint |
the root |
Returns a Unary<T, T>
function which once called returns the root of b
under a
Example
import { BigInt } from 'tiinvo';
const root2 = BigInt.root(2n)
root2(4n) // 2n
root2(9n) // 3n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the root |
the unary function
▸ sub(a
, b
): T
Subtracts b
to a
Example
import { BigInt } from 'tiinvo';
BigInt.sub(5n, -2n) // 7n
BigInt.sub(5n, 12n) // -7n
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first bigint |
b |
bigint |
the second bigint |
a - b
Returns a Unary<T, T>
function which once called subtracts a
to b
Example
import { BigInt } from 'tiinvo';
const sub5 = BigInt.sub(5n)
sub5(10n) // 5n
sub5(-2n) // -7n
Since
4.0.0
Name | Type |
---|---|
a |
bigint |
the unary function (b - a)
▸ asc(a
, b
): ComparableResult
Compares two bigints a
and b
if b
Great to sort a bigint array in ASC direction.
Example
import { BigInt } from 'tiinvo';
const collection = [10n, 5n, 6n, 4n, 12n, 22n, 3n];
collection.sort(BigInt.asc) // [3n, 4n, 5n, 6n, 10n, 12n, 22n]
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first comparison bigint |
b |
bigint |
the second comparison bigint |
the result:
▸ asc(a
): Unary
<T
, ComparableResult
>
Returns a Unary<T, T>
function which once called compares b
and a
Example
import { BigInt } from 'tiinvo';
BigInt.asc(1n)(2n) // 1
BigInt.asc(1n)(1n) // 0
BigInt.asc(1n)(0n) // -1
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
the comparator unary function
▸ desc(a
, b
): ComparableResult
Compares two numbers b
and a
if b
is defined, otherwise returns a
Unary<number, number>
function which once called compares a
and b
Great to sort a numeric array in DESC direction.
Example
import { BigInt } from 'tiinvo';
const collection = [10n, 5n, 6n, 4n, 12n, 22n, 3n];
collection.sort(BigInt.desc) // [22n, 12n, 10n, 6n, 5n, 4n, 3n]
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the first comparison bigint |
b |
bigint |
the second comparison bigint |
the result:
▸ desc(a
): Unary
<T
, ComparableResult
>
Name | Type |
---|---|
a |
bigint |
▸ toBin(a
): T
<string
>
Returns a bigint in binary notation.
If the passed argument at runtime is not a bigint, an Error will be returned.
Example
import { BigInt } from 'tiinvo';
BigInt.toBin(10n) // "0b1010"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
T
<string
>
the binary bigint value
▸ toHex(a
): T
<string
>
Returns a bigint in hexadecimal notation
If the passed argument at runtime is not a bigint, an Error will be returned.
Example
import { BigInt } from 'tiinvo';
BigInt.toHex(10n) // "0xa"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
T
<string
>
the hexadecimal bigint value
▸ toOct(a
): T
<string
>
Returns a bigint in octal notation
If the passed argument at runtime is not a bigint, an Error will be returned.
Example
import { BigInt } from 'tiinvo';
BigInt.toOct(10n) // "0o12"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
T
<string
>
the octal bigint value
▸ toJSON(a
): T
<string
>
Returns a bigint in json notation.
If the passed argument at runtime is not a bigint, an Error will be returned.
Example
import { BigInt } from 'tiinvo';
BigInt.toJSON(10n) // "10"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
T
<string
>
the json bigint value
▸ toString(a
): T
<string
>
Returns a stringified number.
If the passed argument at runtime is not a bigint, an Error will be returned.
Example
import { BigInt } from 'tiinvo';
BigInt.toString(10n) // "10"
Since
4.0.0
Name | Type | Description |
---|---|---|
a |
bigint |
the bigint |
T
<string
>
the string