@hairy/utils 1.0.21 → 1.5.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.
@@ -0,0 +1,1599 @@
1
+ "use strict";
2
+ (() => {
3
+ // ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
4
+ var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
5
+ var mathceil = Math.ceil;
6
+ var mathfloor = Math.floor;
7
+ var bignumberError = "[BigNumber Error] ";
8
+ var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
9
+ var BASE = 1e14;
10
+ var LOG_BASE = 14;
11
+ var MAX_SAFE_INTEGER = 9007199254740991;
12
+ var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
13
+ var SQRT_BASE = 1e7;
14
+ var MAX = 1e9;
15
+ function clone(configObject) {
16
+ var div, convertBase, parseNumeric2, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
17
+ prefix: "",
18
+ groupSize: 3,
19
+ secondaryGroupSize: 0,
20
+ groupSeparator: ",",
21
+ decimalSeparator: ".",
22
+ fractionGroupSize: 0,
23
+ fractionGroupSeparator: "\xA0",
24
+ // non-breaking space
25
+ suffix: ""
26
+ }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
27
+ function BigNumber2(v, b) {
28
+ var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
29
+ if (!(x instanceof BigNumber2)) return new BigNumber2(v, b);
30
+ if (b == null) {
31
+ if (v && v._isBigNumber === true) {
32
+ x.s = v.s;
33
+ if (!v.c || v.e > MAX_EXP) {
34
+ x.c = x.e = null;
35
+ } else if (v.e < MIN_EXP) {
36
+ x.c = [x.e = 0];
37
+ } else {
38
+ x.e = v.e;
39
+ x.c = v.c.slice();
40
+ }
41
+ return;
42
+ }
43
+ if ((isNum = typeof v == "number") && v * 0 == 0) {
44
+ x.s = 1 / v < 0 ? (v = -v, -1) : 1;
45
+ if (v === ~~v) {
46
+ for (e = 0, i = v; i >= 10; i /= 10, e++) ;
47
+ if (e > MAX_EXP) {
48
+ x.c = x.e = null;
49
+ } else {
50
+ x.e = e;
51
+ x.c = [v];
52
+ }
53
+ return;
54
+ }
55
+ str = String(v);
56
+ } else {
57
+ if (!isNumeric.test(str = String(v))) return parseNumeric2(x, str, isNum);
58
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
59
+ }
60
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
61
+ if ((i = str.search(/e/i)) > 0) {
62
+ if (e < 0) e = i;
63
+ e += +str.slice(i + 1);
64
+ str = str.substring(0, i);
65
+ } else if (e < 0) {
66
+ e = str.length;
67
+ }
68
+ } else {
69
+ intCheck(b, 2, ALPHABET.length, "Base");
70
+ if (b == 10 && alphabetHasNormalDecimalDigits) {
71
+ x = new BigNumber2(v);
72
+ return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
73
+ }
74
+ str = String(v);
75
+ if (isNum = typeof v == "number") {
76
+ if (v * 0 != 0) return parseNumeric2(x, str, isNum, b);
77
+ x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
78
+ if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
79
+ throw Error(tooManyDigits + v);
80
+ }
81
+ } else {
82
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
83
+ }
84
+ alphabet = ALPHABET.slice(0, b);
85
+ e = i = 0;
86
+ for (len = str.length; i < len; i++) {
87
+ if (alphabet.indexOf(c = str.charAt(i)) < 0) {
88
+ if (c == ".") {
89
+ if (i > e) {
90
+ e = len;
91
+ continue;
92
+ }
93
+ } else if (!caseChanged) {
94
+ if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
95
+ caseChanged = true;
96
+ i = -1;
97
+ e = 0;
98
+ continue;
99
+ }
100
+ }
101
+ return parseNumeric2(x, String(v), isNum, b);
102
+ }
103
+ }
104
+ isNum = false;
105
+ str = convertBase(str, b, 10, x.s);
106
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
107
+ else e = str.length;
108
+ }
109
+ for (i = 0; str.charCodeAt(i) === 48; i++) ;
110
+ for (len = str.length; str.charCodeAt(--len) === 48; ) ;
111
+ if (str = str.slice(i, ++len)) {
112
+ len -= i;
113
+ if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
114
+ throw Error(tooManyDigits + x.s * v);
115
+ }
116
+ if ((e = e - i - 1) > MAX_EXP) {
117
+ x.c = x.e = null;
118
+ } else if (e < MIN_EXP) {
119
+ x.c = [x.e = 0];
120
+ } else {
121
+ x.e = e;
122
+ x.c = [];
123
+ i = (e + 1) % LOG_BASE;
124
+ if (e < 0) i += LOG_BASE;
125
+ if (i < len) {
126
+ if (i) x.c.push(+str.slice(0, i));
127
+ for (len -= LOG_BASE; i < len; ) {
128
+ x.c.push(+str.slice(i, i += LOG_BASE));
129
+ }
130
+ i = LOG_BASE - (str = str.slice(i)).length;
131
+ } else {
132
+ i -= len;
133
+ }
134
+ for (; i--; str += "0") ;
135
+ x.c.push(+str);
136
+ }
137
+ } else {
138
+ x.c = [x.e = 0];
139
+ }
140
+ }
141
+ BigNumber2.clone = clone;
142
+ BigNumber2.ROUND_UP = 0;
143
+ BigNumber2.ROUND_DOWN = 1;
144
+ BigNumber2.ROUND_CEIL = 2;
145
+ BigNumber2.ROUND_FLOOR = 3;
146
+ BigNumber2.ROUND_HALF_UP = 4;
147
+ BigNumber2.ROUND_HALF_DOWN = 5;
148
+ BigNumber2.ROUND_HALF_EVEN = 6;
149
+ BigNumber2.ROUND_HALF_CEIL = 7;
150
+ BigNumber2.ROUND_HALF_FLOOR = 8;
151
+ BigNumber2.EUCLID = 9;
152
+ BigNumber2.config = BigNumber2.set = function(obj) {
153
+ var p, v;
154
+ if (obj != null) {
155
+ if (typeof obj == "object") {
156
+ if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
157
+ v = obj[p];
158
+ intCheck(v, 0, MAX, p);
159
+ DECIMAL_PLACES = v;
160
+ }
161
+ if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
162
+ v = obj[p];
163
+ intCheck(v, 0, 8, p);
164
+ ROUNDING_MODE = v;
165
+ }
166
+ if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
167
+ v = obj[p];
168
+ if (v && v.pop) {
169
+ intCheck(v[0], -MAX, 0, p);
170
+ intCheck(v[1], 0, MAX, p);
171
+ TO_EXP_NEG = v[0];
172
+ TO_EXP_POS = v[1];
173
+ } else {
174
+ intCheck(v, -MAX, MAX, p);
175
+ TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
176
+ }
177
+ }
178
+ if (obj.hasOwnProperty(p = "RANGE")) {
179
+ v = obj[p];
180
+ if (v && v.pop) {
181
+ intCheck(v[0], -MAX, -1, p);
182
+ intCheck(v[1], 1, MAX, p);
183
+ MIN_EXP = v[0];
184
+ MAX_EXP = v[1];
185
+ } else {
186
+ intCheck(v, -MAX, MAX, p);
187
+ if (v) {
188
+ MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
189
+ } else {
190
+ throw Error(bignumberError + p + " cannot be zero: " + v);
191
+ }
192
+ }
193
+ }
194
+ if (obj.hasOwnProperty(p = "CRYPTO")) {
195
+ v = obj[p];
196
+ if (v === !!v) {
197
+ if (v) {
198
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
199
+ CRYPTO = v;
200
+ } else {
201
+ CRYPTO = !v;
202
+ throw Error(bignumberError + "crypto unavailable");
203
+ }
204
+ } else {
205
+ CRYPTO = v;
206
+ }
207
+ } else {
208
+ throw Error(bignumberError + p + " not true or false: " + v);
209
+ }
210
+ }
211
+ if (obj.hasOwnProperty(p = "MODULO_MODE")) {
212
+ v = obj[p];
213
+ intCheck(v, 0, 9, p);
214
+ MODULO_MODE = v;
215
+ }
216
+ if (obj.hasOwnProperty(p = "POW_PRECISION")) {
217
+ v = obj[p];
218
+ intCheck(v, 0, MAX, p);
219
+ POW_PRECISION = v;
220
+ }
221
+ if (obj.hasOwnProperty(p = "FORMAT")) {
222
+ v = obj[p];
223
+ if (typeof v == "object") FORMAT = v;
224
+ else throw Error(bignumberError + p + " not an object: " + v);
225
+ }
226
+ if (obj.hasOwnProperty(p = "ALPHABET")) {
227
+ v = obj[p];
228
+ if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
229
+ alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
230
+ ALPHABET = v;
231
+ } else {
232
+ throw Error(bignumberError + p + " invalid: " + v);
233
+ }
234
+ }
235
+ } else {
236
+ throw Error(bignumberError + "Object expected: " + obj);
237
+ }
238
+ }
239
+ return {
240
+ DECIMAL_PLACES,
241
+ ROUNDING_MODE,
242
+ EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
243
+ RANGE: [MIN_EXP, MAX_EXP],
244
+ CRYPTO,
245
+ MODULO_MODE,
246
+ POW_PRECISION,
247
+ FORMAT,
248
+ ALPHABET
249
+ };
250
+ };
251
+ BigNumber2.isBigNumber = function(v) {
252
+ if (!v || v._isBigNumber !== true) return false;
253
+ if (!BigNumber2.DEBUG) return true;
254
+ var i, n, c = v.c, e = v.e, s = v.s;
255
+ out: if ({}.toString.call(c) == "[object Array]") {
256
+ if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
257
+ if (c[0] === 0) {
258
+ if (e === 0 && c.length === 1) return true;
259
+ break out;
260
+ }
261
+ i = (e + 1) % LOG_BASE;
262
+ if (i < 1) i += LOG_BASE;
263
+ if (String(c[0]).length == i) {
264
+ for (i = 0; i < c.length; i++) {
265
+ n = c[i];
266
+ if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
267
+ }
268
+ if (n !== 0) return true;
269
+ }
270
+ }
271
+ } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
272
+ return true;
273
+ }
274
+ throw Error(bignumberError + "Invalid BigNumber: " + v);
275
+ };
276
+ BigNumber2.maximum = BigNumber2.max = function() {
277
+ return maxOrMin(arguments, -1);
278
+ };
279
+ BigNumber2.minimum = BigNumber2.min = function() {
280
+ return maxOrMin(arguments, 1);
281
+ };
282
+ BigNumber2.random = function() {
283
+ var pow2_53 = 9007199254740992;
284
+ var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
285
+ return mathfloor(Math.random() * pow2_53);
286
+ } : function() {
287
+ return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
288
+ };
289
+ return function(dp) {
290
+ var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
291
+ if (dp == null) dp = DECIMAL_PLACES;
292
+ else intCheck(dp, 0, MAX);
293
+ k = mathceil(dp / LOG_BASE);
294
+ if (CRYPTO) {
295
+ if (crypto.getRandomValues) {
296
+ a = crypto.getRandomValues(new Uint32Array(k *= 2));
297
+ for (; i < k; ) {
298
+ v = a[i] * 131072 + (a[i + 1] >>> 11);
299
+ if (v >= 9e15) {
300
+ b = crypto.getRandomValues(new Uint32Array(2));
301
+ a[i] = b[0];
302
+ a[i + 1] = b[1];
303
+ } else {
304
+ c.push(v % 1e14);
305
+ i += 2;
306
+ }
307
+ }
308
+ i = k / 2;
309
+ } else if (crypto.randomBytes) {
310
+ a = crypto.randomBytes(k *= 7);
311
+ for (; i < k; ) {
312
+ v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
313
+ if (v >= 9e15) {
314
+ crypto.randomBytes(7).copy(a, i);
315
+ } else {
316
+ c.push(v % 1e14);
317
+ i += 7;
318
+ }
319
+ }
320
+ i = k / 7;
321
+ } else {
322
+ CRYPTO = false;
323
+ throw Error(bignumberError + "crypto unavailable");
324
+ }
325
+ }
326
+ if (!CRYPTO) {
327
+ for (; i < k; ) {
328
+ v = random53bitInt();
329
+ if (v < 9e15) c[i++] = v % 1e14;
330
+ }
331
+ }
332
+ k = c[--i];
333
+ dp %= LOG_BASE;
334
+ if (k && dp) {
335
+ v = POWS_TEN[LOG_BASE - dp];
336
+ c[i] = mathfloor(k / v) * v;
337
+ }
338
+ for (; c[i] === 0; c.pop(), i--) ;
339
+ if (i < 0) {
340
+ c = [e = 0];
341
+ } else {
342
+ for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE) ;
343
+ for (i = 1, v = c[0]; v >= 10; v /= 10, i++) ;
344
+ if (i < LOG_BASE) e -= LOG_BASE - i;
345
+ }
346
+ rand.e = e;
347
+ rand.c = c;
348
+ return rand;
349
+ };
350
+ }();
351
+ BigNumber2.sum = function() {
352
+ var i = 1, args = arguments, sum = new BigNumber2(args[0]);
353
+ for (; i < args.length; ) sum = sum.plus(args[i++]);
354
+ return sum;
355
+ };
356
+ convertBase = /* @__PURE__ */ function() {
357
+ var decimal2 = "0123456789";
358
+ function toBaseOut(str, baseIn, baseOut, alphabet) {
359
+ var j, arr = [0], arrL, i = 0, len = str.length;
360
+ for (; i < len; ) {
361
+ for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) ;
362
+ arr[0] += alphabet.indexOf(str.charAt(i++));
363
+ for (j = 0; j < arr.length; j++) {
364
+ if (arr[j] > baseOut - 1) {
365
+ if (arr[j + 1] == null) arr[j + 1] = 0;
366
+ arr[j + 1] += arr[j] / baseOut | 0;
367
+ arr[j] %= baseOut;
368
+ }
369
+ }
370
+ }
371
+ return arr.reverse();
372
+ }
373
+ return function(str, baseIn, baseOut, sign, callerIsToString) {
374
+ var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
375
+ if (i >= 0) {
376
+ k = POW_PRECISION;
377
+ POW_PRECISION = 0;
378
+ str = str.replace(".", "");
379
+ y = new BigNumber2(baseIn);
380
+ x = y.pow(str.length - i);
381
+ POW_PRECISION = k;
382
+ y.c = toBaseOut(
383
+ toFixedPoint(coeffToString(x.c), x.e, "0"),
384
+ 10,
385
+ baseOut,
386
+ decimal2
387
+ );
388
+ y.e = y.c.length;
389
+ }
390
+ xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal2) : (alphabet = decimal2, ALPHABET));
391
+ e = k = xc.length;
392
+ for (; xc[--k] == 0; xc.pop()) ;
393
+ if (!xc[0]) return alphabet.charAt(0);
394
+ if (i < 0) {
395
+ --e;
396
+ } else {
397
+ x.c = xc;
398
+ x.e = e;
399
+ x.s = sign;
400
+ x = div(x, y, dp, rm, baseOut);
401
+ xc = x.c;
402
+ r = x.r;
403
+ e = x.e;
404
+ }
405
+ d = e + dp + 1;
406
+ i = xc[d];
407
+ k = baseOut / 2;
408
+ r = r || d < 0 || xc[d + 1] != null;
409
+ r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
410
+ if (d < 1 || !xc[0]) {
411
+ str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
412
+ } else {
413
+ xc.length = d;
414
+ if (r) {
415
+ for (--baseOut; ++xc[--d] > baseOut; ) {
416
+ xc[d] = 0;
417
+ if (!d) {
418
+ ++e;
419
+ xc = [1].concat(xc);
420
+ }
421
+ }
422
+ }
423
+ for (k = xc.length; !xc[--k]; ) ;
424
+ for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++])) ;
425
+ str = toFixedPoint(str, e, alphabet.charAt(0));
426
+ }
427
+ return str;
428
+ };
429
+ }();
430
+ div = /* @__PURE__ */ function() {
431
+ function multiply(x, k, base) {
432
+ var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
433
+ for (x = x.slice(); i--; ) {
434
+ xlo = x[i] % SQRT_BASE;
435
+ xhi = x[i] / SQRT_BASE | 0;
436
+ m = khi * xlo + xhi * klo;
437
+ temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
438
+ carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
439
+ x[i] = temp % base;
440
+ }
441
+ if (carry) x = [carry].concat(x);
442
+ return x;
443
+ }
444
+ function compare2(a, b, aL, bL) {
445
+ var i, cmp;
446
+ if (aL != bL) {
447
+ cmp = aL > bL ? 1 : -1;
448
+ } else {
449
+ for (i = cmp = 0; i < aL; i++) {
450
+ if (a[i] != b[i]) {
451
+ cmp = a[i] > b[i] ? 1 : -1;
452
+ break;
453
+ }
454
+ }
455
+ }
456
+ return cmp;
457
+ }
458
+ function subtract(a, b, aL, base) {
459
+ var i = 0;
460
+ for (; aL--; ) {
461
+ a[aL] -= i;
462
+ i = a[aL] < b[aL] ? 1 : 0;
463
+ a[aL] = i * base + a[aL] - b[aL];
464
+ }
465
+ for (; !a[0] && a.length > 1; a.splice(0, 1)) ;
466
+ }
467
+ return function(x, y, dp, rm, base) {
468
+ var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
469
+ if (!xc || !xc[0] || !yc || !yc[0]) {
470
+ return new BigNumber2(
471
+ // Return NaN if either NaN, or both Infinity or 0.
472
+ !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
473
+ // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
474
+ xc && xc[0] == 0 || !yc ? s * 0 : s / 0
475
+ )
476
+ );
477
+ }
478
+ q = new BigNumber2(s);
479
+ qc = q.c = [];
480
+ e = x.e - y.e;
481
+ s = dp + e + 1;
482
+ if (!base) {
483
+ base = BASE;
484
+ e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
485
+ s = s / LOG_BASE | 0;
486
+ }
487
+ for (i = 0; yc[i] == (xc[i] || 0); i++) ;
488
+ if (yc[i] > (xc[i] || 0)) e--;
489
+ if (s < 0) {
490
+ qc.push(1);
491
+ more = true;
492
+ } else {
493
+ xL = xc.length;
494
+ yL = yc.length;
495
+ i = 0;
496
+ s += 2;
497
+ n = mathfloor(base / (yc[0] + 1));
498
+ if (n > 1) {
499
+ yc = multiply(yc, n, base);
500
+ xc = multiply(xc, n, base);
501
+ yL = yc.length;
502
+ xL = xc.length;
503
+ }
504
+ xi = yL;
505
+ rem = xc.slice(0, yL);
506
+ remL = rem.length;
507
+ for (; remL < yL; rem[remL++] = 0) ;
508
+ yz = yc.slice();
509
+ yz = [0].concat(yz);
510
+ yc0 = yc[0];
511
+ if (yc[1] >= base / 2) yc0++;
512
+ do {
513
+ n = 0;
514
+ cmp = compare2(yc, rem, yL, remL);
515
+ if (cmp < 0) {
516
+ rem0 = rem[0];
517
+ if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
518
+ n = mathfloor(rem0 / yc0);
519
+ if (n > 1) {
520
+ if (n >= base) n = base - 1;
521
+ prod = multiply(yc, n, base);
522
+ prodL = prod.length;
523
+ remL = rem.length;
524
+ while (compare2(prod, rem, prodL, remL) == 1) {
525
+ n--;
526
+ subtract(prod, yL < prodL ? yz : yc, prodL, base);
527
+ prodL = prod.length;
528
+ cmp = 1;
529
+ }
530
+ } else {
531
+ if (n == 0) {
532
+ cmp = n = 1;
533
+ }
534
+ prod = yc.slice();
535
+ prodL = prod.length;
536
+ }
537
+ if (prodL < remL) prod = [0].concat(prod);
538
+ subtract(rem, prod, remL, base);
539
+ remL = rem.length;
540
+ if (cmp == -1) {
541
+ while (compare2(yc, rem, yL, remL) < 1) {
542
+ n++;
543
+ subtract(rem, yL < remL ? yz : yc, remL, base);
544
+ remL = rem.length;
545
+ }
546
+ }
547
+ } else if (cmp === 0) {
548
+ n++;
549
+ rem = [0];
550
+ }
551
+ qc[i++] = n;
552
+ if (rem[0]) {
553
+ rem[remL++] = xc[xi] || 0;
554
+ } else {
555
+ rem = [xc[xi]];
556
+ remL = 1;
557
+ }
558
+ } while ((xi++ < xL || rem[0] != null) && s--);
559
+ more = rem[0] != null;
560
+ if (!qc[0]) qc.splice(0, 1);
561
+ }
562
+ if (base == BASE) {
563
+ for (i = 1, s = qc[0]; s >= 10; s /= 10, i++) ;
564
+ round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
565
+ } else {
566
+ q.e = e;
567
+ q.r = +more;
568
+ }
569
+ return q;
570
+ };
571
+ }();
572
+ function format(n, i, rm, id) {
573
+ var c0, e, ne, len, str;
574
+ if (rm == null) rm = ROUNDING_MODE;
575
+ else intCheck(rm, 0, 8);
576
+ if (!n.c) return n.toString();
577
+ c0 = n.c[0];
578
+ ne = n.e;
579
+ if (i == null) {
580
+ str = coeffToString(n.c);
581
+ str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
582
+ } else {
583
+ n = round(new BigNumber2(n), i, rm);
584
+ e = n.e;
585
+ str = coeffToString(n.c);
586
+ len = str.length;
587
+ if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
588
+ for (; len < i; str += "0", len++) ;
589
+ str = toExponential(str, e);
590
+ } else {
591
+ i -= ne;
592
+ str = toFixedPoint(str, e, "0");
593
+ if (e + 1 > len) {
594
+ if (--i > 0) for (str += "."; i--; str += "0") ;
595
+ } else {
596
+ i += e - len;
597
+ if (i > 0) {
598
+ if (e + 1 == len) str += ".";
599
+ for (; i--; str += "0") ;
600
+ }
601
+ }
602
+ }
603
+ }
604
+ return n.s < 0 && c0 ? "-" + str : str;
605
+ }
606
+ function maxOrMin(args, n) {
607
+ var k, y, i = 1, x = new BigNumber2(args[0]);
608
+ for (; i < args.length; i++) {
609
+ y = new BigNumber2(args[i]);
610
+ if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
611
+ x = y;
612
+ }
613
+ }
614
+ return x;
615
+ }
616
+ function normalise(n, c, e) {
617
+ var i = 1, j = c.length;
618
+ for (; !c[--j]; c.pop()) ;
619
+ for (j = c[0]; j >= 10; j /= 10, i++) ;
620
+ if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
621
+ n.c = n.e = null;
622
+ } else if (e < MIN_EXP) {
623
+ n.c = [n.e = 0];
624
+ } else {
625
+ n.e = e;
626
+ n.c = c;
627
+ }
628
+ return n;
629
+ }
630
+ parseNumeric2 = /* @__PURE__ */ function() {
631
+ var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
632
+ return function(x, str, isNum, b) {
633
+ var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
634
+ if (isInfinityOrNaN.test(s)) {
635
+ x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
636
+ } else {
637
+ if (!isNum) {
638
+ s = s.replace(basePrefix, function(m, p1, p2) {
639
+ base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
640
+ return !b || b == base ? p1 : m;
641
+ });
642
+ if (b) {
643
+ base = b;
644
+ s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
645
+ }
646
+ if (str != s) return new BigNumber2(s, base);
647
+ }
648
+ if (BigNumber2.DEBUG) {
649
+ throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
650
+ }
651
+ x.s = null;
652
+ }
653
+ x.c = x.e = null;
654
+ };
655
+ }();
656
+ function round(x, sd, rm, r) {
657
+ var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
658
+ if (xc) {
659
+ out: {
660
+ for (d = 1, k = xc[0]; k >= 10; k /= 10, d++) ;
661
+ i = sd - d;
662
+ if (i < 0) {
663
+ i += LOG_BASE;
664
+ j = sd;
665
+ n = xc[ni = 0];
666
+ rd = mathfloor(n / pows10[d - j - 1] % 10);
667
+ } else {
668
+ ni = mathceil((i + 1) / LOG_BASE);
669
+ if (ni >= xc.length) {
670
+ if (r) {
671
+ for (; xc.length <= ni; xc.push(0)) ;
672
+ n = rd = 0;
673
+ d = 1;
674
+ i %= LOG_BASE;
675
+ j = i - LOG_BASE + 1;
676
+ } else {
677
+ break out;
678
+ }
679
+ } else {
680
+ n = k = xc[ni];
681
+ for (d = 1; k >= 10; k /= 10, d++) ;
682
+ i %= LOG_BASE;
683
+ j = i - LOG_BASE + d;
684
+ rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
685
+ }
686
+ }
687
+ r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
688
+ // The expression n % pows10[d - j - 1] returns all digits of n to the right
689
+ // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
690
+ xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
691
+ r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
692
+ (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
693
+ if (sd < 1 || !xc[0]) {
694
+ xc.length = 0;
695
+ if (r) {
696
+ sd -= x.e + 1;
697
+ xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
698
+ x.e = -sd || 0;
699
+ } else {
700
+ xc[0] = x.e = 0;
701
+ }
702
+ return x;
703
+ }
704
+ if (i == 0) {
705
+ xc.length = ni;
706
+ k = 1;
707
+ ni--;
708
+ } else {
709
+ xc.length = ni + 1;
710
+ k = pows10[LOG_BASE - i];
711
+ xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
712
+ }
713
+ if (r) {
714
+ for (; ; ) {
715
+ if (ni == 0) {
716
+ for (i = 1, j = xc[0]; j >= 10; j /= 10, i++) ;
717
+ j = xc[0] += k;
718
+ for (k = 1; j >= 10; j /= 10, k++) ;
719
+ if (i != k) {
720
+ x.e++;
721
+ if (xc[0] == BASE) xc[0] = 1;
722
+ }
723
+ break;
724
+ } else {
725
+ xc[ni] += k;
726
+ if (xc[ni] != BASE) break;
727
+ xc[ni--] = 0;
728
+ k = 1;
729
+ }
730
+ }
731
+ }
732
+ for (i = xc.length; xc[--i] === 0; xc.pop()) ;
733
+ }
734
+ if (x.e > MAX_EXP) {
735
+ x.c = x.e = null;
736
+ } else if (x.e < MIN_EXP) {
737
+ x.c = [x.e = 0];
738
+ }
739
+ }
740
+ return x;
741
+ }
742
+ function valueOf(n) {
743
+ var str, e = n.e;
744
+ if (e === null) return n.toString();
745
+ str = coeffToString(n.c);
746
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
747
+ return n.s < 0 ? "-" + str : str;
748
+ }
749
+ P.absoluteValue = P.abs = function() {
750
+ var x = new BigNumber2(this);
751
+ if (x.s < 0) x.s = 1;
752
+ return x;
753
+ };
754
+ P.comparedTo = function(y, b) {
755
+ return compare(this, new BigNumber2(y, b));
756
+ };
757
+ P.decimalPlaces = P.dp = function(dp, rm) {
758
+ var c, n, v, x = this;
759
+ if (dp != null) {
760
+ intCheck(dp, 0, MAX);
761
+ if (rm == null) rm = ROUNDING_MODE;
762
+ else intCheck(rm, 0, 8);
763
+ return round(new BigNumber2(x), dp + x.e + 1, rm);
764
+ }
765
+ if (!(c = x.c)) return null;
766
+ n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
767
+ if (v = c[v]) for (; v % 10 == 0; v /= 10, n--) ;
768
+ if (n < 0) n = 0;
769
+ return n;
770
+ };
771
+ P.dividedBy = P.div = function(y, b) {
772
+ return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
773
+ };
774
+ P.dividedToIntegerBy = P.idiv = function(y, b) {
775
+ return div(this, new BigNumber2(y, b), 0, 1);
776
+ };
777
+ P.exponentiatedBy = P.pow = function(n, m) {
778
+ var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
779
+ n = new BigNumber2(n);
780
+ if (n.c && !n.isInteger()) {
781
+ throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
782
+ }
783
+ if (m != null) m = new BigNumber2(m);
784
+ nIsBig = n.e > 14;
785
+ if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
786
+ y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
787
+ return m ? y.mod(m) : y;
788
+ }
789
+ nIsNeg = n.s < 0;
790
+ if (m) {
791
+ if (m.c ? !m.c[0] : !m.s) return new BigNumber2(NaN);
792
+ isModExp = !nIsNeg && x.isInteger() && m.isInteger();
793
+ if (isModExp) x = x.mod(m);
794
+ } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
795
+ k = x.s < 0 && isOdd(n) ? -0 : 0;
796
+ if (x.e > -1) k = 1 / k;
797
+ return new BigNumber2(nIsNeg ? 1 / k : k);
798
+ } else if (POW_PRECISION) {
799
+ k = mathceil(POW_PRECISION / LOG_BASE + 2);
800
+ }
801
+ if (nIsBig) {
802
+ half = new BigNumber2(0.5);
803
+ if (nIsNeg) n.s = 1;
804
+ nIsOdd = isOdd(n);
805
+ } else {
806
+ i = Math.abs(+valueOf(n));
807
+ nIsOdd = i % 2;
808
+ }
809
+ y = new BigNumber2(ONE);
810
+ for (; ; ) {
811
+ if (nIsOdd) {
812
+ y = y.times(x);
813
+ if (!y.c) break;
814
+ if (k) {
815
+ if (y.c.length > k) y.c.length = k;
816
+ } else if (isModExp) {
817
+ y = y.mod(m);
818
+ }
819
+ }
820
+ if (i) {
821
+ i = mathfloor(i / 2);
822
+ if (i === 0) break;
823
+ nIsOdd = i % 2;
824
+ } else {
825
+ n = n.times(half);
826
+ round(n, n.e + 1, 1);
827
+ if (n.e > 14) {
828
+ nIsOdd = isOdd(n);
829
+ } else {
830
+ i = +valueOf(n);
831
+ if (i === 0) break;
832
+ nIsOdd = i % 2;
833
+ }
834
+ }
835
+ x = x.times(x);
836
+ if (k) {
837
+ if (x.c && x.c.length > k) x.c.length = k;
838
+ } else if (isModExp) {
839
+ x = x.mod(m);
840
+ }
841
+ }
842
+ if (isModExp) return y;
843
+ if (nIsNeg) y = ONE.div(y);
844
+ return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
845
+ };
846
+ P.integerValue = function(rm) {
847
+ var n = new BigNumber2(this);
848
+ if (rm == null) rm = ROUNDING_MODE;
849
+ else intCheck(rm, 0, 8);
850
+ return round(n, n.e + 1, rm);
851
+ };
852
+ P.isEqualTo = P.eq = function(y, b) {
853
+ return compare(this, new BigNumber2(y, b)) === 0;
854
+ };
855
+ P.isFinite = function() {
856
+ return !!this.c;
857
+ };
858
+ P.isGreaterThan = P.gt = function(y, b) {
859
+ return compare(this, new BigNumber2(y, b)) > 0;
860
+ };
861
+ P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
862
+ return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
863
+ };
864
+ P.isInteger = function() {
865
+ return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
866
+ };
867
+ P.isLessThan = P.lt = function(y, b) {
868
+ return compare(this, new BigNumber2(y, b)) < 0;
869
+ };
870
+ P.isLessThanOrEqualTo = P.lte = function(y, b) {
871
+ return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
872
+ };
873
+ P.isNaN = function() {
874
+ return !this.s;
875
+ };
876
+ P.isNegative = function() {
877
+ return this.s < 0;
878
+ };
879
+ P.isPositive = function() {
880
+ return this.s > 0;
881
+ };
882
+ P.isZero = function() {
883
+ return !!this.c && this.c[0] == 0;
884
+ };
885
+ P.minus = function(y, b) {
886
+ var i, j, t, xLTy, x = this, a = x.s;
887
+ y = new BigNumber2(y, b);
888
+ b = y.s;
889
+ if (!a || !b) return new BigNumber2(NaN);
890
+ if (a != b) {
891
+ y.s = -b;
892
+ return x.plus(y);
893
+ }
894
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
895
+ if (!xe || !ye) {
896
+ if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
897
+ if (!xc[0] || !yc[0]) {
898
+ return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
899
+ // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
900
+ ROUNDING_MODE == 3 ? -0 : 0
901
+ ));
902
+ }
903
+ }
904
+ xe = bitFloor(xe);
905
+ ye = bitFloor(ye);
906
+ xc = xc.slice();
907
+ if (a = xe - ye) {
908
+ if (xLTy = a < 0) {
909
+ a = -a;
910
+ t = xc;
911
+ } else {
912
+ ye = xe;
913
+ t = yc;
914
+ }
915
+ t.reverse();
916
+ for (b = a; b--; t.push(0)) ;
917
+ t.reverse();
918
+ } else {
919
+ j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
920
+ for (a = b = 0; b < j; b++) {
921
+ if (xc[b] != yc[b]) {
922
+ xLTy = xc[b] < yc[b];
923
+ break;
924
+ }
925
+ }
926
+ }
927
+ if (xLTy) {
928
+ t = xc;
929
+ xc = yc;
930
+ yc = t;
931
+ y.s = -y.s;
932
+ }
933
+ b = (j = yc.length) - (i = xc.length);
934
+ if (b > 0) for (; b--; xc[i++] = 0) ;
935
+ b = BASE - 1;
936
+ for (; j > a; ) {
937
+ if (xc[--j] < yc[j]) {
938
+ for (i = j; i && !xc[--i]; xc[i] = b) ;
939
+ --xc[i];
940
+ xc[j] += BASE;
941
+ }
942
+ xc[j] -= yc[j];
943
+ }
944
+ for (; xc[0] == 0; xc.splice(0, 1), --ye) ;
945
+ if (!xc[0]) {
946
+ y.s = ROUNDING_MODE == 3 ? -1 : 1;
947
+ y.c = [y.e = 0];
948
+ return y;
949
+ }
950
+ return normalise(y, xc, ye);
951
+ };
952
+ P.modulo = P.mod = function(y, b) {
953
+ var q, s, x = this;
954
+ y = new BigNumber2(y, b);
955
+ if (!x.c || !y.s || y.c && !y.c[0]) {
956
+ return new BigNumber2(NaN);
957
+ } else if (!y.c || x.c && !x.c[0]) {
958
+ return new BigNumber2(x);
959
+ }
960
+ if (MODULO_MODE == 9) {
961
+ s = y.s;
962
+ y.s = 1;
963
+ q = div(x, y, 0, 3);
964
+ y.s = s;
965
+ q.s *= s;
966
+ } else {
967
+ q = div(x, y, 0, MODULO_MODE);
968
+ }
969
+ y = x.minus(q.times(y));
970
+ if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
971
+ return y;
972
+ };
973
+ P.multipliedBy = P.times = function(y, b) {
974
+ var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
975
+ if (!xc || !yc || !xc[0] || !yc[0]) {
976
+ if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
977
+ y.c = y.e = y.s = null;
978
+ } else {
979
+ y.s *= x.s;
980
+ if (!xc || !yc) {
981
+ y.c = y.e = null;
982
+ } else {
983
+ y.c = [0];
984
+ y.e = 0;
985
+ }
986
+ }
987
+ return y;
988
+ }
989
+ e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
990
+ y.s *= x.s;
991
+ xcL = xc.length;
992
+ ycL = yc.length;
993
+ if (xcL < ycL) {
994
+ zc = xc;
995
+ xc = yc;
996
+ yc = zc;
997
+ i = xcL;
998
+ xcL = ycL;
999
+ ycL = i;
1000
+ }
1001
+ for (i = xcL + ycL, zc = []; i--; zc.push(0)) ;
1002
+ base = BASE;
1003
+ sqrtBase = SQRT_BASE;
1004
+ for (i = ycL; --i >= 0; ) {
1005
+ c = 0;
1006
+ ylo = yc[i] % sqrtBase;
1007
+ yhi = yc[i] / sqrtBase | 0;
1008
+ for (k = xcL, j = i + k; j > i; ) {
1009
+ xlo = xc[--k] % sqrtBase;
1010
+ xhi = xc[k] / sqrtBase | 0;
1011
+ m = yhi * xlo + xhi * ylo;
1012
+ xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
1013
+ c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
1014
+ zc[j--] = xlo % base;
1015
+ }
1016
+ zc[j] = c;
1017
+ }
1018
+ if (c) {
1019
+ ++e;
1020
+ } else {
1021
+ zc.splice(0, 1);
1022
+ }
1023
+ return normalise(y, zc, e);
1024
+ };
1025
+ P.negated = function() {
1026
+ var x = new BigNumber2(this);
1027
+ x.s = -x.s || null;
1028
+ return x;
1029
+ };
1030
+ P.plus = function(y, b) {
1031
+ var t, x = this, a = x.s;
1032
+ y = new BigNumber2(y, b);
1033
+ b = y.s;
1034
+ if (!a || !b) return new BigNumber2(NaN);
1035
+ if (a != b) {
1036
+ y.s = -b;
1037
+ return x.minus(y);
1038
+ }
1039
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
1040
+ if (!xe || !ye) {
1041
+ if (!xc || !yc) return new BigNumber2(a / 0);
1042
+ if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
1043
+ }
1044
+ xe = bitFloor(xe);
1045
+ ye = bitFloor(ye);
1046
+ xc = xc.slice();
1047
+ if (a = xe - ye) {
1048
+ if (a > 0) {
1049
+ ye = xe;
1050
+ t = yc;
1051
+ } else {
1052
+ a = -a;
1053
+ t = xc;
1054
+ }
1055
+ t.reverse();
1056
+ for (; a--; t.push(0)) ;
1057
+ t.reverse();
1058
+ }
1059
+ a = xc.length;
1060
+ b = yc.length;
1061
+ if (a - b < 0) {
1062
+ t = yc;
1063
+ yc = xc;
1064
+ xc = t;
1065
+ b = a;
1066
+ }
1067
+ for (a = 0; b; ) {
1068
+ a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
1069
+ xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
1070
+ }
1071
+ if (a) {
1072
+ xc = [a].concat(xc);
1073
+ ++ye;
1074
+ }
1075
+ return normalise(y, xc, ye);
1076
+ };
1077
+ P.precision = P.sd = function(sd, rm) {
1078
+ var c, n, v, x = this;
1079
+ if (sd != null && sd !== !!sd) {
1080
+ intCheck(sd, 1, MAX);
1081
+ if (rm == null) rm = ROUNDING_MODE;
1082
+ else intCheck(rm, 0, 8);
1083
+ return round(new BigNumber2(x), sd, rm);
1084
+ }
1085
+ if (!(c = x.c)) return null;
1086
+ v = c.length - 1;
1087
+ n = v * LOG_BASE + 1;
1088
+ if (v = c[v]) {
1089
+ for (; v % 10 == 0; v /= 10, n--) ;
1090
+ for (v = c[0]; v >= 10; v /= 10, n++) ;
1091
+ }
1092
+ if (sd && x.e + 1 > n) n = x.e + 1;
1093
+ return n;
1094
+ };
1095
+ P.shiftedBy = function(k) {
1096
+ intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
1097
+ return this.times("1e" + k);
1098
+ };
1099
+ P.squareRoot = P.sqrt = function() {
1100
+ var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
1101
+ if (s !== 1 || !c || !c[0]) {
1102
+ return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
1103
+ }
1104
+ s = Math.sqrt(+valueOf(x));
1105
+ if (s == 0 || s == 1 / 0) {
1106
+ n = coeffToString(c);
1107
+ if ((n.length + e) % 2 == 0) n += "0";
1108
+ s = Math.sqrt(+n);
1109
+ e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
1110
+ if (s == 1 / 0) {
1111
+ n = "5e" + e;
1112
+ } else {
1113
+ n = s.toExponential();
1114
+ n = n.slice(0, n.indexOf("e") + 1) + e;
1115
+ }
1116
+ r = new BigNumber2(n);
1117
+ } else {
1118
+ r = new BigNumber2(s + "");
1119
+ }
1120
+ if (r.c[0]) {
1121
+ e = r.e;
1122
+ s = e + dp;
1123
+ if (s < 3) s = 0;
1124
+ for (; ; ) {
1125
+ t = r;
1126
+ r = half.times(t.plus(div(x, t, dp, 1)));
1127
+ if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
1128
+ if (r.e < e) --s;
1129
+ n = n.slice(s - 3, s + 1);
1130
+ if (n == "9999" || !rep && n == "4999") {
1131
+ if (!rep) {
1132
+ round(t, t.e + DECIMAL_PLACES + 2, 0);
1133
+ if (t.times(t).eq(x)) {
1134
+ r = t;
1135
+ break;
1136
+ }
1137
+ }
1138
+ dp += 4;
1139
+ s += 4;
1140
+ rep = 1;
1141
+ } else {
1142
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
1143
+ round(r, r.e + DECIMAL_PLACES + 2, 1);
1144
+ m = !r.times(r).eq(x);
1145
+ }
1146
+ break;
1147
+ }
1148
+ }
1149
+ }
1150
+ }
1151
+ return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
1152
+ };
1153
+ P.toExponential = function(dp, rm) {
1154
+ if (dp != null) {
1155
+ intCheck(dp, 0, MAX);
1156
+ dp++;
1157
+ }
1158
+ return format(this, dp, rm, 1);
1159
+ };
1160
+ P.toFixed = function(dp, rm) {
1161
+ if (dp != null) {
1162
+ intCheck(dp, 0, MAX);
1163
+ dp = dp + this.e + 1;
1164
+ }
1165
+ return format(this, dp, rm);
1166
+ };
1167
+ P.toFormat = function(dp, rm, format2) {
1168
+ var str, x = this;
1169
+ if (format2 == null) {
1170
+ if (dp != null && rm && typeof rm == "object") {
1171
+ format2 = rm;
1172
+ rm = null;
1173
+ } else if (dp && typeof dp == "object") {
1174
+ format2 = dp;
1175
+ dp = rm = null;
1176
+ } else {
1177
+ format2 = FORMAT;
1178
+ }
1179
+ } else if (typeof format2 != "object") {
1180
+ throw Error(bignumberError + "Argument not an object: " + format2);
1181
+ }
1182
+ str = x.toFixed(dp, rm);
1183
+ if (x.c) {
1184
+ var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
1185
+ if (g2) {
1186
+ i = g1;
1187
+ g1 = g2;
1188
+ g2 = i;
1189
+ len -= i;
1190
+ }
1191
+ if (g1 > 0 && len > 0) {
1192
+ i = len % g1 || g1;
1193
+ intPart = intDigits.substr(0, i);
1194
+ for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
1195
+ if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
1196
+ if (isNeg) intPart = "-" + intPart;
1197
+ }
1198
+ str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
1199
+ new RegExp("\\d{" + g2 + "}\\B", "g"),
1200
+ "$&" + (format2.fractionGroupSeparator || "")
1201
+ ) : fractionPart) : intPart;
1202
+ }
1203
+ return (format2.prefix || "") + str + (format2.suffix || "");
1204
+ };
1205
+ P.toFraction = function(md) {
1206
+ var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
1207
+ if (md != null) {
1208
+ n = new BigNumber2(md);
1209
+ if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
1210
+ throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
1211
+ }
1212
+ }
1213
+ if (!xc) return new BigNumber2(x);
1214
+ d = new BigNumber2(ONE);
1215
+ n1 = d0 = new BigNumber2(ONE);
1216
+ d1 = n0 = new BigNumber2(ONE);
1217
+ s = coeffToString(xc);
1218
+ e = d.e = s.length - x.e - 1;
1219
+ d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
1220
+ md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
1221
+ exp = MAX_EXP;
1222
+ MAX_EXP = 1 / 0;
1223
+ n = new BigNumber2(s);
1224
+ n0.c[0] = 0;
1225
+ for (; ; ) {
1226
+ q = div(n, d, 0, 1);
1227
+ d2 = d0.plus(q.times(d1));
1228
+ if (d2.comparedTo(md) == 1) break;
1229
+ d0 = d1;
1230
+ d1 = d2;
1231
+ n1 = n0.plus(q.times(d2 = n1));
1232
+ n0 = d2;
1233
+ d = n.minus(q.times(d2 = d));
1234
+ n = d2;
1235
+ }
1236
+ d2 = div(md.minus(d0), d1, 0, 1);
1237
+ n0 = n0.plus(d2.times(n1));
1238
+ d0 = d0.plus(d2.times(d1));
1239
+ n0.s = n1.s = x.s;
1240
+ e = e * 2;
1241
+ r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
1242
+ div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
1243
+ ) < 1 ? [n1, d1] : [n0, d0];
1244
+ MAX_EXP = exp;
1245
+ return r;
1246
+ };
1247
+ P.toNumber = function() {
1248
+ return +valueOf(this);
1249
+ };
1250
+ P.toPrecision = function(sd, rm) {
1251
+ if (sd != null) intCheck(sd, 1, MAX);
1252
+ return format(this, sd, rm, 2);
1253
+ };
1254
+ P.toString = function(b) {
1255
+ var str, n = this, s = n.s, e = n.e;
1256
+ if (e === null) {
1257
+ if (s) {
1258
+ str = "Infinity";
1259
+ if (s < 0) str = "-" + str;
1260
+ } else {
1261
+ str = "NaN";
1262
+ }
1263
+ } else {
1264
+ if (b == null) {
1265
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
1266
+ } else if (b === 10 && alphabetHasNormalDecimalDigits) {
1267
+ n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
1268
+ str = toFixedPoint(coeffToString(n.c), n.e, "0");
1269
+ } else {
1270
+ intCheck(b, 2, ALPHABET.length, "Base");
1271
+ str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
1272
+ }
1273
+ if (s < 0 && n.c[0]) str = "-" + str;
1274
+ }
1275
+ return str;
1276
+ };
1277
+ P.valueOf = P.toJSON = function() {
1278
+ return valueOf(this);
1279
+ };
1280
+ P._isBigNumber = true;
1281
+ P[Symbol.toStringTag] = "BigNumber";
1282
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
1283
+ if (configObject != null) BigNumber2.set(configObject);
1284
+ return BigNumber2;
1285
+ }
1286
+ function bitFloor(n) {
1287
+ var i = n | 0;
1288
+ return n > 0 || n === i ? i : i - 1;
1289
+ }
1290
+ function coeffToString(a) {
1291
+ var s, z, i = 1, j = a.length, r = a[0] + "";
1292
+ for (; i < j; ) {
1293
+ s = a[i++] + "";
1294
+ z = LOG_BASE - s.length;
1295
+ for (; z--; s = "0" + s) ;
1296
+ r += s;
1297
+ }
1298
+ for (j = r.length; r.charCodeAt(--j) === 48; ) ;
1299
+ return r.slice(0, j + 1 || 1);
1300
+ }
1301
+ function compare(x, y) {
1302
+ var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
1303
+ if (!i || !j) return null;
1304
+ a = xc && !xc[0];
1305
+ b = yc && !yc[0];
1306
+ if (a || b) return a ? b ? 0 : -j : i;
1307
+ if (i != j) return i;
1308
+ a = i < 0;
1309
+ b = k == l;
1310
+ if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
1311
+ if (!b) return k > l ^ a ? 1 : -1;
1312
+ j = (k = xc.length) < (l = yc.length) ? k : l;
1313
+ for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
1314
+ return k == l ? 0 : k > l ^ a ? 1 : -1;
1315
+ }
1316
+ function intCheck(n, min, max, name) {
1317
+ if (n < min || n > max || n !== mathfloor(n)) {
1318
+ throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
1319
+ }
1320
+ }
1321
+ function isOdd(n) {
1322
+ var k = n.c.length - 1;
1323
+ return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
1324
+ }
1325
+ function toExponential(str, e) {
1326
+ return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
1327
+ }
1328
+ function toFixedPoint(str, e, z) {
1329
+ var len, zs;
1330
+ if (e < 0) {
1331
+ for (zs = z + "."; ++e; zs += z) ;
1332
+ str = zs + str;
1333
+ } else {
1334
+ len = str.length;
1335
+ if (++e > len) {
1336
+ for (zs = z, e -= len; --e; zs += z) ;
1337
+ str += zs;
1338
+ } else if (e < len) {
1339
+ str = str.slice(0, e) + "." + str.slice(e);
1340
+ }
1341
+ }
1342
+ return str;
1343
+ }
1344
+ var BigNumber = clone();
1345
+ var bignumber_default = BigNumber;
1346
+
1347
+ // src/number/index.ts
1348
+ var BIG_INTS = {
1349
+ t: { v: 10 ** 12, d: 13, n: "t" },
1350
+ b: { v: 10 ** 9, d: 10, n: "b" },
1351
+ m: { v: 10 ** 6, d: 7, n: "m" },
1352
+ k: { v: 10 ** 3, d: 4, n: "k" }
1353
+ };
1354
+ function unum(num = "0") {
1355
+ return new bignumber_default(numerfix(num));
1356
+ }
1357
+ function gte(num, n) {
1358
+ return unum(num).gte(unum(n));
1359
+ }
1360
+ function gt(num, n) {
1361
+ return unum(num).gt(unum(n));
1362
+ }
1363
+ function lte(num, n) {
1364
+ return unum(num).lte(unum(n));
1365
+ }
1366
+ function lt(num, n) {
1367
+ return unum(num).lt(unum(n));
1368
+ }
1369
+ function plus(array, options) {
1370
+ const rounding = options?.r || bignumber_default.ROUND_DOWN;
1371
+ const decimal2 = options?.d || 0;
1372
+ return array.filter((v) => unum(v).gt(0)).reduce((t, v) => t.plus(unum(v)), unum(0)).toFixed(decimal2, rounding);
1373
+ }
1374
+ function average(array, options) {
1375
+ const rounding = options?.r || bignumber_default.ROUND_DOWN;
1376
+ const decimal2 = options?.d || 0;
1377
+ if (array.length === 0)
1378
+ return "0";
1379
+ return unum(plus(array)).div(array.length).toFixed(decimal2, rounding);
1380
+ }
1381
+ function percentage(total, count, options) {
1382
+ options ??= { d: 3, r: bignumber_default.ROUND_DOWN };
1383
+ const rounding = options?.r || bignumber_default.ROUND_DOWN;
1384
+ const decimal2 = options?.d || 3;
1385
+ if (unum(total).lte(0) || unum(count).lte(0))
1386
+ return "0";
1387
+ return unum(count).div(unum(total)).times(100).toFixed(decimal2, rounding);
1388
+ }
1389
+ function zerofill(value, n = 2, type = "positive") {
1390
+ const _value = integer(value);
1391
+ if (_value.length >= n)
1392
+ return value;
1393
+ const zero = "0".repeat(n - _value.length);
1394
+ if (type === "positive")
1395
+ return zero + value;
1396
+ if (type === "reverse")
1397
+ return zero + value;
1398
+ return "";
1399
+ }
1400
+ function zeromove(value) {
1401
+ return value.toString().replace(/\.?0+$/, "");
1402
+ }
1403
+ function numerfix(value) {
1404
+ const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
1405
+ if (_isNaN)
1406
+ console.warn(`numerfix(${value}): value is not the correct value. To ensure the normal operation of the program, it will be converted to zero`);
1407
+ return _isNaN ? "0" : String(value);
1408
+ }
1409
+ function integer(value) {
1410
+ return new bignumber_default(numerfix(value)).toFixed(0);
1411
+ }
1412
+ function decimal(value, n = 2) {
1413
+ let [integer2, decimal2] = numerfix(value).split(".");
1414
+ if (n <= 0)
1415
+ return integer2;
1416
+ if (!decimal2)
1417
+ decimal2 = "0";
1418
+ decimal2 = decimal2.slice(0, n);
1419
+ decimal2 = decimal2 + "0".repeat(n - decimal2.length);
1420
+ return `${integer2}.${decimal2}`;
1421
+ }
1422
+ function parseNumeric(num, delimiters = ["t", "b", "m"]) {
1423
+ const mappings = [
1424
+ delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
1425
+ delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
1426
+ delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
1427
+ delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
1428
+ ];
1429
+ let options;
1430
+ for (const analy of mappings) {
1431
+ const opts = analy && analy(unum(num).toFixed(0));
1432
+ opts && (options = opts);
1433
+ }
1434
+ return options || { v: 1, d: 0, n: "" };
1435
+ }
1436
+ function formatNumeric(value = "0", options) {
1437
+ const {
1438
+ rounding = bignumber_default.ROUND_DOWN,
1439
+ delimiters,
1440
+ format,
1441
+ decimals = 2
1442
+ } = options || {};
1443
+ const config = parseNumeric(value, delimiters || []);
1444
+ let number = unum(value).div(config.v).toFormat(decimals, rounding, {
1445
+ decimalSeparator: ".",
1446
+ groupSeparator: ",",
1447
+ groupSize: 3,
1448
+ secondaryGroupSize: 0,
1449
+ fractionGroupSeparator: " ",
1450
+ fractionGroupSize: 0,
1451
+ ...format
1452
+ });
1453
+ number = options?.zeromove ? zeromove(number) : number;
1454
+ return `${number}${config.n}`;
1455
+ }
1456
+
1457
+ // src/util/compose.ts
1458
+ var compose = (...fns) => fns.reduceRight((v, f) => f(v));
1459
+
1460
+ // src/util/converts.ts
1461
+ function formToObject(formData) {
1462
+ return Object.fromEntries(formData.entries());
1463
+ }
1464
+ function objectToForm(object) {
1465
+ const formData = new FormData();
1466
+ for (const [key, value] of Object.entries(object)) formData.append(key, value);
1467
+ return formData;
1468
+ }
1469
+
1470
+ // src/util/deferred.ts
1471
+ var Deferred = class extends Promise {
1472
+ resolve;
1473
+ reject;
1474
+ constructor() {
1475
+ let _resolve, _reject;
1476
+ super((resolve_, reject_) => {
1477
+ _resolve = resolve_;
1478
+ _reject = reject_;
1479
+ });
1480
+ this.resolve = (value) => {
1481
+ _resolve(value);
1482
+ return this;
1483
+ };
1484
+ this.reject = (reason) => {
1485
+ _reject(reason);
1486
+ return this;
1487
+ };
1488
+ }
1489
+ };
1490
+
1491
+ // src/util/delay.ts
1492
+ function delay(ms) {
1493
+ return new Promise((resolve) => setTimeout(resolve, ms));
1494
+ }
1495
+
1496
+ // src/util/is.ts
1497
+ var isBrowser = () => typeof window !== "undefined";
1498
+ var isWeex = () => typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
1499
+ var weexPlatform = () => isWeex() && WXEnvironment.platform.toLowerCase();
1500
+ var UA = () => isBrowser() && window.navigator.userAgent.toLowerCase() || "";
1501
+ var isIE = () => UA() && /msie|trident/.test(UA());
1502
+ var isIE9 = () => UA() && UA().indexOf("msie 9.0") > 0;
1503
+ var isIE11 = () => isBrowser() && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
1504
+ var isEdge = () => UA() && UA().indexOf("edge/") > 0;
1505
+ var isAndroid = () => UA() && UA().indexOf("android") > 0 || weexPlatform() === "android";
1506
+ var isIOS = () => UA() && /iphone|ipad|ipod|ios/.test(UA()) || weexPlatform() === "ios";
1507
+ var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
1508
+ var isPhantomJS = () => UA() && /phantomjs/.test(UA());
1509
+ var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
1510
+ var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
1511
+ var isObject = (value) => typeof value === "object" && !Array.isArray(value);
1512
+ var isNumber = (value) => typeof value === "number";
1513
+ var isString = (value) => typeof value === "string";
1514
+ var isArray = (value) => Array.isArray(value);
1515
+ var isNull = (value) => value === null;
1516
+ var isPlainObject = (value) => typeof value === "object" && value !== null && value.constructor === Object;
1517
+ var isFormData = (value) => isObject(value) && isBrowser() && value instanceof FormData;
1518
+ var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
1519
+
1520
+ // src/util/noop.ts
1521
+ var noop = () => {
1522
+ };
1523
+
1524
+ // src/util/p-pipe.ts
1525
+ function pPipe(...functions) {
1526
+ if (functions.length === 0)
1527
+ throw new Error("Expected at least one argument");
1528
+ return async (input) => {
1529
+ let currentValue = input;
1530
+ for (const function_ of functions)
1531
+ currentValue = await function_(currentValue);
1532
+ return currentValue;
1533
+ };
1534
+ }
1535
+
1536
+ // src/util/pipe.ts
1537
+ var pipe = (...fns) => fns.reduce((v, f) => f(v));
1538
+
1539
+ // src/util/util.ts
1540
+ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
1541
+ if (!x2)
1542
+ x1 -= x2 = x1;
1543
+ for (let z1 = z0 + Math.max(Math.ceil((++x2 - x1) / stp), 0); z0 < z1; x1 += stp)
1544
+ z[z0++] = x1;
1545
+ return z;
1546
+ }
1547
+ function loop(fn) {
1548
+ async function next(ms) {
1549
+ await delay(ms);
1550
+ return fn(next);
1551
+ }
1552
+ return fn(next);
1553
+ }
1554
+ function riposte(...args) {
1555
+ for (const [cond, value] of args) {
1556
+ if (cond)
1557
+ return value;
1558
+ }
1559
+ return void 0;
1560
+ }
1561
+ function unwrap(value) {
1562
+ return typeof value === "function" ? value() : value;
1563
+ }
1564
+ function whenever(value, callback) {
1565
+ return value ? callback(value) : void 0;
1566
+ }
1567
+
1568
+ // src/size/index.ts
1569
+ function formatUnit(value, unit = "px") {
1570
+ if (!(isString(value) || isNumber(value)))
1571
+ return "";
1572
+ value = String(value);
1573
+ return /\D/.test(value) ? value : value + unit;
1574
+ }
1575
+ function formatSize(dimension, unit) {
1576
+ const _formatUnit = (value) => formatUnit(value, unit);
1577
+ if (typeof dimension === "string" || typeof dimension === "number")
1578
+ return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
1579
+ if (Array.isArray(dimension))
1580
+ return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
1581
+ if (typeof dimension === "object")
1582
+ return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
1583
+ return { width: "", height: "" };
1584
+ }
1585
+
1586
+ // src/string/index.ts
1587
+ function cover(value, mode, symbol = "*") {
1588
+ return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
1589
+ }
1590
+
1591
+ // src/typeof/index.ts
1592
+ function getTypeof(target) {
1593
+ const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
1594
+ return value;
1595
+ }
1596
+ function isTypeof(target, type) {
1597
+ return getTypeof(target) === type;
1598
+ }
1599
+ })();