big.esm 1.0.1 → 1.0.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 +7 -0
  2. package/README.md +56 -14
  3. package/package.json +3 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.0.2](https://github.com/dschewchenko/big.esm/compare/v1.0.1...v1.0.2) (2023-05-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update readme and add benchmark ([8e9c2fc](https://github.com/dschewchenko/big.esm/commit/8e9c2fccf23887ca2699d6120dce42733e25945d))
7
+
1
8
  ## [1.0.1](https://github.com/dschewchenko/big.esm/compare/v1.0.0...v1.0.1) (2023-05-13)
2
9
 
3
10
 
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Library for working with large numbers and fractions using `BigInt`.
4
4
  It provides advanced functionality for performing arithmetic operations with precision and decimal handling.
5
+ [Documentation](https://dschewchenko.github.io/big.esm/).
5
6
 
6
7
  100% test coverage.
7
8
 
@@ -63,26 +64,15 @@ Creates a new `Big` instance from a string, number or `BigInt`. Optionally, you
63
64
  Alias for `new Big(value)`.
64
65
  But it does not support the scale parameter and if the value is instance of `Big` it will be returned without changes.
65
66
 
66
- ```js
67
- const a = createBig("12345678910.12345678910"); // value = 1234567891012345678910 ,scale = 11
68
- const b = createBig(12345678910.12345678910); // value = 1234567891012345678910 ,scale = 11
69
- const c = createBig(1234567891012345678910n); // value = 1234567891012345678910 ,scale = 0
70
- ```
71
-
72
- ### `cloneBig(a: Big): Big`
67
+ #### `cloneBig(a: Big): Big`
73
68
 
74
69
  Creates a new `Big` instance from another `Big` instance.
75
70
 
76
- ```js
77
- const a = createBig("12345678910.12345678910");
78
- const b = cloneBig(a);
79
- ```
80
-
81
- ### `alignScale(a: Big, b: Big): [Big, Big]`
71
+ #### `alignScale(a: Big, b: Big): [Big, Big]`
82
72
 
83
73
  Aligns the scale of two `Big` instances. The scale of the result will be equal to the maximum scale of the two numbers.
84
74
 
85
- ### `isNumericValue(value: any): boolean`
75
+ #### `isNumericValue(value: any): boolean`
86
76
 
87
77
  Checks if the value is a valid numeric value for creating a `Big` instance.
88
78
 
@@ -120,6 +110,58 @@ Calculates the square root of `a`.
120
110
 
121
111
  Returns the absolute value of `a`.
122
112
 
113
+ #### `compareBig(a: Big, b: Big): -1 | 0 | 1`
114
+
115
+ Compares two `Big` instances. Returns `-1` if `a < b`, `0` if `a == b` and `1` if `a > b`.
116
+
117
+ ## Benchmark
118
+
119
+ Compare `big.esm` with `big.js`. 100_000 iterations for each operation.
120
+
121
+ | Operation | big.esm | big.js | Difference |
122
+ | --- | --- | --- | --- |
123
+ | init - smallInt | 40.538ms | 23.042ms | -75.93% slower |
124
+ | add - smallInt | 25.755ms | 15.443ms | -66.77% slower |
125
+ | subtract - smallInt | 22.998ms | 15.419ms | -49.15% slower |
126
+ | multiply - smallInt | 22.684ms | 19.931ms | -13.81% slower |
127
+ | divide - smallInt | 67.082ms | 182.769ms | 63.30% faster |
128
+ | power of 4 - smallInt | 115.589ms | 40.343ms | -186.51% slower |
129
+ | init - smallNumber | 45.344ms | 37.790ms | -19.99% slower |
130
+ | add - smallNumber | 21.636ms | 22.357ms | 3.23% faster |
131
+ | subtract - smallNumber | 21.750ms | 24.691ms | 11.91% faster |
132
+ | multiply - smallNumber | 23.852ms | 35.742ms | 33.27% faster |
133
+ | divide - smallNumber | 61.577ms | 194.170ms | 68.29% faster |
134
+ | power of 4 - smallNumber | 137.407ms | 70.480ms | -94.96% slower |
135
+ | init - bigInt | 51.163ms | 37.148ms | -37.73% slower |
136
+ | add - bigInt | 27.229ms | 25.447ms | -7.00% slower |
137
+ | subtract - bigInt | 27.146ms | 24.872ms | -9.14% slower |
138
+ | multiply - bigInt | 33.915ms | 124.638ms | 72.79% faster |
139
+ | divide - bigInt | 81.944ms | 624.192ms | 86.87% faster |
140
+ | power of 4 - bigInt | 251.438ms | 512.083ms | 50.90% faster |
141
+ | init - bigNumber | 57.123ms | 77.780ms | 26.56% faster |
142
+ | add - bigNumber | 30.457ms | 49.525ms | 38.50% faster |
143
+ | subtract - bigNumber | 30.979ms | 49.906ms | 37.93% faster |
144
+ | multiply - bigNumber | 41.303ms | 271.533ms | 84.79% faster |
145
+ | divide - bigNumber | 81.252ms | 940.948ms | 91.36% faster |
146
+ | power of 4 - bigNumber | 375.813ms | 1281.233ms | 70.67% faster |
147
+
148
+ #### Test data:
149
+
150
+ ```js
151
+ const smallIntA = 123;
152
+ const smallIntB = 456;
153
+ const smallNumberA = 123.456;
154
+ const smallNumberB = 789.012;
155
+ const bigIntA = "12345678901234567890";
156
+ const bigIntB = "67890123456789012345";
157
+ const bigNumberA = "12345678901234567890.1234567890";
158
+ const bigNumberB = "67890123456789012345.6789012345";
159
+ ```
160
+
161
+ Benchmarked on MacBook Pro M1 2021.
162
+
163
+ Code for benchmarking is in the `benchmark.js` file. You can run it with `npm run benchmark`.
164
+
123
165
  ## Roadmap
124
166
 
125
167
  - [x] Generate documentation from JSDoc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big.esm",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -14,6 +14,7 @@
14
14
  "docs": "typedoc --out docs src/index.ts",
15
15
  "lint": "eslint --ext .ts,.js,.json ./src",
16
16
  "lint:fix": "eslint --fix --ext .ts,.js,.json ./src",
17
+ "benchmark": "node ./benchmark.js",
17
18
  "semantic-release": "semantic-release",
18
19
  "prepare": "is-ci || husky install"
19
20
  },
@@ -49,6 +50,7 @@
49
50
  "node": ">=16"
50
51
  },
51
52
  "devDependencies": {
53
+ "big.js": "^6.2.1",
52
54
  "@commitlint/cli": "^17.6.3",
53
55
  "@commitlint/config-conventional": "^17.6.3",
54
56
  "@semantic-release/changelog": "^6.0.3",