UNPKG

@numio/bigmath

Version:

@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)

10 lines (9 loc) 384 B
import { round } from "../round/round.js"; import { bi2s, s2bi } from "../shared/utils.js"; import { sqrtInner } from "./utils.js"; /** Find square root of a number */ export const sqrt = (value, precision) => { const valueInner = s2bi(value); const [bi, decimals] = sqrtInner(valueInner, precision ? s2bi(precision) : undefined); return round(bi2s(bi), { decimals }); };