ztxkutils 2.10.55 → 2.10.56

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2446 @@
1
+ import { _ as __assign } from './tslib.es6-35653116.js';
2
+ import dayjs from 'dayjs';
3
+
4
+ /*
5
+ * decimal.js-light v2.5.1
6
+ * An arbitrary-precision Decimal type for JavaScript.
7
+ * https://github.com/MikeMcl/decimal.js-light
8
+ * Copyright (c) 2020 Michael Mclaughlin <M8ch88l@gmail.com>
9
+ * MIT Expat Licence
10
+ */
11
+
12
+
13
+ // ------------------------------------ EDITABLE DEFAULTS ------------------------------------- //
14
+
15
+
16
+ // The limit on the value of `precision`, and on the value of the first argument to
17
+ // `toDecimalPlaces`, `toExponential`, `toFixed`, `toPrecision` and `toSignificantDigits`.
18
+ var MAX_DIGITS = 1e9, // 0 to 1e9
19
+
20
+
21
+ // The initial configuration properties of the Decimal constructor.
22
+ defaults = {
23
+
24
+ // These values must be integers within the stated ranges (inclusive).
25
+ // Most of these values can be changed during run-time using `Decimal.config`.
26
+
27
+ // The maximum number of significant digits of the result of a calculation or base conversion.
28
+ // E.g. `Decimal.config({ precision: 20 });`
29
+ precision: 20, // 1 to MAX_DIGITS
30
+
31
+ // The rounding mode used by default by `toInteger`, `toDecimalPlaces`, `toExponential`,
32
+ // `toFixed`, `toPrecision` and `toSignificantDigits`.
33
+ //
34
+ // ROUND_UP 0 Away from zero.
35
+ // ROUND_DOWN 1 Towards zero.
36
+ // ROUND_CEIL 2 Towards +Infinity.
37
+ // ROUND_FLOOR 3 Towards -Infinity.
38
+ // ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
39
+ // ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
40
+ // ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
41
+ // ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
42
+ // ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
43
+ //
44
+ // E.g.
45
+ // `Decimal.rounding = 4;`
46
+ // `Decimal.rounding = Decimal.ROUND_HALF_UP;`
47
+ rounding: 4, // 0 to 8
48
+
49
+ // The exponent value at and beneath which `toString` returns exponential notation.
50
+ // JavaScript numbers: -7
51
+ toExpNeg: -7, // 0 to -MAX_E
52
+
53
+ // The exponent value at and above which `toString` returns exponential notation.
54
+ // JavaScript numbers: 21
55
+ toExpPos: 21, // 0 to MAX_E
56
+
57
+ // The natural logarithm of 10.
58
+ // 115 digits
59
+ LN10: '2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286'
60
+ },
61
+
62
+
63
+ // ------------------------------------ END OF EDITABLE DEFAULTS -------------------------------- //
64
+
65
+
66
+ Decimal,
67
+ external = true,
68
+
69
+ decimalError = '[DecimalError] ',
70
+ invalidArgument = decimalError + 'Invalid argument: ',
71
+ exponentOutOfRange = decimalError + 'Exponent out of range: ',
72
+
73
+ mathfloor = Math.floor,
74
+ mathpow = Math.pow,
75
+
76
+ isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
77
+
78
+ ONE,
79
+ BASE = 1e7,
80
+ LOG_BASE = 7,
81
+ MAX_SAFE_INTEGER = 9007199254740991,
82
+ MAX_E = mathfloor(MAX_SAFE_INTEGER / LOG_BASE), // 1286742750677284
83
+
84
+ // Decimal.prototype object
85
+ P = {};
86
+
87
+
88
+ // Decimal prototype methods
89
+
90
+
91
+ /*
92
+ * absoluteValue abs
93
+ * comparedTo cmp
94
+ * decimalPlaces dp
95
+ * dividedBy div
96
+ * dividedToIntegerBy idiv
97
+ * equals eq
98
+ * exponent
99
+ * greaterThan gt
100
+ * greaterThanOrEqualTo gte
101
+ * isInteger isint
102
+ * isNegative isneg
103
+ * isPositive ispos
104
+ * isZero
105
+ * lessThan lt
106
+ * lessThanOrEqualTo lte
107
+ * logarithm log
108
+ * minus sub
109
+ * modulo mod
110
+ * naturalExponential exp
111
+ * naturalLogarithm ln
112
+ * negated neg
113
+ * plus add
114
+ * precision sd
115
+ * squareRoot sqrt
116
+ * times mul
117
+ * toDecimalPlaces todp
118
+ * toExponential
119
+ * toFixed
120
+ * toInteger toint
121
+ * toNumber
122
+ * toPower pow
123
+ * toPrecision
124
+ * toSignificantDigits tosd
125
+ * toString
126
+ * valueOf val
127
+ */
128
+
129
+
130
+ /*
131
+ * Return a new Decimal whose value is the absolute value of this Decimal.
132
+ *
133
+ */
134
+ P.absoluteValue = P.abs = function () {
135
+ var x = new this.constructor(this);
136
+ if (x.s) x.s = 1;
137
+ return x;
138
+ };
139
+
140
+
141
+ /*
142
+ * Return
143
+ * 1 if the value of this Decimal is greater than the value of `y`,
144
+ * -1 if the value of this Decimal is less than the value of `y`,
145
+ * 0 if they have the same value
146
+ *
147
+ */
148
+ P.comparedTo = P.cmp = function (y) {
149
+ var i, j, xdL, ydL,
150
+ x = this;
151
+
152
+ y = new x.constructor(y);
153
+
154
+ // Signs differ?
155
+ if (x.s !== y.s) return x.s || -y.s;
156
+
157
+ // Compare exponents.
158
+ if (x.e !== y.e) return x.e > y.e ^ x.s < 0 ? 1 : -1;
159
+
160
+ xdL = x.d.length;
161
+ ydL = y.d.length;
162
+
163
+ // Compare digit by digit.
164
+ for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
165
+ if (x.d[i] !== y.d[i]) return x.d[i] > y.d[i] ^ x.s < 0 ? 1 : -1;
166
+ }
167
+
168
+ // Compare lengths.
169
+ return xdL === ydL ? 0 : xdL > ydL ^ x.s < 0 ? 1 : -1;
170
+ };
171
+
172
+
173
+ /*
174
+ * Return the number of decimal places of the value of this Decimal.
175
+ *
176
+ */
177
+ P.decimalPlaces = P.dp = function () {
178
+ var x = this,
179
+ w = x.d.length - 1,
180
+ dp = (w - x.e) * LOG_BASE;
181
+
182
+ // Subtract the number of trailing zeros of the last word.
183
+ w = x.d[w];
184
+ if (w) for (; w % 10 == 0; w /= 10) dp--;
185
+
186
+ return dp < 0 ? 0 : dp;
187
+ };
188
+
189
+
190
+ /*
191
+ * Return a new Decimal whose value is the value of this Decimal divided by `y`, truncated to
192
+ * `precision` significant digits.
193
+ *
194
+ */
195
+ P.dividedBy = P.div = function (y) {
196
+ return divide$1(this, new this.constructor(y));
197
+ };
198
+
199
+
200
+ /*
201
+ * Return a new Decimal whose value is the integer part of dividing the value of this Decimal
202
+ * by the value of `y`, truncated to `precision` significant digits.
203
+ *
204
+ */
205
+ P.dividedToIntegerBy = P.idiv = function (y) {
206
+ var x = this,
207
+ Ctor = x.constructor;
208
+ return round(divide$1(x, new Ctor(y), 0, 1), Ctor.precision);
209
+ };
210
+
211
+
212
+ /*
213
+ * Return true if the value of this Decimal is equal to the value of `y`, otherwise return false.
214
+ *
215
+ */
216
+ P.equals = P.eq = function (y) {
217
+ return !this.cmp(y);
218
+ };
219
+
220
+
221
+ /*
222
+ * Return the (base 10) exponent value of this Decimal (this.e is the base 10000000 exponent).
223
+ *
224
+ */
225
+ P.exponent = function () {
226
+ return getBase10Exponent(this);
227
+ };
228
+
229
+
230
+ /*
231
+ * Return true if the value of this Decimal is greater than the value of `y`, otherwise return
232
+ * false.
233
+ *
234
+ */
235
+ P.greaterThan = P.gt = function (y) {
236
+ return this.cmp(y) > 0;
237
+ };
238
+
239
+
240
+ /*
241
+ * Return true if the value of this Decimal is greater than or equal to the value of `y`,
242
+ * otherwise return false.
243
+ *
244
+ */
245
+ P.greaterThanOrEqualTo = P.gte = function (y) {
246
+ return this.cmp(y) >= 0;
247
+ };
248
+
249
+
250
+ /*
251
+ * Return true if the value of this Decimal is an integer, otherwise return false.
252
+ *
253
+ */
254
+ P.isInteger = P.isint = function () {
255
+ return this.e > this.d.length - 2;
256
+ };
257
+
258
+
259
+ /*
260
+ * Return true if the value of this Decimal is negative, otherwise return false.
261
+ *
262
+ */
263
+ P.isNegative = P.isneg = function () {
264
+ return this.s < 0;
265
+ };
266
+
267
+
268
+ /*
269
+ * Return true if the value of this Decimal is positive, otherwise return false.
270
+ *
271
+ */
272
+ P.isPositive = P.ispos = function () {
273
+ return this.s > 0;
274
+ };
275
+
276
+
277
+ /*
278
+ * Return true if the value of this Decimal is 0, otherwise return false.
279
+ *
280
+ */
281
+ P.isZero = function () {
282
+ return this.s === 0;
283
+ };
284
+
285
+
286
+ /*
287
+ * Return true if the value of this Decimal is less than `y`, otherwise return false.
288
+ *
289
+ */
290
+ P.lessThan = P.lt = function (y) {
291
+ return this.cmp(y) < 0;
292
+ };
293
+
294
+
295
+ /*
296
+ * Return true if the value of this Decimal is less than or equal to `y`, otherwise return false.
297
+ *
298
+ */
299
+ P.lessThanOrEqualTo = P.lte = function (y) {
300
+ return this.cmp(y) < 1;
301
+ };
302
+
303
+
304
+ /*
305
+ * Return the logarithm of the value of this Decimal to the specified base, truncated to
306
+ * `precision` significant digits.
307
+ *
308
+ * If no base is specified, return log[10](x).
309
+ *
310
+ * log[base](x) = ln(x) / ln(base)
311
+ *
312
+ * The maximum error of the result is 1 ulp (unit in the last place).
313
+ *
314
+ * [base] {number|string|Decimal} The base of the logarithm.
315
+ *
316
+ */
317
+ P.logarithm = P.log = function (base) {
318
+ var r,
319
+ x = this,
320
+ Ctor = x.constructor,
321
+ pr = Ctor.precision,
322
+ wpr = pr + 5;
323
+
324
+ // Default base is 10.
325
+ if (base === void 0) {
326
+ base = new Ctor(10);
327
+ } else {
328
+ base = new Ctor(base);
329
+
330
+ // log[-b](x) = NaN
331
+ // log[0](x) = NaN
332
+ // log[1](x) = NaN
333
+ if (base.s < 1 || base.eq(ONE)) throw Error(decimalError + 'NaN');
334
+ }
335
+
336
+ // log[b](-x) = NaN
337
+ // log[b](0) = -Infinity
338
+ if (x.s < 1) throw Error(decimalError + (x.s ? 'NaN' : '-Infinity'));
339
+
340
+ // log[b](1) = 0
341
+ if (x.eq(ONE)) return new Ctor(0);
342
+
343
+ external = false;
344
+ r = divide$1(ln(x, wpr), ln(base, wpr), wpr);
345
+ external = true;
346
+
347
+ return round(r, pr);
348
+ };
349
+
350
+
351
+ /*
352
+ * Return a new Decimal whose value is the value of this Decimal minus `y`, truncated to
353
+ * `precision` significant digits.
354
+ *
355
+ */
356
+ P.minus = P.sub = function (y) {
357
+ var x = this;
358
+ y = new x.constructor(y);
359
+ return x.s == y.s ? subtract(x, y) : add(x, (y.s = -y.s, y));
360
+ };
361
+
362
+
363
+ /*
364
+ * Return a new Decimal whose value is the value of this Decimal modulo `y`, truncated to
365
+ * `precision` significant digits.
366
+ *
367
+ */
368
+ P.modulo = P.mod = function (y) {
369
+ var q,
370
+ x = this,
371
+ Ctor = x.constructor,
372
+ pr = Ctor.precision;
373
+
374
+ y = new Ctor(y);
375
+
376
+ // x % 0 = NaN
377
+ if (!y.s) throw Error(decimalError + 'NaN');
378
+
379
+ // Return x if x is 0.
380
+ if (!x.s) return round(new Ctor(x), pr);
381
+
382
+ // Prevent rounding of intermediate calculations.
383
+ external = false;
384
+ q = divide$1(x, y, 0, 1).times(y);
385
+ external = true;
386
+
387
+ return x.minus(q);
388
+ };
389
+
390
+
391
+ /*
392
+ * Return a new Decimal whose value is the natural exponential of the value of this Decimal,
393
+ * i.e. the base e raised to the power the value of this Decimal, truncated to `precision`
394
+ * significant digits.
395
+ *
396
+ */
397
+ P.naturalExponential = P.exp = function () {
398
+ return exp(this);
399
+ };
400
+
401
+
402
+ /*
403
+ * Return a new Decimal whose value is the natural logarithm of the value of this Decimal,
404
+ * truncated to `precision` significant digits.
405
+ *
406
+ */
407
+ P.naturalLogarithm = P.ln = function () {
408
+ return ln(this);
409
+ };
410
+
411
+
412
+ /*
413
+ * Return a new Decimal whose value is the value of this Decimal negated, i.e. as if multiplied by
414
+ * -1.
415
+ *
416
+ */
417
+ P.negated = P.neg = function () {
418
+ var x = new this.constructor(this);
419
+ x.s = -x.s || 0;
420
+ return x;
421
+ };
422
+
423
+
424
+ /*
425
+ * Return a new Decimal whose value is the value of this Decimal plus `y`, truncated to
426
+ * `precision` significant digits.
427
+ *
428
+ */
429
+ P.plus = P.add = function (y) {
430
+ var x = this;
431
+ y = new x.constructor(y);
432
+ return x.s == y.s ? add(x, y) : subtract(x, (y.s = -y.s, y));
433
+ };
434
+
435
+
436
+ /*
437
+ * Return the number of significant digits of the value of this Decimal.
438
+ *
439
+ * [z] {boolean|number} Whether to count integer-part trailing zeros: true, false, 1 or 0.
440
+ *
441
+ */
442
+ P.precision = P.sd = function (z) {
443
+ var e, sd, w,
444
+ x = this;
445
+
446
+ if (z !== void 0 && z !== !!z && z !== 1 && z !== 0) throw Error(invalidArgument + z);
447
+
448
+ e = getBase10Exponent(x) + 1;
449
+ w = x.d.length - 1;
450
+ sd = w * LOG_BASE + 1;
451
+ w = x.d[w];
452
+
453
+ // If non-zero...
454
+ if (w) {
455
+
456
+ // Subtract the number of trailing zeros of the last word.
457
+ for (; w % 10 == 0; w /= 10) sd--;
458
+
459
+ // Add the number of digits of the first word.
460
+ for (w = x.d[0]; w >= 10; w /= 10) sd++;
461
+ }
462
+
463
+ return z && e > sd ? e : sd;
464
+ };
465
+
466
+
467
+ /*
468
+ * Return a new Decimal whose value is the square root of this Decimal, truncated to `precision`
469
+ * significant digits.
470
+ *
471
+ */
472
+ P.squareRoot = P.sqrt = function () {
473
+ var e, n, pr, r, s, t, wpr,
474
+ x = this,
475
+ Ctor = x.constructor;
476
+
477
+ // Negative or zero?
478
+ if (x.s < 1) {
479
+ if (!x.s) return new Ctor(0);
480
+
481
+ // sqrt(-x) = NaN
482
+ throw Error(decimalError + 'NaN');
483
+ }
484
+
485
+ e = getBase10Exponent(x);
486
+ external = false;
487
+
488
+ // Initial estimate.
489
+ s = Math.sqrt(+x);
490
+
491
+ // Math.sqrt underflow/overflow?
492
+ // Pass x to Math.sqrt as integer, then adjust the exponent of the result.
493
+ if (s == 0 || s == 1 / 0) {
494
+ n = digitsToString(x.d);
495
+ if ((n.length + e) % 2 == 0) n += '0';
496
+ s = Math.sqrt(n);
497
+ e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
498
+
499
+ if (s == 1 / 0) {
500
+ n = '5e' + e;
501
+ } else {
502
+ n = s.toExponential();
503
+ n = n.slice(0, n.indexOf('e') + 1) + e;
504
+ }
505
+
506
+ r = new Ctor(n);
507
+ } else {
508
+ r = new Ctor(s.toString());
509
+ }
510
+
511
+ pr = Ctor.precision;
512
+ s = wpr = pr + 3;
513
+
514
+ // Newton-Raphson iteration.
515
+ for (;;) {
516
+ t = r;
517
+ r = t.plus(divide$1(x, t, wpr + 2)).times(0.5);
518
+
519
+ if (digitsToString(t.d).slice(0, wpr) === (n = digitsToString(r.d)).slice(0, wpr)) {
520
+ n = n.slice(wpr - 3, wpr + 1);
521
+
522
+ // The 4th rounding digit may be in error by -1 so if the 4 rounding digits are 9999 or
523
+ // 4999, i.e. approaching a rounding boundary, continue the iteration.
524
+ if (s == wpr && n == '4999') {
525
+
526
+ // On the first iteration only, check to see if rounding up gives the exact result as the
527
+ // nines may infinitely repeat.
528
+ round(t, pr + 1, 0);
529
+
530
+ if (t.times(t).eq(x)) {
531
+ r = t;
532
+ break;
533
+ }
534
+ } else if (n != '9999') {
535
+ break;
536
+ }
537
+
538
+ wpr += 4;
539
+ }
540
+ }
541
+
542
+ external = true;
543
+
544
+ return round(r, pr);
545
+ };
546
+
547
+
548
+ /*
549
+ * Return a new Decimal whose value is the value of this Decimal times `y`, truncated to
550
+ * `precision` significant digits.
551
+ *
552
+ */
553
+ P.times = P.mul = function (y) {
554
+ var carry, e, i, k, r, rL, t, xdL, ydL,
555
+ x = this,
556
+ Ctor = x.constructor,
557
+ xd = x.d,
558
+ yd = (y = new Ctor(y)).d;
559
+
560
+ // Return 0 if either is 0.
561
+ if (!x.s || !y.s) return new Ctor(0);
562
+
563
+ y.s *= x.s;
564
+ e = x.e + y.e;
565
+ xdL = xd.length;
566
+ ydL = yd.length;
567
+
568
+ // Ensure xd points to the longer array.
569
+ if (xdL < ydL) {
570
+ r = xd;
571
+ xd = yd;
572
+ yd = r;
573
+ rL = xdL;
574
+ xdL = ydL;
575
+ ydL = rL;
576
+ }
577
+
578
+ // Initialise the result array with zeros.
579
+ r = [];
580
+ rL = xdL + ydL;
581
+ for (i = rL; i--;) r.push(0);
582
+
583
+ // Multiply!
584
+ for (i = ydL; --i >= 0;) {
585
+ carry = 0;
586
+ for (k = xdL + i; k > i;) {
587
+ t = r[k] + yd[i] * xd[k - i - 1] + carry;
588
+ r[k--] = t % BASE | 0;
589
+ carry = t / BASE | 0;
590
+ }
591
+
592
+ r[k] = (r[k] + carry) % BASE | 0;
593
+ }
594
+
595
+ // Remove trailing zeros.
596
+ for (; !r[--rL];) r.pop();
597
+
598
+ if (carry) ++e;
599
+ else r.shift();
600
+
601
+ y.d = r;
602
+ y.e = e;
603
+
604
+ return external ? round(y, Ctor.precision) : y;
605
+ };
606
+
607
+
608
+ /*
609
+ * Return a new Decimal whose value is the value of this Decimal rounded to a maximum of `dp`
610
+ * decimal places using rounding mode `rm` or `rounding` if `rm` is omitted.
611
+ *
612
+ * If `dp` is omitted, return a new Decimal whose value is the value of this Decimal.
613
+ *
614
+ * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
615
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
616
+ *
617
+ */
618
+ P.toDecimalPlaces = P.todp = function (dp, rm) {
619
+ var x = this,
620
+ Ctor = x.constructor;
621
+
622
+ x = new Ctor(x);
623
+ if (dp === void 0) return x;
624
+
625
+ checkInt32(dp, 0, MAX_DIGITS);
626
+
627
+ if (rm === void 0) rm = Ctor.rounding;
628
+ else checkInt32(rm, 0, 8);
629
+
630
+ return round(x, dp + getBase10Exponent(x) + 1, rm);
631
+ };
632
+
633
+
634
+ /*
635
+ * Return a string representing the value of this Decimal in exponential notation rounded to
636
+ * `dp` fixed decimal places using rounding mode `rounding`.
637
+ *
638
+ * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
639
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
640
+ *
641
+ */
642
+ P.toExponential = function (dp, rm) {
643
+ var str,
644
+ x = this,
645
+ Ctor = x.constructor;
646
+
647
+ if (dp === void 0) {
648
+ str = toString(x, true);
649
+ } else {
650
+ checkInt32(dp, 0, MAX_DIGITS);
651
+
652
+ if (rm === void 0) rm = Ctor.rounding;
653
+ else checkInt32(rm, 0, 8);
654
+
655
+ x = round(new Ctor(x), dp + 1, rm);
656
+ str = toString(x, true, dp + 1);
657
+ }
658
+
659
+ return str;
660
+ };
661
+
662
+
663
+ /*
664
+ * Return a string representing the value of this Decimal in normal (fixed-point) notation to
665
+ * `dp` fixed decimal places and rounded using rounding mode `rm` or `rounding` if `rm` is
666
+ * omitted.
667
+ *
668
+ * As with JavaScript numbers, (-0).toFixed(0) is '0', but e.g. (-0.00001).toFixed(0) is '-0'.
669
+ *
670
+ * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
671
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
672
+ *
673
+ * (-0).toFixed(0) is '0', but (-0.1).toFixed(0) is '-0'.
674
+ * (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'.
675
+ * (-0).toFixed(3) is '0.000'.
676
+ * (-0.5).toFixed(0) is '-0'.
677
+ *
678
+ */
679
+ P.toFixed = function (dp, rm) {
680
+ var str, y,
681
+ x = this,
682
+ Ctor = x.constructor;
683
+
684
+ if (dp === void 0) return toString(x);
685
+
686
+ checkInt32(dp, 0, MAX_DIGITS);
687
+
688
+ if (rm === void 0) rm = Ctor.rounding;
689
+ else checkInt32(rm, 0, 8);
690
+
691
+ y = round(new Ctor(x), dp + getBase10Exponent(x) + 1, rm);
692
+ str = toString(y.abs(), false, dp + getBase10Exponent(y) + 1);
693
+
694
+ // To determine whether to add the minus sign look at the value before it was rounded,
695
+ // i.e. look at `x` rather than `y`.
696
+ return x.isneg() && !x.isZero() ? '-' + str : str;
697
+ };
698
+
699
+
700
+ /*
701
+ * Return a new Decimal whose value is the value of this Decimal rounded to a whole number using
702
+ * rounding mode `rounding`.
703
+ *
704
+ */
705
+ P.toInteger = P.toint = function () {
706
+ var x = this,
707
+ Ctor = x.constructor;
708
+ return round(new Ctor(x), getBase10Exponent(x) + 1, Ctor.rounding);
709
+ };
710
+
711
+
712
+ /*
713
+ * Return the value of this Decimal converted to a number primitive.
714
+ *
715
+ */
716
+ P.toNumber = function () {
717
+ return +this;
718
+ };
719
+
720
+
721
+ /*
722
+ * Return a new Decimal whose value is the value of this Decimal raised to the power `y`,
723
+ * truncated to `precision` significant digits.
724
+ *
725
+ * For non-integer or very large exponents pow(x, y) is calculated using
726
+ *
727
+ * x^y = exp(y*ln(x))
728
+ *
729
+ * The maximum error is 1 ulp (unit in last place).
730
+ *
731
+ * y {number|string|Decimal} The power to which to raise this Decimal.
732
+ *
733
+ */
734
+ P.toPower = P.pow = function (y) {
735
+ var e, k, pr, r, sign, yIsInt,
736
+ x = this,
737
+ Ctor = x.constructor,
738
+ guard = 12,
739
+ yn = +(y = new Ctor(y));
740
+
741
+ // pow(x, 0) = 1
742
+ if (!y.s) return new Ctor(ONE);
743
+
744
+ x = new Ctor(x);
745
+
746
+ // pow(0, y > 0) = 0
747
+ // pow(0, y < 0) = Infinity
748
+ if (!x.s) {
749
+ if (y.s < 1) throw Error(decimalError + 'Infinity');
750
+ return x;
751
+ }
752
+
753
+ // pow(1, y) = 1
754
+ if (x.eq(ONE)) return x;
755
+
756
+ pr = Ctor.precision;
757
+
758
+ // pow(x, 1) = x
759
+ if (y.eq(ONE)) return round(x, pr);
760
+
761
+ e = y.e;
762
+ k = y.d.length - 1;
763
+ yIsInt = e >= k;
764
+ sign = x.s;
765
+
766
+ if (!yIsInt) {
767
+
768
+ // pow(x < 0, y non-integer) = NaN
769
+ if (sign < 0) throw Error(decimalError + 'NaN');
770
+
771
+ // If y is a small integer use the 'exponentiation by squaring' algorithm.
772
+ } else if ((k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
773
+ r = new Ctor(ONE);
774
+
775
+ // Max k of 9007199254740991 takes 53 loop iterations.
776
+ // Maximum digits array length; leaves [28, 34] guard digits.
777
+ e = Math.ceil(pr / LOG_BASE + 4);
778
+
779
+ external = false;
780
+
781
+ for (;;) {
782
+ if (k % 2) {
783
+ r = r.times(x);
784
+ truncate(r.d, e);
785
+ }
786
+
787
+ k = mathfloor(k / 2);
788
+ if (k === 0) break;
789
+
790
+ x = x.times(x);
791
+ truncate(x.d, e);
792
+ }
793
+
794
+ external = true;
795
+
796
+ return y.s < 0 ? new Ctor(ONE).div(r) : round(r, pr);
797
+ }
798
+
799
+ // Result is negative if x is negative and the last digit of integer y is odd.
800
+ sign = sign < 0 && y.d[Math.max(e, k)] & 1 ? -1 : 1;
801
+
802
+ x.s = 1;
803
+ external = false;
804
+ r = y.times(ln(x, pr + guard));
805
+ external = true;
806
+ r = exp(r);
807
+ r.s = sign;
808
+
809
+ return r;
810
+ };
811
+
812
+
813
+ /*
814
+ * Return a string representing the value of this Decimal rounded to `sd` significant digits
815
+ * using rounding mode `rounding`.
816
+ *
817
+ * Return exponential notation if `sd` is less than the number of digits necessary to represent
818
+ * the integer part of the value in normal notation.
819
+ *
820
+ * [sd] {number} Significant digits. Integer, 1 to MAX_DIGITS inclusive.
821
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
822
+ *
823
+ */
824
+ P.toPrecision = function (sd, rm) {
825
+ var e, str,
826
+ x = this,
827
+ Ctor = x.constructor;
828
+
829
+ if (sd === void 0) {
830
+ e = getBase10Exponent(x);
831
+ str = toString(x, e <= Ctor.toExpNeg || e >= Ctor.toExpPos);
832
+ } else {
833
+ checkInt32(sd, 1, MAX_DIGITS);
834
+
835
+ if (rm === void 0) rm = Ctor.rounding;
836
+ else checkInt32(rm, 0, 8);
837
+
838
+ x = round(new Ctor(x), sd, rm);
839
+ e = getBase10Exponent(x);
840
+ str = toString(x, sd <= e || e <= Ctor.toExpNeg, sd);
841
+ }
842
+
843
+ return str;
844
+ };
845
+
846
+
847
+ /*
848
+ * Return a new Decimal whose value is the value of this Decimal rounded to a maximum of `sd`
849
+ * significant digits using rounding mode `rm`, or to `precision` and `rounding` respectively if
850
+ * omitted.
851
+ *
852
+ * [sd] {number} Significant digits. Integer, 1 to MAX_DIGITS inclusive.
853
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
854
+ *
855
+ */
856
+ P.toSignificantDigits = P.tosd = function (sd, rm) {
857
+ var x = this,
858
+ Ctor = x.constructor;
859
+
860
+ if (sd === void 0) {
861
+ sd = Ctor.precision;
862
+ rm = Ctor.rounding;
863
+ } else {
864
+ checkInt32(sd, 1, MAX_DIGITS);
865
+
866
+ if (rm === void 0) rm = Ctor.rounding;
867
+ else checkInt32(rm, 0, 8);
868
+ }
869
+
870
+ return round(new Ctor(x), sd, rm);
871
+ };
872
+
873
+
874
+ /*
875
+ * Return a string representing the value of this Decimal.
876
+ *
877
+ * Return exponential notation if this Decimal has a positive exponent equal to or greater than
878
+ * `toExpPos`, or a negative exponent equal to or less than `toExpNeg`.
879
+ *
880
+ */
881
+ P.toString = P.valueOf = P.val = P.toJSON = P[Symbol.for('nodejs.util.inspect.custom')] = function () {
882
+ var x = this,
883
+ e = getBase10Exponent(x),
884
+ Ctor = x.constructor;
885
+
886
+ return toString(x, e <= Ctor.toExpNeg || e >= Ctor.toExpPos);
887
+ };
888
+
889
+
890
+ // Helper functions for Decimal.prototype (P) and/or Decimal methods, and their callers.
891
+
892
+
893
+ /*
894
+ * add P.minus, P.plus
895
+ * checkInt32 P.todp, P.toExponential, P.toFixed, P.toPrecision, P.tosd
896
+ * digitsToString P.log, P.sqrt, P.pow, toString, exp, ln
897
+ * divide P.div, P.idiv, P.log, P.mod, P.sqrt, exp, ln
898
+ * exp P.exp, P.pow
899
+ * getBase10Exponent P.exponent, P.sd, P.toint, P.sqrt, P.todp, P.toFixed, P.toPrecision,
900
+ * P.toString, divide, round, toString, exp, ln
901
+ * getLn10 P.log, ln
902
+ * getZeroString digitsToString, toString
903
+ * ln P.log, P.ln, P.pow, exp
904
+ * parseDecimal Decimal
905
+ * round P.abs, P.idiv, P.log, P.minus, P.mod, P.neg, P.plus, P.toint, P.sqrt,
906
+ * P.times, P.todp, P.toExponential, P.toFixed, P.pow, P.toPrecision, P.tosd,
907
+ * divide, getLn10, exp, ln
908
+ * subtract P.minus, P.plus
909
+ * toString P.toExponential, P.toFixed, P.toPrecision, P.toString, P.valueOf
910
+ * truncate P.pow
911
+ *
912
+ * Throws: P.log, P.mod, P.sd, P.sqrt, P.pow, checkInt32, divide, round,
913
+ * getLn10, exp, ln, parseDecimal, Decimal, config
914
+ */
915
+
916
+
917
+ function add(x, y) {
918
+ var carry, d, e, i, k, len, xd, yd,
919
+ Ctor = x.constructor,
920
+ pr = Ctor.precision;
921
+
922
+ // If either is zero...
923
+ if (!x.s || !y.s) {
924
+
925
+ // Return x if y is zero.
926
+ // Return y if y is non-zero.
927
+ if (!y.s) y = new Ctor(x);
928
+ return external ? round(y, pr) : y;
929
+ }
930
+
931
+ xd = x.d;
932
+ yd = y.d;
933
+
934
+ // x and y are finite, non-zero numbers with the same sign.
935
+
936
+ k = x.e;
937
+ e = y.e;
938
+ xd = xd.slice();
939
+ i = k - e;
940
+
941
+ // If base 1e7 exponents differ...
942
+ if (i) {
943
+ if (i < 0) {
944
+ d = xd;
945
+ i = -i;
946
+ len = yd.length;
947
+ } else {
948
+ d = yd;
949
+ e = k;
950
+ len = xd.length;
951
+ }
952
+
953
+ // Limit number of zeros prepended to max(ceil(pr / LOG_BASE), len) + 1.
954
+ k = Math.ceil(pr / LOG_BASE);
955
+ len = k > len ? k + 1 : len + 1;
956
+
957
+ if (i > len) {
958
+ i = len;
959
+ d.length = 1;
960
+ }
961
+
962
+ // Prepend zeros to equalise exponents. Note: Faster to use reverse then do unshifts.
963
+ d.reverse();
964
+ for (; i--;) d.push(0);
965
+ d.reverse();
966
+ }
967
+
968
+ len = xd.length;
969
+ i = yd.length;
970
+
971
+ // If yd is longer than xd, swap xd and yd so xd points to the longer array.
972
+ if (len - i < 0) {
973
+ i = len;
974
+ d = yd;
975
+ yd = xd;
976
+ xd = d;
977
+ }
978
+
979
+ // Only start adding at yd.length - 1 as the further digits of xd can be left as they are.
980
+ for (carry = 0; i;) {
981
+ carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
982
+ xd[i] %= BASE;
983
+ }
984
+
985
+ if (carry) {
986
+ xd.unshift(carry);
987
+ ++e;
988
+ }
989
+
990
+ // Remove trailing zeros.
991
+ // No need to check for zero, as +x + +y != 0 && -x + -y != 0
992
+ for (len = xd.length; xd[--len] == 0;) xd.pop();
993
+
994
+ y.d = xd;
995
+ y.e = e;
996
+
997
+ return external ? round(y, pr) : y;
998
+ }
999
+
1000
+
1001
+ function checkInt32(i, min, max) {
1002
+ if (i !== ~~i || i < min || i > max) {
1003
+ throw Error(invalidArgument + i);
1004
+ }
1005
+ }
1006
+
1007
+
1008
+ function digitsToString(d) {
1009
+ var i, k, ws,
1010
+ indexOfLastWord = d.length - 1,
1011
+ str = '',
1012
+ w = d[0];
1013
+
1014
+ if (indexOfLastWord > 0) {
1015
+ str += w;
1016
+ for (i = 1; i < indexOfLastWord; i++) {
1017
+ ws = d[i] + '';
1018
+ k = LOG_BASE - ws.length;
1019
+ if (k) str += getZeroString(k);
1020
+ str += ws;
1021
+ }
1022
+
1023
+ w = d[i];
1024
+ ws = w + '';
1025
+ k = LOG_BASE - ws.length;
1026
+ if (k) str += getZeroString(k);
1027
+ } else if (w === 0) {
1028
+ return '0';
1029
+ }
1030
+
1031
+ // Remove trailing zeros of last w.
1032
+ for (; w % 10 === 0;) w /= 10;
1033
+
1034
+ return str + w;
1035
+ }
1036
+
1037
+
1038
+ var divide$1 = (function () {
1039
+
1040
+ // Assumes non-zero x and k, and hence non-zero result.
1041
+ function multiplyInteger(x, k) {
1042
+ var temp,
1043
+ carry = 0,
1044
+ i = x.length;
1045
+
1046
+ for (x = x.slice(); i--;) {
1047
+ temp = x[i] * k + carry;
1048
+ x[i] = temp % BASE | 0;
1049
+ carry = temp / BASE | 0;
1050
+ }
1051
+
1052
+ if (carry) x.unshift(carry);
1053
+
1054
+ return x;
1055
+ }
1056
+
1057
+ function compare(a, b, aL, bL) {
1058
+ var i, r;
1059
+
1060
+ if (aL != bL) {
1061
+ r = aL > bL ? 1 : -1;
1062
+ } else {
1063
+ for (i = r = 0; i < aL; i++) {
1064
+ if (a[i] != b[i]) {
1065
+ r = a[i] > b[i] ? 1 : -1;
1066
+ break;
1067
+ }
1068
+ }
1069
+ }
1070
+
1071
+ return r;
1072
+ }
1073
+
1074
+ function subtract(a, b, aL) {
1075
+ var i = 0;
1076
+
1077
+ // Subtract b from a.
1078
+ for (; aL--;) {
1079
+ a[aL] -= i;
1080
+ i = a[aL] < b[aL] ? 1 : 0;
1081
+ a[aL] = i * BASE + a[aL] - b[aL];
1082
+ }
1083
+
1084
+ // Remove leading zeros.
1085
+ for (; !a[0] && a.length > 1;) a.shift();
1086
+ }
1087
+
1088
+ return function (x, y, pr, dp) {
1089
+ var cmp, e, i, k, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz,
1090
+ Ctor = x.constructor,
1091
+ sign = x.s == y.s ? 1 : -1,
1092
+ xd = x.d,
1093
+ yd = y.d;
1094
+
1095
+ // Either 0?
1096
+ if (!x.s) return new Ctor(x);
1097
+ if (!y.s) throw Error(decimalError + 'Division by zero');
1098
+
1099
+ e = x.e - y.e;
1100
+ yL = yd.length;
1101
+ xL = xd.length;
1102
+ q = new Ctor(sign);
1103
+ qd = q.d = [];
1104
+
1105
+ // Result exponent may be one less than e.
1106
+ for (i = 0; yd[i] == (xd[i] || 0); ) ++i;
1107
+ if (yd[i] > (xd[i] || 0)) --e;
1108
+
1109
+ if (pr == null) {
1110
+ sd = pr = Ctor.precision;
1111
+ } else if (dp) {
1112
+ sd = pr + (getBase10Exponent(x) - getBase10Exponent(y)) + 1;
1113
+ } else {
1114
+ sd = pr;
1115
+ }
1116
+
1117
+ if (sd < 0) return new Ctor(0);
1118
+
1119
+ // Convert precision in number of base 10 digits to base 1e7 digits.
1120
+ sd = sd / LOG_BASE + 2 | 0;
1121
+ i = 0;
1122
+
1123
+ // divisor < 1e7
1124
+ if (yL == 1) {
1125
+ k = 0;
1126
+ yd = yd[0];
1127
+ sd++;
1128
+
1129
+ // k is the carry.
1130
+ for (; (i < xL || k) && sd--; i++) {
1131
+ t = k * BASE + (xd[i] || 0);
1132
+ qd[i] = t / yd | 0;
1133
+ k = t % yd | 0;
1134
+ }
1135
+
1136
+ // divisor >= 1e7
1137
+ } else {
1138
+
1139
+ // Normalise xd and yd so highest order digit of yd is >= BASE/2
1140
+ k = BASE / (yd[0] + 1) | 0;
1141
+
1142
+ if (k > 1) {
1143
+ yd = multiplyInteger(yd, k);
1144
+ xd = multiplyInteger(xd, k);
1145
+ yL = yd.length;
1146
+ xL = xd.length;
1147
+ }
1148
+
1149
+ xi = yL;
1150
+ rem = xd.slice(0, yL);
1151
+ remL = rem.length;
1152
+
1153
+ // Add zeros to make remainder as long as divisor.
1154
+ for (; remL < yL;) rem[remL++] = 0;
1155
+
1156
+ yz = yd.slice();
1157
+ yz.unshift(0);
1158
+ yd0 = yd[0];
1159
+
1160
+ if (yd[1] >= BASE / 2) ++yd0;
1161
+
1162
+ do {
1163
+ k = 0;
1164
+
1165
+ // Compare divisor and remainder.
1166
+ cmp = compare(yd, rem, yL, remL);
1167
+
1168
+ // If divisor < remainder.
1169
+ if (cmp < 0) {
1170
+
1171
+ // Calculate trial digit, k.
1172
+ rem0 = rem[0];
1173
+ if (yL != remL) rem0 = rem0 * BASE + (rem[1] || 0);
1174
+
1175
+ // k will be how many times the divisor goes into the current remainder.
1176
+ k = rem0 / yd0 | 0;
1177
+
1178
+ // Algorithm:
1179
+ // 1. product = divisor * trial digit (k)
1180
+ // 2. if product > remainder: product -= divisor, k--
1181
+ // 3. remainder -= product
1182
+ // 4. if product was < remainder at 2:
1183
+ // 5. compare new remainder and divisor
1184
+ // 6. If remainder > divisor: remainder -= divisor, k++
1185
+
1186
+ if (k > 1) {
1187
+ if (k >= BASE) k = BASE - 1;
1188
+
1189
+ // product = divisor * trial digit.
1190
+ prod = multiplyInteger(yd, k);
1191
+ prodL = prod.length;
1192
+ remL = rem.length;
1193
+
1194
+ // Compare product and remainder.
1195
+ cmp = compare(prod, rem, prodL, remL);
1196
+
1197
+ // product > remainder.
1198
+ if (cmp == 1) {
1199
+ k--;
1200
+
1201
+ // Subtract divisor from product.
1202
+ subtract(prod, yL < prodL ? yz : yd, prodL);
1203
+ }
1204
+ } else {
1205
+
1206
+ // cmp is -1.
1207
+ // If k is 0, there is no need to compare yd and rem again below, so change cmp to 1
1208
+ // to avoid it. If k is 1 there is a need to compare yd and rem again below.
1209
+ if (k == 0) cmp = k = 1;
1210
+ prod = yd.slice();
1211
+ }
1212
+
1213
+ prodL = prod.length;
1214
+ if (prodL < remL) prod.unshift(0);
1215
+
1216
+ // Subtract product from remainder.
1217
+ subtract(rem, prod, remL);
1218
+
1219
+ // If product was < previous remainder.
1220
+ if (cmp == -1) {
1221
+ remL = rem.length;
1222
+
1223
+ // Compare divisor and new remainder.
1224
+ cmp = compare(yd, rem, yL, remL);
1225
+
1226
+ // If divisor < new remainder, subtract divisor from remainder.
1227
+ if (cmp < 1) {
1228
+ k++;
1229
+
1230
+ // Subtract divisor from remainder.
1231
+ subtract(rem, yL < remL ? yz : yd, remL);
1232
+ }
1233
+ }
1234
+
1235
+ remL = rem.length;
1236
+ } else if (cmp === 0) {
1237
+ k++;
1238
+ rem = [0];
1239
+ } // if cmp === 1, k will be 0
1240
+
1241
+ // Add the next digit, k, to the result array.
1242
+ qd[i++] = k;
1243
+
1244
+ // Update the remainder.
1245
+ if (cmp && rem[0]) {
1246
+ rem[remL++] = xd[xi] || 0;
1247
+ } else {
1248
+ rem = [xd[xi]];
1249
+ remL = 1;
1250
+ }
1251
+
1252
+ } while ((xi++ < xL || rem[0] !== void 0) && sd--);
1253
+ }
1254
+
1255
+ // Leading zero?
1256
+ if (!qd[0]) qd.shift();
1257
+
1258
+ q.e = e;
1259
+
1260
+ return round(q, dp ? pr + getBase10Exponent(q) + 1 : pr);
1261
+ };
1262
+ })();
1263
+
1264
+
1265
+ /*
1266
+ * Return a new Decimal whose value is the natural exponential of `x` truncated to `sd`
1267
+ * significant digits.
1268
+ *
1269
+ * Taylor/Maclaurin series.
1270
+ *
1271
+ * exp(x) = x^0/0! + x^1/1! + x^2/2! + x^3/3! + ...
1272
+ *
1273
+ * Argument reduction:
1274
+ * Repeat x = x / 32, k += 5, until |x| < 0.1
1275
+ * exp(x) = exp(x / 2^k)^(2^k)
1276
+ *
1277
+ * Previously, the argument was initially reduced by
1278
+ * exp(x) = exp(r) * 10^k where r = x - k * ln10, k = floor(x / ln10)
1279
+ * to first put r in the range [0, ln10], before dividing by 32 until |x| < 0.1, but this was
1280
+ * found to be slower than just dividing repeatedly by 32 as above.
1281
+ *
1282
+ * (Math object integer min/max: Math.exp(709) = 8.2e+307, Math.exp(-745) = 5e-324)
1283
+ *
1284
+ * exp(x) is non-terminating for any finite, non-zero x.
1285
+ *
1286
+ */
1287
+ function exp(x, sd) {
1288
+ var denominator, guard, pow, sum, t, wpr,
1289
+ i = 0,
1290
+ k = 0,
1291
+ Ctor = x.constructor,
1292
+ pr = Ctor.precision;
1293
+
1294
+ if (getBase10Exponent(x) > 16) throw Error(exponentOutOfRange + getBase10Exponent(x));
1295
+
1296
+ // exp(0) = 1
1297
+ if (!x.s) return new Ctor(ONE);
1298
+
1299
+ if (sd == null) {
1300
+ external = false;
1301
+ wpr = pr;
1302
+ } else {
1303
+ wpr = sd;
1304
+ }
1305
+
1306
+ t = new Ctor(0.03125);
1307
+
1308
+ while (x.abs().gte(0.1)) {
1309
+ x = x.times(t); // x = x / 2^5
1310
+ k += 5;
1311
+ }
1312
+
1313
+ // Estimate the precision increase necessary to ensure the first 4 rounding digits are correct.
1314
+ guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1315
+ wpr += guard;
1316
+ denominator = pow = sum = new Ctor(ONE);
1317
+ Ctor.precision = wpr;
1318
+
1319
+ for (;;) {
1320
+ pow = round(pow.times(x), wpr);
1321
+ denominator = denominator.times(++i);
1322
+ t = sum.plus(divide$1(pow, denominator, wpr));
1323
+
1324
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
1325
+ while (k--) sum = round(sum.times(sum), wpr);
1326
+ Ctor.precision = pr;
1327
+ return sd == null ? (external = true, round(sum, pr)) : sum;
1328
+ }
1329
+
1330
+ sum = t;
1331
+ }
1332
+ }
1333
+
1334
+
1335
+ // Calculate the base 10 exponent from the base 1e7 exponent.
1336
+ function getBase10Exponent(x) {
1337
+ var e = x.e * LOG_BASE,
1338
+ w = x.d[0];
1339
+
1340
+ // Add the number of digits of the first word of the digits array.
1341
+ for (; w >= 10; w /= 10) e++;
1342
+ return e;
1343
+ }
1344
+
1345
+
1346
+ function getLn10(Ctor, sd, pr) {
1347
+
1348
+ if (sd > Ctor.LN10.sd()) {
1349
+
1350
+
1351
+ // Reset global state in case the exception is caught.
1352
+ external = true;
1353
+ if (pr) Ctor.precision = pr;
1354
+ throw Error(decimalError + 'LN10 precision limit exceeded');
1355
+ }
1356
+
1357
+ return round(new Ctor(Ctor.LN10), sd);
1358
+ }
1359
+
1360
+
1361
+ function getZeroString(k) {
1362
+ var zs = '';
1363
+ for (; k--;) zs += '0';
1364
+ return zs;
1365
+ }
1366
+
1367
+
1368
+ /*
1369
+ * Return a new Decimal whose value is the natural logarithm of `x` truncated to `sd` significant
1370
+ * digits.
1371
+ *
1372
+ * ln(n) is non-terminating (n != 1)
1373
+ *
1374
+ */
1375
+ function ln(y, sd) {
1376
+ var c, c0, denominator, e, numerator, sum, t, wpr, x2,
1377
+ n = 1,
1378
+ guard = 10,
1379
+ x = y,
1380
+ xd = x.d,
1381
+ Ctor = x.constructor,
1382
+ pr = Ctor.precision;
1383
+
1384
+ // ln(-x) = NaN
1385
+ // ln(0) = -Infinity
1386
+ if (x.s < 1) throw Error(decimalError + (x.s ? 'NaN' : '-Infinity'));
1387
+
1388
+ // ln(1) = 0
1389
+ if (x.eq(ONE)) return new Ctor(0);
1390
+
1391
+ if (sd == null) {
1392
+ external = false;
1393
+ wpr = pr;
1394
+ } else {
1395
+ wpr = sd;
1396
+ }
1397
+
1398
+ if (x.eq(10)) {
1399
+ if (sd == null) external = true;
1400
+ return getLn10(Ctor, wpr);
1401
+ }
1402
+
1403
+ wpr += guard;
1404
+ Ctor.precision = wpr;
1405
+ c = digitsToString(xd);
1406
+ c0 = c.charAt(0);
1407
+ e = getBase10Exponent(x);
1408
+
1409
+ if (Math.abs(e) < 1.5e15) {
1410
+
1411
+ // Argument reduction.
1412
+ // The series converges faster the closer the argument is to 1, so using
1413
+ // ln(a^b) = b * ln(a), ln(a) = ln(a^b) / b
1414
+ // multiply the argument by itself until the leading digits of the significand are 7, 8, 9,
1415
+ // 10, 11, 12 or 13, recording the number of multiplications so the sum of the series can
1416
+ // later be divided by this number, then separate out the power of 10 using
1417
+ // ln(a*10^b) = ln(a) + b*ln(10).
1418
+
1419
+ // max n is 21 (gives 0.9, 1.0 or 1.1) (9e15 / 21 = 4.2e14).
1420
+ //while (c0 < 9 && c0 != 1 || c0 == 1 && c.charAt(1) > 1) {
1421
+ // max n is 6 (gives 0.7 - 1.3)
1422
+ while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
1423
+ x = x.times(y);
1424
+ c = digitsToString(x.d);
1425
+ c0 = c.charAt(0);
1426
+ n++;
1427
+ }
1428
+
1429
+ e = getBase10Exponent(x);
1430
+
1431
+ if (c0 > 1) {
1432
+ x = new Ctor('0.' + c);
1433
+ e++;
1434
+ } else {
1435
+ x = new Ctor(c0 + '.' + c.slice(1));
1436
+ }
1437
+ } else {
1438
+
1439
+ // The argument reduction method above may result in overflow if the argument y is a massive
1440
+ // number with exponent >= 1500000000000000 (9e15 / 6 = 1.5e15), so instead recall this
1441
+ // function using ln(x*10^e) = ln(x) + e*ln(10).
1442
+ t = getLn10(Ctor, wpr + 2, pr).times(e + '');
1443
+ x = ln(new Ctor(c0 + '.' + c.slice(1)), wpr - guard).plus(t);
1444
+
1445
+ Ctor.precision = pr;
1446
+ return sd == null ? (external = true, round(x, pr)) : x;
1447
+ }
1448
+
1449
+ // x is reduced to a value near 1.
1450
+
1451
+ // Taylor series.
1452
+ // ln(y) = ln((1 + x)/(1 - x)) = 2(x + x^3/3 + x^5/5 + x^7/7 + ...)
1453
+ // where x = (y - 1)/(y + 1) (|x| < 1)
1454
+ sum = numerator = x = divide$1(x.minus(ONE), x.plus(ONE), wpr);
1455
+ x2 = round(x.times(x), wpr);
1456
+ denominator = 3;
1457
+
1458
+ for (;;) {
1459
+ numerator = round(numerator.times(x2), wpr);
1460
+ t = sum.plus(divide$1(numerator, new Ctor(denominator), wpr));
1461
+
1462
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
1463
+ sum = sum.times(2);
1464
+
1465
+ // Reverse the argument reduction.
1466
+ if (e !== 0) sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ''));
1467
+ sum = divide$1(sum, new Ctor(n), wpr);
1468
+
1469
+ Ctor.precision = pr;
1470
+ return sd == null ? (external = true, round(sum, pr)) : sum;
1471
+ }
1472
+
1473
+ sum = t;
1474
+ denominator += 2;
1475
+ }
1476
+ }
1477
+
1478
+
1479
+ /*
1480
+ * Parse the value of a new Decimal `x` from string `str`.
1481
+ */
1482
+ function parseDecimal(x, str) {
1483
+ var e, i, len;
1484
+
1485
+ // Decimal point?
1486
+ if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
1487
+
1488
+ // Exponential form?
1489
+ if ((i = str.search(/e/i)) > 0) {
1490
+
1491
+ // Determine exponent.
1492
+ if (e < 0) e = i;
1493
+ e += +str.slice(i + 1);
1494
+ str = str.substring(0, i);
1495
+ } else if (e < 0) {
1496
+
1497
+ // Integer.
1498
+ e = str.length;
1499
+ }
1500
+
1501
+ // Determine leading zeros.
1502
+ for (i = 0; str.charCodeAt(i) === 48;) ++i;
1503
+
1504
+ // Determine trailing zeros.
1505
+ for (len = str.length; str.charCodeAt(len - 1) === 48;) --len;
1506
+ str = str.slice(i, len);
1507
+
1508
+ if (str) {
1509
+ len -= i;
1510
+ e = e - i - 1;
1511
+ x.e = mathfloor(e / LOG_BASE);
1512
+ x.d = [];
1513
+
1514
+ // Transform base
1515
+
1516
+ // e is the base 10 exponent.
1517
+ // i is where to slice str to get the first word of the digits array.
1518
+ i = (e + 1) % LOG_BASE;
1519
+ if (e < 0) i += LOG_BASE;
1520
+
1521
+ if (i < len) {
1522
+ if (i) x.d.push(+str.slice(0, i));
1523
+ for (len -= LOG_BASE; i < len;) x.d.push(+str.slice(i, i += LOG_BASE));
1524
+ str = str.slice(i);
1525
+ i = LOG_BASE - str.length;
1526
+ } else {
1527
+ i -= len;
1528
+ }
1529
+
1530
+ for (; i--;) str += '0';
1531
+ x.d.push(+str);
1532
+
1533
+ if (external && (x.e > MAX_E || x.e < -MAX_E)) throw Error(exponentOutOfRange + e);
1534
+ } else {
1535
+
1536
+ // Zero.
1537
+ x.s = 0;
1538
+ x.e = 0;
1539
+ x.d = [0];
1540
+ }
1541
+
1542
+ return x;
1543
+ }
1544
+
1545
+
1546
+ /*
1547
+ * Round `x` to `sd` significant digits, using rounding mode `rm` if present (truncate otherwise).
1548
+ */
1549
+ function round(x, sd, rm) {
1550
+ var i, j, k, n, rd, doRound, w, xdi,
1551
+ xd = x.d;
1552
+
1553
+ // rd: the rounding digit, i.e. the digit after the digit that may be rounded up.
1554
+ // w: the word of xd which contains the rounding digit, a base 1e7 number.
1555
+ // xdi: the index of w within xd.
1556
+ // n: the number of digits of w.
1557
+ // i: what would be the index of rd within w if all the numbers were 7 digits long (i.e. if
1558
+ // they had leading zeros)
1559
+ // j: if > 0, the actual index of rd within w (if < 0, rd is a leading zero).
1560
+
1561
+ // Get the length of the first word of the digits array xd.
1562
+ for (n = 1, k = xd[0]; k >= 10; k /= 10) n++;
1563
+ i = sd - n;
1564
+
1565
+ // Is the rounding digit in the first word of xd?
1566
+ if (i < 0) {
1567
+ i += LOG_BASE;
1568
+ j = sd;
1569
+ w = xd[xdi = 0];
1570
+ } else {
1571
+ xdi = Math.ceil((i + 1) / LOG_BASE);
1572
+ k = xd.length;
1573
+ if (xdi >= k) return x;
1574
+ w = k = xd[xdi];
1575
+
1576
+ // Get the number of digits of w.
1577
+ for (n = 1; k >= 10; k /= 10) n++;
1578
+
1579
+ // Get the index of rd within w.
1580
+ i %= LOG_BASE;
1581
+
1582
+ // Get the index of rd within w, adjusted for leading zeros.
1583
+ // The number of leading zeros of w is given by LOG_BASE - n.
1584
+ j = i - LOG_BASE + n;
1585
+ }
1586
+
1587
+ if (rm !== void 0) {
1588
+ k = mathpow(10, n - j - 1);
1589
+
1590
+ // Get the rounding digit at index j of w.
1591
+ rd = w / k % 10 | 0;
1592
+
1593
+ // Are there any non-zero digits after the rounding digit?
1594
+ doRound = sd < 0 || xd[xdi + 1] !== void 0 || w % k;
1595
+
1596
+ // The expression `w % mathpow(10, n - j - 1)` returns all the digits of w to the right of the
1597
+ // digit at (left-to-right) index j, e.g. if w is 908714 and j is 2, the expression will give
1598
+ // 714.
1599
+
1600
+ doRound = rm < 4
1601
+ ? (rd || doRound) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
1602
+ : rd > 5 || rd == 5 && (rm == 4 || doRound || rm == 6 &&
1603
+
1604
+ // Check whether the digit to the left of the rounding digit is odd.
1605
+ ((i > 0 ? j > 0 ? w / mathpow(10, n - j) : 0 : xd[xdi - 1]) % 10) & 1 ||
1606
+ rm == (x.s < 0 ? 8 : 7));
1607
+ }
1608
+
1609
+ if (sd < 1 || !xd[0]) {
1610
+ if (doRound) {
1611
+ k = getBase10Exponent(x);
1612
+ xd.length = 1;
1613
+
1614
+ // Convert sd to decimal places.
1615
+ sd = sd - k - 1;
1616
+
1617
+ // 1, 0.1, 0.01, 0.001, 0.0001 etc.
1618
+ xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
1619
+ x.e = mathfloor(-sd / LOG_BASE) || 0;
1620
+ } else {
1621
+ xd.length = 1;
1622
+
1623
+ // Zero.
1624
+ xd[0] = x.e = x.s = 0;
1625
+ }
1626
+
1627
+ return x;
1628
+ }
1629
+
1630
+ // Remove excess digits.
1631
+ if (i == 0) {
1632
+ xd.length = xdi;
1633
+ k = 1;
1634
+ xdi--;
1635
+ } else {
1636
+ xd.length = xdi + 1;
1637
+ k = mathpow(10, LOG_BASE - i);
1638
+
1639
+ // E.g. 56700 becomes 56000 if 7 is the rounding digit.
1640
+ // j > 0 means i > number of leading zeros of w.
1641
+ xd[xdi] = j > 0 ? (w / mathpow(10, n - j) % mathpow(10, j) | 0) * k : 0;
1642
+ }
1643
+
1644
+ if (doRound) {
1645
+ for (;;) {
1646
+
1647
+ // Is the digit to be rounded up in the first word of xd?
1648
+ if (xdi == 0) {
1649
+ if ((xd[0] += k) == BASE) {
1650
+ xd[0] = 1;
1651
+ ++x.e;
1652
+ }
1653
+
1654
+ break;
1655
+ } else {
1656
+ xd[xdi] += k;
1657
+ if (xd[xdi] != BASE) break;
1658
+ xd[xdi--] = 0;
1659
+ k = 1;
1660
+ }
1661
+ }
1662
+ }
1663
+
1664
+ // Remove trailing zeros.
1665
+ for (i = xd.length; xd[--i] === 0;) xd.pop();
1666
+
1667
+ if (external && (x.e > MAX_E || x.e < -MAX_E)) {
1668
+ throw Error(exponentOutOfRange + getBase10Exponent(x));
1669
+ }
1670
+
1671
+ return x;
1672
+ }
1673
+
1674
+
1675
+ function subtract(x, y) {
1676
+ var d, e, i, j, k, len, xd, xe, xLTy, yd,
1677
+ Ctor = x.constructor,
1678
+ pr = Ctor.precision;
1679
+
1680
+ // Return y negated if x is zero.
1681
+ // Return x if y is zero and x is non-zero.
1682
+ if (!x.s || !y.s) {
1683
+ if (y.s) y.s = -y.s;
1684
+ else y = new Ctor(x);
1685
+ return external ? round(y, pr) : y;
1686
+ }
1687
+
1688
+ xd = x.d;
1689
+ yd = y.d;
1690
+
1691
+ // x and y are non-zero numbers with the same sign.
1692
+
1693
+ e = y.e;
1694
+ xe = x.e;
1695
+ xd = xd.slice();
1696
+ k = xe - e;
1697
+
1698
+ // If exponents differ...
1699
+ if (k) {
1700
+ xLTy = k < 0;
1701
+
1702
+ if (xLTy) {
1703
+ d = xd;
1704
+ k = -k;
1705
+ len = yd.length;
1706
+ } else {
1707
+ d = yd;
1708
+ e = xe;
1709
+ len = xd.length;
1710
+ }
1711
+
1712
+ // Numbers with massively different exponents would result in a very high number of zeros
1713
+ // needing to be prepended, but this can be avoided while still ensuring correct rounding by
1714
+ // limiting the number of zeros to `Math.ceil(pr / LOG_BASE) + 2`.
1715
+ i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
1716
+
1717
+ if (k > i) {
1718
+ k = i;
1719
+ d.length = 1;
1720
+ }
1721
+
1722
+ // Prepend zeros to equalise exponents.
1723
+ d.reverse();
1724
+ for (i = k; i--;) d.push(0);
1725
+ d.reverse();
1726
+
1727
+ // Base 1e7 exponents equal.
1728
+ } else {
1729
+
1730
+ // Check digits to determine which is the bigger number.
1731
+
1732
+ i = xd.length;
1733
+ len = yd.length;
1734
+ xLTy = i < len;
1735
+ if (xLTy) len = i;
1736
+
1737
+ for (i = 0; i < len; i++) {
1738
+ if (xd[i] != yd[i]) {
1739
+ xLTy = xd[i] < yd[i];
1740
+ break;
1741
+ }
1742
+ }
1743
+
1744
+ k = 0;
1745
+ }
1746
+
1747
+ if (xLTy) {
1748
+ d = xd;
1749
+ xd = yd;
1750
+ yd = d;
1751
+ y.s = -y.s;
1752
+ }
1753
+
1754
+ len = xd.length;
1755
+
1756
+ // Append zeros to xd if shorter.
1757
+ // Don't add zeros to yd if shorter as subtraction only needs to start at yd length.
1758
+ for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
1759
+
1760
+ // Subtract yd from xd.
1761
+ for (i = yd.length; i > k;) {
1762
+ if (xd[--i] < yd[i]) {
1763
+ for (j = i; j && xd[--j] === 0;) xd[j] = BASE - 1;
1764
+ --xd[j];
1765
+ xd[i] += BASE;
1766
+ }
1767
+
1768
+ xd[i] -= yd[i];
1769
+ }
1770
+
1771
+ // Remove trailing zeros.
1772
+ for (; xd[--len] === 0;) xd.pop();
1773
+
1774
+ // Remove leading zeros and adjust exponent accordingly.
1775
+ for (; xd[0] === 0; xd.shift()) --e;
1776
+
1777
+ // Zero?
1778
+ if (!xd[0]) return new Ctor(0);
1779
+
1780
+ y.d = xd;
1781
+ y.e = e;
1782
+
1783
+ //return external && xd.length >= pr / LOG_BASE ? round(y, pr) : y;
1784
+ return external ? round(y, pr) : y;
1785
+ }
1786
+
1787
+
1788
+ function toString(x, isExp, sd) {
1789
+ var k,
1790
+ e = getBase10Exponent(x),
1791
+ str = digitsToString(x.d),
1792
+ len = str.length;
1793
+
1794
+ if (isExp) {
1795
+ if (sd && (k = sd - len) > 0) {
1796
+ str = str.charAt(0) + '.' + str.slice(1) + getZeroString(k);
1797
+ } else if (len > 1) {
1798
+ str = str.charAt(0) + '.' + str.slice(1);
1799
+ }
1800
+
1801
+ str = str + (e < 0 ? 'e' : 'e+') + e;
1802
+ } else if (e < 0) {
1803
+ str = '0.' + getZeroString(-e - 1) + str;
1804
+ if (sd && (k = sd - len) > 0) str += getZeroString(k);
1805
+ } else if (e >= len) {
1806
+ str += getZeroString(e + 1 - len);
1807
+ if (sd && (k = sd - e - 1) > 0) str = str + '.' + getZeroString(k);
1808
+ } else {
1809
+ if ((k = e + 1) < len) str = str.slice(0, k) + '.' + str.slice(k);
1810
+ if (sd && (k = sd - len) > 0) {
1811
+ if (e + 1 === len) str += '.';
1812
+ str += getZeroString(k);
1813
+ }
1814
+ }
1815
+
1816
+ return x.s < 0 ? '-' + str : str;
1817
+ }
1818
+
1819
+
1820
+ // Does not strip trailing zeros.
1821
+ function truncate(arr, len) {
1822
+ if (arr.length > len) {
1823
+ arr.length = len;
1824
+ return true;
1825
+ }
1826
+ }
1827
+
1828
+
1829
+ // Decimal methods
1830
+
1831
+
1832
+ /*
1833
+ * clone
1834
+ * config/set
1835
+ */
1836
+
1837
+
1838
+ /*
1839
+ * Create and return a Decimal constructor with the same configuration properties as this Decimal
1840
+ * constructor.
1841
+ *
1842
+ */
1843
+ function clone(obj) {
1844
+ var i, p, ps;
1845
+
1846
+ /*
1847
+ * The Decimal constructor and exported function.
1848
+ * Return a new Decimal instance.
1849
+ *
1850
+ * value {number|string|Decimal} A numeric value.
1851
+ *
1852
+ */
1853
+ function Decimal(value) {
1854
+ var x = this;
1855
+
1856
+ // Decimal called without new.
1857
+ if (!(x instanceof Decimal)) return new Decimal(value);
1858
+
1859
+ // Retain a reference to this Decimal constructor, and shadow Decimal.prototype.constructor
1860
+ // which points to Object.
1861
+ x.constructor = Decimal;
1862
+
1863
+ // Duplicate.
1864
+ if (value instanceof Decimal) {
1865
+ x.s = value.s;
1866
+ x.e = value.e;
1867
+ x.d = (value = value.d) ? value.slice() : value;
1868
+ return;
1869
+ }
1870
+
1871
+ if (typeof value === 'number') {
1872
+
1873
+ // Reject Infinity/NaN.
1874
+ if (value * 0 !== 0) {
1875
+ throw Error(invalidArgument + value);
1876
+ }
1877
+
1878
+ if (value > 0) {
1879
+ x.s = 1;
1880
+ } else if (value < 0) {
1881
+ value = -value;
1882
+ x.s = -1;
1883
+ } else {
1884
+ x.s = 0;
1885
+ x.e = 0;
1886
+ x.d = [0];
1887
+ return;
1888
+ }
1889
+
1890
+ // Fast path for small integers.
1891
+ if (value === ~~value && value < 1e7) {
1892
+ x.e = 0;
1893
+ x.d = [value];
1894
+ return;
1895
+ }
1896
+
1897
+ return parseDecimal(x, value.toString());
1898
+ } else if (typeof value !== 'string') {
1899
+ throw Error(invalidArgument + value);
1900
+ }
1901
+
1902
+ // Minus sign?
1903
+ if (value.charCodeAt(0) === 45) {
1904
+ value = value.slice(1);
1905
+ x.s = -1;
1906
+ } else {
1907
+ x.s = 1;
1908
+ }
1909
+
1910
+ if (isDecimal.test(value)) parseDecimal(x, value);
1911
+ else throw Error(invalidArgument + value);
1912
+ }
1913
+
1914
+ Decimal.prototype = P;
1915
+
1916
+ Decimal.ROUND_UP = 0;
1917
+ Decimal.ROUND_DOWN = 1;
1918
+ Decimal.ROUND_CEIL = 2;
1919
+ Decimal.ROUND_FLOOR = 3;
1920
+ Decimal.ROUND_HALF_UP = 4;
1921
+ Decimal.ROUND_HALF_DOWN = 5;
1922
+ Decimal.ROUND_HALF_EVEN = 6;
1923
+ Decimal.ROUND_HALF_CEIL = 7;
1924
+ Decimal.ROUND_HALF_FLOOR = 8;
1925
+
1926
+ Decimal.clone = clone;
1927
+ Decimal.config = Decimal.set = config;
1928
+
1929
+ if (obj === void 0) obj = {};
1930
+ if (obj) {
1931
+ ps = ['precision', 'rounding', 'toExpNeg', 'toExpPos', 'LN10'];
1932
+ for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
1933
+ }
1934
+
1935
+ Decimal.config(obj);
1936
+
1937
+ return Decimal;
1938
+ }
1939
+
1940
+
1941
+ /*
1942
+ * Configure global settings for a Decimal constructor.
1943
+ *
1944
+ * `obj` is an object with one or more of the following properties,
1945
+ *
1946
+ * precision {number}
1947
+ * rounding {number}
1948
+ * toExpNeg {number}
1949
+ * toExpPos {number}
1950
+ *
1951
+ * E.g. Decimal.config({ precision: 20, rounding: 4 })
1952
+ *
1953
+ */
1954
+ function config(obj) {
1955
+ if (!obj || typeof obj !== 'object') {
1956
+ throw Error(decimalError + 'Object expected');
1957
+ }
1958
+ var i, p, v,
1959
+ ps = [
1960
+ 'precision', 1, MAX_DIGITS,
1961
+ 'rounding', 0, 8,
1962
+ 'toExpNeg', -1 / 0, 0,
1963
+ 'toExpPos', 0, 1 / 0
1964
+ ];
1965
+
1966
+ for (i = 0; i < ps.length; i += 3) {
1967
+ if ((v = obj[p = ps[i]]) !== void 0) {
1968
+ if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
1969
+ else throw Error(invalidArgument + p + ': ' + v);
1970
+ }
1971
+ }
1972
+
1973
+ if ((v = obj[p = 'LN10']) !== void 0) {
1974
+ if (v == Math.LN10) this[p] = new this(v);
1975
+ else throw Error(invalidArgument + p + ': ' + v);
1976
+ }
1977
+
1978
+ return this;
1979
+ }
1980
+
1981
+
1982
+ // Create and configure initial Decimal constructor.
1983
+ var Decimal = clone(defaults);
1984
+
1985
+ // Internal constant.
1986
+ ONE = new Decimal(1);
1987
+
1988
+ var Decimal$1 = Decimal;
1989
+
1990
+ /**
1991
+ * @description 时间格式转换
1992
+ */
1993
+ function timeTransfrom(timeParams) {
1994
+ var _a, _b, _c, _d, _e;
1995
+ var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f, format = timeParams.format;
1996
+ var copyParams = __assign({}, params);
1997
+ for (var i = 0; i < fromKey.length; i++) {
1998
+ var fromKeyItem = fromKey[i];
1999
+ var toKeyItem = toKey[i];
2000
+ var formatItem = Array.isArray(format)
2001
+ ? format[i]
2002
+ ? format[i]
2003
+ : 'YYYY-MM-DD'
2004
+ : format
2005
+ ? format
2006
+ : 'YYYY-MM-DD';
2007
+ // 从一个键转换成两个键
2008
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
2009
+ if (type === 'string' && copyParams[fromKeyItem]) {
2010
+ var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
2011
+ var start = void 0, end = void 0;
2012
+ if (dayjs.isDayjs(startMoment)) {
2013
+ start = startMoment.format(formatItem);
2014
+ }
2015
+ if (dayjs.isDayjs(endMoment)) {
2016
+ end = endMoment.format(formatItem);
2017
+ }
2018
+ if (formatItem === 'YYYY-MM-DD HH:mm:ss') {
2019
+ start = start.substr(0, 10) + ' 00:00:00';
2020
+ end = end.substr(0, 10) + ' 23:59:59';
2021
+ }
2022
+ delete copyParams[fromKeyItem];
2023
+ copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
2024
+ }
2025
+ else {
2026
+ copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
2027
+ }
2028
+ }
2029
+ // 从一个键转换成一个键
2030
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
2031
+ if (type === 'string') {
2032
+ var _dayjsObj = copyParams[fromKeyItem];
2033
+ var start = void 0;
2034
+ if (dayjs.isDayjs(_dayjsObj)) {
2035
+ start = _dayjsObj.format(formatItem);
2036
+ }
2037
+ if (formatItem === 'startTime') {
2038
+ start = start.substr(0, 10) + ' 00:00:00';
2039
+ }
2040
+ if (formatItem === 'endTime') {
2041
+ start = start.substr(0, 10) + ' 23:59:59';
2042
+ }
2043
+ delete copyParams[fromKeyItem];
2044
+ copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
2045
+ }
2046
+ if (type === 'object') {
2047
+ var start = copyParams[fromKeyItem]
2048
+ ? dayjs(copyParams[fromKeyItem])
2049
+ : undefined;
2050
+ delete copyParams[fromKeyItem];
2051
+ copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
2052
+ }
2053
+ }
2054
+ // 从两个键转换成一个键
2055
+ if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
2056
+ if (type === 'object') {
2057
+ var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
2058
+ var intime = copyParams[toKeyItem] || [null, null];
2059
+ if (copyParams[startMoment]) {
2060
+ intime[0] = dayjs(copyParams[startMoment]);
2061
+ delete copyParams[startMoment];
2062
+ }
2063
+ if (copyParams[endMoment]) {
2064
+ intime[1] = dayjs(copyParams[endMoment]);
2065
+ delete copyParams[endMoment];
2066
+ }
2067
+ if (intime[0] == null || intime[1] == null) {
2068
+ intime = null;
2069
+ }
2070
+ copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
2071
+ }
2072
+ }
2073
+ }
2074
+ return copyParams;
2075
+ }
2076
+ /**
2077
+ * 精确加法
2078
+ */
2079
+ function plus(num1, num2) {
2080
+ var others = [];
2081
+ for (var _i = 2; _i < arguments.length; _i++) {
2082
+ others[_i - 2] = arguments[_i];
2083
+ }
2084
+ try {
2085
+ // const _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
2086
+ // const _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
2087
+ // const _others = Array.isArray(others)
2088
+ // ? others?.map((item) => (isNaN(Number(item)) ? item : Number(item)))
2089
+ // : [];
2090
+ // return _plus(_num1, _num2, ..._others);
2091
+ var _num1 = num1 || 0;
2092
+ var _num2 = num2 || 0;
2093
+ var _others = Array.isArray(others)
2094
+ ? others.map(function (item) { return item || 0; })
2095
+ : [];
2096
+ var _num_1 = new Decimal$1(_num1).add(_num2);
2097
+ if (_others.length > 0) {
2098
+ _others.forEach(function (item) {
2099
+ _num_1 = _num_1.add(item);
2100
+ });
2101
+ }
2102
+ return _num_1.toNumber();
2103
+ }
2104
+ catch (err) {
2105
+ console.log(err);
2106
+ return 0;
2107
+ }
2108
+ }
2109
+ /**
2110
+ * 精确减法
2111
+ */
2112
+ function minus(num1, num2) {
2113
+ var others = [];
2114
+ for (var _i = 2; _i < arguments.length; _i++) {
2115
+ others[_i - 2] = arguments[_i];
2116
+ }
2117
+ try {
2118
+ // const _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
2119
+ // const _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
2120
+ // const _others = Array.isArray(others)
2121
+ // ? others?.map((item) => (isNaN(Number(item)) ? item : Number(item)))
2122
+ // : [];
2123
+ // return _minus(_num1, _num2, ..._others);
2124
+ var _num1 = num1 || 0;
2125
+ var _num2 = num2 || 0;
2126
+ var _others = Array.isArray(others)
2127
+ ? others.map(function (item) { return item || 0; })
2128
+ : [];
2129
+ var _num_2 = new Decimal$1(_num1).sub(_num2);
2130
+ if (_others.length > 0) {
2131
+ _others.forEach(function (item) {
2132
+ _num_2 = _num_2.sub(item);
2133
+ });
2134
+ }
2135
+ return _num_2.toNumber();
2136
+ }
2137
+ catch (err) {
2138
+ console.log(err);
2139
+ return 0;
2140
+ }
2141
+ }
2142
+ /**
2143
+ * 精确乘法
2144
+ */
2145
+ function times(num1, num2) {
2146
+ var others = [];
2147
+ for (var _i = 2; _i < arguments.length; _i++) {
2148
+ others[_i - 2] = arguments[_i];
2149
+ }
2150
+ try {
2151
+ // const _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
2152
+ // const _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
2153
+ // const _others = Array.isArray(others)
2154
+ // ? others?.map((item) => (isNaN(Number(item)) ? item : Number(item)))
2155
+ // : [];
2156
+ // return _times(_num1, _num2, ..._others);
2157
+ var _num1 = num1 || 0;
2158
+ var _num2 = num2 || 0;
2159
+ var _others = Array.isArray(others)
2160
+ ? others.map(function (item) { return item || 0; })
2161
+ : [];
2162
+ var _num_3 = new Decimal$1(_num1).mul(_num2);
2163
+ if (_others.length > 0) {
2164
+ _others.forEach(function (item) {
2165
+ _num_3 = _num_3.mul(item);
2166
+ });
2167
+ }
2168
+ return _num_3.toNumber();
2169
+ }
2170
+ catch (err) {
2171
+ console.log(err);
2172
+ return 0;
2173
+ }
2174
+ }
2175
+ /**
2176
+ * 精确除法
2177
+ */
2178
+ function divide(num1, num2) {
2179
+ var others = [];
2180
+ for (var _i = 2; _i < arguments.length; _i++) {
2181
+ others[_i - 2] = arguments[_i];
2182
+ }
2183
+ try {
2184
+ // const _num1 = isNaN(Number(num1)) ? num1 : Number(num1);
2185
+ // const _num2 = isNaN(Number(num2)) ? num2 : Number(num2);
2186
+ // const _others = Array.isArray(others)
2187
+ // ? others?.map((item) => (isNaN(Number(item)) ? item : Number(item)))
2188
+ // : [];
2189
+ // return _divide(_num1, _num2, ..._others);
2190
+ var _num1 = num1 || 0;
2191
+ var _num2 = num2 || 0;
2192
+ var _others = Array.isArray(others)
2193
+ ? others.map(function (item) { return item || 0; })
2194
+ : [];
2195
+ var _num_4 = new Decimal$1(_num1).div(_num2);
2196
+ if (_others.length > 0) {
2197
+ _others.forEach(function (item) {
2198
+ _num_4 = _num_4.div(item);
2199
+ });
2200
+ }
2201
+ return _num_4.toNumber();
2202
+ }
2203
+ catch (err) {
2204
+ console.log(err);
2205
+ return 0;
2206
+ }
2207
+ }
2208
+ /**
2209
+ * @description 精确四舍五入后保留几位小数
2210
+ */
2211
+ function exactRound(num, ratio) {
2212
+ var typeNum = typeof num;
2213
+ if (typeNum !== 'number' && typeNum !== 'string') {
2214
+ return num;
2215
+ }
2216
+ try {
2217
+ // return _round(num, ratio).toFixed(ratio);
2218
+ return Number(new Decimal$1(num).toFixed(ratio)).toFixed(ratio);
2219
+ }
2220
+ catch (err) {
2221
+ console.error(err);
2222
+ return num;
2223
+ }
2224
+ }
2225
+ /**
2226
+ * @description 添加千分符符号
2227
+ */
2228
+ // export function toThousand(num: number | string) {
2229
+ // const typeNum = typeof num;
2230
+ // if (typeNum !== 'number' && typeNum !== 'string') {
2231
+ // return num;
2232
+ // }
2233
+ // let str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
2234
+ // return str;
2235
+ // }
2236
+ function toThousand(n) {
2237
+ if (n != null) {
2238
+ var _n = n.toString();
2239
+ var pointBeforeNum = '';
2240
+ var pointAfterNum = '';
2241
+ if (_n.startsWith('-')) {
2242
+ pointBeforeNum = '-';
2243
+ _n = _n.slice(1);
2244
+ }
2245
+ var pointIndex = _n.indexOf('.');
2246
+ if (pointIndex !== -1) {
2247
+ n = _n.slice(0, pointIndex);
2248
+ pointAfterNum = _n.slice(pointIndex);
2249
+ }
2250
+ else {
2251
+ n = _n;
2252
+ }
2253
+ var res = '';
2254
+ var s = n.toString();
2255
+ var length_1 = s.length;
2256
+ for (var i = length_1 - 1; i >= 0; i--) {
2257
+ var j = length_1 - i;
2258
+ if (j % 3 === 0) {
2259
+ if (i === 0) {
2260
+ res = s[i] + res;
2261
+ }
2262
+ else {
2263
+ res = ',' + s[i] + res;
2264
+ }
2265
+ }
2266
+ else {
2267
+ res = s[i] + res;
2268
+ }
2269
+ }
2270
+ return pointBeforeNum + res + pointAfterNum;
2271
+ }
2272
+ else {
2273
+ return n;
2274
+ }
2275
+ }
2276
+ /**
2277
+ * @description 去除指定字符串
2278
+ */
2279
+ function clearAssignStr(str, originalStr) {
2280
+ if (!originalStr) {
2281
+ return originalStr;
2282
+ }
2283
+ if (originalStr.startsWith(str)) {
2284
+ return originalStr.replace(str, '');
2285
+ }
2286
+ return originalStr;
2287
+ }
2288
+ /**
2289
+ * @description 下载重命名
2290
+ */
2291
+ function loadFileRename(fileUrl, fileName) {
2292
+ var xhr = new XMLHttpRequest();
2293
+ xhr.open('GET', fileUrl, true);
2294
+ xhr.responseType = 'blob';
2295
+ xhr.onload = function () {
2296
+ if (xhr.status === 200) {
2297
+ var link = document.createElement('a');
2298
+ var body = document.querySelector('body');
2299
+ link.href = window.URL.createObjectURL(xhr.response);
2300
+ link.download = fileName;
2301
+ // fix Firefox
2302
+ link.style.display = 'none';
2303
+ body.appendChild(link);
2304
+ link.click();
2305
+ body.removeChild(link);
2306
+ window.URL.revokeObjectURL(link.href);
2307
+ }
2308
+ };
2309
+ xhr.send();
2310
+ }
2311
+ /**
2312
+ * @description 文件大小提示转换
2313
+ */
2314
+ function transformFileSize(value) {
2315
+ if (value < 1024) {
2316
+ // return _round(value, 2).toFixed(2) + 'B';
2317
+ return exactRound(value, 2) + 'B';
2318
+ }
2319
+ else if (value < 1024 * 1024) {
2320
+ // return _round(divide(value, 1024), 2).toFixed(2) + 'KB';
2321
+ return exactRound(divide(value, 1024), 2) + 'KB';
2322
+ }
2323
+ // return _round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
2324
+ return exactRound(divide(value, 1024, 1024), 2) + 'MB';
2325
+ }
2326
+ /**
2327
+ * @description 更具key判断前后值是否一致
2328
+ */
2329
+ function isEqualByKey(keys, record, preRecord) {
2330
+ var isEqual = false; // 是否相等
2331
+ if (!record || !preRecord) {
2332
+ isEqual = true;
2333
+ return isEqual;
2334
+ }
2335
+ // 如果数据源相同的话,那么判断是初次更改,应该更新
2336
+ if (record === preRecord) {
2337
+ isEqual = true;
2338
+ return isEqual;
2339
+ }
2340
+ for (var i = 0; i < keys.length; i++) {
2341
+ var key = keys[i];
2342
+ if (record[key] !== preRecord[key]) {
2343
+ isEqual = true;
2344
+ break;
2345
+ }
2346
+ }
2347
+ return isEqual;
2348
+ }
2349
+ /**
2350
+ * @description 判断是否显示框架
2351
+ */
2352
+ var SHOWFRAME_KEY = 'showFrame';
2353
+ function showFrame() {
2354
+ var _a;
2355
+ var search = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search;
2356
+ try {
2357
+ if (search) {
2358
+ var searchList = search.slice(1).split('&');
2359
+ for (var i = 0; i < searchList.length; i++) {
2360
+ var _b = searchList[i].split('='), key = _b[0], value = _b[1];
2361
+ if (key === SHOWFRAME_KEY)
2362
+ return false;
2363
+ }
2364
+ }
2365
+ }
2366
+ catch (err) {
2367
+ return true;
2368
+ }
2369
+ return true;
2370
+ }
2371
+ /**
2372
+ *
2373
+ * @description 取地址栏参数
2374
+ */
2375
+ function getUrlSearch() {
2376
+ var _a;
2377
+ var search = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search;
2378
+ var result = {};
2379
+ try {
2380
+ if (search) {
2381
+ var searchList = search.slice(1).split('&');
2382
+ for (var i = 0; i < searchList.length; i++) {
2383
+ var _b = searchList[i].split('='), key = _b[0], value = _b[1];
2384
+ result[key] = value;
2385
+ }
2386
+ }
2387
+ }
2388
+ catch (err) {
2389
+ console.log(err);
2390
+ }
2391
+ return result;
2392
+ }
2393
+ /**
2394
+ * @description 复制
2395
+ */
2396
+ function copyContent(text) {
2397
+ var textarea = document.createElement('textarea');
2398
+ textarea.setAttribute('readonly', 'readonly');
2399
+ textarea.value = text;
2400
+ document.body.appendChild(textarea);
2401
+ textarea.select();
2402
+ document === null || document === void 0 ? void 0 : document.execCommand('copy');
2403
+ document.body.removeChild(textarea);
2404
+ }
2405
+ /**
2406
+ * @author 陈亚雄
2407
+ * @description 处理转义字符
2408
+ */
2409
+ function dangerouslySetXss(str) {
2410
+ var _a;
2411
+ // 兼容str不是字符串的情况,返回原值
2412
+ if (!str || typeof str !== 'string') {
2413
+ return str;
2414
+ }
2415
+ try {
2416
+ var arrEntities_1 = { lt: '', gt: '', nbsp: ' ', amp: '&', quot: '"' };
2417
+ return (_a = str === null || str === void 0 ? void 0 : str.replace) === null || _a === void 0 ? void 0 : _a.call(str, /&(lt|gt|nbsp|amp|quot);/gi, function (all, t) {
2418
+ return arrEntities_1[t];
2419
+ });
2420
+ }
2421
+ catch (err) {
2422
+ return str;
2423
+ }
2424
+ }
2425
+
2426
+ var tools = /*#__PURE__*/Object.freeze({
2427
+ __proto__: null,
2428
+ timeTransfrom: timeTransfrom,
2429
+ plus: plus,
2430
+ minus: minus,
2431
+ times: times,
2432
+ divide: divide,
2433
+ exactRound: exactRound,
2434
+ toThousand: toThousand,
2435
+ clearAssignStr: clearAssignStr,
2436
+ loadFileRename: loadFileRename,
2437
+ transformFileSize: transformFileSize,
2438
+ isEqualByKey: isEqualByKey,
2439
+ SHOWFRAME_KEY: SHOWFRAME_KEY,
2440
+ showFrame: showFrame,
2441
+ getUrlSearch: getUrlSearch,
2442
+ copyContent: copyContent,
2443
+ dangerouslySetXss: dangerouslySetXss
2444
+ });
2445
+
2446
+ export { SHOWFRAME_KEY as S, timeTransfrom as a, times as b, divide as c, dangerouslySetXss as d, exactRound as e, toThousand as f, getUrlSearch as g, clearAssignStr as h, transformFileSize as i, isEqualByKey as j, copyContent as k, loadFileRename as l, minus as m, plus as p, showFrame as s, tools as t };