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/big.esm.js
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
const h = 0n, m = 1n, I = 10n;
|
|
2
|
+
function D(e) {
|
|
3
|
+
if (e === null || typeof e != "object") return !1;
|
|
4
|
+
const t = e;
|
|
5
|
+
return typeof t.value == "bigint" && typeof t.scale == "number";
|
|
6
|
+
}
|
|
7
|
+
function f(e, t) {
|
|
8
|
+
return e instanceof B ? e : D(e) ? new B(e.value, e.scale) : t === void 0 ? new B(e) : new B(e, t);
|
|
9
|
+
}
|
|
10
|
+
function O(e, t = !1, n = !0) {
|
|
11
|
+
const r = typeof e == "number" ? String(e) : e, s = /^(-)?(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(r);
|
|
12
|
+
if (!s) throw new Error("Num");
|
|
13
|
+
const l = s[1] ? "-" : "";
|
|
14
|
+
let u = s[2] || "", i = s[3] || "";
|
|
15
|
+
if (u.length === 0 && i.length === 0)
|
|
16
|
+
throw new Error("Num");
|
|
17
|
+
t && (i = "");
|
|
18
|
+
const c = Number.parseInt(s[4] || "0", 10);
|
|
19
|
+
if (!Number.isFinite(c)) throw new Error("Exp");
|
|
20
|
+
if (c > 0) {
|
|
21
|
+
const w = Math.min(c, i.length);
|
|
22
|
+
u += i.slice(0, w), i = i.slice(w), w < c && (u += "0".repeat(c - w));
|
|
23
|
+
} else if (c < 0) {
|
|
24
|
+
const w = Math.min(-c, u.length);
|
|
25
|
+
i = u.slice(-w) + i, u = u.slice(0, u.length - w), w < -c && (i = "0".repeat(-c - w) + i);
|
|
26
|
+
}
|
|
27
|
+
const o = BigInt(l + u + i), a = i.length;
|
|
28
|
+
return o === h ? n ? f(h) : { value: h, scale: 0 } : n ? f(o, a) : { value: o, scale: a };
|
|
29
|
+
}
|
|
30
|
+
const T = /0+$/, _ = (e) => e.replace(T, "");
|
|
31
|
+
class B {
|
|
32
|
+
/**
|
|
33
|
+
* The value of the Big instance.
|
|
34
|
+
*/
|
|
35
|
+
value;
|
|
36
|
+
/**
|
|
37
|
+
* The scale of the Big instance, representing the number of decimal places.
|
|
38
|
+
*/
|
|
39
|
+
scale;
|
|
35
40
|
/**
|
|
36
41
|
* Implements the overloaded constructors for the Big class.
|
|
37
42
|
* @param {BigValue} value - The value to create the Big instance from. Can be a number, string, BigInt, or another Big instance.
|
|
@@ -40,26 +45,27 @@ class w {
|
|
|
40
45
|
* @return {Big} - A new Big instance.
|
|
41
46
|
*/
|
|
42
47
|
constructor(t, n) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* The scale of the Big instance, representing the number of decimal places.
|
|
49
|
-
*/
|
|
50
|
-
I(this, "scale");
|
|
51
|
-
if (P(t))
|
|
48
|
+
if (t instanceof B) {
|
|
49
|
+
this.value = t.value, this.scale = t.scale;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (D(t)) {
|
|
52
53
|
this.value = t.value, this.scale = t.scale;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (typeof t == "object" && t !== null)
|
|
57
|
+
throw new TypeError("Big");
|
|
58
|
+
let r = n !== void 0, s = 0;
|
|
59
|
+
if (r && (s = typeof n == "number" ? n : Number(n), r = !Number.isNaN(s), r && (s = Math.floor(s))), typeof t == "bigint") {
|
|
60
|
+
this.value = t, this.scale = r ? s : 0;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof t == "number" || typeof t == "string") {
|
|
64
|
+
const { value: l, scale: u } = O(t, r, !1);
|
|
65
|
+
this.value = l, this.scale = r ? s : u;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
throw new TypeError("Big");
|
|
63
69
|
}
|
|
64
70
|
/**
|
|
65
71
|
* Returns the primitive value of the Big instance.
|
|
@@ -80,9 +86,10 @@ class w {
|
|
|
80
86
|
const r = n.startsWith("-") ? "-" : "";
|
|
81
87
|
r && (n = n.substring(1));
|
|
82
88
|
let s = "";
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
const l = this.scale;
|
|
90
|
+
if (l > 0) {
|
|
91
|
+
const u = n.length > l ? n.length - l : 0;
|
|
92
|
+
s = n.slice(u).padStart(l, "0"), t && (s = _(s)), s.length > 0 && (s = `.${s}`), n = n.slice(0, u);
|
|
86
93
|
}
|
|
87
94
|
return `${r}${n || "0"}${s}`;
|
|
88
95
|
}
|
|
@@ -95,113 +102,195 @@ class w {
|
|
|
95
102
|
return this.toString();
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
105
|
+
function V(e) {
|
|
106
|
+
return e.value = e.value < h ? -e.value : e.value, e;
|
|
107
|
+
}
|
|
108
|
+
const x = 256, g = [m];
|
|
109
|
+
function v(e) {
|
|
110
|
+
if (e < 0)
|
|
111
|
+
throw new Error("Exp");
|
|
112
|
+
if (e <= x) {
|
|
113
|
+
const t = g[e];
|
|
114
|
+
if (t !== void 0) return t;
|
|
115
|
+
for (let n = g.length; n <= e; n++)
|
|
116
|
+
g[n] = g[n - 1] * I;
|
|
117
|
+
return g[e];
|
|
118
|
+
}
|
|
119
|
+
return I ** BigInt(e);
|
|
120
|
+
}
|
|
121
|
+
function N(e, t) {
|
|
122
|
+
const n = e.scale - t.scale;
|
|
123
|
+
if (n === 0)
|
|
124
|
+
return e.value += t.value, e;
|
|
125
|
+
const r = v(Math.abs(n));
|
|
126
|
+
return n > 0 ? (e.value += t.value * r, e) : (e.value = e.value * r + t.value, e.scale = t.scale, e);
|
|
127
|
+
}
|
|
128
|
+
const M = (e, t) => {
|
|
129
|
+
const n = e.scale - t.scale;
|
|
130
|
+
if (n === 0)
|
|
131
|
+
return e.value > t.value ? 1 : e.value < t.value ? -1 : 0;
|
|
132
|
+
const r = v(Math.abs(n)), s = n > 0 ? e.value : e.value * r, l = n < 0 ? t.value : t.value * r;
|
|
133
|
+
return s > l ? 1 : s < l ? -1 : 0;
|
|
134
|
+
}, S = (e) => e.value === h;
|
|
135
|
+
function E(e, t, n = 20, r = "half-up") {
|
|
136
|
+
if (S(t))
|
|
137
|
+
throw new Error("Div0");
|
|
138
|
+
const s = Math.max(e.scale, t.scale), l = Math.max(0, n), u = e.value * v(s + l - e.scale), i = t.value * v(s - t.scale), c = u / i, o = u % i;
|
|
139
|
+
let a = c;
|
|
126
140
|
switch (r) {
|
|
127
141
|
case "down":
|
|
128
|
-
c = a;
|
|
129
142
|
break;
|
|
130
143
|
case "up":
|
|
131
|
-
|
|
144
|
+
a = o !== h ? c + m : c;
|
|
132
145
|
break;
|
|
133
|
-
case "half-up":
|
|
134
146
|
default:
|
|
135
|
-
|
|
147
|
+
a = o * 2n >= i ? c + m : c;
|
|
136
148
|
break;
|
|
137
149
|
}
|
|
138
|
-
return
|
|
150
|
+
return e.value = a, e.scale = l, e;
|
|
139
151
|
}
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
throw new Error("Division by zero is not allowed.");
|
|
143
|
-
const r = B(e, t, 0, "down");
|
|
144
|
-
if (n)
|
|
145
|
-
return E(r, t, !0), N(e, r, !0);
|
|
146
|
-
const s = E(r, t);
|
|
147
|
-
return N(e, s);
|
|
152
|
+
function F(e, t) {
|
|
153
|
+
return M(e, t) >= 0 ? e : t;
|
|
148
154
|
}
|
|
149
|
-
function
|
|
155
|
+
function G(e, t) {
|
|
156
|
+
return M(e, t) > 0 ? t : e;
|
|
157
|
+
}
|
|
158
|
+
const p = (e) => new B(e.value, e.scale);
|
|
159
|
+
function y(e, t) {
|
|
160
|
+
return e.value = e.value * t.value, e.scale = e.scale + t.scale, e;
|
|
161
|
+
}
|
|
162
|
+
function P(e, t) {
|
|
163
|
+
const n = e.scale - t.scale;
|
|
164
|
+
if (n === 0)
|
|
165
|
+
return e.value -= t.value, e;
|
|
166
|
+
const r = v(Math.abs(n));
|
|
167
|
+
return n > 0 ? (e.value -= t.value * r, e) : (e.value = e.value * r - t.value, e.scale = t.scale, e);
|
|
168
|
+
}
|
|
169
|
+
function C(e, t) {
|
|
170
|
+
if (S(t))
|
|
171
|
+
throw new Error("Div0");
|
|
172
|
+
const n = p(e);
|
|
173
|
+
return E(n, t, 0, "down"), y(n, t), P(e, n);
|
|
174
|
+
}
|
|
175
|
+
function d(e, t = 2) {
|
|
150
176
|
if (!Number.isInteger(t) || t < 0)
|
|
151
|
-
throw new Error("
|
|
152
|
-
|
|
153
|
-
return n ? (e.value = r, e.scale = s, e) : o(r, s);
|
|
177
|
+
throw new Error("Exp");
|
|
178
|
+
return e.value = e.value ** BigInt(t), e.scale = e.scale * t, e;
|
|
154
179
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (d(e))
|
|
165
|
-
return o(0);
|
|
166
|
-
if (e.valueOf() === BigInt(1))
|
|
167
|
-
return o(1);
|
|
168
|
-
if (e.value < m && t % 2 === 0)
|
|
169
|
-
throw new Error("The root must be an odd integer when the number is negative.");
|
|
180
|
+
function R(e, t = 2, n = 20) {
|
|
181
|
+
if (n < 0) throw new Error("Prec");
|
|
182
|
+
const r = Math.max(0, n);
|
|
183
|
+
if (S(e))
|
|
184
|
+
return e.value = h, e.scale = r, e;
|
|
185
|
+
if (e.value === m)
|
|
186
|
+
return e.value = m, e.scale = r, e;
|
|
187
|
+
if (e.value < h && t % 2 === 0)
|
|
188
|
+
throw new Error("Root");
|
|
170
189
|
if (!Number.isInteger(t) || t < 2)
|
|
171
|
-
throw new Error("
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
const s =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
throw new Error("Root");
|
|
191
|
+
if (t === 2)
|
|
192
|
+
return e.value = A(e, r), e.scale = r, e;
|
|
193
|
+
const s = p(e);
|
|
194
|
+
return q(e, s, t, r), e;
|
|
195
|
+
}
|
|
196
|
+
function q(e, t, n, r) {
|
|
197
|
+
const s = f(n), l = f(n - 1), u = f(2), i = p(t);
|
|
198
|
+
E(i, u, r), e.value = t.value, e.scale = t.scale, N(e, i), E(e, u, r);
|
|
199
|
+
const c = p(e), o = p(e), a = p(t);
|
|
200
|
+
for (; ; ) {
|
|
201
|
+
if (c.value = e.value, c.scale = e.scale, y(c, l), o.value = e.value, o.scale = e.scale, d(o, n - 1), a.value = t.value, a.scale = t.scale, E(a, o, r), N(c, a), E(c, s, r), k(e.value - c.value) <= m) {
|
|
202
|
+
e.value = c.value, e.scale = r;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
e.value = c.value, e.scale = c.scale;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function A(e, t) {
|
|
209
|
+
const r = 2 * (t + 1) - e.scale, s = e.value < h ? -e.value : e.value, l = r >= 0 ? s * v(r) : s / v(-r), u = $(l), i = u % I;
|
|
210
|
+
let c = u / I;
|
|
211
|
+
return i >= 5n && (c += m), c;
|
|
212
|
+
}
|
|
213
|
+
function j(e) {
|
|
214
|
+
const t = e.toString(16), n = t.charCodeAt(0), r = n < 58 ? n - 48 : n - 87;
|
|
215
|
+
return (t.length - 1) * 4 + (32 - Math.clz32(r));
|
|
216
|
+
}
|
|
217
|
+
function $(e) {
|
|
218
|
+
if (e < h)
|
|
219
|
+
throw new Error("Sqrt");
|
|
220
|
+
if (e < 2n) return e;
|
|
221
|
+
const t = j(e);
|
|
222
|
+
let n = m << BigInt(t + 1 >> 1), r = n + e / n >> m;
|
|
223
|
+
for (; r < n; )
|
|
224
|
+
n = r, r = n + e / n >> m;
|
|
225
|
+
return n;
|
|
226
|
+
}
|
|
227
|
+
function k(e) {
|
|
228
|
+
return e < h ? -e : e;
|
|
229
|
+
}
|
|
230
|
+
class L {
|
|
231
|
+
current;
|
|
232
|
+
constructor(t) {
|
|
233
|
+
this.current = f(t);
|
|
234
|
+
}
|
|
235
|
+
add(t) {
|
|
236
|
+
return N(this.current, f(t)), this;
|
|
237
|
+
}
|
|
238
|
+
sub(t) {
|
|
239
|
+
return P(this.current, f(t)), this;
|
|
240
|
+
}
|
|
241
|
+
mul(t) {
|
|
242
|
+
return y(this.current, f(t)), this;
|
|
243
|
+
}
|
|
244
|
+
div(t, n, r) {
|
|
245
|
+
return E(this.current, f(t), n, r), this;
|
|
246
|
+
}
|
|
247
|
+
mod(t) {
|
|
248
|
+
return C(this.current, f(t)), this;
|
|
249
|
+
}
|
|
250
|
+
pow(t = 2) {
|
|
251
|
+
return d(this.current, t), this;
|
|
252
|
+
}
|
|
253
|
+
sqrt(t = 2, n) {
|
|
254
|
+
return R(this.current, t, n), this;
|
|
255
|
+
}
|
|
256
|
+
value() {
|
|
257
|
+
return this.current;
|
|
258
|
+
}
|
|
259
|
+
toString(t = !0) {
|
|
260
|
+
return this.current.toString(t);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function Z(e) {
|
|
264
|
+
return new L(e);
|
|
265
|
+
}
|
|
266
|
+
function U(e, t) {
|
|
267
|
+
const n = e.scale - t.scale;
|
|
268
|
+
if (n === 0)
|
|
269
|
+
return [e, t];
|
|
270
|
+
const r = v(Math.abs(n));
|
|
271
|
+
return n > 0 ? (t.value *= r, t.scale = e.scale, [e, t]) : (e.value *= r, e.scale = t.scale, [e, t]);
|
|
272
|
+
}
|
|
273
|
+
const W = (e) => typeof e == "bigint" || typeof e == "number" || typeof e == "string" && !Number.isNaN(Number(e));
|
|
188
274
|
export {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
Z as
|
|
206
|
-
|
|
275
|
+
B as Big,
|
|
276
|
+
L as BigPipe,
|
|
277
|
+
V as absBig,
|
|
278
|
+
N as addBig,
|
|
279
|
+
U as alignScale,
|
|
280
|
+
p as cloneBig,
|
|
281
|
+
M as compareBig,
|
|
282
|
+
f as createBig,
|
|
283
|
+
E as divBig,
|
|
284
|
+
O as fromString,
|
|
285
|
+
D as isBigObject,
|
|
286
|
+
W as isNumericValue,
|
|
287
|
+
F as maxBig,
|
|
288
|
+
G as minBig,
|
|
289
|
+
C as modBig,
|
|
290
|
+
y as mulBig,
|
|
291
|
+
Z as pipeBig,
|
|
292
|
+
v as pow10,
|
|
293
|
+
d as powBig,
|
|
294
|
+
R as sqrtBig,
|
|
295
|
+
P as subBig
|
|
207
296
|
};
|
package/dist/big.esm.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(c=typeof globalThis<"u"?globalThis:c||self,I((c.big=c.big||{},c.big.esm={})))})(this,(function(c){"use strict";const f=0n,g=1n,S=10n;function M(e){if(e===null||typeof e!="object")return!1;const t=e;return typeof t.value=="bigint"&&typeof t.scale=="number"}function a(e,t){return e instanceof v?e:M(e)?new v(e.value,e.scale):t===void 0?new v(e):new v(e,t)}function _(e,t=!1,n=!0){const r=typeof e=="number"?String(e):e,i=/^(-)?(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(r);if(!i)throw new Error("Num");const o=i[1]?"-":"";let u=i[2]||"",l=i[3]||"";if(u.length===0&&l.length===0)throw new Error("Num");t&&(l="");const s=Number.parseInt(i[4]||"0",10);if(!Number.isFinite(s))throw new Error("Exp");if(s>0){const w=Math.min(s,l.length);u+=l.slice(0,w),l=l.slice(w),w<s&&(u+="0".repeat(s-w))}else if(s<0){const w=Math.min(-s,u.length);l=u.slice(-w)+l,u=u.slice(0,u.length-w),w<-s&&(l="0".repeat(-s-w)+l)}const h=BigInt(o+u+l),m=l.length;return h===f?n?a(f):{value:f,scale:0}:n?a(h,m):{value:h,scale:m}}const R=/0+$/,A=e=>e.replace(R,"");class v{value;scale;constructor(t,n){if(t instanceof v){this.value=t.value,this.scale=t.scale;return}if(M(t)){this.value=t.value,this.scale=t.scale;return}if(typeof t=="object"&&t!==null)throw new TypeError("Big");let r=n!==void 0,i=0;if(r&&(i=typeof n=="number"?n:Number(n),r=!Number.isNaN(i),r&&(i=Math.floor(i))),typeof t=="bigint"){this.value=t,this.scale=r?i:0;return}if(typeof t=="number"||typeof t=="string"){const{value:o,scale:u}=_(t,r,!1);this.value=o,this.scale=r?i:u;return}throw new TypeError("Big")}valueOf(){return this.value}toString(t=!0){let n=this.value.toString();const r=n.startsWith("-")?"-":"";r&&(n=n.substring(1));let i="";const o=this.scale;if(o>0){const u=n.length>o?n.length-o:0;i=n.slice(u).padStart(o,"0"),t&&(i=A(i)),i.length>0&&(i=`.${i}`),n=n.slice(0,u)}return`${r}${n||"0"}${i}`}toJSON(){return this.toString()}}function V(e){return e.value=e.value<f?-e.value:e.value,e}const $=256,N=[g];function B(e){if(e<0)throw new Error("Exp");if(e<=$){const t=N[e];if(t!==void 0)return t;for(let n=N.length;n<=e;n++)N[n]=N[n-1]*S;return N[e]}return S**BigInt(e)}function p(e,t){const n=e.scale-t.scale;if(n===0)return e.value+=t.value,e;const r=B(Math.abs(n));return n>0?(e.value+=t.value*r,e):(e.value=e.value*r+t.value,e.scale=t.scale,e)}const P=(e,t)=>{const n=e.scale-t.scale;if(n===0)return e.value>t.value?1:e.value<t.value?-1:0;const r=B(Math.abs(n)),i=n>0?e.value:e.value*r,o=n<0?t.value:t.value*r;return i>o?1:i<o?-1:0},D=e=>e.value===f;function E(e,t,n=20,r="half-up"){if(D(t))throw new Error("Div0");const i=Math.max(e.scale,t.scale),o=Math.max(0,n),u=e.value*B(i+o-e.scale),l=t.value*B(i-t.scale),s=u/l,h=u%l;let m=s;switch(r){case"down":break;case"up":m=h!==f?s+g:s;break;default:m=h*2n>=l?s+g:s;break}return e.value=m,e.scale=o,e}function k(e,t){return P(e,t)>=0?e:t}function L(e,t){return P(e,t)>0?t:e}const d=e=>new v(e.value,e.scale);function y(e,t){return e.value=e.value*t.value,e.scale=e.scale+t.scale,e}function O(e,t){const n=e.scale-t.scale;if(n===0)return e.value-=t.value,e;const r=B(Math.abs(n));return n>0?(e.value-=t.value*r,e):(e.value=e.value*r-t.value,e.scale=t.scale,e)}function j(e,t){if(D(t))throw new Error("Div0");const n=d(e);return E(n,t,0,"down"),y(n,t),O(e,n)}function T(e,t=2){if(!Number.isInteger(t)||t<0)throw new Error("Exp");return e.value=e.value**BigInt(t),e.scale=e.scale*t,e}function q(e,t=2,n=20){if(n<0)throw new Error("Prec");const r=Math.max(0,n);if(D(e))return e.value=f,e.scale=r,e;if(e.value===g)return e.value=g,e.scale=r,e;if(e.value<f&&t%2===0)throw new Error("Root");if(!Number.isInteger(t)||t<2)throw new Error("Root");if(t===2)return e.value=G(e,r),e.scale=r,e;const i=d(e);return F(e,i,t,r),e}function F(e,t,n,r){const i=a(n),o=a(n-1),u=a(2),l=d(t);E(l,u,r),e.value=t.value,e.scale=t.scale,p(e,l),E(e,u,r);const s=d(e),h=d(e),m=d(t);for(;;){if(s.value=e.value,s.scale=e.scale,y(s,o),h.value=e.value,h.scale=e.scale,T(h,n-1),m.value=t.value,m.scale=t.scale,E(m,h,r),p(s,m),E(s,i,r),W(e.value-s.value)<=g){e.value=s.value,e.scale=r;return}e.value=s.value,e.scale=s.scale}}function G(e,t){const r=2*(t+1)-e.scale,i=e.value<f?-e.value:e.value,o=r>=0?i*B(r):i/B(-r),u=U(o),l=u%S;let s=u/S;return l>=5n&&(s+=g),s}function Z(e){const t=e.toString(16),n=t.charCodeAt(0),r=n<58?n-48:n-87;return(t.length-1)*4+(32-Math.clz32(r))}function U(e){if(e<f)throw new Error("Sqrt");if(e<2n)return e;const t=Z(e);let n=g<<BigInt(t+1>>1),r=n+e/n>>g;for(;r<n;)n=r,r=n+e/n>>g;return n}function W(e){return e<f?-e:e}class C{current;constructor(t){this.current=a(t)}add(t){return p(this.current,a(t)),this}sub(t){return O(this.current,a(t)),this}mul(t){return y(this.current,a(t)),this}div(t,n,r){return E(this.current,a(t),n,r),this}mod(t){return j(this.current,a(t)),this}pow(t=2){return T(this.current,t),this}sqrt(t=2,n){return q(this.current,t,n),this}value(){return this.current}toString(t=!0){return this.current.toString(t)}}function H(e){return new C(e)}function z(e,t){const n=e.scale-t.scale;if(n===0)return[e,t];const r=B(Math.abs(n));return n>0?(t.value*=r,t.scale=e.scale,[e,t]):(e.value*=r,e.scale=t.scale,[e,t])}const J=e=>typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!Number.isNaN(Number(e));c.Big=v,c.BigPipe=C,c.absBig=V,c.addBig=p,c.alignScale=z,c.cloneBig=d,c.compareBig=P,c.createBig=a,c.divBig=E,c.fromString=_,c.isBigObject=M,c.isNumericValue=J,c.maxBig=k,c.minBig=L,c.modBig=j,c.mulBig=y,c.pipeBig=H,c.pow10=B,c.powBig=T,c.sqrtBig=q,c.subBig=O,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
export { Big } from
|
|
2
|
-
export
|
|
3
|
-
export { addBig } from
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export { alignScale } from
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export { fromString } from
|
|
1
|
+
export { Big } from './big';
|
|
2
|
+
export { absBig } from './operations/abs';
|
|
3
|
+
export { addBig } from './operations/add';
|
|
4
|
+
export { compareBig } from './operations/compare';
|
|
5
|
+
export { divBig } from './operations/div';
|
|
6
|
+
export { maxBig } from './operations/max';
|
|
7
|
+
export { minBig } from './operations/min';
|
|
8
|
+
export { modBig } from './operations/mod';
|
|
9
|
+
export { mulBig } from './operations/mul';
|
|
10
|
+
export { powBig } from './operations/pow';
|
|
11
|
+
export { sqrtBig } from './operations/sqrt';
|
|
12
|
+
export { subBig } from './operations/sub';
|
|
13
|
+
export type { BigPipeline } from './pipeline';
|
|
14
|
+
export { BigPipe, pipeBig } from './pipeline';
|
|
15
|
+
export type { BigValue, CompareResult, PossibleNumber, RoundingMode } from './types';
|
|
16
|
+
export { alignScale } from './utils/align-scale';
|
|
17
|
+
export { cloneBig } from './utils/clone';
|
|
18
|
+
export { createBig } from './utils/create';
|
|
19
|
+
export { fromString } from './utils/from-string';
|
|
20
|
+
export { isBigObject } from './utils/is-big-object';
|
|
21
|
+
export { isNumericValue } from './utils/numeric';
|
|
22
|
+
export { pow10 } from './utils/pow10';
|
package/dist/operations/abs.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
|
-
* Returns the absolute value
|
|
4
|
-
*
|
|
5
|
-
* @param {Big} big - The Big instance.
|
|
6
|
-
* @param {boolean} [mutable=false] - Whether to mutate the Big instance. Defaults to false.
|
|
7
|
-
* @returns {Big} The absolute value of the Big instance.
|
|
8
|
-
*
|
|
9
|
-
* @category Operations
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* absBig(new Big(-1)); // new Big instance with value 1
|
|
13
|
-
* absBig(new Big(-1.1)); // new Big instance with value 1.1
|
|
14
|
-
* absBig(new Big(1)); // new Big instance with value 1
|
|
3
|
+
* Returns the absolute value and mutates the given Big instance.
|
|
15
4
|
*/
|
|
16
|
-
export declare function absBig(big: Big
|
|
5
|
+
export declare function absBig(big: Big): Big;
|
package/dist/operations/add.d.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
|
-
* Adds two
|
|
4
|
-
*
|
|
5
|
-
* @param {Big} a - The first value to add.
|
|
6
|
-
* @param {Big} b - The second value to add.
|
|
7
|
-
* @param {boolean} [mutable=false] - Whether to mutate the first value. Defaults to false.
|
|
8
|
-
* @returns {Big} The sum of the two values.
|
|
9
|
-
*
|
|
10
|
-
* @category Operations
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* addBig(new Big(1), new Big(2)); // new Big instance with value 3
|
|
14
|
-
* addBig(new Big(1.1), new Big(2.2)); // new Big instance with value 3.3
|
|
15
|
-
* addBig(new Big(1.1), new Big(2)); // new Big instance with value 3.1
|
|
3
|
+
* Adds two Big instances and mutates the first one.
|
|
16
4
|
*/
|
|
17
|
-
export declare function addBig(a: Big, b: Big
|
|
5
|
+
export declare function addBig(a: Big, b: Big): Big;
|
package/dist/operations/div.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
|
+
import { RoundingMode } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
* Divides two Big instances and
|
|
4
|
+
* Divides two Big instances and mutates the dividend with the result.
|
|
5
5
|
*
|
|
6
6
|
* @param {Big} dividend - The dividend Big instance.
|
|
7
7
|
* @param {Big} divisor - The divisor Big instance.
|
|
8
8
|
* @param {number} [precision] - The number of decimal places to keep in the result (optional). Defaults to the maximum scale of both Big instances. If the precision is lower than the scale of the result, the result will be rounded. If input numbers are without scale, the precision will be 0, so the result will be rounded to an integer.
|
|
9
9
|
* @param {string} [roundingMode="half-up"] - The rounding mode to apply ("half-up", "down" or "up"). Defaults to "half-up".
|
|
10
|
-
* @
|
|
11
|
-
* @returns {Big} - A new Big instance representing the result of the division.
|
|
10
|
+
* @returns {Big} - The mutated dividend instance.
|
|
12
11
|
* @throws {Error} Division by zero is not allowed.
|
|
13
12
|
*
|
|
14
13
|
* @category Operations
|
|
@@ -22,4 +21,4 @@ import type { Big } from "../big";
|
|
|
22
21
|
* console.log(divBig(big1, big2, 2, "down").toString()); // "3.33"
|
|
23
22
|
* console.log(divBig(big1, big2, 2, "up").toString()); // "3.34"
|
|
24
23
|
*/
|
|
25
|
-
export declare function divBig(dividend: Big, divisor: Big, precision?: number, roundingMode?: RoundingMode
|
|
24
|
+
export declare function divBig(dividend: Big, divisor: Big, precision?: number, roundingMode?: RoundingMode): Big;
|
package/dist/operations/max.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
3
|
* Returns the maximum 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
|
-
* maxBig(new Big(1), new Big(2)); //
|
|
15
|
-
* maxBig(new Big(2), new Big(1)); //
|
|
16
|
-
* maxBig(new Big(1), new Big(1)); //
|
|
17
|
-
* maxBig(new Big(1), new Big(1), true); // first Big number with value 1 and same instance
|
|
13
|
+
* maxBig(new Big(1), new Big(2)); // returns the second Big number
|
|
14
|
+
* maxBig(new Big(2), new Big(1)); // returns the first Big number
|
|
15
|
+
* maxBig(new Big(1), new Big(1)); // returns the first Big number
|
|
18
16
|
*/
|
|
19
|
-
export declare
|
|
17
|
+
export declare function maxBig(a: Big, b: Big): Big;
|