@numio/bigmath 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/cbrt/utils.js +7 -3
- package/src/sqrt/utils.js +6 -3
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@numio/bigmath",
|
3
3
|
"description": "@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)",
|
4
|
-
"version": "2.2.
|
4
|
+
"version": "2.2.3",
|
5
5
|
"keywords": [
|
6
6
|
"precision",
|
7
7
|
"arithmetic",
|
package/src/cbrt/utils.js
CHANGED
@@ -3,14 +3,18 @@ import { divInner } from "../operations/div/utils.js";
|
|
3
3
|
import { PipeInner } from "../pipe/utils.js";
|
4
4
|
import { calcInner } from "../shared/utils.js";
|
5
5
|
export const cbrtInner = (value, prec = [1n, 13], max = 100) => {
|
6
|
+
var _a, _b;
|
7
|
+
if (value[0] < 0n) {
|
8
|
+
throw new Error("Invalid input: Cannot take the cube root of a negative value.");
|
9
|
+
}
|
6
10
|
let guess = value;
|
7
11
|
for (let i = 0; i < max; i++) {
|
8
12
|
const mul = calcInner([guess, guess], (a, b) => a * b);
|
9
|
-
const nextGuess = new PipeInner().add([
|
13
|
+
const nextGuess = (_a = new PipeInner().add([
|
10
14
|
calcInner([guess, [2n, 0]], (a, b) => a * b),
|
11
15
|
divInner([value, mul], 20),
|
12
|
-
]).div([[3n, 0]]).
|
13
|
-
let [bi, fpe] = new PipeInner().sub([nextGuess, guess]).
|
16
|
+
]).div([[3n, 0]]).result) !== null && _a !== void 0 ? _a : [0n, 0];
|
17
|
+
let [bi, fpe] = (_b = new PipeInner().sub([nextGuess, guess]).result) !== null && _b !== void 0 ? _b : [0n, 0];
|
14
18
|
if (bi < 0n)
|
15
19
|
bi *= -1n;
|
16
20
|
if (isLeftGreaterInner({ left: prec, right: [bi, fpe] })) {
|
package/src/sqrt/utils.js
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
import { isLeftGreaterInner } from "../compare/utils.js";
|
2
2
|
import { PipeInner } from "../pipe/utils.js";
|
3
3
|
export const sqrtInner = (value, prec = [1n, 13], max = 100) => {
|
4
|
+
var _a;
|
5
|
+
if (value[0] < 0n) {
|
6
|
+
throw new Error("Invalid input: Cannot take the square root of a negative value.");
|
7
|
+
}
|
4
8
|
let guess = value;
|
5
9
|
for (let i = 0; i < max; i++) {
|
6
|
-
const nextGuess = new PipeInner()
|
10
|
+
const nextGuess = (_a = new PipeInner()
|
7
11
|
.div([value, guess])
|
8
12
|
.add([guess])
|
9
|
-
.mul([[5n, 1]])
|
10
|
-
.calc();
|
13
|
+
.mul([[5n, 1]]).result) !== null && _a !== void 0 ? _a : [0n, 0];
|
11
14
|
let [bi, fpe] = new PipeInner().sub([nextGuess, guess]).calc();
|
12
15
|
if (bi < 0n)
|
13
16
|
bi *= -1n;
|