effect-io-ai

Package: effect
Module: BigInt

BigInt.fromNumber

Converts a number to a bigint.

When to use

Use to convert a JavaScript number to bigint only when it is a safe integer.

Details

If the number is outside the safe integer range for JavaScript (Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER) or if the number is not a valid bigint, it returns Option.none().

Example (Converting numbers to bigints)

import { BigInt } from "effect"

BigInt.fromNumber(42) // Option.some(42n)

BigInt.fromNumber(Number.MAX_SAFE_INTEGER + 1) // Option.none()
BigInt.fromNumber(Number.MIN_SAFE_INTEGER - 1) // Option.none()

See

Signature

declare const fromNumber: (n: number) => Option.Option<bigint>

Source

Since v2.4.12