DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact
Overview
Stdlib
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
    • t
      t
    • v
      asIntN
    • v
      asUintN
    • v
      fromStringOrThrow
    • v
      fromString
    • v
      fromStringExn
      D
    • v
      fromInt
    • v
      fromFloatOrThrow
    • v
      fromFloat
    • v
      toString
    • v
      toStringWithRadix
      D
    • v
      toLocaleString
    • v
      toFloat
    • v
      toInt
    • v
      add
    • v
      sub
    • v
      mul
    • v
      div
    • v
      mod
    • v
      bitwiseAnd
    • v
      bitwiseOr
    • v
      bitwiseXor
    • v
      bitwiseNot
    • v
      shiftLeft
    • v
      shiftRight
    • v
      ignore
    • v
      land
      D
    • v
      lor
      D
    • v
      lxor
      D
    • v
      lnot
      D
    • v
      lsl
      D
    • v
      asr
      D
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Bool
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Ref
    • Bitwise
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • IntervalId
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
    JsError
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • JsExn
  • Lazy
  • List
  • Map
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Pair
  • Promise
  • RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • TimeoutId
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • Docs / API / Stdlib / Bigint

    BigInt

    t

    RESCRIPT
    type t = bigint

    Type representing a bigint.

    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

    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

    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) }

    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

    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

    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) }

    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

    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

    toLocaleString

    RESCRIPT
    let toLocaleString: bigint => string

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

    Examples

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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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
    Types and values
    • t
      t
    • v
      asIntN
    • v
      asUintN
    • v
      fromStringOrThrow
    • v
      fromString
    • v
      fromStringExn
      D
    • v
      fromInt
    • v
      fromFloatOrThrow
    • v
      fromFloat
    • v
      toString
    • v
      toStringWithRadix
      D
    • v
      toLocaleString
    • v
      toFloat
    • v
      toInt
    • v
      add
    • v
      sub
    • v
      mul
    • v
      div
    • v
      mod
    • v
      bitwiseAnd
    • v
      bitwiseOr
    • v
      bitwiseXor
    • v
      bitwiseNot
    • v
      shiftLeft
    • v
      shiftRight
    • v
      ignore
    • v
      land
      D
    • v
      lor
      D
    • v
      lxor
      D
    • v
      lnot
      D
    • v
      lsl
      D
    • v
      asr
      D

    © 2025 The ReScript Project

    About
    • Community
    • ReScript Association
    Find us on