effect-io-ai

Package: effect
Module: BigInt

BigInt.divide

Divides one bigint by another safely.

When to use

Use to divide bigint values while representing division by zero as Option.none.

Details

Uses JavaScript bigint division, so non-exact quotients are truncated toward zero. Returns Option.none() when the divisor is 0n.

Example (Dividing bigints safely)

import { BigInt, Option } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(BigInt.divide(6n, 3n), Option.some(2n))
assert.deepStrictEqual(BigInt.divide(6n, 0n), Option.none())

See

Signature

declare const divide: { (that: bigint): (self: bigint) => Option.Option<bigint>; (self: bigint, that: bigint): Option.Option<bigint>; }

Source

Since v2.0.0