effect-io-ai

Package: effect
Module: BigInt

BigInt.sqrtUnsafe

Returns the integer square root of a non-negative bigint.

When to use

Use when you need to compute an integer square root for a bigint that has already been validated as non-negative, and you want negative input to throw instead of returning Option.none.

Details

For non-perfect squares, returns the largest bigint whose square is less than or equal to the input.

Gotchas

Throws a RangeError if the input is negative.

Example (Calculating square roots unsafely)

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

assert.deepStrictEqual(BigInt.sqrtUnsafe(4n), 2n)
assert.deepStrictEqual(BigInt.sqrtUnsafe(9n), 3n)
assert.deepStrictEqual(BigInt.sqrtUnsafe(16n), 4n)

See

Signature

declare const sqrtUnsafe: (n: bigint) => bigint

Source

Since v4.0.0