@numio/bigmath 2.4.0 → 2.4.1
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 +3 -0
- package/package.json +1 -1
- package/src/mod/mod.js +8 -3
- package/src/mod/types.d.ts +2 -5
- package/src/mod/utils.js +2 -5
- package/src/pipe/pipe.d.ts +1 -2
- package/src/pipe/pipe.js +2 -2
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.4.
|
4
|
+
"version": "2.4.1",
|
5
5
|
"keywords": [
|
6
6
|
"precision",
|
7
7
|
"arithmetic",
|
package/src/mod/mod.js
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
import { bi2s, s2bi } from "../shared/utils.js";
|
2
2
|
import { modInner } from "./utils.js";
|
3
|
-
export const mod = (left, right
|
4
|
-
const
|
5
|
-
|
3
|
+
export const mod = (left, right) => {
|
4
|
+
const bil = s2bi(left);
|
5
|
+
const bir = s2bi(right);
|
6
|
+
if (bil[1] > 0)
|
7
|
+
throw new Error(`${left} is no valid. It should be integer`);
|
8
|
+
if (bir[1] > 0)
|
9
|
+
throw new Error(`${right} is no valid. It should be integer`);
|
10
|
+
return bi2s(modInner(bil, bir));
|
6
11
|
};
|
package/src/mod/types.d.ts
CHANGED
@@ -1,6 +1,3 @@
|
|
1
1
|
import type { BI } from "../shared/types.d.ts";
|
2
|
-
export type
|
3
|
-
|
4
|
-
};
|
5
|
-
export type Mod = (left: string, right: string, options?: ModOptions) => string;
|
6
|
-
export type ModInner = (left: BI, right: BI, options: ModOptions) => BI;
|
2
|
+
export type Mod = (left: string, right: string) => string;
|
3
|
+
export type ModInner = (left: BI, right: BI) => BI;
|
package/src/mod/utils.js
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
export const modInner = (left, right, { precision }) => {
|
4
|
-
const bi = divInner([left, right], precision);
|
5
|
-
return bi[1] === 0 ? [0n, 0] : [bi[0] % (10n ** tryBigInt(bi[1])), 0];
|
1
|
+
export const modInner = (left, right) => {
|
2
|
+
return [((left[0] % right[0]) + right[0]) % right[0], 0];
|
6
3
|
};
|
package/src/pipe/pipe.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { BI2S } from "../shared/types.d.ts";
|
2
|
-
import type { ModOptions } from "../mod/types.d.ts";
|
3
2
|
/** Using this function you can chain operations (add, sub, div, mul). */
|
4
3
|
export declare class Pipe {
|
5
4
|
#private;
|
@@ -9,7 +8,7 @@ export declare class Pipe {
|
|
9
8
|
div(array: string[], precision?: number): Pipe;
|
10
9
|
mul(array: string[]): Pipe;
|
11
10
|
abs(): Pipe;
|
12
|
-
mod(value: string
|
11
|
+
mod(value: string): Pipe;
|
13
12
|
calc(): ReturnType<BI2S>;
|
14
13
|
resultToBase(radix: number): string;
|
15
14
|
}
|
package/src/pipe/pipe.js
CHANGED
@@ -47,11 +47,11 @@ export class Pipe {
|
|
47
47
|
__classPrivateFieldSet(this, _Pipe_result, absInner(__classPrivateFieldGet(this, _Pipe_result, "f")), "f");
|
48
48
|
return this;
|
49
49
|
}
|
50
|
-
mod(value
|
50
|
+
mod(value) {
|
51
51
|
if (!__classPrivateFieldGet(this, _Pipe_result, "f")) {
|
52
52
|
throw new Error("Value is undefined.");
|
53
53
|
}
|
54
|
-
__classPrivateFieldSet(this, _Pipe_result, modInner(__classPrivateFieldGet(this, _Pipe_result, "f"), s2bi(value)
|
54
|
+
__classPrivateFieldSet(this, _Pipe_result, modInner(__classPrivateFieldGet(this, _Pipe_result, "f"), s2bi(value)), "f");
|
55
55
|
return this;
|
56
56
|
}
|
57
57
|
calc() {
|