UNPKG

360 BJavaScriptView Raw
1function sqrtPos(x) {
2 var a = x, b = x + 1n;
3 while (a < b) {
4 b = a;
5 a = (b + x / b) / 2n;
6 }
7 return b;
8}
9/**
10 * Gives square root of value.
11 * @param x a bigint
12 */
13function sqrt(x) {
14 if (x === 0n)
15 return 0n;
16 else
17 return x > 0n ? sqrtPos(x) : null;
18}
19export default sqrt;
20//# sourceMappingURL=index.js.map
\No newline at end of file