@chainflip/utils 0.4.1 → 0.4.3

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