tiinvo

tiinvo / Exports / BigInt

Namespace: BigInt

Table of contents

Type Aliases

Guards

Comparables

Mappables

Operables

Sortables

Serializables

Type Aliases

T

Ƭ T: bigint

Represents a very large integer.

Since

4.0.0

Defined in

src/BigInt.ts:10

Guards

guard

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

Parameters

Name Type Description
x unknown the parameter to check

Returns

x is bigint

returns true if is a bigint, false otherwise

Defined in

src/BigInt.ts:31

Comparables

cmp

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

Parameters

Name Type Description
a bigint the first bigint
b bigint -

Returns

ComparableResult

Defined in

src/BigInt.ts:59

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

Parameters

Name Type Description
a bigint the first bigint

Returns

Unary<T, ComparableResult>

the unary function

Defined in

src/BigInt.ts:81


eq

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

Parameters

Name Type Description
a bigint the first bigint
b bigint the second bigint

Returns

boolean

true if two bigints are equal

Defined in

src/BigInt.ts:111

eq(a): Unary<T, boolean>

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

Parameters

Name Type Description
a bigint the first bigint

Returns

Unary<T, boolean>

the unary function

Defined in

src/BigInt.ts:132

Mappables

map

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

Type parameters

Name Description
A the mapped value

Parameters

Name Type Description
a bigint the bigint
m Mappable<bigint, A> the mappable functor

Returns

T<A>

the mapped value or TypeError if a is not a bigint

Defined in

src/BigInt.ts:169

map<A>(a): Unary<T, T<A>>

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

Type parameters

Name Description
A the mapped value

Parameters

Name Type Description
a Mappable<bigint, A> the mappable functor

Returns

Unary<T, T<A>>

the unary function

Defined in

src/BigInt.ts:191


mapOr

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

Type parameters

Name Description
A the mapped value type

Parameters

Name Type Description
a bigint the bigint
m Mappable<bigint, A> the mappable functor
b A the fallback value

Returns

A

Defined in

src/BigInt.ts:226

mapOr<A>(a, m): Unary<T, 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

Type parameters

Name Description
A the mapped value type

Parameters

Name Type Description
a Mappable<bigint, A> the bigint
m A the mappable functor

Returns

Unary<T, A>

the unary function

Defined in

src/BigInt.ts:248

Operables

add

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

Parameters

Name Type Description
a bigint the first bigint
b bigint the second bigint

Returns

T

the result

Defined in

src/BigInt.ts:288

add(a): Unary<T, T>

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

Parameters

Name Type Description
a bigint the first bigint

Returns

Unary<T, T>

Defined in

src/BigInt.ts:307


div

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

Parameters

Name Type Description
a bigint first value (top of division)
b bigint second value (bottom of division)

Returns

T

the result

Defined in

src/BigInt.ts:336

div(a): Unary<T, T>

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

Parameters

Name Type Description
a bigint second value (bottom of division)

Returns

Unary<T, T>

the unary function

Defined in

src/BigInt.ts:354


mod

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

Parameters

Name Type Description
a bigint the value
b bigint the modulus

Returns

T

the remainder

Defined in

src/BigInt.ts:383

mod(a): Unary<T, T>

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

Parameters

Name Type Description
a bigint the value

Returns

Unary<T, T>

the unary function

Defined in

src/BigInt.ts:403


mul

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

Parameters

Name Type Description
a bigint the first bigint
b bigint the second bigint

Returns

T

the result

Defined in

src/BigInt.ts:432

mul(a): Unary<T, T>

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

Parameters

Name Type Description
a bigint the first bigint

Returns

Unary<T, T>

the unary function

Defined in

src/BigInt.ts:451


pow

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

Parameters

Name Type Description
a bigint the first bigint
b bigint the second bigint

Returns

T

the result

Defined in

src/BigInt.ts:480

pow(a): Unary<T, T>

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

Parameters

Name Type
a bigint

Returns

Unary<T, T>

Defined in

src/BigInt.ts:497


root

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

Parameters

Name Type Description
a bigint the bigint
b bigint the root

Returns

T

Defined in

src/BigInt.ts:526

root(a): Unary<T, T>

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

Parameters

Name Type Description
a bigint the root

Returns

Unary<T, T>

the unary function

Defined in

src/BigInt.ts:546


sub

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

Parameters

Name Type Description
a bigint the first bigint
b bigint the second bigint

Returns

T

a - b

Defined in

src/BigInt.ts:588

sub(a): Unary<T, T>

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

Parameters

Name Type
a bigint

Returns

Unary<T, T>

the unary function (b - a)

Defined in

src/BigInt.ts:608

Sortables

asc

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

Parameters

Name Type Description
a bigint the first comparison bigint
b bigint the second comparison bigint

Returns

ComparableResult

the result:

Defined in

src/BigInt.ts:647

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

Parameters

Name Type Description
a bigint the bigint

Returns

Unary<T, ComparableResult>

the comparator unary function

Defined in

src/BigInt.ts:666


desc

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

Parameters

Name Type Description
a bigint the first comparison bigint
b bigint the second comparison bigint

Returns

ComparableResult

the result:

Defined in

src/BigInt.ts:702

desc(a): Unary<T, ComparableResult>

Parameters

Name Type
a bigint

Returns

Unary<T, ComparableResult>

Defined in

src/BigInt.ts:703

Serializables

toBin

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

Parameters

Name Type Description
a bigint the bigint

Returns

T<string>

the binary bigint value

Defined in

src/Fn.ts:22


toHex

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

Parameters

Name Type Description
a bigint the bigint

Returns

T<string>

the hexadecimal bigint value

Defined in

src/Fn.ts:22


toOct

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

Parameters

Name Type Description
a bigint the bigint

Returns

T<string>

the octal bigint value

Defined in

src/Fn.ts:22


toJSON

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

Parameters

Name Type Description
a bigint the bigint

Returns

T<string>

the json bigint value

Defined in

src/Fn.ts:22


toString

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

Parameters

Name Type Description
a bigint the bigint

Returns

T<string>

the string

Defined in

src/Fn.ts:22