@chainflip/utils 0.4.0 → 0.4.1

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