big.esm 1.3.1 → 2.0.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 +17 -0
- package/README.md +83 -43
- package/dist/big.d.ts +1 -1
- package/dist/big.esm.js +240 -151
- package/dist/big.esm.umd.cjs +1 -1
- package/dist/index.d.ts +22 -19
- package/dist/operations/abs.d.ts +3 -14
- package/dist/operations/add.d.ts +3 -15
- package/dist/operations/compare.d.ts +2 -2
- package/dist/operations/div.d.ts +5 -6
- package/dist/operations/max.d.ts +6 -8
- package/dist/operations/min.d.ts +6 -8
- package/dist/operations/mod.d.ts +3 -4
- package/dist/operations/mul.d.ts +3 -15
- package/dist/operations/pow.d.ts +3 -18
- package/dist/operations/sqrt.d.ts +3 -24
- package/dist/operations/sub.d.ts +3 -14
- package/dist/pipeline.d.ts +42 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils/align-scale.d.ts +3 -6
- package/dist/utils/clone.d.ts +1 -1
- package/dist/utils/constants.d.ts +3 -3
- package/dist/utils/create.d.ts +6 -2
- package/dist/utils/from-string.d.ts +3 -3
- package/dist/utils/is-big-object.d.ts +2 -3
- package/dist/utils/is-zero.d.ts +1 -1
- package/dist/utils/pow10.d.ts +1 -0
- package/package.json +35 -39
package/dist/operations/min.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
3
|
* Returns the minimum of two Big numbers.
|
|
4
4
|
*
|
|
5
5
|
* @param {Big} a - The first Big number.
|
|
6
6
|
* @param {Big} b - The second Big number.
|
|
7
|
-
* @param {boolean} [mutable=false] - Whether to return same Big instance. Defaults to false.
|
|
8
7
|
*
|
|
9
|
-
* @returns {Big} -
|
|
8
|
+
* @returns {Big} - Returns either `a` or `b`. If the two numbers are equal, `a` is returned.
|
|
10
9
|
*
|
|
11
10
|
* @category Operations
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
|
-
* minBig(new Big(1), new Big(2)); //
|
|
15
|
-
* minBig(new Big(2), new Big(1)); //
|
|
16
|
-
* minBig(new Big(1), new Big(1)); //
|
|
17
|
-
* minBig(new Big(1), new Big(1), true); // first Big number with value 1 and same instance
|
|
13
|
+
* minBig(new Big(1), new Big(2)); // returns the first Big number
|
|
14
|
+
* minBig(new Big(2), new Big(1)); // returns the second Big number
|
|
15
|
+
* minBig(new Big(1), new Big(1)); // returns the first Big number
|
|
18
16
|
*/
|
|
19
|
-
export declare
|
|
17
|
+
export declare function minBig(a: Big, b: Big): Big;
|
package/dist/operations/mod.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
3
|
* Performs the modulo operation (remainder of division) for two Big instances.
|
|
4
4
|
*
|
|
5
5
|
* @param dividend The Big instance representing the dividend.
|
|
6
6
|
* @param divisor The Big instance representing the divisor.
|
|
7
|
-
* @
|
|
8
|
-
* @returns A new Big instance representing the remainder of the division.
|
|
7
|
+
* @returns The mutated dividend instance representing the remainder of the division.
|
|
9
8
|
* @throws {Error} Division by zero is not allowed.
|
|
10
9
|
*
|
|
11
10
|
* @category Operations
|
|
@@ -17,4 +16,4 @@ import type { Big } from "../big";
|
|
|
17
16
|
* console.log(modBig(big2, big1).toString()); // "3"
|
|
18
17
|
* console.log(modBig(big1, big1).toString()); // "0"
|
|
19
18
|
*/
|
|
20
|
-
export declare function modBig(dividend: Big, divisor: Big
|
|
19
|
+
export declare function modBig(dividend: Big, divisor: Big): Big;
|
package/dist/operations/mul.d.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
|
-
* Multiplies two Big instances and
|
|
4
|
-
*
|
|
5
|
-
* @param {Big} a - The first Big instance.
|
|
6
|
-
* @param {Big} b - The second Big instance.
|
|
7
|
-
* @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
|
|
8
|
-
* @returns {Big} The result of the multiplication.
|
|
9
|
-
*
|
|
10
|
-
* @category Operations
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* mulBig(new Big(1), new Big(2)); // new Big instance with value 2
|
|
14
|
-
* mulBig(new Big(1.1), new Big(2.2)); // new Big instance with value 2.42
|
|
15
|
-
* mulBig(new Big(1.1), new Big(2)); // new Big instance with value 2.2
|
|
3
|
+
* Multiplies two Big instances and mutates the first one.
|
|
16
4
|
*/
|
|
17
|
-
export declare function mulBig(a: Big, b: Big
|
|
5
|
+
export declare function mulBig(a: Big, b: Big): Big;
|
package/dist/operations/pow.d.ts
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
|
-
* Raises a Big number to the power
|
|
4
|
-
*
|
|
5
|
-
* @param {Big} big - The base Big number.
|
|
6
|
-
* @param {number} exp - The exponent (non-negative integer). Defaults to 2.
|
|
7
|
-
* @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
|
|
8
|
-
* @returns {Big} - The result of a raised to the power of b.
|
|
9
|
-
* @throws {Error} - If the exponent is not a non-negative integer.
|
|
10
|
-
*
|
|
11
|
-
* @category Operations
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* powBig(new Big(2), 0); // new Big instance with value 1
|
|
15
|
-
* powBig(new Big(2), 1); // new Big instance with value 2
|
|
16
|
-
* powBig(new Big(2), 3); // new Big instance with value 8
|
|
17
|
-
* powBig(new Big(2), 3.3); // throws Error
|
|
18
|
-
* powBig(new Big(2), -3); // throws Error
|
|
3
|
+
* Raises a Big number to the power and mutates the base instance.
|
|
19
4
|
*/
|
|
20
|
-
export declare function powBig(big: Big, exp?: number
|
|
5
|
+
export declare function powBig(big: Big, exp?: number): Big;
|
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
|
-
* Calculates the nth root of a Big instance
|
|
4
|
-
*
|
|
5
|
-
* Note: it's the most weighted function in the library. It's reusing a lot of other functions, and it's not perfect in performance, recommended to use it only when you need it and with default precision and rounding mode. It uses the Newton's method to calculate the root.
|
|
6
|
-
*
|
|
7
|
-
* @param {Big} big - The Big instance.
|
|
8
|
-
* @param {number} root - The root to calculate. Must be an integer. Defaults to 2.
|
|
9
|
-
* @param {number} precision - The number of decimal places to keep in the result (optional). Defaults to 20.
|
|
10
|
-
* @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
|
|
11
|
-
* @returns {Big} The nth root of the Big instance with the specified precision and rounding mode.
|
|
12
|
-
* @throws {Error} - If the root is not an integer.
|
|
3
|
+
* Calculates the nth root of a Big instance and mutates it with the result.
|
|
13
4
|
*
|
|
14
5
|
* @category Operations
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const big1 = new Big(16);
|
|
18
|
-
* console.log(sqrtBig(big1).toString()); // 4.00000000000000000000
|
|
19
|
-
* console.log(sqrtBig(big1, 4, 0).toString()); // 2
|
|
20
|
-
* console.log(sqrtBig(big1, 4, 1).toString()); // 2.0
|
|
21
|
-
* console.log(sqrtBig(Big(0), 4).toString()); // 0
|
|
22
|
-
* console.log(sqrtBig(Big(1), 4).toString()); // 1
|
|
23
|
-
* console.log(sqrtBig(Big(-1), 4).toString()); // throws Error
|
|
24
|
-
* console.log(sqrtBig(Big(16), 0.5).toString()); // throws Error
|
|
25
|
-
* console.log(sqrtBig(Big(16), -2).toString()); // throws Error
|
|
26
|
-
* console.log(sqrtBig(Big(16), 4, -1).toString()); // throws Error
|
|
27
6
|
*/
|
|
28
|
-
export declare function sqrtBig(big: Big, root?: number, precision?: number
|
|
7
|
+
export declare function sqrtBig(big: Big, root?: number, precision?: number): Big;
|
package/dist/operations/sub.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
|
-
* Subtracts two
|
|
4
|
-
*
|
|
5
|
-
* @param {Big} a - The first Big instance.
|
|
6
|
-
* @param {Big} b - The second Big instance.
|
|
7
|
-
* @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
|
|
8
|
-
* @returns {Big} The result of the subtraction.
|
|
9
|
-
*
|
|
10
|
-
* @category Operations
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* subBig(new Big(1), new Big(2)); // new Big instance with value -1
|
|
14
|
-
* subBig(new Big(1.1), new Big(2.2)); // new Big instance with value -1.1
|
|
3
|
+
* Subtracts two Big instances and mutates the first one.
|
|
15
4
|
*/
|
|
16
|
-
export declare function subBig(a: Big, b: Big
|
|
5
|
+
export declare function subBig(a: Big, b: Big): Big;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Big } from './big';
|
|
2
|
+
import { BigValue, RoundingMode } from './types';
|
|
3
|
+
export type BigPipeline = {
|
|
4
|
+
/**
|
|
5
|
+
* The current Big value inside the pipeline.
|
|
6
|
+
*/
|
|
7
|
+
readonly current: Big;
|
|
8
|
+
add: (value: BigValue) => BigPipeline;
|
|
9
|
+
sub: (value: BigValue) => BigPipeline;
|
|
10
|
+
mul: (value: BigValue) => BigPipeline;
|
|
11
|
+
div: (value: BigValue, precision?: number, roundingMode?: RoundingMode) => BigPipeline;
|
|
12
|
+
mod: (value: BigValue) => BigPipeline;
|
|
13
|
+
pow: (exp?: number) => BigPipeline;
|
|
14
|
+
sqrt: (root?: number, precision?: number) => BigPipeline;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current Big value. Alias to avoid accessing the getter directly.
|
|
17
|
+
*/
|
|
18
|
+
value: () => Big;
|
|
19
|
+
/**
|
|
20
|
+
* String representation of the current value.
|
|
21
|
+
*/
|
|
22
|
+
toString: (trimZeros?: boolean) => string;
|
|
23
|
+
};
|
|
24
|
+
export declare class BigPipe implements BigPipeline {
|
|
25
|
+
current: Big;
|
|
26
|
+
constructor(initial: BigValue);
|
|
27
|
+
add(value: BigValue): this;
|
|
28
|
+
sub(value: BigValue): this;
|
|
29
|
+
mul(value: BigValue): this;
|
|
30
|
+
div(value: BigValue, precision?: number, roundingMode?: RoundingMode): this;
|
|
31
|
+
mod(value: BigValue): this;
|
|
32
|
+
pow(exp?: number): this;
|
|
33
|
+
sqrt(root?: number, precision?: number): this;
|
|
34
|
+
value(): Big;
|
|
35
|
+
toString(trimZeros?: boolean): string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a pipeline for chaining Big operations.
|
|
39
|
+
* The pipeline owns and mutates its `Big` instance in-place.
|
|
40
|
+
* Passing an existing `Big` will mutate that instance.
|
|
41
|
+
*/
|
|
42
|
+
export declare function pipeBig(initial: BigValue): BigPipeline;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
3
|
* Aligns the scale(decimal places) of two Big instances before performing arithmetic operations.
|
|
4
|
-
* It takes two Big instances as input and
|
|
4
|
+
* It takes two Big instances as input and mutates the one with the smaller scale to match the other.
|
|
5
5
|
*
|
|
6
6
|
* When the scales of the two input instances are different, the function adjusts the value and scale of one of the instances so that their scales are equal, allowing the arithmetic operations to be performed correctly.
|
|
7
7
|
*
|
|
8
|
-
* Note: This function does not modify the input instances. It creates new instances with the aligned scales.
|
|
9
|
-
*
|
|
10
8
|
* @param {Big} a - The first Big instance.
|
|
11
9
|
* @param {Big} b - The second Big instance.
|
|
12
|
-
* @param {boolean} [mutable=false] - Whether to mutate the both Big instances. Defaults to false.
|
|
13
10
|
* @returns {[Big, Big]} A tuple of two Big instances with the same scale.
|
|
14
11
|
*
|
|
15
12
|
* @category Utilities
|
|
@@ -21,4 +18,4 @@ import type { Big } from "../big";
|
|
|
21
18
|
* console.log(x.toString()); // "123.456000"
|
|
22
19
|
* console.log(y.toString()); // "123.456789"
|
|
23
20
|
*/
|
|
24
|
-
export declare function alignScale(a: Big, b: Big
|
|
21
|
+
export declare function alignScale(a: Big, b: Big): [Big, Big];
|
package/dist/utils/clone.d.ts
CHANGED
|
@@ -9,17 +9,17 @@ export declare const DEFAULT_PRECISION = 20;
|
|
|
9
9
|
*
|
|
10
10
|
* @category Constants
|
|
11
11
|
*/
|
|
12
|
-
export declare const ZERO_BIGINT
|
|
12
|
+
export declare const ZERO_BIGINT = 0n;
|
|
13
13
|
/**
|
|
14
14
|
* One as a BigInt.
|
|
15
15
|
*
|
|
16
16
|
* @category Constants
|
|
17
17
|
*/
|
|
18
|
-
export declare const ONE_BIGINT
|
|
18
|
+
export declare const ONE_BIGINT = 1n;
|
|
19
19
|
/**
|
|
20
20
|
* Ten as a BigInt.
|
|
21
21
|
* Often used as scale multiplier to adjust the scale of a Big instance.
|
|
22
22
|
*
|
|
23
23
|
* @category Constants
|
|
24
24
|
*/
|
|
25
|
-
export declare const TEN_BIGINT
|
|
25
|
+
export declare const TEN_BIGINT = 10n;
|
package/dist/utils/create.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Big } from
|
|
2
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
|
+
import { BigObject, BigValue, PossibleNumber } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Big instance from the given value.
|
|
5
5
|
* If the value is already a Big instance, it returns the value itself.
|
|
@@ -35,3 +35,7 @@ export declare function createBig(value: PossibleNumber): Big;
|
|
|
35
35
|
* const big3 = createBig(123.456, 2); // 1.23, because the scale is 2 and it removes the fractional part
|
|
36
36
|
*/
|
|
37
37
|
export declare function createBig(value: PossibleNumber, scale: number | string | undefined): Big;
|
|
38
|
+
/**
|
|
39
|
+
* Overload accepting the full BigValue union. Useful for helpers that accept any supported input.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createBig(value: BigValue, scale?: number | string | undefined): Big;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Big } from
|
|
2
|
-
import { BigObject } from
|
|
1
|
+
import { Big } from '../big';
|
|
2
|
+
import { BigObject } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Convert a number or string to normal string number. Supports scientific notation.
|
|
5
5
|
*
|
|
6
6
|
* @param {string | number} num - The number to convert
|
|
7
7
|
* @param {boolean} [ignoreFraction=false] - Whether to ignore the fractional part of the number. Defaults to false.
|
|
8
|
-
* @param {boolean} [returnInstance=
|
|
8
|
+
* @param {boolean} [returnInstance=true] - Whether to return a Big instance or BigObject. Defaults to true.
|
|
9
9
|
*
|
|
10
10
|
* @return {Big | BigObject} - A Big instance or BigObject representing the number
|
|
11
11
|
* @throws {Error} - If the number is too big or too small
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Big } from "../big";
|
|
1
|
+
import { BigObject } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Determines if the value is a BigObject. A BigObject is an object with a value property of type bigint and a scale property of type number. It usually represents a Big instance.
|
|
5
4
|
*
|
|
@@ -17,4 +16,4 @@ import type { Big } from "../big";
|
|
|
17
16
|
* isBigObject(123456n); // false
|
|
18
17
|
* isBigObject({ value: "abc", scale: "2"}); // false
|
|
19
18
|
*/
|
|
20
|
-
export declare function isBigObject(value:
|
|
19
|
+
export declare function isBigObject(value: unknown): value is BigObject;
|
package/dist/utils/is-zero.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pow10(exp: number): bigint;
|
package/package.json
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "big.esm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "tsc && vite build",
|
|
9
|
-
"preview": "vite preview",
|
|
10
|
-
"test": "vitest",
|
|
11
|
-
"test:ui": "vitest --ui",
|
|
12
|
-
"test:run": "vitest run",
|
|
13
|
-
"coverage": "vitest run --coverage",
|
|
14
|
-
"docs": "typedoc --out docs",
|
|
15
|
-
"lint": "
|
|
16
|
-
"lint:fix": "
|
|
17
|
-
"benchmark": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
7
|
+
"dev": "bunx vite",
|
|
8
|
+
"build": "bunx tsc && bunx vite build",
|
|
9
|
+
"preview": "bunx vite preview",
|
|
10
|
+
"test": "bunx vitest",
|
|
11
|
+
"test:ui": "bunx vitest --ui",
|
|
12
|
+
"test:run": "bunx vitest run",
|
|
13
|
+
"coverage": "bunx vitest run --coverage",
|
|
14
|
+
"docs": "bunx typedoc --out docs",
|
|
15
|
+
"lint": "bunx biome check",
|
|
16
|
+
"lint:fix": "bun run lint -- --write",
|
|
17
|
+
"benchmark": "bun benchmarks/benchmark.js",
|
|
18
|
+
"benchmark:weight": "bun benchmarks/size-compare.js",
|
|
19
|
+
"semantic-release": "bunx semantic-release",
|
|
20
|
+
"prepare": "bunx is-ci || bunx husky"
|
|
20
21
|
},
|
|
21
22
|
"main": "dist/big.esm.umd.cjs",
|
|
22
23
|
"module": "dist/big.esm.js",
|
|
@@ -46,37 +47,32 @@
|
|
|
46
47
|
"url": "https://github.com/dschewchenko/big.esm/issues"
|
|
47
48
|
},
|
|
48
49
|
"homepage": "https://github.com/dschewchenko/big.esm#readme",
|
|
50
|
+
"packageManager": "bun@1.3.1",
|
|
49
51
|
"engines": {
|
|
52
|
+
"bun": ">=1.0.0",
|
|
50
53
|
"node": ">=16"
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|
|
53
|
-
"@
|
|
54
|
-
"@commitlint/
|
|
56
|
+
"@biomejs/biome": "2.3.0",
|
|
57
|
+
"@commitlint/cli": "^20.1.0",
|
|
58
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
55
59
|
"@semantic-release/changelog": "^6.0.3",
|
|
56
60
|
"@semantic-release/git": "^10.0.1",
|
|
57
|
-
"@types/
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"is-ci": "^3.0.1",
|
|
69
|
-
"prettier": "^2.8.8",
|
|
70
|
-
"rollup-plugin-visualizer": "^5.9.0",
|
|
71
|
-
"semantic-release": "^21.0.5",
|
|
72
|
-
"ts-jest": "^29.1.0",
|
|
73
|
-
"typedoc": "^0.24.8",
|
|
74
|
-
"typedoc-plugin-mdn-links": "^3.0.3",
|
|
75
|
-
"typedoc-plugin-merge-modules": "^5.0.1",
|
|
61
|
+
"@types/node": "^24.9.1",
|
|
62
|
+
"@vitest/ui": "^4.0.3",
|
|
63
|
+
"@vitest/coverage-v8": "^4.0.3",
|
|
64
|
+
"big.js": "^7.0.1",
|
|
65
|
+
"husky": "^9.1.7",
|
|
66
|
+
"is-ci": "^4.1.0",
|
|
67
|
+
"rollup-plugin-visualizer": "^6.0.5",
|
|
68
|
+
"semantic-release": "^25.0.1",
|
|
69
|
+
"typedoc": "^0.28.14",
|
|
70
|
+
"typedoc-plugin-mdn-links": "^5.0.10",
|
|
71
|
+
"typedoc-plugin-merge-modules": "^7.0.0",
|
|
76
72
|
"typedoc-plugin-pages": "^1.1.0",
|
|
77
|
-
"typescript": "^5.
|
|
78
|
-
"vite": "^
|
|
79
|
-
"vite-plugin-dts": "^
|
|
80
|
-
"vitest": "^0.
|
|
73
|
+
"typescript": "^5.9.3",
|
|
74
|
+
"vite": "^7.1.12",
|
|
75
|
+
"vite-plugin-dts": "^4.5.4",
|
|
76
|
+
"vitest": "^4.0.3"
|
|
81
77
|
}
|
|
82
78
|
}
|