BigInt

add

RESCRIPT
let add: (bigint, bigint) => bigint

add(a, b) calculates the sum of two bigints.

Examples

RESCRIPT
BigInt.add(5n, 3n) == 8n BigInt.add(-2n, 7n) == 5n

asIntN

RESCRIPT
let asIntN: (~width: int, bigint) => bigint

asIntN(~width, bigint) returns a bigint value truncated to the given number of bits as a signed integer.

See BigInt.asIntN on MDN.

Examples

RESCRIPT
BigInt.asIntN(~width=4, 25n) == -7n BigInt.asIntN(~width=4, 3n) == 3n

asr

Deprecated

RESCRIPT
let asr: (bigint, bigint) => bigint

asr(bigint, amount) calculates the shifted value of a bigint by amount bits to the right.

Deprecated: Use >> operator or shiftRight instead.

Examples

RESCRIPT
BigInt.asr(8n, 1n) == 4n

asUintN

RESCRIPT
let asUintN: (~width: int, bigint) => bigint

asUintN(~width, bigint) returns a bigint value truncated to the given number of bits as an unsigned integer.

See BigInt.asUintN on MDN.

Examples

RESCRIPT
BigInt.asUintN(~width=4, 25n) == 9n BigInt.asUintN(~width=4, 3n) == 3n

bitwiseAnd

RESCRIPT
let bitwiseAnd: (bigint, bigint) => bigint

bitwiseAnd(a, b) calculates the bitwise AND of two bigints.

Examples

RESCRIPT
BigInt.bitwiseAnd(7n, 4n) == 4n BigInt.bitwiseAnd(15n, 8n) == 8n

bitwiseNot

RESCRIPT
let bitwiseNot: bigint => bigint

bitwiseNot(bigint) calculates the bitwise NOT of a bigint.

Examples

RESCRIPT
BigInt.bitwiseNot(2n) == -3n BigInt.bitwiseNot(-1n) == 0n

bitwiseOr

RESCRIPT
let bitwiseOr: (bigint, bigint) => bigint

bitwiseOr(a, b) calculates the bitwise OR of two bigints.

Examples

RESCRIPT
BigInt.bitwiseOr(7n, 4n) == 7n BigInt.bitwiseOr(8n, 4n) == 12n

bitwiseXor

RESCRIPT
let bitwiseXor: (bigint, bigint) => bigint

bitwiseXor(a, b) calculates the bitwise XOR of two bigints.

Examples

RESCRIPT
BigInt.bitwiseXor(7n, 4n) == 3n BigInt.bitwiseXor(15n, 8n) == 7n

div

RESCRIPT
let div: (bigint, bigint) => bigint

div(a, b) calculates the quotient of two bigints.

Examples

RESCRIPT
BigInt.div(15n, 3n) == 5n BigInt.div(14n, 3n) == 4n

fromFloat

RESCRIPT
let fromFloat: float => option<bigint>

fromFloat(float) converts a float to a bigint using JavaScript semantics. Returns Some(bigint) if the float is a valid bigint, None otherwise.

Examples

RESCRIPT
BigInt.fromFloat(123.0) == Some(123n) BigInt.fromFloat(0.0) == Some(0n) BigInt.fromFloat(-456.0) == Some(-456n) BigInt.fromFloat(123.5) == None

fromFloatOrThrow

RESCRIPT
let fromFloatOrThrow: float => bigint

Converts a float to a bigint using JavaScript semantics. Throws an exception if the float is not an integer or is infinite/NaN.

Examples

RESCRIPT
BigInt.fromFloatOrThrow(123.0) == 123n BigInt.fromFloatOrThrow(0.0) == 0n BigInt.fromFloatOrThrow(-456.0) == -456n /* This will throw an exception */ switch BigInt.fromFloatOrThrow(123.5) { | exception JsExn(_error) => assert(true) | _bigInt => assert(false) }

fromInt

RESCRIPT
let fromInt: int => bigint

fromInt(int) converts an int to a bigint.

Examples

RESCRIPT
BigInt.fromInt(123) == 123n BigInt.fromInt(0) == 0n BigInt.fromInt(-456) == -456n

fromString

RESCRIPT
let fromString: string => option<bigint>

Parses the given string into a bigint using JavaScript semantics. Returns Some(bigint) if the string can be parsed, None otherwise.

Examples

RESCRIPT
BigInt.fromString("123") == Some(123n) BigInt.fromString("") == Some(0n) BigInt.fromString("0x11") == Some(17n) BigInt.fromString("0b11") == Some(3n) BigInt.fromString("0o11") == Some(9n) BigInt.fromString("invalid") == None

fromStringExn

Deprecated

RESCRIPT
let fromStringExn: string => bigint

fromStringOrThrow

RESCRIPT
let fromStringOrThrow: string => bigint

Parses the given string into a bigint using JavaScript semantics. Return the number as a bigint if successfully parsed. Throws a syntax exception otherwise.

Examples

RESCRIPT
BigInt.fromStringOrThrow("123") == 123n BigInt.fromStringOrThrow("") == 0n BigInt.fromStringOrThrow("0x11") == 17n BigInt.fromStringOrThrow("0b11") == 3n BigInt.fromStringOrThrow("0o11") == 9n /* catch exception */ switch BigInt.fromStringOrThrow("a") { | exception JsExn(_error) => assert(true) | _bigInt => assert(false) }

ignore

RESCRIPT
let ignore: bigint => unit

ignore(bigint) ignores the provided bigint and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

land

Deprecated

RESCRIPT
let land: (bigint, bigint) => bigint

land(a, b) calculates the bitwise AND of two bigints.

Deprecated: Use &&& operator or bitwiseAnd instead.

Examples

RESCRIPT
BigInt.land(7n, 4n) == 4n

lnot

Deprecated

RESCRIPT
let lnot: bigint => bigint

lnot(bigint) calculates the bitwise NOT of a bigint.

Deprecated: Use ~~~ operator or bitwiseNot instead.

Examples

RESCRIPT
BigInt.lnot(2n) == -3n

lor

Deprecated

RESCRIPT
let lor: (bigint, bigint) => bigint

lor(a, b) calculates the bitwise OR of two bigints.

Deprecated: Use ||| operator or bitwiseOr instead.

Examples

RESCRIPT
BigInt.lor(7n, 4n) == 7n

lsl

Deprecated

RESCRIPT
let lsl: (bigint, bigint) => bigint

lsl(bigint, amount) calculates the shifted value of a bigint by amount bits to the left.

Deprecated: Use << operator or shiftLeft instead.

Examples

RESCRIPT
BigInt.lsl(4n, 1n) == 8n

lxor

Deprecated

RESCRIPT
let lxor: (bigint, bigint) => bigint

lxor(a, b) calculates the bitwise XOR of two bigints.

Deprecated: Use ^^^ operator or bitwiseXor instead.

Examples

RESCRIPT
BigInt.lxor(7n, 4n) == 3n

mod

RESCRIPT
let mod: (bigint, bigint) => bigint

mod(a, b) calculates the remainder of dividing two bigints.

Examples

RESCRIPT
BigInt.mod(15n, 4n) == 3n BigInt.mod(14n, 3n) == 2n

mul

RESCRIPT
let mul: (bigint, bigint) => bigint

mul(a, b) calculates the product of two bigints.

Examples

RESCRIPT
BigInt.mul(5n, 3n) == 15n BigInt.mul(-2n, 7n) == -14n

shiftLeft

RESCRIPT
let shiftLeft: (bigint, bigint) => bigint

shiftLeft(bigint, amount) calculates the shifted value of a bigint by amount bits to the left.

Examples

RESCRIPT
BigInt.shiftLeft(4n, 1n) == 8n BigInt.shiftLeft(1n, 3n) == 8n

shiftRight

RESCRIPT
let shiftRight: (bigint, bigint) => bigint

shiftRight(bigint, amount) calculates the shifted value of a bigint by amount bits to the right.

Examples

RESCRIPT
BigInt.shiftRight(8n, 1n) == 4n BigInt.shiftRight(16n, 2n) == 4n

sub

RESCRIPT
let sub: (bigint, bigint) => bigint

sub(a, b) calculates the difference of two bigints.

Examples

RESCRIPT
BigInt.sub(8n, 3n) == 5n BigInt.sub(2n, 7n) == -5n

t

RESCRIPT
type t = bigint

Type representing a bigint.

toFloat

RESCRIPT
let toFloat: bigint => float

toFloat(bigint) converts a bigint to a float.

Examples

RESCRIPT
BigInt.toFloat(123n) == 123.0 BigInt.toFloat(0n) == 0.0 BigInt.toFloat(-456n) == -456.0

toInt

RESCRIPT
let toInt: bigint => int

toInt(bigint) converts a bigint to an int.

Examples

RESCRIPT
BigInt.toInt(123n) == 123 BigInt.toInt(0n) == 0 BigInt.toInt(-456n) == -456

toLocaleString

RESCRIPT
let toLocaleString: bigint => string

Returns a string with a language-sensitive representation of this BigInt value.

Examples

RESCRIPT
BigInt.toString(123n) == "123"

toString

RESCRIPT
let toString: (bigint, ~radix: int=?) => string

Formats a bigint as a string. Return a string representing the given value. See toString on MDN.

Examples

RESCRIPT
BigInt.toString(123n) == "123"

toStringWithRadix

Deprecated

RESCRIPT
let toStringWithRadix: (bigint, ~radix: int) => string