big.esm 1.1.0 → 1.1.2
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 +14 -0
- package/README.md +57 -47
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.1.2](https://github.com/dschewchenko/big.esm/compare/v1.1.1...v1.1.2) (2023-05-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* benchmark update and readme notes ([7b8d446](https://github.com/dschewchenko/big.esm/commit/7b8d446be55eb0f0979ab310491e9bb685215753))
|
|
7
|
+
|
|
8
|
+
## [1.1.1](https://github.com/dschewchenko/big.esm/compare/v1.1.0...v1.1.1) (2023-05-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* readme update and ci update ([d43d486](https://github.com/dschewchenko/big.esm/commit/d43d4869a468d7092674778c97ad888cd4600af8))
|
|
14
|
+
|
|
1
15
|
# [1.1.0](https://github.com/dschewchenko/big.esm/compare/v1.0.2...v1.1.0) (2023-05-14)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
# big.esm
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/big.esm)
|
|
4
|
+
[](https://www.npmjs.com/package/big.esm)
|
|
5
|
+
|
|
3
6
|
Library for working with large numbers and fractions using `BigInt`.
|
|
4
7
|
It provides advanced functionality for performing arithmetic operations with precision and decimal handling.
|
|
5
8
|
[Documentation](https://dschewchenko.github.io/big.esm/).
|
|
6
9
|
|
|
7
|
-
100% test coverage.
|
|
10
|
+
- 100% test coverage.
|
|
8
11
|
|
|
9
|
-
No dependencies.
|
|
12
|
+
- No dependencies.
|
|
10
13
|
|
|
11
|
-
No limitations on the size of the numbers, except for the limitations of `BigInt`, so limited by system memory =).
|
|
14
|
+
- No limitations on the size of the numbers, except for the limitations of `BigInt`, so limited by system memory =).
|
|
12
15
|
|
|
13
|
-
Fully written in TypeScript, so it provides type definitions out of the box.
|
|
16
|
+
- Fully written in TypeScript, so it provides type definitions out of the box.
|
|
14
17
|
|
|
15
|
-
Tree-shaking is supported.
|
|
18
|
+
- Tree-shaking is supported.
|
|
16
19
|
|
|
17
20
|
Full bundle size(ESM) — 3.12 kB minified and 1.42 kB gzipped.
|
|
18
21
|
`powBig` operation is half of this size, 1.5kB/0.7kB(minified/gzip),
|
|
19
22
|
because it's big and reuses most of the operations from `big.esm`.
|
|
20
23
|
|
|
21
|
-
Full bundle size(UMD) — 3.43 kB minified and 1.57 kB gzipped.
|
|
22
|
-
|
|
23
24
|
## Installation
|
|
24
25
|
|
|
25
26
|
Install `big.esm` using npm:
|
|
@@ -60,10 +61,9 @@ Creates a new `Big` instance from a string, number or `BigInt`. Optionally, you
|
|
|
60
61
|
|
|
61
62
|
### Utilities
|
|
62
63
|
|
|
63
|
-
#### `createBig(value: string | number | bigint): Big`
|
|
64
|
+
#### `createBig(value: string | number | bigint, scale?: number | string): Big`
|
|
64
65
|
|
|
65
|
-
Alias for `new Big(value)`.
|
|
66
|
-
But it does not support the scale parameter and if the value is instance of `Big` it will be returned without changes.
|
|
66
|
+
Alias for `new Big(value, scale)`.
|
|
67
67
|
|
|
68
68
|
#### `cloneBig(a: Big): Big`
|
|
69
69
|
|
|
@@ -91,21 +91,21 @@ Subtracts two `Big` instances.
|
|
|
91
91
|
|
|
92
92
|
Multiplies two `Big` instances.
|
|
93
93
|
|
|
94
|
-
#### `divBig(a: Big, b: Big): Big`
|
|
94
|
+
#### `divBig(a: Big, b: Big, precision = 20, roundingMode = "half-up"): Big`
|
|
95
95
|
|
|
96
|
-
Divides two `Big` instances.
|
|
96
|
+
Divides two `Big` instances. The default precision is 20. The default rounding mode is "half-up".
|
|
97
97
|
|
|
98
98
|
#### `modBig(a: Big, b: Big): Big`
|
|
99
99
|
|
|
100
100
|
Calculates the remainder of dividing two `Big` instances.
|
|
101
101
|
|
|
102
|
-
#### `powBig(a: Big,
|
|
102
|
+
#### `powBig(a: Big, exp: number): Big`
|
|
103
103
|
|
|
104
104
|
Raises `a` to the power of `b`.
|
|
105
105
|
|
|
106
|
-
#### `sqrtBig(a: Big): Big`
|
|
106
|
+
#### `sqrtBig(a: Big, root = 2, precision = 20): Big`
|
|
107
107
|
|
|
108
|
-
Calculates the
|
|
108
|
+
Calculates the root of `a`. The default root is 2, which means the square root. The default precision is 20.
|
|
109
109
|
|
|
110
110
|
#### `absBig(a: Big): Big`
|
|
111
111
|
|
|
@@ -119,44 +119,54 @@ Compares two `Big` instances. Returns `-1` if `a < b`, `0` if `a == b` and `1` i
|
|
|
119
119
|
|
|
120
120
|
Compare `big.esm` with `big.js`. 100_000 iterations for each operation.
|
|
121
121
|
|
|
122
|
-
| Operation
|
|
123
|
-
|
|
124
|
-
| init - smallInt
|
|
125
|
-
| add - smallInt
|
|
126
|
-
| subtract - smallInt
|
|
127
|
-
| multiply - smallInt
|
|
128
|
-
| divide - smallInt
|
|
129
|
-
| power of 4 - smallInt
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
135
|
-
|
|
|
136
|
-
|
|
|
137
|
-
|
|
|
138
|
-
|
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
|
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
122
|
+
| Operation | big.esm | big.js | Difference |
|
|
123
|
+
|---------------------------|-------------|------------|-----------------|
|
|
124
|
+
| init - smallInt | 40.267ms | 24.225ms | -66.22% slower |
|
|
125
|
+
| add - smallInt | 24.570ms | 16.543ms | -48.52% slower |
|
|
126
|
+
| subtract - smallInt | 22.152ms | 16.455ms | -34.63% slower |
|
|
127
|
+
| multiply - smallInt | 23.394ms | 25.183ms | 7.10% faster |
|
|
128
|
+
| divide - smallInt | 68.486ms | 232.593ms | 70.56% faster |
|
|
129
|
+
| power of 4 - smallInt | 124.721ms | 63.314ms | -96.99% slower |
|
|
130
|
+
| square root - smallInt | 5608.635ms | 1489.536ms | -276.54% slower |
|
|
131
|
+
| init - smallNumber | 43.917ms | 38.125ms | -15.19% slower |
|
|
132
|
+
| add - smallNumber | 22.342ms | 26.888ms | 16.91% faster |
|
|
133
|
+
| subtract - smallNumber | 21.692ms | 27.138ms | 20.07% faster |
|
|
134
|
+
| multiply - smallNumber | 27.452ms | 56.488ms | 51.40% faster |
|
|
135
|
+
| divide - smallNumber | 62.497ms | 318.407ms | 80.37% faster |
|
|
136
|
+
| power of 4 - smallNumber | 153.008ms | 156.773ms | 2.40% faster |
|
|
137
|
+
| square root - smallNumber | 5557.749ms | 1558.616ms | -256.58% slower |
|
|
138
|
+
| init - bigInt | 50.074ms | 36.019ms | -39.02% slower |
|
|
139
|
+
| add - bigInt | 27.391ms | 24.467ms | -11.95% slower |
|
|
140
|
+
| subtract - bigInt | 27.009ms | 24.022ms | -12.43% slower |
|
|
141
|
+
| multiply - bigInt | 33.851ms | 120.812ms | 71.98% faster |
|
|
142
|
+
| divide - bigInt | 77.744ms | 714.170ms | 89.11% faster |
|
|
143
|
+
| power of 4 - bigInt | 248.630ms | 498.119ms | 50.09% faster |
|
|
144
|
+
| square root - bigInt | 16917.234ms | 5955.270ms | -184.07% slower |
|
|
145
|
+
| init - bigNumber | 60.159ms | 85.812ms | 29.89% faster |
|
|
146
|
+
| add - bigNumber | 33.340ms | 56.803ms | 41.31% faster |
|
|
147
|
+
| subtract - bigNumber | 34.255ms | 54.496ms | 37.14% faster |
|
|
148
|
+
| multiply - bigNumber | 50.376ms | 452.010ms | 88.86% faster |
|
|
149
|
+
| divide - bigNumber | 80.627ms | 1376.583ms | 94.14% faster |
|
|
150
|
+
| power of 4 - bigNumber | 553.183ms | 2005.740ms | 72.42% faster |
|
|
151
|
+
| square root - bigNumber | 17023.515ms | 5104.271ms | -233.52% slower |
|
|
152
|
+
|
|
153
|
+
Note 1: Square root is slower because it uses Newton's method with variable root(quadratic, cubic, etc.ій) and high precision.
|
|
154
|
+
The more precise the result, the more iterations are required.
|
|
155
|
+
|
|
156
|
+
Node 2: On small numbers big.esm is slower because it uses bigint, which is slower on initialization.
|
|
157
|
+
And each operation returns a new instance of Big, without mutating the original instance.
|
|
148
158
|
|
|
149
159
|
#### Test data:
|
|
150
160
|
|
|
151
161
|
```js
|
|
152
|
-
const smallIntA =
|
|
153
|
-
const smallIntB =
|
|
154
|
-
const smallNumberA =
|
|
155
|
-
const smallNumberB =
|
|
162
|
+
const smallIntA = 12345;
|
|
163
|
+
const smallIntB = 45678;
|
|
164
|
+
const smallNumberA = 12345.67809;
|
|
165
|
+
const smallNumberB = 78901.23456;
|
|
156
166
|
const bigIntA = "12345678901234567890";
|
|
157
167
|
const bigIntB = "67890123456789012345";
|
|
158
|
-
const bigNumberA = "12345678901234567890.
|
|
159
|
-
const bigNumberB = "67890123456789012345.
|
|
168
|
+
const bigNumberA = "12345678901234567890.12345678901234567890"
|
|
169
|
+
const bigNumberB = "67890123456789012345.67890123456789012345";
|
|
160
170
|
```
|
|
161
171
|
|
|
162
172
|
Benchmarked on MacBook Pro M1 2021.
|