Package: effect
Module: BigInt
Computes the integer square root of a bigint safely.
When to use
Use to compute an integer square root while representing negative input as
Option.none.
Details
For non-perfect squares, returns the largest bigint whose square is less
than or equal to the input. Returns Option.none() when the input is
negative.
Example (Calculating square roots safely)
import { BigInt } from "effect"
BigInt.sqrt(4n) // Option.some(2n)
BigInt.sqrt(9n) // Option.some(3n)
BigInt.sqrt(16n) // Option.some(4n)
BigInt.sqrt(-1n) // Option.none()
See
sqrtUnsafe for square root computation that throws on negative inputSignature
declare const sqrt: (n: bigint) => Option.Option<bigint>
Since v2.0.0