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.
Files changed (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +57 -47
  3. 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
+ [![npm version](https://img.shields.io/npm/v/big.esm.svg)](https://www.npmjs.com/package/big.esm)
4
+ [![npm downloads](https://img.shields.io/npm/dw/big.esm)](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, b: Big): 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 square root of `a`.
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 | big.esm | big.js | Difference |
123
- |--------------------------|-----------|------------|-----------------|
124
- | init - smallInt | 39.856ms | 22.169ms | -79.78% slower |
125
- | add - smallInt | 24.227ms | 15.125ms | -60.17% slower |
126
- | subtract - smallInt | 22.181ms | 15.094ms | -46.95% slower |
127
- | multiply - smallInt | 22.276ms | 18.538ms | -20.16% slower |
128
- | divide - smallInt | 66.923ms | 179.699ms | 62.76% faster |
129
- | power of 4 - smallInt | 113.714ms | 39.359ms | -188.92% slower |
130
- | init - smallNumber | 44.606ms | 37.136ms | -20.12% slower |
131
- | add - smallNumber | 21.719ms | 21.857ms | 0.63% faster |
132
- | subtract - smallNumber | 21.090ms | 24.064ms | 12.36% faster |
133
- | multiply - smallNumber | 23.246ms | 35.010ms | 33.60% faster |
134
- | divide - smallNumber | 60.102ms | 189.603ms | 68.30% faster |
135
- | power of 4 - smallNumber | 136.611ms | 68.859ms | -98.39% slower |
136
- | init - bigInt | 50.278ms | 36.880ms | -36.33% slower |
137
- | add - bigInt | 27.485ms | 25.402ms | -8.20% slower |
138
- | subtract - bigInt | 27.402ms | 24.622ms | -11.29% slower |
139
- | multiply - bigInt | 33.650ms | 121.126ms | 72.22% faster |
140
- | divide - bigInt | 79.523ms | 602.879ms | 86.81% faster |
141
- | power of 4 - bigInt | 248.514ms | 499.246ms | 50.22% faster |
142
- | init - bigNumber | 55.661ms | 77.789ms | 28.45% faster |
143
- | add - bigNumber | 29.755ms | 47.843ms | 37.81% faster |
144
- | subtract - bigNumber | 29.107ms | 47.313ms | 38.48% faster |
145
- | multiply - bigNumber | 39.976ms | 266.814ms | 85.02% faster |
146
- | divide - bigNumber | 78.278ms | 931.610ms | 91.60% faster |
147
- | power of 4 - bigNumber | 376.169ms | 1132.657ms | 66.79% faster |
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 = 123;
153
- const smallIntB = 456;
154
- const smallNumberA = 123.456;
155
- const smallNumberB = 789.012;
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.1234567890";
159
- const bigNumberB = "67890123456789012345.6789012345";
168
+ const bigNumberA = "12345678901234567890.12345678901234567890"
169
+ const bigNumberB = "67890123456789012345.67890123456789012345";
160
170
  ```
161
171
 
162
172
  Benchmarked on MacBook Pro M1 2021.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big.esm",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
5
5
  "type": "module",
6
6
  "scripts": {