@numio/bigmath 2.3.1 → 2.4.0
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 +21 -15
- package/README.md +5 -4
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +3 -2
- package/src/FDR/fdr.js +2 -2
- package/src/FDR/types.d.ts +2 -2
- package/src/FDR/utils.js +8 -8
- package/src/mod/mod.d.ts +2 -0
- package/src/mod/mod.js +6 -0
- package/src/mod/types.d.ts +6 -0
- package/src/mod/utils.d.ts +2 -0
- package/src/mod/utils.js +6 -0
- package/src/operations/add/add.js +1 -1
- package/src/pipe/pipe.d.ts +2 -0
- package/src/pipe/pipe.js +8 -0
- package/src/shared/types.d.ts +1 -0
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
+
### 2.4.0
|
2
|
+
Add Mod - Modulo operation, which finds the remainder when one number is divided by another
|
3
|
+
|
4
|
+
### 2.3.2
|
5
|
+
FDR - change variable name to make it consistent
|
6
|
+
|
1
7
|
### 2.3.1
|
2
8
|
Fix import
|
3
9
|
|
4
10
|
### 2.2.8
|
5
|
-
Better error handling
|
6
|
-
Add FDR - Freedman-Diaconis Rule
|
11
|
+
Better error handling \
|
12
|
+
Add FDR - Freedman-Diaconis Rule \
|
7
13
|
MAD - median of the absolute deviations from `median` or `mean`
|
8
14
|
|
9
15
|
### 2.2.7
|
@@ -13,48 +19,48 @@ Throw an error if input is not valid. In the error show exact invalid input.
|
|
13
19
|
Optimize performance for small numbers (add operation)
|
14
20
|
|
15
21
|
### 2.2.5
|
16
|
-
Handle "0B", "0X", "0O", "-0B", "-0X", "-0O" as a start of the input for toBase function.
|
22
|
+
Handle "0B", "0X", "0O", "-0B", "-0X", "-0O" as a start of the input for toBase function. \
|
17
23
|
Move documentation from README.md to web-site http://numio.deno.dev
|
18
24
|
|
19
25
|
### 2.2.4
|
20
26
|
Fix handling negative numbers for toBase function.
|
21
27
|
|
22
28
|
### 2.2.3
|
23
|
-
Add validation for negative number input in square root function
|
29
|
+
Add validation for negative number input in square root function \
|
24
30
|
Add validation for negative number input in cube root function
|
25
31
|
|
26
32
|
### 2.2.2
|
27
|
-
Throw an error if input for MAD and IQR is less than 3 elements
|
33
|
+
Throw an error if input for MAD and IQR is less than 3 elements \
|
28
34
|
Add home-page url
|
29
35
|
|
30
36
|
### 2.2.1
|
31
37
|
Add Number format validation examples (README.md)
|
32
38
|
|
33
39
|
### 2.2.0
|
34
|
-
Added `isHex(str: string): boolean` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`).
|
35
|
-
Added `isBinary(str: string): boolean` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`).
|
36
|
-
Added `isDecimal(str: string): boolean` - Checks if a string is a valid decimal number.
|
37
|
-
Added `isOctal(str: string): boolean` - Checks if a string is a valid octal number (prefixed with `0o` or `-0o`).
|
40
|
+
Added `isHex(str: string): boolean` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`). \
|
41
|
+
Added `isBinary(str: string): boolean` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`). \
|
42
|
+
Added `isDecimal(str: string): boolean` - Checks if a string is a valid decimal number. \
|
43
|
+
Added `isOctal(str: string): boolean` - Checks if a string is a valid octal number (prefixed with `0o` or `-0o`). \
|
38
44
|
Added `isNumber(str: string): boolean` - Checks if a string is a valid number in any of the formats supported by the library (decimal, hexadecimal, binary, octal).
|
39
45
|
|
40
46
|
### 2.1.3
|
41
47
|
Optimize performance for small numbers
|
42
48
|
|
43
49
|
### 2.1.2
|
44
|
-
Renamed main.ts files
|
45
|
-
Changed import path in test files
|
50
|
+
Renamed main.ts files \
|
51
|
+
Changed import path in test files \
|
46
52
|
Change build config - run test on JSR and NPM versions
|
47
53
|
|
48
54
|
### 2.1.1
|
49
55
|
Fixed lib crash (NPM version)
|
50
56
|
|
51
57
|
### 2.1.0
|
52
|
-
Added `toBase` - convert number to another base
|
53
|
-
Added `abs` - absolute value
|
54
|
-
Added `isLeftGreaterOrEqual` - Is the left-hand side value greater than or equal to the right-hand side value
|
58
|
+
Added `toBase` - convert number to another base \
|
59
|
+
Added `abs` - absolute value \
|
60
|
+
Added `isLeftGreaterOrEqual` - Is the left-hand side value greater \ than or equal to the right-hand side value \
|
55
61
|
Added `cbrt` - cube root of a number
|
56
62
|
|
57
|
-
Added `Pipe().abs` - absolute value in pipe
|
63
|
+
Added `Pipe().abs` - absolute value in pipe \
|
58
64
|
Added `Pipe().resultToBase` - convert number to another base in pipe
|
59
65
|
|
60
66
|
### 2.0.0
|
package/README.md
CHANGED
@@ -5,11 +5,10 @@
|
|
5
5
|
|
6
6
|
## Latest Update
|
7
7
|
|
8
|
-
This update introduces
|
8
|
+
This update introduces new functionalities:
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
- **Median Absolute Deviation (MAD):** Implemented calculation for the Median Absolute Deviation, allowing users to compute it based on either the `median` or the `mean` of the dataset.
|
10
|
+
* **Modulo Operation (`mod`):** A new `mod` function has been added for performing modulo operations.
|
11
|
+
* **Pipe Function Enhancement:** The `mod` function has been integrated into the `Pipe` function for seamless chaining of operations.
|
13
12
|
|
14
13
|
## Existing Functionality
|
15
14
|
|
@@ -32,6 +31,7 @@ The application currently supports the following operations:
|
|
32
31
|
- `min`: Finding the minimum value in a dataset.
|
33
32
|
- `MAD`: Calculating the Median Absolute Deviation (based on either median or mean).
|
34
33
|
- `IQR`: Calculating the Interquartile Range.
|
34
|
+
- `FDR`: Freedman-Diaconis rule
|
35
35
|
- **Comparison:**
|
36
36
|
- `isEqual`: Checking if two values are equal.
|
37
37
|
- `isLeftGreater`: Checking if the left value is greater than the right value.
|
@@ -40,6 +40,7 @@ The application currently supports the following operations:
|
|
40
40
|
- `sqrt`: Calculating the square root of a number.
|
41
41
|
- `cbrt`: Calculating the cube root of a number.
|
42
42
|
- `abs`: Calculating the absolute value of a number.
|
43
|
+
- `mod`: Modulo operation, which finds the remainder when one number is divided by another
|
43
44
|
- **Number Base Conversion:**
|
44
45
|
- `toBase`: Converting a number to a specified base.
|
45
46
|
- `isHex`: Checking if a string is a valid hexadecimal number.
|
package/index.d.ts
CHANGED
@@ -24,4 +24,5 @@ import { isDecimal } from "./src/isValid/isDecimal.d.ts";
|
|
24
24
|
import { isOctal } from "./src/isValid/isOctal.d.ts";
|
25
25
|
import { isNumber } from "./src/isValid/isNumber.d.ts";
|
26
26
|
import { FDR } from "./src/FDR/fdr.d.ts";
|
27
|
-
|
27
|
+
import { mod } from "./src/mod/mod.d.ts";
|
28
|
+
export { abs, add, cbrt, div, IQR, isEqual, isLeftGreater, isLeftGreaterOrEqual, MAD, max, mean, min, mul, Pipe, quartile, round, sort, sqrt, sub, toBase, isHex, isBinary, isDecimal, isOctal, isNumber, FDR, mod };
|
package/index.js
CHANGED
@@ -24,4 +24,5 @@ import { isDecimal } from "./src/isValid/isDecimal.js";
|
|
24
24
|
import { isOctal } from "./src/isValid/isOctal.js";
|
25
25
|
import { isNumber } from "./src/isValid/isNumber.js";
|
26
26
|
import { FDR } from "./src/FDR/fdr.js";
|
27
|
-
|
27
|
+
import { mod } from "./src/mod/mod.js";
|
28
|
+
export { abs, add, cbrt, div, IQR, isEqual, isLeftGreater, isLeftGreaterOrEqual, MAD, max, mean, min, mul, Pipe, quartile, round, sort, sqrt, sub, toBase, isHex, isBinary, isDecimal, isOctal, isNumber, FDR, mod };
|
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
|
+
"version": "2.4.0",
|
5
5
|
"keywords": [
|
6
6
|
"precision",
|
7
7
|
"arithmetic",
|
@@ -54,7 +54,8 @@
|
|
54
54
|
"binary",
|
55
55
|
"cube root",
|
56
56
|
"FDR",
|
57
|
-
"Freedman-Diaconis Rule"
|
57
|
+
"Freedman-Diaconis Rule",
|
58
|
+
"mod"
|
58
59
|
],
|
59
60
|
"repository": {
|
60
61
|
"type": "git",
|
package/src/FDR/fdr.js
CHANGED
@@ -6,13 +6,13 @@ export const FDR = (array, options) => {
|
|
6
6
|
for (let i = 0; i < array.length; i++) {
|
7
7
|
arrayInner[i] = s2bi(array[i]);
|
8
8
|
}
|
9
|
-
const { binWidth,
|
9
|
+
const { binWidth, binNum } = fdrInner(arrayInner, {
|
10
10
|
useMadAbove: (_a = options === null || options === void 0 ? void 0 : options.useMadAbove) !== null && _a !== void 0 ? _a : 0,
|
11
11
|
maxBinNumber: (_b = options === null || options === void 0 ? void 0 : options.maxBinNumber) !== null && _b !== void 0 ? _b : 90,
|
12
12
|
madFrom: (_c = options === null || options === void 0 ? void 0 : options.madFrom) !== null && _c !== void 0 ? _c : "median",
|
13
13
|
});
|
14
14
|
return {
|
15
|
-
|
15
|
+
binNum: bi2s(binNum),
|
16
16
|
binWidth: bi2s(binWidth),
|
17
17
|
};
|
18
18
|
};
|
package/src/FDR/types.d.ts
CHANGED
@@ -12,10 +12,10 @@ type OptionsInner = {
|
|
12
12
|
};
|
13
13
|
export type FDRInner = (array: BI[], options: OptionsInner) => {
|
14
14
|
binWidth: BI;
|
15
|
-
|
15
|
+
binNum: BI;
|
16
16
|
};
|
17
17
|
export type TFDR = (array: string[], options?: Options) => {
|
18
18
|
binWidth: string;
|
19
|
-
|
19
|
+
binNum: string;
|
20
20
|
};
|
21
21
|
export {};
|
package/src/FDR/utils.js
CHANGED
@@ -6,11 +6,11 @@ import { divInner } from "../operations/div/utils.js";
|
|
6
6
|
import { PipeInner } from "../pipe/utils.js";
|
7
7
|
import { tryBigInt } from "../shared/utils.js";
|
8
8
|
const getBinsNum = (range, binWidth) => {
|
9
|
-
let
|
10
|
-
if (
|
11
|
-
|
9
|
+
let binNum = new PipeInner().div([range, binWidth], 10).bi;
|
10
|
+
if (binNum[1] > 0) {
|
11
|
+
binNum = [new PipeInner().div([range, binWidth], 0).bi[0] + 1n, 0];
|
12
12
|
}
|
13
|
-
return
|
13
|
+
return binNum;
|
14
14
|
};
|
15
15
|
export const fdrInner = (array, options = { useMadAbove: 0, maxBinNumber: 90, madFrom: "mean" }) => {
|
16
16
|
const mad = MADInner(array, { from: options.madFrom });
|
@@ -21,14 +21,14 @@ export const fdrInner = (array, options = { useMadAbove: 0, maxBinNumber: 90, ma
|
|
21
21
|
const [cbrtLen] = cbrtInner([tryBigInt(array.length), 0]);
|
22
22
|
const binWidth = new PipeInner().mul([[2n, 0], validIQR]).div([cbrtLen]).bi;
|
23
23
|
const range = new PipeInner().sub([array[array.length - 1], array[0]]).bi;
|
24
|
-
const
|
24
|
+
const binNum = getBinsNum(range, binWidth);
|
25
25
|
const maxBinNum = [tryBigInt(options.maxBinNumber), 0];
|
26
|
-
const scale = isLeftGreaterOrEqualInner({ left:
|
27
|
-
? divInner([
|
26
|
+
const scale = isLeftGreaterOrEqualInner({ left: binNum, right: maxBinNum })
|
27
|
+
? divInner([binNum, maxBinNum], 20)
|
28
28
|
: [1n, 0];
|
29
29
|
const scaledBinWidth = new PipeInner().mul([binWidth, scale]).bi;
|
30
30
|
return {
|
31
31
|
binWidth: scaledBinWidth,
|
32
|
-
|
32
|
+
binNum: getBinsNum(range, scaledBinWidth),
|
33
33
|
};
|
34
34
|
};
|
package/src/mod/mod.d.ts
ADDED
package/src/mod/mod.js
ADDED
package/src/mod/utils.js
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
import { divInner } from "../operations/div/utils.js";
|
2
|
+
import { tryBigInt } from "../shared/utils.js";
|
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];
|
6
|
+
};
|
package/src/pipe/pipe.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { BI2S } from "../shared/types.d.ts";
|
2
|
+
import type { ModOptions } from "../mod/types.d.ts";
|
2
3
|
/** Using this function you can chain operations (add, sub, div, mul). */
|
3
4
|
export declare class Pipe {
|
4
5
|
#private;
|
@@ -8,6 +9,7 @@ export declare class Pipe {
|
|
8
9
|
div(array: string[], precision?: number): Pipe;
|
9
10
|
mul(array: string[]): Pipe;
|
10
11
|
abs(): Pipe;
|
12
|
+
mod(value: string, options?: ModOptions): Pipe;
|
11
13
|
calc(): ReturnType<BI2S>;
|
12
14
|
resultToBase(radix: number): string;
|
13
15
|
}
|
package/src/pipe/pipe.js
CHANGED
@@ -13,6 +13,7 @@ var _Pipe_result;
|
|
13
13
|
import { bi2s, calcInner, s2bi } from "../shared/utils.js";
|
14
14
|
import { divInner } from "../operations/div/utils.js";
|
15
15
|
import { absInner } from "../abs/utils.js";
|
16
|
+
import { modInner } from "../mod/utils.js";
|
16
17
|
/** Using this function you can chain operations (add, sub, div, mul). */
|
17
18
|
export class Pipe {
|
18
19
|
constructor(value) {
|
@@ -46,6 +47,13 @@ export class Pipe {
|
|
46
47
|
__classPrivateFieldSet(this, _Pipe_result, absInner(__classPrivateFieldGet(this, _Pipe_result, "f")), "f");
|
47
48
|
return this;
|
48
49
|
}
|
50
|
+
mod(value, options = { precision: 20 }) {
|
51
|
+
if (!__classPrivateFieldGet(this, _Pipe_result, "f")) {
|
52
|
+
throw new Error("Value is undefined.");
|
53
|
+
}
|
54
|
+
__classPrivateFieldSet(this, _Pipe_result, modInner(__classPrivateFieldGet(this, _Pipe_result, "f"), s2bi(value), options), "f");
|
55
|
+
return this;
|
56
|
+
}
|
49
57
|
calc() {
|
50
58
|
if (!__classPrivateFieldGet(this, _Pipe_result, "f")) {
|
51
59
|
throw new Error("Cannot calculate based on an undefined input.");
|
package/src/shared/types.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export type BI = [bigint, number];
|
2
|
+
export type Input = string[];
|
2
3
|
export type FillHead = (len: number, fpe: number, isNeg: boolean, hasBefore: boolean) => string;
|
3
4
|
export type TrimTail = (str: string) => string;
|
4
5
|
export type CalcInner = (array: BI[], op: (a: bigint, b: bigint) => bigint, def?: BI) => BI;
|