@formatjs/intl-numberformat 8.14.6 → 8.15.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.
package/polyfill.iife.js CHANGED
@@ -4,6 +4,2361 @@
4
4
  return Intl.getCanonicalLocales(locales);
5
5
  }
6
6
 
7
+ // node_modules/.aspect_rules_js/decimal.js@10.4.3/node_modules/decimal.js/decimal.mjs
8
+ var EXP_LIMIT = 9e15;
9
+ var MAX_DIGITS = 1e9;
10
+ var NUMERALS = "0123456789abcdef";
11
+ var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
12
+ var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
13
+ var DEFAULTS = {
14
+ // These values must be integers within the stated ranges (inclusive).
15
+ // Most of these values can be changed at run-time using the `Decimal.config` method.
16
+ // The maximum number of significant digits of the result of a calculation or base conversion.
17
+ // E.g. `Decimal.config({ precision: 20 });`
18
+ precision: 20,
19
+ // 1 to MAX_DIGITS
20
+ // The rounding mode used when rounding to `precision`.
21
+ //
22
+ // ROUND_UP 0 Away from zero.
23
+ // ROUND_DOWN 1 Towards zero.
24
+ // ROUND_CEIL 2 Towards +Infinity.
25
+ // ROUND_FLOOR 3 Towards -Infinity.
26
+ // ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
27
+ // ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
28
+ // ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
29
+ // ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
30
+ // ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
31
+ //
32
+ // E.g.
33
+ // `Decimal.rounding = 4;`
34
+ // `Decimal.rounding = Decimal.ROUND_HALF_UP;`
35
+ rounding: 4,
36
+ // 0 to 8
37
+ // The modulo mode used when calculating the modulus: a mod n.
38
+ // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
39
+ // The remainder (r) is calculated as: r = a - n * q.
40
+ //
41
+ // UP 0 The remainder is positive if the dividend is negative, else is negative.
42
+ // DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
43
+ // FLOOR 3 The remainder has the same sign as the divisor (Python %).
44
+ // HALF_EVEN 6 The IEEE 754 remainder function.
45
+ // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
46
+ //
47
+ // Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
48
+ // division (9) are commonly used for the modulus operation. The other rounding modes can also
49
+ // be used, but they may not give useful results.
50
+ modulo: 1,
51
+ // 0 to 9
52
+ // The exponent value at and beneath which `toString` returns exponential notation.
53
+ // JavaScript numbers: -7
54
+ toExpNeg: -7,
55
+ // 0 to -EXP_LIMIT
56
+ // The exponent value at and above which `toString` returns exponential notation.
57
+ // JavaScript numbers: 21
58
+ toExpPos: 21,
59
+ // 0 to EXP_LIMIT
60
+ // The minimum exponent value, beneath which underflow to zero occurs.
61
+ // JavaScript numbers: -324 (5e-324)
62
+ minE: -EXP_LIMIT,
63
+ // -1 to -EXP_LIMIT
64
+ // The maximum exponent value, above which overflow to Infinity occurs.
65
+ // JavaScript numbers: 308 (1.7976931348623157e+308)
66
+ maxE: EXP_LIMIT,
67
+ // 1 to EXP_LIMIT
68
+ // Whether to use cryptographically-secure random number generation, if available.
69
+ crypto: false
70
+ // true/false
71
+ };
72
+ var inexact;
73
+ var quadrant;
74
+ var external = true;
75
+ var decimalError = "[DecimalError] ";
76
+ var invalidArgument = decimalError + "Invalid argument: ";
77
+ var precisionLimitExceeded = decimalError + "Precision limit exceeded";
78
+ var cryptoUnavailable = decimalError + "crypto unavailable";
79
+ var tag = "[object Decimal]";
80
+ var mathfloor = Math.floor;
81
+ var mathpow = Math.pow;
82
+ var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
83
+ var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
84
+ var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
85
+ var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
86
+ var BASE = 1e7;
87
+ var LOG_BASE = 7;
88
+ var MAX_SAFE_INTEGER = 9007199254740991;
89
+ var LN10_PRECISION = LN10.length - 1;
90
+ var PI_PRECISION = PI.length - 1;
91
+ var P = { toStringTag: tag };
92
+ P.absoluteValue = P.abs = function() {
93
+ var x = new this.constructor(this);
94
+ if (x.s < 0)
95
+ x.s = 1;
96
+ return finalise(x);
97
+ };
98
+ P.ceil = function() {
99
+ return finalise(new this.constructor(this), this.e + 1, 2);
100
+ };
101
+ P.clampedTo = P.clamp = function(min2, max2) {
102
+ var k, x = this, Ctor = x.constructor;
103
+ min2 = new Ctor(min2);
104
+ max2 = new Ctor(max2);
105
+ if (!min2.s || !max2.s)
106
+ return new Ctor(NaN);
107
+ if (min2.gt(max2))
108
+ throw Error(invalidArgument + max2);
109
+ k = x.cmp(min2);
110
+ return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
111
+ };
112
+ P.comparedTo = P.cmp = function(y) {
113
+ var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
114
+ if (!xd || !yd) {
115
+ return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
116
+ }
117
+ if (!xd[0] || !yd[0])
118
+ return xd[0] ? xs : yd[0] ? -ys : 0;
119
+ if (xs !== ys)
120
+ return xs;
121
+ if (x.e !== y.e)
122
+ return x.e > y.e ^ xs < 0 ? 1 : -1;
123
+ xdL = xd.length;
124
+ ydL = yd.length;
125
+ for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
126
+ if (xd[i] !== yd[i])
127
+ return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
128
+ }
129
+ return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
130
+ };
131
+ P.cosine = P.cos = function() {
132
+ var pr, rm, x = this, Ctor = x.constructor;
133
+ if (!x.d)
134
+ return new Ctor(NaN);
135
+ if (!x.d[0])
136
+ return new Ctor(1);
137
+ pr = Ctor.precision;
138
+ rm = Ctor.rounding;
139
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
140
+ Ctor.rounding = 1;
141
+ x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
142
+ Ctor.precision = pr;
143
+ Ctor.rounding = rm;
144
+ return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
145
+ };
146
+ P.cubeRoot = P.cbrt = function() {
147
+ var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
148
+ if (!x.isFinite() || x.isZero())
149
+ return new Ctor(x);
150
+ external = false;
151
+ s = x.s * mathpow(x.s * x, 1 / 3);
152
+ if (!s || Math.abs(s) == 1 / 0) {
153
+ n = digitsToString(x.d);
154
+ e = x.e;
155
+ if (s = (e - n.length + 1) % 3)
156
+ n += s == 1 || s == -2 ? "0" : "00";
157
+ s = mathpow(n, 1 / 3);
158
+ e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
159
+ if (s == 1 / 0) {
160
+ n = "5e" + e;
161
+ } else {
162
+ n = s.toExponential();
163
+ n = n.slice(0, n.indexOf("e") + 1) + e;
164
+ }
165
+ r = new Ctor(n);
166
+ r.s = x.s;
167
+ } else {
168
+ r = new Ctor(s.toString());
169
+ }
170
+ sd = (e = Ctor.precision) + 3;
171
+ for (; ; ) {
172
+ t = r;
173
+ t3 = t.times(t).times(t);
174
+ t3plusx = t3.plus(x);
175
+ r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
176
+ if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
177
+ n = n.slice(sd - 3, sd + 1);
178
+ if (n == "9999" || !rep && n == "4999") {
179
+ if (!rep) {
180
+ finalise(t, e + 1, 0);
181
+ if (t.times(t).times(t).eq(x)) {
182
+ r = t;
183
+ break;
184
+ }
185
+ }
186
+ sd += 4;
187
+ rep = 1;
188
+ } else {
189
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
190
+ finalise(r, e + 1, 1);
191
+ m = !r.times(r).times(r).eq(x);
192
+ }
193
+ break;
194
+ }
195
+ }
196
+ }
197
+ external = true;
198
+ return finalise(r, e, Ctor.rounding, m);
199
+ };
200
+ P.decimalPlaces = P.dp = function() {
201
+ var w, d = this.d, n = NaN;
202
+ if (d) {
203
+ w = d.length - 1;
204
+ n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
205
+ w = d[w];
206
+ if (w)
207
+ for (; w % 10 == 0; w /= 10)
208
+ n--;
209
+ if (n < 0)
210
+ n = 0;
211
+ }
212
+ return n;
213
+ };
214
+ P.dividedBy = P.div = function(y) {
215
+ return divide(this, new this.constructor(y));
216
+ };
217
+ P.dividedToIntegerBy = P.divToInt = function(y) {
218
+ var x = this, Ctor = x.constructor;
219
+ return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
220
+ };
221
+ P.equals = P.eq = function(y) {
222
+ return this.cmp(y) === 0;
223
+ };
224
+ P.floor = function() {
225
+ return finalise(new this.constructor(this), this.e + 1, 3);
226
+ };
227
+ P.greaterThan = P.gt = function(y) {
228
+ return this.cmp(y) > 0;
229
+ };
230
+ P.greaterThanOrEqualTo = P.gte = function(y) {
231
+ var k = this.cmp(y);
232
+ return k == 1 || k === 0;
233
+ };
234
+ P.hyperbolicCosine = P.cosh = function() {
235
+ var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
236
+ if (!x.isFinite())
237
+ return new Ctor(x.s ? 1 / 0 : NaN);
238
+ if (x.isZero())
239
+ return one;
240
+ pr = Ctor.precision;
241
+ rm = Ctor.rounding;
242
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
243
+ Ctor.rounding = 1;
244
+ len = x.d.length;
245
+ if (len < 32) {
246
+ k = Math.ceil(len / 3);
247
+ n = (1 / tinyPow(4, k)).toString();
248
+ } else {
249
+ k = 16;
250
+ n = "2.3283064365386962890625e-10";
251
+ }
252
+ x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
253
+ var cosh2_x, i = k, d8 = new Ctor(8);
254
+ for (; i--; ) {
255
+ cosh2_x = x.times(x);
256
+ x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
257
+ }
258
+ return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
259
+ };
260
+ P.hyperbolicSine = P.sinh = function() {
261
+ var k, pr, rm, len, x = this, Ctor = x.constructor;
262
+ if (!x.isFinite() || x.isZero())
263
+ return new Ctor(x);
264
+ pr = Ctor.precision;
265
+ rm = Ctor.rounding;
266
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
267
+ Ctor.rounding = 1;
268
+ len = x.d.length;
269
+ if (len < 3) {
270
+ x = taylorSeries(Ctor, 2, x, x, true);
271
+ } else {
272
+ k = 1.4 * Math.sqrt(len);
273
+ k = k > 16 ? 16 : k | 0;
274
+ x = x.times(1 / tinyPow(5, k));
275
+ x = taylorSeries(Ctor, 2, x, x, true);
276
+ var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
277
+ for (; k--; ) {
278
+ sinh2_x = x.times(x);
279
+ x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
280
+ }
281
+ }
282
+ Ctor.precision = pr;
283
+ Ctor.rounding = rm;
284
+ return finalise(x, pr, rm, true);
285
+ };
286
+ P.hyperbolicTangent = P.tanh = function() {
287
+ var pr, rm, x = this, Ctor = x.constructor;
288
+ if (!x.isFinite())
289
+ return new Ctor(x.s);
290
+ if (x.isZero())
291
+ return new Ctor(x);
292
+ pr = Ctor.precision;
293
+ rm = Ctor.rounding;
294
+ Ctor.precision = pr + 7;
295
+ Ctor.rounding = 1;
296
+ return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
297
+ };
298
+ P.inverseCosine = P.acos = function() {
299
+ var halfPi, x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
300
+ if (k !== -1) {
301
+ return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
302
+ }
303
+ if (x.isZero())
304
+ return getPi(Ctor, pr + 4, rm).times(0.5);
305
+ Ctor.precision = pr + 6;
306
+ Ctor.rounding = 1;
307
+ x = x.asin();
308
+ halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
309
+ Ctor.precision = pr;
310
+ Ctor.rounding = rm;
311
+ return halfPi.minus(x);
312
+ };
313
+ P.inverseHyperbolicCosine = P.acosh = function() {
314
+ var pr, rm, x = this, Ctor = x.constructor;
315
+ if (x.lte(1))
316
+ return new Ctor(x.eq(1) ? 0 : NaN);
317
+ if (!x.isFinite())
318
+ return new Ctor(x);
319
+ pr = Ctor.precision;
320
+ rm = Ctor.rounding;
321
+ Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
322
+ Ctor.rounding = 1;
323
+ external = false;
324
+ x = x.times(x).minus(1).sqrt().plus(x);
325
+ external = true;
326
+ Ctor.precision = pr;
327
+ Ctor.rounding = rm;
328
+ return x.ln();
329
+ };
330
+ P.inverseHyperbolicSine = P.asinh = function() {
331
+ var pr, rm, x = this, Ctor = x.constructor;
332
+ if (!x.isFinite() || x.isZero())
333
+ return new Ctor(x);
334
+ pr = Ctor.precision;
335
+ rm = Ctor.rounding;
336
+ Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
337
+ Ctor.rounding = 1;
338
+ external = false;
339
+ x = x.times(x).plus(1).sqrt().plus(x);
340
+ external = true;
341
+ Ctor.precision = pr;
342
+ Ctor.rounding = rm;
343
+ return x.ln();
344
+ };
345
+ P.inverseHyperbolicTangent = P.atanh = function() {
346
+ var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
347
+ if (!x.isFinite())
348
+ return new Ctor(NaN);
349
+ if (x.e >= 0)
350
+ return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
351
+ pr = Ctor.precision;
352
+ rm = Ctor.rounding;
353
+ xsd = x.sd();
354
+ if (Math.max(xsd, pr) < 2 * -x.e - 1)
355
+ return finalise(new Ctor(x), pr, rm, true);
356
+ Ctor.precision = wpr = xsd - x.e;
357
+ x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
358
+ Ctor.precision = pr + 4;
359
+ Ctor.rounding = 1;
360
+ x = x.ln();
361
+ Ctor.precision = pr;
362
+ Ctor.rounding = rm;
363
+ return x.times(0.5);
364
+ };
365
+ P.inverseSine = P.asin = function() {
366
+ var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
367
+ if (x.isZero())
368
+ return new Ctor(x);
369
+ k = x.abs().cmp(1);
370
+ pr = Ctor.precision;
371
+ rm = Ctor.rounding;
372
+ if (k !== -1) {
373
+ if (k === 0) {
374
+ halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
375
+ halfPi.s = x.s;
376
+ return halfPi;
377
+ }
378
+ return new Ctor(NaN);
379
+ }
380
+ Ctor.precision = pr + 6;
381
+ Ctor.rounding = 1;
382
+ x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
383
+ Ctor.precision = pr;
384
+ Ctor.rounding = rm;
385
+ return x.times(2);
386
+ };
387
+ P.inverseTangent = P.atan = function() {
388
+ var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
389
+ if (!x.isFinite()) {
390
+ if (!x.s)
391
+ return new Ctor(NaN);
392
+ if (pr + 4 <= PI_PRECISION) {
393
+ r = getPi(Ctor, pr + 4, rm).times(0.5);
394
+ r.s = x.s;
395
+ return r;
396
+ }
397
+ } else if (x.isZero()) {
398
+ return new Ctor(x);
399
+ } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
400
+ r = getPi(Ctor, pr + 4, rm).times(0.25);
401
+ r.s = x.s;
402
+ return r;
403
+ }
404
+ Ctor.precision = wpr = pr + 10;
405
+ Ctor.rounding = 1;
406
+ k = Math.min(28, wpr / LOG_BASE + 2 | 0);
407
+ for (i = k; i; --i)
408
+ x = x.div(x.times(x).plus(1).sqrt().plus(1));
409
+ external = false;
410
+ j = Math.ceil(wpr / LOG_BASE);
411
+ n = 1;
412
+ x2 = x.times(x);
413
+ r = new Ctor(x);
414
+ px = x;
415
+ for (; i !== -1; ) {
416
+ px = px.times(x2);
417
+ t = r.minus(px.div(n += 2));
418
+ px = px.times(x2);
419
+ r = t.plus(px.div(n += 2));
420
+ if (r.d[j] !== void 0)
421
+ for (i = j; r.d[i] === t.d[i] && i--; )
422
+ ;
423
+ }
424
+ if (k)
425
+ r = r.times(2 << k - 1);
426
+ external = true;
427
+ return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
428
+ };
429
+ P.isFinite = function() {
430
+ return !!this.d;
431
+ };
432
+ P.isInteger = P.isInt = function() {
433
+ return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
434
+ };
435
+ P.isNaN = function() {
436
+ return !this.s;
437
+ };
438
+ P.isNegative = P.isNeg = function() {
439
+ return this.s < 0;
440
+ };
441
+ P.isPositive = P.isPos = function() {
442
+ return this.s > 0;
443
+ };
444
+ P.isZero = function() {
445
+ return !!this.d && this.d[0] === 0;
446
+ };
447
+ P.lessThan = P.lt = function(y) {
448
+ return this.cmp(y) < 0;
449
+ };
450
+ P.lessThanOrEqualTo = P.lte = function(y) {
451
+ return this.cmp(y) < 1;
452
+ };
453
+ P.logarithm = P.log = function(base) {
454
+ var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
455
+ if (base == null) {
456
+ base = new Ctor(10);
457
+ isBase10 = true;
458
+ } else {
459
+ base = new Ctor(base);
460
+ d = base.d;
461
+ if (base.s < 0 || !d || !d[0] || base.eq(1))
462
+ return new Ctor(NaN);
463
+ isBase10 = base.eq(10);
464
+ }
465
+ d = arg.d;
466
+ if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
467
+ return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
468
+ }
469
+ if (isBase10) {
470
+ if (d.length > 1) {
471
+ inf = true;
472
+ } else {
473
+ for (k = d[0]; k % 10 === 0; )
474
+ k /= 10;
475
+ inf = k !== 1;
476
+ }
477
+ }
478
+ external = false;
479
+ sd = pr + guard;
480
+ num = naturalLogarithm(arg, sd);
481
+ denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
482
+ r = divide(num, denominator, sd, 1);
483
+ if (checkRoundingDigits(r.d, k = pr, rm)) {
484
+ do {
485
+ sd += 10;
486
+ num = naturalLogarithm(arg, sd);
487
+ denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
488
+ r = divide(num, denominator, sd, 1);
489
+ if (!inf) {
490
+ if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
491
+ r = finalise(r, pr + 1, 0);
492
+ }
493
+ break;
494
+ }
495
+ } while (checkRoundingDigits(r.d, k += 10, rm));
496
+ }
497
+ external = true;
498
+ return finalise(r, pr, rm);
499
+ };
500
+ P.minus = P.sub = function(y) {
501
+ var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
502
+ y = new Ctor(y);
503
+ if (!x.d || !y.d) {
504
+ if (!x.s || !y.s)
505
+ y = new Ctor(NaN);
506
+ else if (x.d)
507
+ y.s = -y.s;
508
+ else
509
+ y = new Ctor(y.d || x.s !== y.s ? x : NaN);
510
+ return y;
511
+ }
512
+ if (x.s != y.s) {
513
+ y.s = -y.s;
514
+ return x.plus(y);
515
+ }
516
+ xd = x.d;
517
+ yd = y.d;
518
+ pr = Ctor.precision;
519
+ rm = Ctor.rounding;
520
+ if (!xd[0] || !yd[0]) {
521
+ if (yd[0])
522
+ y.s = -y.s;
523
+ else if (xd[0])
524
+ y = new Ctor(x);
525
+ else
526
+ return new Ctor(rm === 3 ? -0 : 0);
527
+ return external ? finalise(y, pr, rm) : y;
528
+ }
529
+ e = mathfloor(y.e / LOG_BASE);
530
+ xe = mathfloor(x.e / LOG_BASE);
531
+ xd = xd.slice();
532
+ k = xe - e;
533
+ if (k) {
534
+ xLTy = k < 0;
535
+ if (xLTy) {
536
+ d = xd;
537
+ k = -k;
538
+ len = yd.length;
539
+ } else {
540
+ d = yd;
541
+ e = xe;
542
+ len = xd.length;
543
+ }
544
+ i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
545
+ if (k > i) {
546
+ k = i;
547
+ d.length = 1;
548
+ }
549
+ d.reverse();
550
+ for (i = k; i--; )
551
+ d.push(0);
552
+ d.reverse();
553
+ } else {
554
+ i = xd.length;
555
+ len = yd.length;
556
+ xLTy = i < len;
557
+ if (xLTy)
558
+ len = i;
559
+ for (i = 0; i < len; i++) {
560
+ if (xd[i] != yd[i]) {
561
+ xLTy = xd[i] < yd[i];
562
+ break;
563
+ }
564
+ }
565
+ k = 0;
566
+ }
567
+ if (xLTy) {
568
+ d = xd;
569
+ xd = yd;
570
+ yd = d;
571
+ y.s = -y.s;
572
+ }
573
+ len = xd.length;
574
+ for (i = yd.length - len; i > 0; --i)
575
+ xd[len++] = 0;
576
+ for (i = yd.length; i > k; ) {
577
+ if (xd[--i] < yd[i]) {
578
+ for (j = i; j && xd[--j] === 0; )
579
+ xd[j] = BASE - 1;
580
+ --xd[j];
581
+ xd[i] += BASE;
582
+ }
583
+ xd[i] -= yd[i];
584
+ }
585
+ for (; xd[--len] === 0; )
586
+ xd.pop();
587
+ for (; xd[0] === 0; xd.shift())
588
+ --e;
589
+ if (!xd[0])
590
+ return new Ctor(rm === 3 ? -0 : 0);
591
+ y.d = xd;
592
+ y.e = getBase10Exponent(xd, e);
593
+ return external ? finalise(y, pr, rm) : y;
594
+ };
595
+ P.modulo = P.mod = function(y) {
596
+ var q, x = this, Ctor = x.constructor;
597
+ y = new Ctor(y);
598
+ if (!x.d || !y.s || y.d && !y.d[0])
599
+ return new Ctor(NaN);
600
+ if (!y.d || x.d && !x.d[0]) {
601
+ return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
602
+ }
603
+ external = false;
604
+ if (Ctor.modulo == 9) {
605
+ q = divide(x, y.abs(), 0, 3, 1);
606
+ q.s *= y.s;
607
+ } else {
608
+ q = divide(x, y, 0, Ctor.modulo, 1);
609
+ }
610
+ q = q.times(y);
611
+ external = true;
612
+ return x.minus(q);
613
+ };
614
+ P.naturalExponential = P.exp = function() {
615
+ return naturalExponential(this);
616
+ };
617
+ P.naturalLogarithm = P.ln = function() {
618
+ return naturalLogarithm(this);
619
+ };
620
+ P.negated = P.neg = function() {
621
+ var x = new this.constructor(this);
622
+ x.s = -x.s;
623
+ return finalise(x);
624
+ };
625
+ P.plus = P.add = function(y) {
626
+ var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
627
+ y = new Ctor(y);
628
+ if (!x.d || !y.d) {
629
+ if (!x.s || !y.s)
630
+ y = new Ctor(NaN);
631
+ else if (!x.d)
632
+ y = new Ctor(y.d || x.s === y.s ? x : NaN);
633
+ return y;
634
+ }
635
+ if (x.s != y.s) {
636
+ y.s = -y.s;
637
+ return x.minus(y);
638
+ }
639
+ xd = x.d;
640
+ yd = y.d;
641
+ pr = Ctor.precision;
642
+ rm = Ctor.rounding;
643
+ if (!xd[0] || !yd[0]) {
644
+ if (!yd[0])
645
+ y = new Ctor(x);
646
+ return external ? finalise(y, pr, rm) : y;
647
+ }
648
+ k = mathfloor(x.e / LOG_BASE);
649
+ e = mathfloor(y.e / LOG_BASE);
650
+ xd = xd.slice();
651
+ i = k - e;
652
+ if (i) {
653
+ if (i < 0) {
654
+ d = xd;
655
+ i = -i;
656
+ len = yd.length;
657
+ } else {
658
+ d = yd;
659
+ e = k;
660
+ len = xd.length;
661
+ }
662
+ k = Math.ceil(pr / LOG_BASE);
663
+ len = k > len ? k + 1 : len + 1;
664
+ if (i > len) {
665
+ i = len;
666
+ d.length = 1;
667
+ }
668
+ d.reverse();
669
+ for (; i--; )
670
+ d.push(0);
671
+ d.reverse();
672
+ }
673
+ len = xd.length;
674
+ i = yd.length;
675
+ if (len - i < 0) {
676
+ i = len;
677
+ d = yd;
678
+ yd = xd;
679
+ xd = d;
680
+ }
681
+ for (carry = 0; i; ) {
682
+ carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
683
+ xd[i] %= BASE;
684
+ }
685
+ if (carry) {
686
+ xd.unshift(carry);
687
+ ++e;
688
+ }
689
+ for (len = xd.length; xd[--len] == 0; )
690
+ xd.pop();
691
+ y.d = xd;
692
+ y.e = getBase10Exponent(xd, e);
693
+ return external ? finalise(y, pr, rm) : y;
694
+ };
695
+ P.precision = P.sd = function(z) {
696
+ var k, x = this;
697
+ if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
698
+ throw Error(invalidArgument + z);
699
+ if (x.d) {
700
+ k = getPrecision(x.d);
701
+ if (z && x.e + 1 > k)
702
+ k = x.e + 1;
703
+ } else {
704
+ k = NaN;
705
+ }
706
+ return k;
707
+ };
708
+ P.round = function() {
709
+ var x = this, Ctor = x.constructor;
710
+ return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
711
+ };
712
+ P.sine = P.sin = function() {
713
+ var pr, rm, x = this, Ctor = x.constructor;
714
+ if (!x.isFinite())
715
+ return new Ctor(NaN);
716
+ if (x.isZero())
717
+ return new Ctor(x);
718
+ pr = Ctor.precision;
719
+ rm = Ctor.rounding;
720
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
721
+ Ctor.rounding = 1;
722
+ x = sine(Ctor, toLessThanHalfPi(Ctor, x));
723
+ Ctor.precision = pr;
724
+ Ctor.rounding = rm;
725
+ return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
726
+ };
727
+ P.squareRoot = P.sqrt = function() {
728
+ var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
729
+ if (s !== 1 || !d || !d[0]) {
730
+ return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
731
+ }
732
+ external = false;
733
+ s = Math.sqrt(+x);
734
+ if (s == 0 || s == 1 / 0) {
735
+ n = digitsToString(d);
736
+ if ((n.length + e) % 2 == 0)
737
+ n += "0";
738
+ s = Math.sqrt(n);
739
+ e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
740
+ if (s == 1 / 0) {
741
+ n = "5e" + e;
742
+ } else {
743
+ n = s.toExponential();
744
+ n = n.slice(0, n.indexOf("e") + 1) + e;
745
+ }
746
+ r = new Ctor(n);
747
+ } else {
748
+ r = new Ctor(s.toString());
749
+ }
750
+ sd = (e = Ctor.precision) + 3;
751
+ for (; ; ) {
752
+ t = r;
753
+ r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
754
+ if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
755
+ n = n.slice(sd - 3, sd + 1);
756
+ if (n == "9999" || !rep && n == "4999") {
757
+ if (!rep) {
758
+ finalise(t, e + 1, 0);
759
+ if (t.times(t).eq(x)) {
760
+ r = t;
761
+ break;
762
+ }
763
+ }
764
+ sd += 4;
765
+ rep = 1;
766
+ } else {
767
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
768
+ finalise(r, e + 1, 1);
769
+ m = !r.times(r).eq(x);
770
+ }
771
+ break;
772
+ }
773
+ }
774
+ }
775
+ external = true;
776
+ return finalise(r, e, Ctor.rounding, m);
777
+ };
778
+ P.tangent = P.tan = function() {
779
+ var pr, rm, x = this, Ctor = x.constructor;
780
+ if (!x.isFinite())
781
+ return new Ctor(NaN);
782
+ if (x.isZero())
783
+ return new Ctor(x);
784
+ pr = Ctor.precision;
785
+ rm = Ctor.rounding;
786
+ Ctor.precision = pr + 10;
787
+ Ctor.rounding = 1;
788
+ x = x.sin();
789
+ x.s = 1;
790
+ x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
791
+ Ctor.precision = pr;
792
+ Ctor.rounding = rm;
793
+ return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
794
+ };
795
+ P.times = P.mul = function(y) {
796
+ var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
797
+ y.s *= x.s;
798
+ if (!xd || !xd[0] || !yd || !yd[0]) {
799
+ return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
800
+ }
801
+ e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
802
+ xdL = xd.length;
803
+ ydL = yd.length;
804
+ if (xdL < ydL) {
805
+ r = xd;
806
+ xd = yd;
807
+ yd = r;
808
+ rL = xdL;
809
+ xdL = ydL;
810
+ ydL = rL;
811
+ }
812
+ r = [];
813
+ rL = xdL + ydL;
814
+ for (i = rL; i--; )
815
+ r.push(0);
816
+ for (i = ydL; --i >= 0; ) {
817
+ carry = 0;
818
+ for (k = xdL + i; k > i; ) {
819
+ t = r[k] + yd[i] * xd[k - i - 1] + carry;
820
+ r[k--] = t % BASE | 0;
821
+ carry = t / BASE | 0;
822
+ }
823
+ r[k] = (r[k] + carry) % BASE | 0;
824
+ }
825
+ for (; !r[--rL]; )
826
+ r.pop();
827
+ if (carry)
828
+ ++e;
829
+ else
830
+ r.shift();
831
+ y.d = r;
832
+ y.e = getBase10Exponent(r, e);
833
+ return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
834
+ };
835
+ P.toBinary = function(sd, rm) {
836
+ return toStringBinary(this, 2, sd, rm);
837
+ };
838
+ P.toDecimalPlaces = P.toDP = function(dp, rm) {
839
+ var x = this, Ctor = x.constructor;
840
+ x = new Ctor(x);
841
+ if (dp === void 0)
842
+ return x;
843
+ checkInt32(dp, 0, MAX_DIGITS);
844
+ if (rm === void 0)
845
+ rm = Ctor.rounding;
846
+ else
847
+ checkInt32(rm, 0, 8);
848
+ return finalise(x, dp + x.e + 1, rm);
849
+ };
850
+ P.toExponential = function(dp, rm) {
851
+ var str, x = this, Ctor = x.constructor;
852
+ if (dp === void 0) {
853
+ str = finiteToString(x, true);
854
+ } else {
855
+ checkInt32(dp, 0, MAX_DIGITS);
856
+ if (rm === void 0)
857
+ rm = Ctor.rounding;
858
+ else
859
+ checkInt32(rm, 0, 8);
860
+ x = finalise(new Ctor(x), dp + 1, rm);
861
+ str = finiteToString(x, true, dp + 1);
862
+ }
863
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
864
+ };
865
+ P.toFixed = function(dp, rm) {
866
+ var str, y, x = this, Ctor = x.constructor;
867
+ if (dp === void 0) {
868
+ str = finiteToString(x);
869
+ } else {
870
+ checkInt32(dp, 0, MAX_DIGITS);
871
+ if (rm === void 0)
872
+ rm = Ctor.rounding;
873
+ else
874
+ checkInt32(rm, 0, 8);
875
+ y = finalise(new Ctor(x), dp + x.e + 1, rm);
876
+ str = finiteToString(y, false, dp + y.e + 1);
877
+ }
878
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
879
+ };
880
+ P.toFraction = function(maxD) {
881
+ var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
882
+ if (!xd)
883
+ return new Ctor(x);
884
+ n1 = d0 = new Ctor(1);
885
+ d1 = n0 = new Ctor(0);
886
+ d = new Ctor(d1);
887
+ e = d.e = getPrecision(xd) - x.e - 1;
888
+ k = e % LOG_BASE;
889
+ d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
890
+ if (maxD == null) {
891
+ maxD = e > 0 ? d : n1;
892
+ } else {
893
+ n = new Ctor(maxD);
894
+ if (!n.isInt() || n.lt(n1))
895
+ throw Error(invalidArgument + n);
896
+ maxD = n.gt(d) ? e > 0 ? d : n1 : n;
897
+ }
898
+ external = false;
899
+ n = new Ctor(digitsToString(xd));
900
+ pr = Ctor.precision;
901
+ Ctor.precision = e = xd.length * LOG_BASE * 2;
902
+ for (; ; ) {
903
+ q = divide(n, d, 0, 1, 1);
904
+ d2 = d0.plus(q.times(d1));
905
+ if (d2.cmp(maxD) == 1)
906
+ break;
907
+ d0 = d1;
908
+ d1 = d2;
909
+ d2 = n1;
910
+ n1 = n0.plus(q.times(d2));
911
+ n0 = d2;
912
+ d2 = d;
913
+ d = n.minus(q.times(d2));
914
+ n = d2;
915
+ }
916
+ d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
917
+ n0 = n0.plus(d2.times(n1));
918
+ d0 = d0.plus(d2.times(d1));
919
+ n0.s = n1.s = x.s;
920
+ r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
921
+ Ctor.precision = pr;
922
+ external = true;
923
+ return r;
924
+ };
925
+ P.toHexadecimal = P.toHex = function(sd, rm) {
926
+ return toStringBinary(this, 16, sd, rm);
927
+ };
928
+ P.toNearest = function(y, rm) {
929
+ var x = this, Ctor = x.constructor;
930
+ x = new Ctor(x);
931
+ if (y == null) {
932
+ if (!x.d)
933
+ return x;
934
+ y = new Ctor(1);
935
+ rm = Ctor.rounding;
936
+ } else {
937
+ y = new Ctor(y);
938
+ if (rm === void 0) {
939
+ rm = Ctor.rounding;
940
+ } else {
941
+ checkInt32(rm, 0, 8);
942
+ }
943
+ if (!x.d)
944
+ return y.s ? x : y;
945
+ if (!y.d) {
946
+ if (y.s)
947
+ y.s = x.s;
948
+ return y;
949
+ }
950
+ }
951
+ if (y.d[0]) {
952
+ external = false;
953
+ x = divide(x, y, 0, rm, 1).times(y);
954
+ external = true;
955
+ finalise(x);
956
+ } else {
957
+ y.s = x.s;
958
+ x = y;
959
+ }
960
+ return x;
961
+ };
962
+ P.toNumber = function() {
963
+ return +this;
964
+ };
965
+ P.toOctal = function(sd, rm) {
966
+ return toStringBinary(this, 8, sd, rm);
967
+ };
968
+ P.toPower = P.pow = function(y) {
969
+ var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
970
+ if (!x.d || !y.d || !x.d[0] || !y.d[0])
971
+ return new Ctor(mathpow(+x, yn));
972
+ x = new Ctor(x);
973
+ if (x.eq(1))
974
+ return x;
975
+ pr = Ctor.precision;
976
+ rm = Ctor.rounding;
977
+ if (y.eq(1))
978
+ return finalise(x, pr, rm);
979
+ e = mathfloor(y.e / LOG_BASE);
980
+ if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
981
+ r = intPow(Ctor, x, k, pr);
982
+ return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
983
+ }
984
+ s = x.s;
985
+ if (s < 0) {
986
+ if (e < y.d.length - 1)
987
+ return new Ctor(NaN);
988
+ if ((y.d[e] & 1) == 0)
989
+ s = 1;
990
+ if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
991
+ x.s = s;
992
+ return x;
993
+ }
994
+ }
995
+ k = mathpow(+x, yn);
996
+ e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
997
+ if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
998
+ return new Ctor(e > 0 ? s / 0 : 0);
999
+ external = false;
1000
+ Ctor.rounding = x.s = 1;
1001
+ k = Math.min(12, (e + "").length);
1002
+ r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
1003
+ if (r.d) {
1004
+ r = finalise(r, pr + 5, 1);
1005
+ if (checkRoundingDigits(r.d, pr, rm)) {
1006
+ e = pr + 10;
1007
+ r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
1008
+ if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
1009
+ r = finalise(r, pr + 1, 0);
1010
+ }
1011
+ }
1012
+ }
1013
+ r.s = s;
1014
+ external = true;
1015
+ Ctor.rounding = rm;
1016
+ return finalise(r, pr, rm);
1017
+ };
1018
+ P.toPrecision = function(sd, rm) {
1019
+ var str, x = this, Ctor = x.constructor;
1020
+ if (sd === void 0) {
1021
+ str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1022
+ } else {
1023
+ checkInt32(sd, 1, MAX_DIGITS);
1024
+ if (rm === void 0)
1025
+ rm = Ctor.rounding;
1026
+ else
1027
+ checkInt32(rm, 0, 8);
1028
+ x = finalise(new Ctor(x), sd, rm);
1029
+ str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
1030
+ }
1031
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
1032
+ };
1033
+ P.toSignificantDigits = P.toSD = function(sd, rm) {
1034
+ var x = this, Ctor = x.constructor;
1035
+ if (sd === void 0) {
1036
+ sd = Ctor.precision;
1037
+ rm = Ctor.rounding;
1038
+ } else {
1039
+ checkInt32(sd, 1, MAX_DIGITS);
1040
+ if (rm === void 0)
1041
+ rm = Ctor.rounding;
1042
+ else
1043
+ checkInt32(rm, 0, 8);
1044
+ }
1045
+ return finalise(new Ctor(x), sd, rm);
1046
+ };
1047
+ P.toString = function() {
1048
+ var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1049
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
1050
+ };
1051
+ P.truncated = P.trunc = function() {
1052
+ return finalise(new this.constructor(this), this.e + 1, 1);
1053
+ };
1054
+ P.valueOf = P.toJSON = function() {
1055
+ var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1056
+ return x.isNeg() ? "-" + str : str;
1057
+ };
1058
+ function digitsToString(d) {
1059
+ var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
1060
+ if (indexOfLastWord > 0) {
1061
+ str += w;
1062
+ for (i = 1; i < indexOfLastWord; i++) {
1063
+ ws = d[i] + "";
1064
+ k = LOG_BASE - ws.length;
1065
+ if (k)
1066
+ str += getZeroString(k);
1067
+ str += ws;
1068
+ }
1069
+ w = d[i];
1070
+ ws = w + "";
1071
+ k = LOG_BASE - ws.length;
1072
+ if (k)
1073
+ str += getZeroString(k);
1074
+ } else if (w === 0) {
1075
+ return "0";
1076
+ }
1077
+ for (; w % 10 === 0; )
1078
+ w /= 10;
1079
+ return str + w;
1080
+ }
1081
+ function checkInt32(i, min2, max2) {
1082
+ if (i !== ~~i || i < min2 || i > max2) {
1083
+ throw Error(invalidArgument + i);
1084
+ }
1085
+ }
1086
+ function checkRoundingDigits(d, i, rm, repeating) {
1087
+ var di, k, r, rd;
1088
+ for (k = d[0]; k >= 10; k /= 10)
1089
+ --i;
1090
+ if (--i < 0) {
1091
+ i += LOG_BASE;
1092
+ di = 0;
1093
+ } else {
1094
+ di = Math.ceil((i + 1) / LOG_BASE);
1095
+ i %= LOG_BASE;
1096
+ }
1097
+ k = mathpow(10, LOG_BASE - i);
1098
+ rd = d[di] % k | 0;
1099
+ if (repeating == null) {
1100
+ if (i < 3) {
1101
+ if (i == 0)
1102
+ rd = rd / 100 | 0;
1103
+ else if (i == 1)
1104
+ rd = rd / 10 | 0;
1105
+ r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
1106
+ } else {
1107
+ r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
1108
+ }
1109
+ } else {
1110
+ if (i < 4) {
1111
+ if (i == 0)
1112
+ rd = rd / 1e3 | 0;
1113
+ else if (i == 1)
1114
+ rd = rd / 100 | 0;
1115
+ else if (i == 2)
1116
+ rd = rd / 10 | 0;
1117
+ r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
1118
+ } else {
1119
+ r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
1120
+ }
1121
+ }
1122
+ return r;
1123
+ }
1124
+ function convertBase(str, baseIn, baseOut) {
1125
+ var j, arr = [0], arrL, i = 0, strL = str.length;
1126
+ for (; i < strL; ) {
1127
+ for (arrL = arr.length; arrL--; )
1128
+ arr[arrL] *= baseIn;
1129
+ arr[0] += NUMERALS.indexOf(str.charAt(i++));
1130
+ for (j = 0; j < arr.length; j++) {
1131
+ if (arr[j] > baseOut - 1) {
1132
+ if (arr[j + 1] === void 0)
1133
+ arr[j + 1] = 0;
1134
+ arr[j + 1] += arr[j] / baseOut | 0;
1135
+ arr[j] %= baseOut;
1136
+ }
1137
+ }
1138
+ }
1139
+ return arr.reverse();
1140
+ }
1141
+ function cosine(Ctor, x) {
1142
+ var k, len, y;
1143
+ if (x.isZero())
1144
+ return x;
1145
+ len = x.d.length;
1146
+ if (len < 32) {
1147
+ k = Math.ceil(len / 3);
1148
+ y = (1 / tinyPow(4, k)).toString();
1149
+ } else {
1150
+ k = 16;
1151
+ y = "2.3283064365386962890625e-10";
1152
+ }
1153
+ Ctor.precision += k;
1154
+ x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
1155
+ for (var i = k; i--; ) {
1156
+ var cos2x = x.times(x);
1157
+ x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
1158
+ }
1159
+ Ctor.precision -= k;
1160
+ return x;
1161
+ }
1162
+ var divide = /* @__PURE__ */ function() {
1163
+ function multiplyInteger(x, k, base) {
1164
+ var temp, carry = 0, i = x.length;
1165
+ for (x = x.slice(); i--; ) {
1166
+ temp = x[i] * k + carry;
1167
+ x[i] = temp % base | 0;
1168
+ carry = temp / base | 0;
1169
+ }
1170
+ if (carry)
1171
+ x.unshift(carry);
1172
+ return x;
1173
+ }
1174
+ function compare(a, b, aL, bL) {
1175
+ var i, r;
1176
+ if (aL != bL) {
1177
+ r = aL > bL ? 1 : -1;
1178
+ } else {
1179
+ for (i = r = 0; i < aL; i++) {
1180
+ if (a[i] != b[i]) {
1181
+ r = a[i] > b[i] ? 1 : -1;
1182
+ break;
1183
+ }
1184
+ }
1185
+ }
1186
+ return r;
1187
+ }
1188
+ function subtract(a, b, aL, base) {
1189
+ var i = 0;
1190
+ for (; aL--; ) {
1191
+ a[aL] -= i;
1192
+ i = a[aL] < b[aL] ? 1 : 0;
1193
+ a[aL] = i * base + a[aL] - b[aL];
1194
+ }
1195
+ for (; !a[0] && a.length > 1; )
1196
+ a.shift();
1197
+ }
1198
+ return function(x, y, pr, rm, dp, base) {
1199
+ var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
1200
+ if (!xd || !xd[0] || !yd || !yd[0]) {
1201
+ return new Ctor(
1202
+ // Return NaN if either NaN, or both Infinity or 0.
1203
+ !x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
1204
+ // Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
1205
+ xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
1206
+ )
1207
+ );
1208
+ }
1209
+ if (base) {
1210
+ logBase = 1;
1211
+ e = x.e - y.e;
1212
+ } else {
1213
+ base = BASE;
1214
+ logBase = LOG_BASE;
1215
+ e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
1216
+ }
1217
+ yL = yd.length;
1218
+ xL = xd.length;
1219
+ q = new Ctor(sign2);
1220
+ qd = q.d = [];
1221
+ for (i = 0; yd[i] == (xd[i] || 0); i++)
1222
+ ;
1223
+ if (yd[i] > (xd[i] || 0))
1224
+ e--;
1225
+ if (pr == null) {
1226
+ sd = pr = Ctor.precision;
1227
+ rm = Ctor.rounding;
1228
+ } else if (dp) {
1229
+ sd = pr + (x.e - y.e) + 1;
1230
+ } else {
1231
+ sd = pr;
1232
+ }
1233
+ if (sd < 0) {
1234
+ qd.push(1);
1235
+ more = true;
1236
+ } else {
1237
+ sd = sd / logBase + 2 | 0;
1238
+ i = 0;
1239
+ if (yL == 1) {
1240
+ k = 0;
1241
+ yd = yd[0];
1242
+ sd++;
1243
+ for (; (i < xL || k) && sd--; i++) {
1244
+ t = k * base + (xd[i] || 0);
1245
+ qd[i] = t / yd | 0;
1246
+ k = t % yd | 0;
1247
+ }
1248
+ more = k || i < xL;
1249
+ } else {
1250
+ k = base / (yd[0] + 1) | 0;
1251
+ if (k > 1) {
1252
+ yd = multiplyInteger(yd, k, base);
1253
+ xd = multiplyInteger(xd, k, base);
1254
+ yL = yd.length;
1255
+ xL = xd.length;
1256
+ }
1257
+ xi = yL;
1258
+ rem = xd.slice(0, yL);
1259
+ remL = rem.length;
1260
+ for (; remL < yL; )
1261
+ rem[remL++] = 0;
1262
+ yz = yd.slice();
1263
+ yz.unshift(0);
1264
+ yd0 = yd[0];
1265
+ if (yd[1] >= base / 2)
1266
+ ++yd0;
1267
+ do {
1268
+ k = 0;
1269
+ cmp = compare(yd, rem, yL, remL);
1270
+ if (cmp < 0) {
1271
+ rem0 = rem[0];
1272
+ if (yL != remL)
1273
+ rem0 = rem0 * base + (rem[1] || 0);
1274
+ k = rem0 / yd0 | 0;
1275
+ if (k > 1) {
1276
+ if (k >= base)
1277
+ k = base - 1;
1278
+ prod = multiplyInteger(yd, k, base);
1279
+ prodL = prod.length;
1280
+ remL = rem.length;
1281
+ cmp = compare(prod, rem, prodL, remL);
1282
+ if (cmp == 1) {
1283
+ k--;
1284
+ subtract(prod, yL < prodL ? yz : yd, prodL, base);
1285
+ }
1286
+ } else {
1287
+ if (k == 0)
1288
+ cmp = k = 1;
1289
+ prod = yd.slice();
1290
+ }
1291
+ prodL = prod.length;
1292
+ if (prodL < remL)
1293
+ prod.unshift(0);
1294
+ subtract(rem, prod, remL, base);
1295
+ if (cmp == -1) {
1296
+ remL = rem.length;
1297
+ cmp = compare(yd, rem, yL, remL);
1298
+ if (cmp < 1) {
1299
+ k++;
1300
+ subtract(rem, yL < remL ? yz : yd, remL, base);
1301
+ }
1302
+ }
1303
+ remL = rem.length;
1304
+ } else if (cmp === 0) {
1305
+ k++;
1306
+ rem = [0];
1307
+ }
1308
+ qd[i++] = k;
1309
+ if (cmp && rem[0]) {
1310
+ rem[remL++] = xd[xi] || 0;
1311
+ } else {
1312
+ rem = [xd[xi]];
1313
+ remL = 1;
1314
+ }
1315
+ } while ((xi++ < xL || rem[0] !== void 0) && sd--);
1316
+ more = rem[0] !== void 0;
1317
+ }
1318
+ if (!qd[0])
1319
+ qd.shift();
1320
+ }
1321
+ if (logBase == 1) {
1322
+ q.e = e;
1323
+ inexact = more;
1324
+ } else {
1325
+ for (i = 1, k = qd[0]; k >= 10; k /= 10)
1326
+ i++;
1327
+ q.e = i + e * logBase - 1;
1328
+ finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
1329
+ }
1330
+ return q;
1331
+ };
1332
+ }();
1333
+ function finalise(x, sd, rm, isTruncated) {
1334
+ var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
1335
+ out:
1336
+ if (sd != null) {
1337
+ xd = x.d;
1338
+ if (!xd)
1339
+ return x;
1340
+ for (digits = 1, k = xd[0]; k >= 10; k /= 10)
1341
+ digits++;
1342
+ i = sd - digits;
1343
+ if (i < 0) {
1344
+ i += LOG_BASE;
1345
+ j = sd;
1346
+ w = xd[xdi = 0];
1347
+ rd = w / mathpow(10, digits - j - 1) % 10 | 0;
1348
+ } else {
1349
+ xdi = Math.ceil((i + 1) / LOG_BASE);
1350
+ k = xd.length;
1351
+ if (xdi >= k) {
1352
+ if (isTruncated) {
1353
+ for (; k++ <= xdi; )
1354
+ xd.push(0);
1355
+ w = rd = 0;
1356
+ digits = 1;
1357
+ i %= LOG_BASE;
1358
+ j = i - LOG_BASE + 1;
1359
+ } else {
1360
+ break out;
1361
+ }
1362
+ } else {
1363
+ w = k = xd[xdi];
1364
+ for (digits = 1; k >= 10; k /= 10)
1365
+ digits++;
1366
+ i %= LOG_BASE;
1367
+ j = i - LOG_BASE + digits;
1368
+ rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
1369
+ }
1370
+ }
1371
+ isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
1372
+ roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
1373
+ (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
1374
+ if (sd < 1 || !xd[0]) {
1375
+ xd.length = 0;
1376
+ if (roundUp) {
1377
+ sd -= x.e + 1;
1378
+ xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
1379
+ x.e = -sd || 0;
1380
+ } else {
1381
+ xd[0] = x.e = 0;
1382
+ }
1383
+ return x;
1384
+ }
1385
+ if (i == 0) {
1386
+ xd.length = xdi;
1387
+ k = 1;
1388
+ xdi--;
1389
+ } else {
1390
+ xd.length = xdi + 1;
1391
+ k = mathpow(10, LOG_BASE - i);
1392
+ xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
1393
+ }
1394
+ if (roundUp) {
1395
+ for (; ; ) {
1396
+ if (xdi == 0) {
1397
+ for (i = 1, j = xd[0]; j >= 10; j /= 10)
1398
+ i++;
1399
+ j = xd[0] += k;
1400
+ for (k = 1; j >= 10; j /= 10)
1401
+ k++;
1402
+ if (i != k) {
1403
+ x.e++;
1404
+ if (xd[0] == BASE)
1405
+ xd[0] = 1;
1406
+ }
1407
+ break;
1408
+ } else {
1409
+ xd[xdi] += k;
1410
+ if (xd[xdi] != BASE)
1411
+ break;
1412
+ xd[xdi--] = 0;
1413
+ k = 1;
1414
+ }
1415
+ }
1416
+ }
1417
+ for (i = xd.length; xd[--i] === 0; )
1418
+ xd.pop();
1419
+ }
1420
+ if (external) {
1421
+ if (x.e > Ctor.maxE) {
1422
+ x.d = null;
1423
+ x.e = NaN;
1424
+ } else if (x.e < Ctor.minE) {
1425
+ x.e = 0;
1426
+ x.d = [0];
1427
+ }
1428
+ }
1429
+ return x;
1430
+ }
1431
+ function finiteToString(x, isExp, sd) {
1432
+ if (!x.isFinite())
1433
+ return nonFiniteToString(x);
1434
+ var k, e = x.e, str = digitsToString(x.d), len = str.length;
1435
+ if (isExp) {
1436
+ if (sd && (k = sd - len) > 0) {
1437
+ str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
1438
+ } else if (len > 1) {
1439
+ str = str.charAt(0) + "." + str.slice(1);
1440
+ }
1441
+ str = str + (x.e < 0 ? "e" : "e+") + x.e;
1442
+ } else if (e < 0) {
1443
+ str = "0." + getZeroString(-e - 1) + str;
1444
+ if (sd && (k = sd - len) > 0)
1445
+ str += getZeroString(k);
1446
+ } else if (e >= len) {
1447
+ str += getZeroString(e + 1 - len);
1448
+ if (sd && (k = sd - e - 1) > 0)
1449
+ str = str + "." + getZeroString(k);
1450
+ } else {
1451
+ if ((k = e + 1) < len)
1452
+ str = str.slice(0, k) + "." + str.slice(k);
1453
+ if (sd && (k = sd - len) > 0) {
1454
+ if (e + 1 === len)
1455
+ str += ".";
1456
+ str += getZeroString(k);
1457
+ }
1458
+ }
1459
+ return str;
1460
+ }
1461
+ function getBase10Exponent(digits, e) {
1462
+ var w = digits[0];
1463
+ for (e *= LOG_BASE; w >= 10; w /= 10)
1464
+ e++;
1465
+ return e;
1466
+ }
1467
+ function getLn10(Ctor, sd, pr) {
1468
+ if (sd > LN10_PRECISION) {
1469
+ external = true;
1470
+ if (pr)
1471
+ Ctor.precision = pr;
1472
+ throw Error(precisionLimitExceeded);
1473
+ }
1474
+ return finalise(new Ctor(LN10), sd, 1, true);
1475
+ }
1476
+ function getPi(Ctor, sd, rm) {
1477
+ if (sd > PI_PRECISION)
1478
+ throw Error(precisionLimitExceeded);
1479
+ return finalise(new Ctor(PI), sd, rm, true);
1480
+ }
1481
+ function getPrecision(digits) {
1482
+ var w = digits.length - 1, len = w * LOG_BASE + 1;
1483
+ w = digits[w];
1484
+ if (w) {
1485
+ for (; w % 10 == 0; w /= 10)
1486
+ len--;
1487
+ for (w = digits[0]; w >= 10; w /= 10)
1488
+ len++;
1489
+ }
1490
+ return len;
1491
+ }
1492
+ function getZeroString(k) {
1493
+ var zs = "";
1494
+ for (; k--; )
1495
+ zs += "0";
1496
+ return zs;
1497
+ }
1498
+ function intPow(Ctor, x, n, pr) {
1499
+ var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
1500
+ external = false;
1501
+ for (; ; ) {
1502
+ if (n % 2) {
1503
+ r = r.times(x);
1504
+ if (truncate(r.d, k))
1505
+ isTruncated = true;
1506
+ }
1507
+ n = mathfloor(n / 2);
1508
+ if (n === 0) {
1509
+ n = r.d.length - 1;
1510
+ if (isTruncated && r.d[n] === 0)
1511
+ ++r.d[n];
1512
+ break;
1513
+ }
1514
+ x = x.times(x);
1515
+ truncate(x.d, k);
1516
+ }
1517
+ external = true;
1518
+ return r;
1519
+ }
1520
+ function isOdd(n) {
1521
+ return n.d[n.d.length - 1] & 1;
1522
+ }
1523
+ function maxOrMin(Ctor, args, ltgt) {
1524
+ var y, x = new Ctor(args[0]), i = 0;
1525
+ for (; ++i < args.length; ) {
1526
+ y = new Ctor(args[i]);
1527
+ if (!y.s) {
1528
+ x = y;
1529
+ break;
1530
+ } else if (x[ltgt](y)) {
1531
+ x = y;
1532
+ }
1533
+ }
1534
+ return x;
1535
+ }
1536
+ function naturalExponential(x, sd) {
1537
+ var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1538
+ if (!x.d || !x.d[0] || x.e > 17) {
1539
+ return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
1540
+ }
1541
+ if (sd == null) {
1542
+ external = false;
1543
+ wpr = pr;
1544
+ } else {
1545
+ wpr = sd;
1546
+ }
1547
+ t = new Ctor(0.03125);
1548
+ while (x.e > -2) {
1549
+ x = x.times(t);
1550
+ k += 5;
1551
+ }
1552
+ guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1553
+ wpr += guard;
1554
+ denominator = pow2 = sum2 = new Ctor(1);
1555
+ Ctor.precision = wpr;
1556
+ for (; ; ) {
1557
+ pow2 = finalise(pow2.times(x), wpr, 1);
1558
+ denominator = denominator.times(++i);
1559
+ t = sum2.plus(divide(pow2, denominator, wpr, 1));
1560
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1561
+ j = k;
1562
+ while (j--)
1563
+ sum2 = finalise(sum2.times(sum2), wpr, 1);
1564
+ if (sd == null) {
1565
+ if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1566
+ Ctor.precision = wpr += 10;
1567
+ denominator = pow2 = t = new Ctor(1);
1568
+ i = 0;
1569
+ rep++;
1570
+ } else {
1571
+ return finalise(sum2, Ctor.precision = pr, rm, external = true);
1572
+ }
1573
+ } else {
1574
+ Ctor.precision = pr;
1575
+ return sum2;
1576
+ }
1577
+ }
1578
+ sum2 = t;
1579
+ }
1580
+ }
1581
+ function naturalLogarithm(y, sd) {
1582
+ var c, c0, denominator, e, numerator, rep, sum2, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1583
+ if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
1584
+ return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
1585
+ }
1586
+ if (sd == null) {
1587
+ external = false;
1588
+ wpr = pr;
1589
+ } else {
1590
+ wpr = sd;
1591
+ }
1592
+ Ctor.precision = wpr += guard;
1593
+ c = digitsToString(xd);
1594
+ c0 = c.charAt(0);
1595
+ if (Math.abs(e = x.e) < 15e14) {
1596
+ while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
1597
+ x = x.times(y);
1598
+ c = digitsToString(x.d);
1599
+ c0 = c.charAt(0);
1600
+ n++;
1601
+ }
1602
+ e = x.e;
1603
+ if (c0 > 1) {
1604
+ x = new Ctor("0." + c);
1605
+ e++;
1606
+ } else {
1607
+ x = new Ctor(c0 + "." + c.slice(1));
1608
+ }
1609
+ } else {
1610
+ t = getLn10(Ctor, wpr + 2, pr).times(e + "");
1611
+ x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
1612
+ Ctor.precision = pr;
1613
+ return sd == null ? finalise(x, pr, rm, external = true) : x;
1614
+ }
1615
+ x1 = x;
1616
+ sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
1617
+ x2 = finalise(x.times(x), wpr, 1);
1618
+ denominator = 3;
1619
+ for (; ; ) {
1620
+ numerator = finalise(numerator.times(x2), wpr, 1);
1621
+ t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
1622
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1623
+ sum2 = sum2.times(2);
1624
+ if (e !== 0)
1625
+ sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
1626
+ sum2 = divide(sum2, new Ctor(n), wpr, 1);
1627
+ if (sd == null) {
1628
+ if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1629
+ Ctor.precision = wpr += guard;
1630
+ t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
1631
+ x2 = finalise(x.times(x), wpr, 1);
1632
+ denominator = rep = 1;
1633
+ } else {
1634
+ return finalise(sum2, Ctor.precision = pr, rm, external = true);
1635
+ }
1636
+ } else {
1637
+ Ctor.precision = pr;
1638
+ return sum2;
1639
+ }
1640
+ }
1641
+ sum2 = t;
1642
+ denominator += 2;
1643
+ }
1644
+ }
1645
+ function nonFiniteToString(x) {
1646
+ return String(x.s * x.s / 0);
1647
+ }
1648
+ function parseDecimal(x, str) {
1649
+ var e, i, len;
1650
+ if ((e = str.indexOf(".")) > -1)
1651
+ str = str.replace(".", "");
1652
+ if ((i = str.search(/e/i)) > 0) {
1653
+ if (e < 0)
1654
+ e = i;
1655
+ e += +str.slice(i + 1);
1656
+ str = str.substring(0, i);
1657
+ } else if (e < 0) {
1658
+ e = str.length;
1659
+ }
1660
+ for (i = 0; str.charCodeAt(i) === 48; i++)
1661
+ ;
1662
+ for (len = str.length; str.charCodeAt(len - 1) === 48; --len)
1663
+ ;
1664
+ str = str.slice(i, len);
1665
+ if (str) {
1666
+ len -= i;
1667
+ x.e = e = e - i - 1;
1668
+ x.d = [];
1669
+ i = (e + 1) % LOG_BASE;
1670
+ if (e < 0)
1671
+ i += LOG_BASE;
1672
+ if (i < len) {
1673
+ if (i)
1674
+ x.d.push(+str.slice(0, i));
1675
+ for (len -= LOG_BASE; i < len; )
1676
+ x.d.push(+str.slice(i, i += LOG_BASE));
1677
+ str = str.slice(i);
1678
+ i = LOG_BASE - str.length;
1679
+ } else {
1680
+ i -= len;
1681
+ }
1682
+ for (; i--; )
1683
+ str += "0";
1684
+ x.d.push(+str);
1685
+ if (external) {
1686
+ if (x.e > x.constructor.maxE) {
1687
+ x.d = null;
1688
+ x.e = NaN;
1689
+ } else if (x.e < x.constructor.minE) {
1690
+ x.e = 0;
1691
+ x.d = [0];
1692
+ }
1693
+ }
1694
+ } else {
1695
+ x.e = 0;
1696
+ x.d = [0];
1697
+ }
1698
+ return x;
1699
+ }
1700
+ function parseOther(x, str) {
1701
+ var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
1702
+ if (str.indexOf("_") > -1) {
1703
+ str = str.replace(/(\d)_(?=\d)/g, "$1");
1704
+ if (isDecimal.test(str))
1705
+ return parseDecimal(x, str);
1706
+ } else if (str === "Infinity" || str === "NaN") {
1707
+ if (!+str)
1708
+ x.s = NaN;
1709
+ x.e = NaN;
1710
+ x.d = null;
1711
+ return x;
1712
+ }
1713
+ if (isHex.test(str)) {
1714
+ base = 16;
1715
+ str = str.toLowerCase();
1716
+ } else if (isBinary.test(str)) {
1717
+ base = 2;
1718
+ } else if (isOctal.test(str)) {
1719
+ base = 8;
1720
+ } else {
1721
+ throw Error(invalidArgument + str);
1722
+ }
1723
+ i = str.search(/p/i);
1724
+ if (i > 0) {
1725
+ p = +str.slice(i + 1);
1726
+ str = str.substring(2, i);
1727
+ } else {
1728
+ str = str.slice(2);
1729
+ }
1730
+ i = str.indexOf(".");
1731
+ isFloat = i >= 0;
1732
+ Ctor = x.constructor;
1733
+ if (isFloat) {
1734
+ str = str.replace(".", "");
1735
+ len = str.length;
1736
+ i = len - i;
1737
+ divisor = intPow(Ctor, new Ctor(base), i, i * 2);
1738
+ }
1739
+ xd = convertBase(str, base, BASE);
1740
+ xe = xd.length - 1;
1741
+ for (i = xe; xd[i] === 0; --i)
1742
+ xd.pop();
1743
+ if (i < 0)
1744
+ return new Ctor(x.s * 0);
1745
+ x.e = getBase10Exponent(xd, xe);
1746
+ x.d = xd;
1747
+ external = false;
1748
+ if (isFloat)
1749
+ x = divide(x, divisor, len * 4);
1750
+ if (p)
1751
+ x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
1752
+ external = true;
1753
+ return x;
1754
+ }
1755
+ function sine(Ctor, x) {
1756
+ var k, len = x.d.length;
1757
+ if (len < 3) {
1758
+ return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
1759
+ }
1760
+ k = 1.4 * Math.sqrt(len);
1761
+ k = k > 16 ? 16 : k | 0;
1762
+ x = x.times(1 / tinyPow(5, k));
1763
+ x = taylorSeries(Ctor, 2, x, x);
1764
+ var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
1765
+ for (; k--; ) {
1766
+ sin2_x = x.times(x);
1767
+ x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
1768
+ }
1769
+ return x;
1770
+ }
1771
+ function taylorSeries(Ctor, n, x, y, isHyperbolic) {
1772
+ var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
1773
+ external = false;
1774
+ x2 = x.times(x);
1775
+ u = new Ctor(y);
1776
+ for (; ; ) {
1777
+ t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
1778
+ u = isHyperbolic ? y.plus(t) : y.minus(t);
1779
+ y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
1780
+ t = u.plus(y);
1781
+ if (t.d[k] !== void 0) {
1782
+ for (j = k; t.d[j] === u.d[j] && j--; )
1783
+ ;
1784
+ if (j == -1)
1785
+ break;
1786
+ }
1787
+ j = u;
1788
+ u = y;
1789
+ y = t;
1790
+ t = j;
1791
+ i++;
1792
+ }
1793
+ external = true;
1794
+ t.d.length = k + 1;
1795
+ return t;
1796
+ }
1797
+ function tinyPow(b, e) {
1798
+ var n = b;
1799
+ while (--e)
1800
+ n *= b;
1801
+ return n;
1802
+ }
1803
+ function toLessThanHalfPi(Ctor, x) {
1804
+ var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
1805
+ x = x.abs();
1806
+ if (x.lte(halfPi)) {
1807
+ quadrant = isNeg ? 4 : 1;
1808
+ return x;
1809
+ }
1810
+ t = x.divToInt(pi);
1811
+ if (t.isZero()) {
1812
+ quadrant = isNeg ? 3 : 2;
1813
+ } else {
1814
+ x = x.minus(t.times(pi));
1815
+ if (x.lte(halfPi)) {
1816
+ quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
1817
+ return x;
1818
+ }
1819
+ quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
1820
+ }
1821
+ return x.minus(pi).abs();
1822
+ }
1823
+ function toStringBinary(x, baseOut, sd, rm) {
1824
+ var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
1825
+ if (isExp) {
1826
+ checkInt32(sd, 1, MAX_DIGITS);
1827
+ if (rm === void 0)
1828
+ rm = Ctor.rounding;
1829
+ else
1830
+ checkInt32(rm, 0, 8);
1831
+ } else {
1832
+ sd = Ctor.precision;
1833
+ rm = Ctor.rounding;
1834
+ }
1835
+ if (!x.isFinite()) {
1836
+ str = nonFiniteToString(x);
1837
+ } else {
1838
+ str = finiteToString(x);
1839
+ i = str.indexOf(".");
1840
+ if (isExp) {
1841
+ base = 2;
1842
+ if (baseOut == 16) {
1843
+ sd = sd * 4 - 3;
1844
+ } else if (baseOut == 8) {
1845
+ sd = sd * 3 - 2;
1846
+ }
1847
+ } else {
1848
+ base = baseOut;
1849
+ }
1850
+ if (i >= 0) {
1851
+ str = str.replace(".", "");
1852
+ y = new Ctor(1);
1853
+ y.e = str.length - i;
1854
+ y.d = convertBase(finiteToString(y), 10, base);
1855
+ y.e = y.d.length;
1856
+ }
1857
+ xd = convertBase(str, 10, base);
1858
+ e = len = xd.length;
1859
+ for (; xd[--len] == 0; )
1860
+ xd.pop();
1861
+ if (!xd[0]) {
1862
+ str = isExp ? "0p+0" : "0";
1863
+ } else {
1864
+ if (i < 0) {
1865
+ e--;
1866
+ } else {
1867
+ x = new Ctor(x);
1868
+ x.d = xd;
1869
+ x.e = e;
1870
+ x = divide(x, y, sd, rm, 0, base);
1871
+ xd = x.d;
1872
+ e = x.e;
1873
+ roundUp = inexact;
1874
+ }
1875
+ i = xd[sd];
1876
+ k = base / 2;
1877
+ roundUp = roundUp || xd[sd + 1] !== void 0;
1878
+ roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
1879
+ xd.length = sd;
1880
+ if (roundUp) {
1881
+ for (; ++xd[--sd] > base - 1; ) {
1882
+ xd[sd] = 0;
1883
+ if (!sd) {
1884
+ ++e;
1885
+ xd.unshift(1);
1886
+ }
1887
+ }
1888
+ }
1889
+ for (len = xd.length; !xd[len - 1]; --len)
1890
+ ;
1891
+ for (i = 0, str = ""; i < len; i++)
1892
+ str += NUMERALS.charAt(xd[i]);
1893
+ if (isExp) {
1894
+ if (len > 1) {
1895
+ if (baseOut == 16 || baseOut == 8) {
1896
+ i = baseOut == 16 ? 4 : 3;
1897
+ for (--len; len % i; len++)
1898
+ str += "0";
1899
+ xd = convertBase(str, base, baseOut);
1900
+ for (len = xd.length; !xd[len - 1]; --len)
1901
+ ;
1902
+ for (i = 1, str = "1."; i < len; i++)
1903
+ str += NUMERALS.charAt(xd[i]);
1904
+ } else {
1905
+ str = str.charAt(0) + "." + str.slice(1);
1906
+ }
1907
+ }
1908
+ str = str + (e < 0 ? "p" : "p+") + e;
1909
+ } else if (e < 0) {
1910
+ for (; ++e; )
1911
+ str = "0" + str;
1912
+ str = "0." + str;
1913
+ } else {
1914
+ if (++e > len)
1915
+ for (e -= len; e--; )
1916
+ str += "0";
1917
+ else if (e < len)
1918
+ str = str.slice(0, e) + "." + str.slice(e);
1919
+ }
1920
+ }
1921
+ str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
1922
+ }
1923
+ return x.s < 0 ? "-" + str : str;
1924
+ }
1925
+ function truncate(arr, len) {
1926
+ if (arr.length > len) {
1927
+ arr.length = len;
1928
+ return true;
1929
+ }
1930
+ }
1931
+ function abs(x) {
1932
+ return new this(x).abs();
1933
+ }
1934
+ function acos(x) {
1935
+ return new this(x).acos();
1936
+ }
1937
+ function acosh(x) {
1938
+ return new this(x).acosh();
1939
+ }
1940
+ function add(x, y) {
1941
+ return new this(x).plus(y);
1942
+ }
1943
+ function asin(x) {
1944
+ return new this(x).asin();
1945
+ }
1946
+ function asinh(x) {
1947
+ return new this(x).asinh();
1948
+ }
1949
+ function atan(x) {
1950
+ return new this(x).atan();
1951
+ }
1952
+ function atanh(x) {
1953
+ return new this(x).atanh();
1954
+ }
1955
+ function atan2(y, x) {
1956
+ y = new this(y);
1957
+ x = new this(x);
1958
+ var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
1959
+ if (!y.s || !x.s) {
1960
+ r = new this(NaN);
1961
+ } else if (!y.d && !x.d) {
1962
+ r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
1963
+ r.s = y.s;
1964
+ } else if (!x.d || y.isZero()) {
1965
+ r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
1966
+ r.s = y.s;
1967
+ } else if (!y.d || x.isZero()) {
1968
+ r = getPi(this, wpr, 1).times(0.5);
1969
+ r.s = y.s;
1970
+ } else if (x.s < 0) {
1971
+ this.precision = wpr;
1972
+ this.rounding = 1;
1973
+ r = this.atan(divide(y, x, wpr, 1));
1974
+ x = getPi(this, wpr, 1);
1975
+ this.precision = pr;
1976
+ this.rounding = rm;
1977
+ r = y.s < 0 ? r.minus(x) : r.plus(x);
1978
+ } else {
1979
+ r = this.atan(divide(y, x, wpr, 1));
1980
+ }
1981
+ return r;
1982
+ }
1983
+ function cbrt(x) {
1984
+ return new this(x).cbrt();
1985
+ }
1986
+ function ceil(x) {
1987
+ return finalise(x = new this(x), x.e + 1, 2);
1988
+ }
1989
+ function clamp(x, min2, max2) {
1990
+ return new this(x).clamp(min2, max2);
1991
+ }
1992
+ function config(obj) {
1993
+ if (!obj || typeof obj !== "object")
1994
+ throw Error(decimalError + "Object expected");
1995
+ var i, p, v, useDefaults = obj.defaults === true, ps = [
1996
+ "precision",
1997
+ 1,
1998
+ MAX_DIGITS,
1999
+ "rounding",
2000
+ 0,
2001
+ 8,
2002
+ "toExpNeg",
2003
+ -EXP_LIMIT,
2004
+ 0,
2005
+ "toExpPos",
2006
+ 0,
2007
+ EXP_LIMIT,
2008
+ "maxE",
2009
+ 0,
2010
+ EXP_LIMIT,
2011
+ "minE",
2012
+ -EXP_LIMIT,
2013
+ 0,
2014
+ "modulo",
2015
+ 0,
2016
+ 9
2017
+ ];
2018
+ for (i = 0; i < ps.length; i += 3) {
2019
+ if (p = ps[i], useDefaults)
2020
+ this[p] = DEFAULTS[p];
2021
+ if ((v = obj[p]) !== void 0) {
2022
+ if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
2023
+ this[p] = v;
2024
+ else
2025
+ throw Error(invalidArgument + p + ": " + v);
2026
+ }
2027
+ }
2028
+ if (p = "crypto", useDefaults)
2029
+ this[p] = DEFAULTS[p];
2030
+ if ((v = obj[p]) !== void 0) {
2031
+ if (v === true || v === false || v === 0 || v === 1) {
2032
+ if (v) {
2033
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
2034
+ this[p] = true;
2035
+ } else {
2036
+ throw Error(cryptoUnavailable);
2037
+ }
2038
+ } else {
2039
+ this[p] = false;
2040
+ }
2041
+ } else {
2042
+ throw Error(invalidArgument + p + ": " + v);
2043
+ }
2044
+ }
2045
+ return this;
2046
+ }
2047
+ function cos(x) {
2048
+ return new this(x).cos();
2049
+ }
2050
+ function cosh(x) {
2051
+ return new this(x).cosh();
2052
+ }
2053
+ function clone(obj) {
2054
+ var i, p, ps;
2055
+ function Decimal2(v) {
2056
+ var e, i2, t, x = this;
2057
+ if (!(x instanceof Decimal2))
2058
+ return new Decimal2(v);
2059
+ x.constructor = Decimal2;
2060
+ if (isDecimalInstance(v)) {
2061
+ x.s = v.s;
2062
+ if (external) {
2063
+ if (!v.d || v.e > Decimal2.maxE) {
2064
+ x.e = NaN;
2065
+ x.d = null;
2066
+ } else if (v.e < Decimal2.minE) {
2067
+ x.e = 0;
2068
+ x.d = [0];
2069
+ } else {
2070
+ x.e = v.e;
2071
+ x.d = v.d.slice();
2072
+ }
2073
+ } else {
2074
+ x.e = v.e;
2075
+ x.d = v.d ? v.d.slice() : v.d;
2076
+ }
2077
+ return;
2078
+ }
2079
+ t = typeof v;
2080
+ if (t === "number") {
2081
+ if (v === 0) {
2082
+ x.s = 1 / v < 0 ? -1 : 1;
2083
+ x.e = 0;
2084
+ x.d = [0];
2085
+ return;
2086
+ }
2087
+ if (v < 0) {
2088
+ v = -v;
2089
+ x.s = -1;
2090
+ } else {
2091
+ x.s = 1;
2092
+ }
2093
+ if (v === ~~v && v < 1e7) {
2094
+ for (e = 0, i2 = v; i2 >= 10; i2 /= 10)
2095
+ e++;
2096
+ if (external) {
2097
+ if (e > Decimal2.maxE) {
2098
+ x.e = NaN;
2099
+ x.d = null;
2100
+ } else if (e < Decimal2.minE) {
2101
+ x.e = 0;
2102
+ x.d = [0];
2103
+ } else {
2104
+ x.e = e;
2105
+ x.d = [v];
2106
+ }
2107
+ } else {
2108
+ x.e = e;
2109
+ x.d = [v];
2110
+ }
2111
+ return;
2112
+ } else if (v * 0 !== 0) {
2113
+ if (!v)
2114
+ x.s = NaN;
2115
+ x.e = NaN;
2116
+ x.d = null;
2117
+ return;
2118
+ }
2119
+ return parseDecimal(x, v.toString());
2120
+ } else if (t !== "string") {
2121
+ throw Error(invalidArgument + v);
2122
+ }
2123
+ if ((i2 = v.charCodeAt(0)) === 45) {
2124
+ v = v.slice(1);
2125
+ x.s = -1;
2126
+ } else {
2127
+ if (i2 === 43)
2128
+ v = v.slice(1);
2129
+ x.s = 1;
2130
+ }
2131
+ return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
2132
+ }
2133
+ Decimal2.prototype = P;
2134
+ Decimal2.ROUND_UP = 0;
2135
+ Decimal2.ROUND_DOWN = 1;
2136
+ Decimal2.ROUND_CEIL = 2;
2137
+ Decimal2.ROUND_FLOOR = 3;
2138
+ Decimal2.ROUND_HALF_UP = 4;
2139
+ Decimal2.ROUND_HALF_DOWN = 5;
2140
+ Decimal2.ROUND_HALF_EVEN = 6;
2141
+ Decimal2.ROUND_HALF_CEIL = 7;
2142
+ Decimal2.ROUND_HALF_FLOOR = 8;
2143
+ Decimal2.EUCLID = 9;
2144
+ Decimal2.config = Decimal2.set = config;
2145
+ Decimal2.clone = clone;
2146
+ Decimal2.isDecimal = isDecimalInstance;
2147
+ Decimal2.abs = abs;
2148
+ Decimal2.acos = acos;
2149
+ Decimal2.acosh = acosh;
2150
+ Decimal2.add = add;
2151
+ Decimal2.asin = asin;
2152
+ Decimal2.asinh = asinh;
2153
+ Decimal2.atan = atan;
2154
+ Decimal2.atanh = atanh;
2155
+ Decimal2.atan2 = atan2;
2156
+ Decimal2.cbrt = cbrt;
2157
+ Decimal2.ceil = ceil;
2158
+ Decimal2.clamp = clamp;
2159
+ Decimal2.cos = cos;
2160
+ Decimal2.cosh = cosh;
2161
+ Decimal2.div = div;
2162
+ Decimal2.exp = exp;
2163
+ Decimal2.floor = floor;
2164
+ Decimal2.hypot = hypot;
2165
+ Decimal2.ln = ln;
2166
+ Decimal2.log = log;
2167
+ Decimal2.log10 = log10;
2168
+ Decimal2.log2 = log2;
2169
+ Decimal2.max = max;
2170
+ Decimal2.min = min;
2171
+ Decimal2.mod = mod;
2172
+ Decimal2.mul = mul;
2173
+ Decimal2.pow = pow;
2174
+ Decimal2.random = random;
2175
+ Decimal2.round = round;
2176
+ Decimal2.sign = sign;
2177
+ Decimal2.sin = sin;
2178
+ Decimal2.sinh = sinh;
2179
+ Decimal2.sqrt = sqrt;
2180
+ Decimal2.sub = sub;
2181
+ Decimal2.sum = sum;
2182
+ Decimal2.tan = tan;
2183
+ Decimal2.tanh = tanh;
2184
+ Decimal2.trunc = trunc;
2185
+ if (obj === void 0)
2186
+ obj = {};
2187
+ if (obj) {
2188
+ if (obj.defaults !== true) {
2189
+ ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
2190
+ for (i = 0; i < ps.length; )
2191
+ if (!obj.hasOwnProperty(p = ps[i++]))
2192
+ obj[p] = this[p];
2193
+ }
2194
+ }
2195
+ Decimal2.config(obj);
2196
+ return Decimal2;
2197
+ }
2198
+ function div(x, y) {
2199
+ return new this(x).div(y);
2200
+ }
2201
+ function exp(x) {
2202
+ return new this(x).exp();
2203
+ }
2204
+ function floor(x) {
2205
+ return finalise(x = new this(x), x.e + 1, 3);
2206
+ }
2207
+ function hypot() {
2208
+ var i, n, t = new this(0);
2209
+ external = false;
2210
+ for (i = 0; i < arguments.length; ) {
2211
+ n = new this(arguments[i++]);
2212
+ if (!n.d) {
2213
+ if (n.s) {
2214
+ external = true;
2215
+ return new this(1 / 0);
2216
+ }
2217
+ t = n;
2218
+ } else if (t.d) {
2219
+ t = t.plus(n.times(n));
2220
+ }
2221
+ }
2222
+ external = true;
2223
+ return t.sqrt();
2224
+ }
2225
+ function isDecimalInstance(obj) {
2226
+ return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
2227
+ }
2228
+ function ln(x) {
2229
+ return new this(x).ln();
2230
+ }
2231
+ function log(x, y) {
2232
+ return new this(x).log(y);
2233
+ }
2234
+ function log2(x) {
2235
+ return new this(x).log(2);
2236
+ }
2237
+ function log10(x) {
2238
+ return new this(x).log(10);
2239
+ }
2240
+ function max() {
2241
+ return maxOrMin(this, arguments, "lt");
2242
+ }
2243
+ function min() {
2244
+ return maxOrMin(this, arguments, "gt");
2245
+ }
2246
+ function mod(x, y) {
2247
+ return new this(x).mod(y);
2248
+ }
2249
+ function mul(x, y) {
2250
+ return new this(x).mul(y);
2251
+ }
2252
+ function pow(x, y) {
2253
+ return new this(x).pow(y);
2254
+ }
2255
+ function random(sd) {
2256
+ var d, e, k, n, i = 0, r = new this(1), rd = [];
2257
+ if (sd === void 0)
2258
+ sd = this.precision;
2259
+ else
2260
+ checkInt32(sd, 1, MAX_DIGITS);
2261
+ k = Math.ceil(sd / LOG_BASE);
2262
+ if (!this.crypto) {
2263
+ for (; i < k; )
2264
+ rd[i++] = Math.random() * 1e7 | 0;
2265
+ } else if (crypto.getRandomValues) {
2266
+ d = crypto.getRandomValues(new Uint32Array(k));
2267
+ for (; i < k; ) {
2268
+ n = d[i];
2269
+ if (n >= 429e7) {
2270
+ d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
2271
+ } else {
2272
+ rd[i++] = n % 1e7;
2273
+ }
2274
+ }
2275
+ } else if (crypto.randomBytes) {
2276
+ d = crypto.randomBytes(k *= 4);
2277
+ for (; i < k; ) {
2278
+ n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
2279
+ if (n >= 214e7) {
2280
+ crypto.randomBytes(4).copy(d, i);
2281
+ } else {
2282
+ rd.push(n % 1e7);
2283
+ i += 4;
2284
+ }
2285
+ }
2286
+ i = k / 4;
2287
+ } else {
2288
+ throw Error(cryptoUnavailable);
2289
+ }
2290
+ k = rd[--i];
2291
+ sd %= LOG_BASE;
2292
+ if (k && sd) {
2293
+ n = mathpow(10, LOG_BASE - sd);
2294
+ rd[i] = (k / n | 0) * n;
2295
+ }
2296
+ for (; rd[i] === 0; i--)
2297
+ rd.pop();
2298
+ if (i < 0) {
2299
+ e = 0;
2300
+ rd = [0];
2301
+ } else {
2302
+ e = -1;
2303
+ for (; rd[0] === 0; e -= LOG_BASE)
2304
+ rd.shift();
2305
+ for (k = 1, n = rd[0]; n >= 10; n /= 10)
2306
+ k++;
2307
+ if (k < LOG_BASE)
2308
+ e -= LOG_BASE - k;
2309
+ }
2310
+ r.e = e;
2311
+ r.d = rd;
2312
+ return r;
2313
+ }
2314
+ function round(x) {
2315
+ return finalise(x = new this(x), x.e + 1, this.rounding);
2316
+ }
2317
+ function sign(x) {
2318
+ x = new this(x);
2319
+ return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
2320
+ }
2321
+ function sin(x) {
2322
+ return new this(x).sin();
2323
+ }
2324
+ function sinh(x) {
2325
+ return new this(x).sinh();
2326
+ }
2327
+ function sqrt(x) {
2328
+ return new this(x).sqrt();
2329
+ }
2330
+ function sub(x, y) {
2331
+ return new this(x).sub(y);
2332
+ }
2333
+ function sum() {
2334
+ var i = 0, args = arguments, x = new this(args[i]);
2335
+ external = false;
2336
+ for (; x.s && ++i < args.length; )
2337
+ x = x.plus(args[i]);
2338
+ external = true;
2339
+ return finalise(x, this.precision, this.rounding);
2340
+ }
2341
+ function tan(x) {
2342
+ return new this(x).tan();
2343
+ }
2344
+ function tanh(x) {
2345
+ return new this(x).tanh();
2346
+ }
2347
+ function trunc(x) {
2348
+ return finalise(x = new this(x), x.e + 1, 1);
2349
+ }
2350
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
2351
+ P[Symbol.toStringTag] = "Decimal";
2352
+ var Decimal = P.constructor = clone(DEFAULTS);
2353
+ LN10 = new Decimal(LN10);
2354
+ PI = new Decimal(PI);
2355
+ var decimal_default = Decimal;
2356
+
2357
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/constants.js
2358
+ var TEN = new decimal_default(10);
2359
+ var ZERO = new decimal_default(0);
2360
+ var NEGATIVE_ZERO = new decimal_default(-0);
2361
+
7
2362
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/262.js
8
2363
  function ToString(o) {
9
2364
  if (typeof o === "symbol") {
@@ -13,21 +2368,18 @@
13
2368
  }
14
2369
  function ToNumber(val) {
15
2370
  if (val === void 0) {
16
- return NaN;
2371
+ return new Decimal(NaN);
17
2372
  }
18
2373
  if (val === null) {
19
- return 0;
2374
+ return ZERO;
20
2375
  }
21
2376
  if (typeof val === "boolean") {
22
- return val ? 1 : 0;
23
- }
24
- if (typeof val === "number") {
25
- return val;
2377
+ return new Decimal(val ? 1 : 0);
26
2378
  }
27
2379
  if (typeof val === "symbol" || typeof val === "bigint") {
28
2380
  throw new TypeError("Cannot convert symbol/bigint to number");
29
2381
  }
30
- return Number(val);
2382
+ return new Decimal(Number(val));
31
2383
  }
32
2384
  function ToObject(arg) {
33
2385
  if (arg == null) {
@@ -35,15 +2387,6 @@
35
2387
  }
36
2388
  return Object(arg);
37
2389
  }
38
- function SameValue(x, y) {
39
- if (Object.is) {
40
- return Object.is(x, y);
41
- }
42
- if (x === y) {
43
- return x !== 0 || 1 / x === 1 / y;
44
- }
45
- return x !== x && y !== y;
46
- }
47
2390
  function ArrayCreate(len) {
48
2391
  return new Array(len);
49
2392
  }
@@ -69,11 +2412,11 @@
69
2412
  if (typeof O !== "object") {
70
2413
  return false;
71
2414
  }
72
- var P = C.prototype;
73
- if (typeof P !== "object") {
2415
+ var P2 = C.prototype;
2416
+ if (typeof P2 !== "object") {
74
2417
  throw new TypeError("OrdinaryHasInstance called on an object with an invalid prototype property.");
75
2418
  }
76
- return Object.prototype.isPrototypeOf.call(P, O);
2419
+ return Object.prototype.isPrototypeOf.call(P2, O);
77
2420
  }
78
2421
 
79
2422
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/CoerceOptionsToObject.js
@@ -85,13 +2428,13 @@
85
2428
  }
86
2429
 
87
2430
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/DefaultNumberOption.js
88
- function DefaultNumberOption(inputVal, min, max, fallback) {
2431
+ function DefaultNumberOption(inputVal, min2, max2, fallback) {
89
2432
  if (inputVal === void 0) {
90
2433
  return fallback;
91
2434
  }
92
2435
  var val = Number(inputVal);
93
- if (isNaN(val) || val < min || val > max) {
94
- throw new RangeError("".concat(val, " is outside of range [").concat(min, ", ").concat(max, "]"));
2436
+ if (isNaN(val) || val < min2 || val > max2) {
2437
+ throw new RangeError("".concat(val, " is outside of range [").concat(min2, ", ").concat(max2, "]"));
95
2438
  }
96
2439
  return Math.floor(val);
97
2440
  }
@@ -231,70 +2574,18 @@
231
2574
  }
232
2575
  function IsWellFormedUnitIdentifier(unit) {
233
2576
  unit = toLowerCase(unit);
234
- if (IsSanctionedSimpleUnitIdentifier(unit)) {
235
- return true;
236
- }
237
- var units = unit.split("-per-");
238
- if (units.length !== 2) {
239
- return false;
240
- }
241
- var numerator = units[0], denominator = units[1];
242
- if (!IsSanctionedSimpleUnitIdentifier(numerator) || !IsSanctionedSimpleUnitIdentifier(denominator)) {
243
- return false;
244
- }
245
- return true;
246
- }
247
-
248
- // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/CollapseNumberRange.js
249
- var PART_TYPES_TO_COLLAPSE = /* @__PURE__ */ new Set([
250
- "unit",
251
- "exponentMinusSign",
252
- "minusSign",
253
- "plusSign",
254
- "percentSign",
255
- "exponentSeparator",
256
- "percent",
257
- "percentSign",
258
- "currency",
259
- "literal"
260
- ]);
261
- function CollapseNumberRange(numberFormat, result, _a) {
262
- var getInternalSlots2 = _a.getInternalSlots;
263
- var internalSlots = getInternalSlots2(numberFormat);
264
- var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
265
- var rangeSignRegex = new RegExp("s?[".concat(symbols.rangeSign, "]s?"));
266
- var rangeSignIndex = result.findIndex(function(r) {
267
- return r.type === "literal" && rangeSignRegex.test(r.value);
268
- });
269
- var prefixSignParts = [];
270
- for (var i = rangeSignIndex - 1; i >= 0; i--) {
271
- if (!PART_TYPES_TO_COLLAPSE.has(result[i].type)) {
272
- break;
273
- }
274
- prefixSignParts.unshift(result[i]);
275
- }
276
- if (Array.from(prefixSignParts.map(function(p) {
277
- return p.value;
278
- }).join("")).length > 1) {
279
- var newResult = Array.from(result);
280
- newResult.splice(rangeSignIndex - prefixSignParts.length, prefixSignParts.length);
281
- return newResult;
282
- }
283
- var suffixSignParts = [];
284
- for (var i = rangeSignIndex + 1; i < result.length; i++) {
285
- if (!PART_TYPES_TO_COLLAPSE.has(result[i].type)) {
286
- break;
287
- }
288
- suffixSignParts.push(result[i]);
2577
+ if (IsSanctionedSimpleUnitIdentifier(unit)) {
2578
+ return true;
289
2579
  }
290
- if (Array.from(suffixSignParts.map(function(p) {
291
- return p.value;
292
- }).join("")).length > 1) {
293
- var newResult = Array.from(result);
294
- newResult.splice(rangeSignIndex + 1, suffixSignParts.length);
295
- return newResult;
2580
+ var units = unit.split("-per-");
2581
+ if (units.length !== 2) {
2582
+ return false;
296
2583
  }
297
- return result;
2584
+ var numerator = units[0], denominator = units[1];
2585
+ if (!IsSanctionedSimpleUnitIdentifier(numerator) || !IsSanctionedSimpleUnitIdentifier(denominator)) {
2586
+ return false;
2587
+ }
2588
+ return true;
298
2589
  }
299
2590
 
300
2591
  // node_modules/.aspect_rules_js/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
@@ -403,9 +2694,6 @@
403
2694
  };
404
2695
 
405
2696
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/utils.js
406
- function getMagnitude(x) {
407
- return Math.floor(Math.log(x) * Math.LOG10E);
408
- }
409
2697
  function repeat(s, times) {
410
2698
  if (typeof s.repeat === "function") {
411
2699
  return s.repeat(times);
@@ -484,7 +2772,96 @@
484
2772
  strategy: strategies.variadic
485
2773
  });
486
2774
 
2775
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ApplyUnsignedRoundingMode.js
2776
+ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
2777
+ if (x.eq(r1))
2778
+ return r1;
2779
+ invariant(r1.lessThan(x) && x.lessThan(r2), "x should be between r1 and r2 but x=".concat(x, ", r1=").concat(r1, ", r2=").concat(r2));
2780
+ if (unsignedRoundingMode === "zero") {
2781
+ return r1;
2782
+ }
2783
+ if (unsignedRoundingMode === "infinity") {
2784
+ return r2;
2785
+ }
2786
+ var d1 = x.minus(r1);
2787
+ var d2 = r2.minus(x);
2788
+ if (d1.lessThan(d2)) {
2789
+ return r1;
2790
+ }
2791
+ if (d2.lessThan(d1)) {
2792
+ return r2;
2793
+ }
2794
+ invariant(d1.eq(d2), "d1 should be equal to d2");
2795
+ if (unsignedRoundingMode === "half-zero") {
2796
+ return r1;
2797
+ }
2798
+ if (unsignedRoundingMode === "half-infinity") {
2799
+ return r2;
2800
+ }
2801
+ invariant(unsignedRoundingMode === "half-even", "unsignedRoundingMode should be half-even");
2802
+ var cardinality = r1.div(r2.minus(r1)).mod(2);
2803
+ if (cardinality.isZero()) {
2804
+ return r1;
2805
+ }
2806
+ return r2;
2807
+ }
2808
+
2809
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/CollapseNumberRange.js
2810
+ var PART_TYPES_TO_COLLAPSE = /* @__PURE__ */ new Set([
2811
+ "unit",
2812
+ "exponentMinusSign",
2813
+ "minusSign",
2814
+ "plusSign",
2815
+ "percentSign",
2816
+ "exponentSeparator",
2817
+ "percent",
2818
+ "percentSign",
2819
+ "currency",
2820
+ "literal"
2821
+ ]);
2822
+ function CollapseNumberRange(numberFormat, result, _a) {
2823
+ var getInternalSlots2 = _a.getInternalSlots;
2824
+ var internalSlots = getInternalSlots2(numberFormat);
2825
+ var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
2826
+ var rangeSignRegex = new RegExp("s?[".concat(symbols.rangeSign, "]s?"));
2827
+ var rangeSignIndex = result.findIndex(function(r) {
2828
+ return r.type === "literal" && rangeSignRegex.test(r.value);
2829
+ });
2830
+ var prefixSignParts = [];
2831
+ for (var i = rangeSignIndex - 1; i >= 0; i--) {
2832
+ if (!PART_TYPES_TO_COLLAPSE.has(result[i].type)) {
2833
+ break;
2834
+ }
2835
+ prefixSignParts.unshift(result[i]);
2836
+ }
2837
+ if (Array.from(prefixSignParts.map(function(p) {
2838
+ return p.value;
2839
+ }).join("")).length > 1) {
2840
+ var newResult = Array.from(result);
2841
+ newResult.splice(rangeSignIndex - prefixSignParts.length, prefixSignParts.length);
2842
+ return newResult;
2843
+ }
2844
+ var suffixSignParts = [];
2845
+ for (var i = rangeSignIndex + 1; i < result.length; i++) {
2846
+ if (!PART_TYPES_TO_COLLAPSE.has(result[i].type)) {
2847
+ break;
2848
+ }
2849
+ suffixSignParts.push(result[i]);
2850
+ }
2851
+ if (Array.from(suffixSignParts.map(function(p) {
2852
+ return p.value;
2853
+ }).join("")).length > 1) {
2854
+ var newResult = Array.from(result);
2855
+ newResult.splice(rangeSignIndex + 1, suffixSignParts.length);
2856
+ return newResult;
2857
+ }
2858
+ return result;
2859
+ }
2860
+
487
2861
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ComputeExponentForMagnitude.js
2862
+ decimal_default.set({
2863
+ toExpPos: 100
2864
+ });
488
2865
  function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
489
2866
  var getInternalSlots2 = _a.getInternalSlots;
490
2867
  var internalSlots = getInternalSlots2(numberFormat);
@@ -493,10 +2870,12 @@
493
2870
  case "standard":
494
2871
  return 0;
495
2872
  case "scientific":
496
- return magnitude;
2873
+ return magnitude.toNumber();
497
2874
  case "engineering":
498
- return Math.floor(magnitude / 3) * 3;
2875
+ var thousands = magnitude.div(3).floor();
2876
+ return thousands.times(3).toNumber();
499
2877
  default: {
2878
+ invariant(notation === "compact", "Invalid notation");
500
2879
  var compactDisplay = internalSlots.compactDisplay, style = internalSlots.style, currencyDisplay = internalSlots.currencyDisplay;
501
2880
  var thresholdMap = void 0;
502
2881
  if (style === "currency" && currencyDisplay !== "name") {
@@ -509,7 +2888,7 @@
509
2888
  if (!thresholdMap) {
510
2889
  return 0;
511
2890
  }
512
- var num = String(Math.pow(10, magnitude));
2891
+ var num = TEN.pow(magnitude).toString();
513
2892
  var thresholds = Object.keys(thresholdMap);
514
2893
  if (num < thresholds[0]) {
515
2894
  return 0;
@@ -531,136 +2910,276 @@
531
2910
  }
532
2911
  }
533
2912
 
534
- // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ToRawPrecision.js
535
- function ToRawPrecision(x, minPrecision, maxPrecision) {
536
- var p = maxPrecision;
537
- var m;
538
- var e;
539
- var xFinal;
540
- if (x === 0) {
541
- m = repeat("0", p);
542
- e = 0;
543
- xFinal = 0;
544
- } else {
545
- var xToString = x.toString();
546
- var xToStringExponentIndex = xToString.indexOf("e");
547
- var _a = xToString.split("e"), xToStringMantissa = _a[0], xToStringExponent = _a[1];
548
- var xToStringMantissaWithoutDecimalPoint = xToStringMantissa.replace(".", "");
549
- if (xToStringExponentIndex >= 0 && xToStringMantissaWithoutDecimalPoint.length <= p) {
550
- e = +xToStringExponent;
551
- m = xToStringMantissaWithoutDecimalPoint + repeat("0", p - xToStringMantissaWithoutDecimalPoint.length);
552
- xFinal = x;
553
- } else {
554
- e = getMagnitude(x);
555
- var decimalPlaceOffset = e - p + 1;
556
- var n = Math.round(adjustDecimalPlace(x, decimalPlaceOffset));
557
- if (adjustDecimalPlace(n, p - 1) >= 10) {
558
- e = e + 1;
559
- n = Math.floor(n / 10);
560
- }
561
- m = n.toString();
562
- xFinal = adjustDecimalPlace(n, p - 1 - e);
563
- }
564
- }
565
- var int;
566
- if (e >= p - 1) {
567
- m = m + repeat("0", e - p + 1);
568
- int = e + 1;
569
- } else if (e >= 0) {
570
- m = "".concat(m.slice(0, e + 1), ".").concat(m.slice(e + 1));
571
- int = e + 1;
572
- } else {
573
- m = "0.".concat(repeat("0", -e - 1)).concat(m);
574
- int = 1;
575
- }
576
- if (m.indexOf(".") >= 0 && maxPrecision > minPrecision) {
577
- var cut = maxPrecision - minPrecision;
578
- while (cut > 0 && m[m.length - 1] === "0") {
579
- m = m.slice(0, -1);
580
- cut--;
581
- }
582
- if (m[m.length - 1] === ".") {
583
- m = m.slice(0, -1);
584
- }
585
- }
586
- return { formattedString: m, roundedNumber: xFinal, integerDigitsCount: int };
587
- function adjustDecimalPlace(x2, magnitude) {
588
- return magnitude < 0 ? x2 * Math.pow(10, -magnitude) : x2 / Math.pow(10, magnitude);
2913
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/GetUnsignedRoundingMode.js
2914
+ var negativeMapping = {
2915
+ ceil: "zero",
2916
+ floor: "infinity",
2917
+ expand: "infinity",
2918
+ trunc: "zero",
2919
+ halfCeil: "half-zero",
2920
+ halfFloor: "half-infinity",
2921
+ halfExpand: "half-infinity",
2922
+ halfTrunc: "half-zero",
2923
+ halfEven: "half-even"
2924
+ };
2925
+ var positiveMapping = {
2926
+ ceil: "infinity",
2927
+ floor: "zero",
2928
+ expand: "infinity",
2929
+ trunc: "zero",
2930
+ halfCeil: "half-infinity",
2931
+ halfFloor: "half-zero",
2932
+ halfExpand: "half-infinity",
2933
+ halfTrunc: "half-zero",
2934
+ halfEven: "half-even"
2935
+ };
2936
+ function GetUnsignedRoundingMode(roundingMode, isNegative) {
2937
+ if (isNegative) {
2938
+ return negativeMapping[roundingMode];
589
2939
  }
2940
+ return positiveMapping[roundingMode];
590
2941
  }
591
2942
 
592
2943
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ToRawFixed.js
593
- function ToRawFixed(x, minFraction, maxFraction) {
2944
+ decimal_default.set({
2945
+ toExpPos: 100
2946
+ });
2947
+ function ToRawFixedFn(n, f) {
2948
+ return n.times(TEN.pow(-f));
2949
+ }
2950
+ function findN1R1(x, f, roundingIncrement) {
2951
+ var nx = x.times(TEN.pow(f)).floor();
2952
+ var n1 = nx.div(roundingIncrement).floor().times(roundingIncrement);
2953
+ var r1 = ToRawFixedFn(n1, f);
2954
+ return {
2955
+ n1,
2956
+ r1
2957
+ };
2958
+ }
2959
+ function findN2R2(x, f, roundingIncrement) {
2960
+ var nx = x.times(TEN.pow(f)).ceil();
2961
+ var n2 = nx.div(roundingIncrement).ceil().times(roundingIncrement);
2962
+ var r2 = ToRawFixedFn(n2, f);
2963
+ return {
2964
+ n2,
2965
+ r2
2966
+ };
2967
+ }
2968
+ function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
594
2969
  var f = maxFraction;
595
- var n = Math.round(x * Math.pow(10, f));
596
- var xFinal = n / Math.pow(10, f);
2970
+ var _a = findN1R1(x, f, roundingIncrement), n1 = _a.n1, r1 = _a.r1;
2971
+ var _b = findN2R2(x, f, roundingIncrement), n2 = _b.n2, r2 = _b.r2;
2972
+ var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
2973
+ var n, xFinal;
597
2974
  var m;
598
- if (n < 1e21) {
599
- m = n.toString();
2975
+ if (r.eq(r1)) {
2976
+ n = n1;
2977
+ xFinal = r1;
2978
+ } else {
2979
+ n = n2;
2980
+ xFinal = r2;
2981
+ }
2982
+ if (n.isZero()) {
2983
+ m = "0";
600
2984
  } else {
601
2985
  m = n.toString();
602
- var _a = m.split("e"), mantissa = _a[0], exponent = _a[1];
603
- m = mantissa.replace(".", "");
604
- m = m + repeat("0", Math.max(+exponent - m.length + 1, 0));
605
2986
  }
606
2987
  var int;
607
2988
  if (f !== 0) {
608
2989
  var k = m.length;
609
2990
  if (k <= f) {
610
- var z = repeat("0", f + 1 - k);
2991
+ var z = repeat("0", f - k + 1);
611
2992
  m = z + m;
612
2993
  k = f + 1;
613
2994
  }
614
2995
  var a = m.slice(0, k - f);
615
- var b = m.slice(k - f);
616
- m = "".concat(a, ".").concat(b);
2996
+ var b = m.slice(m.length - f);
2997
+ m = a + "." + b;
617
2998
  int = a.length;
618
2999
  } else {
619
3000
  int = m.length;
620
3001
  }
621
3002
  var cut = maxFraction - minFraction;
622
3003
  while (cut > 0 && m[m.length - 1] === "0") {
623
- m = m.slice(0, -1);
3004
+ m = m.slice(0, m.length - 1);
624
3005
  cut--;
625
3006
  }
626
3007
  if (m[m.length - 1] === ".") {
627
- m = m.slice(0, -1);
3008
+ m = m.slice(0, m.length - 1);
3009
+ }
3010
+ return {
3011
+ formattedString: m,
3012
+ roundedNumber: xFinal,
3013
+ integerDigitsCount: int,
3014
+ roundingMagnitude: -f
3015
+ };
3016
+ }
3017
+
3018
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ToRawPrecision.js
3019
+ decimal_default.set({
3020
+ toExpPos: 100
3021
+ });
3022
+ function ToRawPrecisionFn(n, e, p) {
3023
+ invariant(TEN.pow(p - 1).lessThanOrEqualTo(n) && n.lessThan(TEN.pow(p)), "n should be in the range ".concat(TEN.pow(p - 1), " <= n < ").concat(TEN.pow(p), " but got ").concat(n));
3024
+ return n.times(TEN.pow(e.minus(p).plus(1)));
3025
+ }
3026
+ function findN1E1R1(x, p) {
3027
+ var maxN1 = TEN.pow(p);
3028
+ var minN1 = TEN.pow(p - 1);
3029
+ var maxE1 = x.div(minN1).log(10).plus(p).minus(1).ceil();
3030
+ for (var currentE1 = maxE1; ; currentE1 = currentE1.minus(1)) {
3031
+ var currentN1 = x.div(TEN.pow(currentE1.minus(p).plus(1))).floor();
3032
+ if (currentN1.lessThan(maxN1) && currentN1.greaterThanOrEqualTo(minN1)) {
3033
+ var currentR1 = ToRawPrecisionFn(currentN1, currentE1, p);
3034
+ if (currentR1.lessThanOrEqualTo(x)) {
3035
+ return {
3036
+ n1: currentN1,
3037
+ e1: currentE1,
3038
+ r1: currentR1
3039
+ };
3040
+ }
3041
+ }
3042
+ }
3043
+ }
3044
+ function findN2E2R2(x, p) {
3045
+ var maxN2 = TEN.pow(p);
3046
+ var minN2 = TEN.pow(p - 1);
3047
+ var minE2 = x.div(maxN2).log(10).plus(p).minus(1).floor();
3048
+ for (var currentE2 = minE2; ; currentE2 = currentE2.plus(1)) {
3049
+ var currentN2 = x.div(TEN.pow(currentE2.minus(p).plus(1))).ceil();
3050
+ if (currentN2.lessThan(maxN2) && currentN2.greaterThanOrEqualTo(minN2)) {
3051
+ var currentR2 = ToRawPrecisionFn(currentN2, currentE2, p);
3052
+ if (currentR2.greaterThanOrEqualTo(x)) {
3053
+ return {
3054
+ n2: currentN2,
3055
+ e2: currentE2,
3056
+ r2: currentR2
3057
+ };
3058
+ }
3059
+ }
3060
+ }
3061
+ }
3062
+ function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
3063
+ var p = maxPrecision;
3064
+ var m;
3065
+ var e;
3066
+ var xFinal;
3067
+ if (x.isZero()) {
3068
+ m = repeat("0", p);
3069
+ e = 0;
3070
+ xFinal = ZERO;
3071
+ } else {
3072
+ var _a = findN1E1R1(x, p), n1 = _a.n1, e1 = _a.e1, r1 = _a.r1;
3073
+ var _b = findN2E2R2(x, p), n2 = _b.n2, e2 = _b.e2, r2 = _b.r2;
3074
+ var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
3075
+ var n = void 0;
3076
+ if (r.eq(r1)) {
3077
+ n = n1;
3078
+ e = e1.toNumber();
3079
+ xFinal = r1;
3080
+ } else {
3081
+ n = n2;
3082
+ e = e2.toNumber();
3083
+ xFinal = r2;
3084
+ }
3085
+ m = n.toString();
3086
+ }
3087
+ var int;
3088
+ if (e >= p - 1) {
3089
+ m = m + repeat("0", e - p + 1);
3090
+ int = e + 1;
3091
+ } else if (e >= 0) {
3092
+ m = m.slice(0, e + 1) + "." + m.slice(m.length - (p - (e + 1)));
3093
+ int = e + 1;
3094
+ } else {
3095
+ invariant(e < 0, "e should be less than 0");
3096
+ m = "0." + repeat("0", -e - 1) + m;
3097
+ int = 1;
628
3098
  }
629
- return { formattedString: m, roundedNumber: xFinal, integerDigitsCount: int };
3099
+ if (m.includes(".") && maxPrecision > minPrecision) {
3100
+ var cut = maxPrecision - minPrecision;
3101
+ while (cut > 0 && m[m.length - 1] === "0") {
3102
+ m = m.slice(0, m.length - 1);
3103
+ cut--;
3104
+ }
3105
+ if (m[m.length - 1] === ".") {
3106
+ m = m.slice(0, m.length - 1);
3107
+ }
3108
+ }
3109
+ return {
3110
+ formattedString: m,
3111
+ roundedNumber: xFinal,
3112
+ integerDigitsCount: int,
3113
+ roundingMagnitude: e
3114
+ };
630
3115
  }
631
3116
 
632
3117
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/FormatNumericToString.js
633
3118
  function FormatNumericToString(intlObject, x) {
634
- var isNegative = x < 0 || SameValue(x, -0);
635
- if (isNegative) {
636
- x = -x;
3119
+ var sign2;
3120
+ if (x.isZero() && x.isNegative()) {
3121
+ sign2 = "negative";
3122
+ x = ZERO;
3123
+ } else {
3124
+ invariant(x.isFinite(), "NumberFormatDigitInternalSlots value is not finite");
3125
+ if (x.lessThan(0)) {
3126
+ sign2 = "negative";
3127
+ } else {
3128
+ sign2 = "positive";
3129
+ }
3130
+ if (sign2 === "negative") {
3131
+ x = x.negated();
3132
+ }
637
3133
  }
638
3134
  var result;
639
- var rourndingType = intlObject.roundingType;
640
- switch (rourndingType) {
3135
+ var roundingType = intlObject.roundingType;
3136
+ var unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign2 === "negative");
3137
+ switch (roundingType) {
641
3138
  case "significantDigits":
642
- result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
3139
+ result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
643
3140
  break;
644
3141
  case "fractionDigits":
645
- result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
3142
+ result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
646
3143
  break;
647
3144
  default:
648
- result = ToRawPrecision(x, 1, 2);
649
- if (result.integerDigitsCount > 1) {
650
- result = ToRawFixed(x, 0, 0);
3145
+ var sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
3146
+ var fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
3147
+ if (intlObject.roundingType === "morePrecision") {
3148
+ if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
3149
+ result = sResult;
3150
+ } else {
3151
+ result = fResult;
3152
+ }
3153
+ } else {
3154
+ invariant(intlObject.roundingType === "lessPrecision", "Invalid roundingType");
3155
+ if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
3156
+ result = fResult;
3157
+ } else {
3158
+ result = sResult;
3159
+ }
651
3160
  }
652
3161
  break;
653
3162
  }
654
3163
  x = result.roundedNumber;
655
3164
  var string = result.formattedString;
3165
+ if (intlObject.trailingZeroDisplay === "stripIfInteger" && x.isInteger()) {
3166
+ var i = string.indexOf(".");
3167
+ if (i > -1) {
3168
+ string = string.slice(0, i);
3169
+ }
3170
+ }
656
3171
  var int = result.integerDigitsCount;
657
3172
  var minInteger = intlObject.minimumIntegerDigits;
658
3173
  if (int < minInteger) {
659
3174
  var forwardZeros = repeat("0", minInteger - int);
660
3175
  string = forwardZeros + string;
661
3176
  }
662
- if (isNegative) {
663
- x = -x;
3177
+ if (sign2 === "negative") {
3178
+ if (x.isZero()) {
3179
+ x = NEGATIVE_ZERO;
3180
+ } else {
3181
+ x = x.negated();
3182
+ }
664
3183
  }
665
3184
  return { roundedNumber: x, formattedString: string };
666
3185
  }
@@ -668,30 +3187,30 @@
668
3187
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ComputeExponent.js
669
3188
  function ComputeExponent(numberFormat, x, _a) {
670
3189
  var getInternalSlots2 = _a.getInternalSlots;
671
- if (x === 0) {
3190
+ if (x.isZero()) {
672
3191
  return [0, 0];
673
3192
  }
674
- if (x < 0) {
675
- x = -x;
3193
+ if (x.isNegative()) {
3194
+ x = x.negated();
676
3195
  }
677
- var magnitude = getMagnitude(x);
3196
+ var magnitude = x.log(10).floor();
678
3197
  var exponent = ComputeExponentForMagnitude(numberFormat, magnitude, {
679
3198
  getInternalSlots: getInternalSlots2
680
3199
  });
681
- x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
3200
+ x = x.times(TEN.pow(-exponent));
682
3201
  var formatNumberResult = FormatNumericToString(getInternalSlots2(numberFormat), x);
683
- if (formatNumberResult.roundedNumber === 0) {
684
- return [exponent, magnitude];
3202
+ if (formatNumberResult.roundedNumber.isZero()) {
3203
+ return [exponent, magnitude.toNumber()];
685
3204
  }
686
- var newMagnitude = getMagnitude(formatNumberResult.roundedNumber);
687
- if (newMagnitude === magnitude - exponent) {
688
- return [exponent, magnitude];
3205
+ var newMagnitude = formatNumberResult.roundedNumber.log(10).floor();
3206
+ if (newMagnitude.eq(magnitude.minus(exponent))) {
3207
+ return [exponent, magnitude.toNumber()];
689
3208
  }
690
3209
  return [
691
- ComputeExponentForMagnitude(numberFormat, magnitude + 1, {
3210
+ ComputeExponentForMagnitude(numberFormat, magnitude.plus(1), {
692
3211
  getInternalSlots: getInternalSlots2
693
3212
  }),
694
- magnitude + 1
3213
+ magnitude.plus(1).toNumber()
695
3214
  ];
696
3215
  }
697
3216
 
@@ -1493,7 +4012,8 @@
1493
4012
  var S_DOLLAR_UNICODE_REGEX = new RegExp("".concat(S_UNICODE_REGEX.source, "$"));
1494
4013
  var CLDR_NUMBER_PATTERN = /[#0](?:[\.,][#0]+)*/g;
1495
4014
  function formatToParts(numberResult, data2, pl, options) {
1496
- var sign = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
4015
+ var _a;
4016
+ var sign2 = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
1497
4017
  var notation = options.notation, style = options.style, numberingSystem = options.numberingSystem;
1498
4018
  var defaultNumberingSystem = data2.numbers.nu[0];
1499
4019
  var compactNumberPattern = null;
@@ -1523,13 +4043,13 @@
1523
4043
  if (!compactNumberPattern) {
1524
4044
  if (style === "decimal" || style === "unit" || style === "currency" && options.currencyDisplay === "name") {
1525
4045
  var decimalData = data2.numbers.decimal[numberingSystem] || data2.numbers.decimal[defaultNumberingSystem];
1526
- numberPattern = getPatternForSign(decimalData.standard, sign);
4046
+ numberPattern = getPatternForSign(decimalData.standard, sign2);
1527
4047
  } else if (style === "currency") {
1528
4048
  var currencyData = data2.numbers.currency[numberingSystem] || data2.numbers.currency[defaultNumberingSystem];
1529
- numberPattern = getPatternForSign(currencyData[options.currencySign], sign);
4049
+ numberPattern = getPatternForSign(currencyData[options.currencySign], sign2);
1530
4050
  } else {
1531
4051
  var percentPattern = data2.numbers.percent[numberingSystem] || data2.numbers.percent[defaultNumberingSystem];
1532
- numberPattern = getPatternForSign(percentPattern, sign);
4052
+ numberPattern = getPatternForSign(percentPattern, sign2);
1533
4053
  }
1534
4054
  } else {
1535
4055
  numberPattern = compactNumberPattern;
@@ -1557,16 +4077,18 @@
1557
4077
  }
1558
4078
  switch (part) {
1559
4079
  case "{0}": {
1560
- numberParts.push.apply(numberParts, paritionNumberIntoParts(
4080
+ numberParts.push.apply(numberParts, partitionNumberIntoParts(
1561
4081
  symbols,
1562
4082
  numberResult,
1563
4083
  notation,
1564
4084
  exponent,
1565
4085
  numberingSystem,
1566
4086
  // If compact number pattern exists, do not insert group separators.
1567
- !compactNumberPattern && Boolean(options.useGrouping),
4087
+ !compactNumberPattern && ((_a = options.useGrouping) !== null && _a !== void 0 ? _a : true),
1568
4088
  decimalNumberPattern,
1569
- style
4089
+ style,
4090
+ options.roundingIncrement,
4091
+ GetUnsignedRoundingMode(options.roundingMode, sign2 === -1)
1570
4092
  ));
1571
4093
  break;
1572
4094
  }
@@ -1601,14 +4123,14 @@
1601
4123
  var unitName = void 0;
1602
4124
  var currencyNameData = data2.currencies[options.currency];
1603
4125
  if (currencyNameData) {
1604
- unitName = selectPlural(pl, numberResult.roundedNumber * Math.pow(10, exponent), currencyNameData.displayName);
4126
+ unitName = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), currencyNameData.displayName);
1605
4127
  } else {
1606
4128
  unitName = options.currency;
1607
4129
  }
1608
4130
  var unitPatternParts = unitPattern.split(/(\{[01]\})/g);
1609
4131
  var result = [];
1610
- for (var _a = 0, unitPatternParts_1 = unitPatternParts; _a < unitPatternParts_1.length; _a++) {
1611
- var part = unitPatternParts_1[_a];
4132
+ for (var _b = 0, unitPatternParts_1 = unitPatternParts; _b < unitPatternParts_1.length; _b++) {
4133
+ var part = unitPatternParts_1[_b];
1612
4134
  switch (part) {
1613
4135
  case "{0}":
1614
4136
  result.push.apply(result, numberParts);
@@ -1633,11 +4155,11 @@
1633
4155
  var unitData = data2.units.simple[unit];
1634
4156
  var unitPattern = void 0;
1635
4157
  if (unitData) {
1636
- unitPattern = selectPlural(pl, numberResult.roundedNumber * Math.pow(10, exponent), data2.units.simple[unit][unitDisplay]);
4158
+ unitPattern = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), data2.units.simple[unit][unitDisplay]);
1637
4159
  } else {
1638
- var _b = unit.split("-per-"), numeratorUnit = _b[0], denominatorUnit = _b[1];
4160
+ var _c = unit.split("-per-"), numeratorUnit = _c[0], denominatorUnit = _c[1];
1639
4161
  unitData = data2.units.simple[numeratorUnit];
1640
- var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber * Math.pow(10, exponent), data2.units.simple[numeratorUnit][unitDisplay]);
4162
+ var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), data2.units.simple[numeratorUnit][unitDisplay]);
1641
4163
  var perUnitPattern = data2.units.simple[denominatorUnit].perUnit[unitDisplay];
1642
4164
  if (perUnitPattern) {
1643
4165
  unitPattern = perUnitPattern.replace("{0}", numeratorUnitPattern);
@@ -1648,8 +4170,8 @@
1648
4170
  }
1649
4171
  }
1650
4172
  var result = [];
1651
- for (var _c = 0, _d = unitPattern.split(/(\s*\{0\}\s*)/); _c < _d.length; _c++) {
1652
- var part = _d[_c];
4173
+ for (var _d = 0, _e = unitPattern.split(/(\s*\{0\}\s*)/); _d < _e.length; _d++) {
4174
+ var part = _e[_d];
1653
4175
  var interpolateMatch = /^(\s*)\{0\}(\s*)$/.exec(part);
1654
4176
  if (interpolateMatch) {
1655
4177
  if (interpolateMatch[1]) {
@@ -1669,12 +4191,12 @@
1669
4191
  return numberParts;
1670
4192
  }
1671
4193
  }
1672
- function paritionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem, useGrouping, decimalNumberPattern, style) {
4194
+ function partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem, useGrouping, decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
1673
4195
  var result = [];
1674
4196
  var n = numberResult.formattedString, x = numberResult.roundedNumber;
1675
- if (isNaN(x)) {
4197
+ if (x.isNaN()) {
1676
4198
  return [{ type: "nan", value: n }];
1677
- } else if (!isFinite(x)) {
4199
+ } else if (!x.isFinite()) {
1678
4200
  return [{ type: "infinity", value: n }];
1679
4201
  }
1680
4202
  var digitReplacementTable = digitMapping[numberingSystem];
@@ -1692,7 +4214,15 @@
1692
4214
  } else {
1693
4215
  integer = n;
1694
4216
  }
1695
- if (useGrouping && (notation !== "compact" || x >= 1e4)) {
4217
+ var shouldUseGrouping = false;
4218
+ if (useGrouping === "always") {
4219
+ shouldUseGrouping = true;
4220
+ } else if (useGrouping === "min2") {
4221
+ shouldUseGrouping = x.greaterThanOrEqualTo(1e4);
4222
+ } else if (useGrouping === "auto" || useGrouping) {
4223
+ shouldUseGrouping = notation !== "compact" || x.greaterThanOrEqualTo(1e4);
4224
+ }
4225
+ if (shouldUseGrouping) {
1696
4226
  var groupSepSymbol = style === "currency" && symbols.currencyGroup != null ? symbols.currencyGroup : symbols.group;
1697
4227
  var groups = [];
1698
4228
  var integerNumberPattern = decimalNumberPattern.split(".")[0];
@@ -1729,13 +4259,13 @@
1729
4259
  var decimalSepSymbol = style === "currency" && symbols.currencyDecimal != null ? symbols.currencyDecimal : symbols.decimal;
1730
4260
  result.push({ type: "decimal", value: decimalSepSymbol }, { type: "fraction", value: fraction });
1731
4261
  }
1732
- if ((notation === "scientific" || notation === "engineering") && isFinite(x)) {
4262
+ if ((notation === "scientific" || notation === "engineering") && x.isFinite()) {
1733
4263
  result.push({ type: "exponentSeparator", value: symbols.exponential });
1734
4264
  if (exponent < 0) {
1735
4265
  result.push({ type: "exponentMinusSign", value: symbols.minusSign });
1736
4266
  exponent = -exponent;
1737
4267
  }
1738
- var exponentResult = ToRawFixed(exponent, 0, 0);
4268
+ var exponentResult = ToRawFixed(new decimal_default(exponent), 0, 0, roundingIncrement, unsignedRoundingMode);
1739
4269
  result.push({
1740
4270
  type: "exponentInteger",
1741
4271
  value: exponentResult.formattedString
@@ -1743,12 +4273,12 @@
1743
4273
  }
1744
4274
  return result;
1745
4275
  }
1746
- function getPatternForSign(pattern, sign) {
4276
+ function getPatternForSign(pattern, sign2) {
1747
4277
  if (pattern.indexOf(";") < 0) {
1748
4278
  pattern = "".concat(pattern, ";-").concat(pattern);
1749
4279
  }
1750
4280
  var _a = pattern.split(";"), zeroPattern = _a[0], negativePattern = _a[1];
1751
- switch (sign) {
4281
+ switch (sign2) {
1752
4282
  case 0:
1753
4283
  return zeroPattern;
1754
4284
  case -1:
@@ -1759,7 +4289,7 @@
1759
4289
  }
1760
4290
  function getCompactDisplayPattern(numberResult, pl, data2, style, compactDisplay, currencyDisplay, numberingSystem) {
1761
4291
  var _a;
1762
- var roundedNumber = numberResult.roundedNumber, sign = numberResult.sign, magnitude = numberResult.magnitude;
4292
+ var roundedNumber = numberResult.roundedNumber, sign2 = numberResult.sign, magnitude = numberResult.magnitude;
1763
4293
  var magnitudeKey = String(Math.pow(10, magnitude));
1764
4294
  var defaultNumberingSystem = data2.numbers.nu[0];
1765
4295
  var pattern;
@@ -1770,7 +4300,7 @@
1770
4300
  if (!compactPluralRules) {
1771
4301
  return null;
1772
4302
  }
1773
- pattern = selectPlural(pl, roundedNumber, compactPluralRules);
4303
+ pattern = selectPlural(pl, roundedNumber.toNumber(), compactPluralRules);
1774
4304
  } else {
1775
4305
  var byNumberingSystem = data2.numbers.decimal;
1776
4306
  var byCompactDisplay = byNumberingSystem[numberingSystem] || byNumberingSystem[defaultNumberingSystem];
@@ -1778,12 +4308,12 @@
1778
4308
  if (!compactPlaralRule) {
1779
4309
  return null;
1780
4310
  }
1781
- pattern = selectPlural(pl, roundedNumber, compactPlaralRule);
4311
+ pattern = selectPlural(pl, roundedNumber.toNumber(), compactPlaralRule);
1782
4312
  }
1783
4313
  if (pattern === "0") {
1784
4314
  return null;
1785
4315
  }
1786
- pattern = getPatternForSign(pattern, sign).replace(/([^\s;\-\+\d¤]+)/g, "{c:$1}").replace(/0+/, "0");
4316
+ pattern = getPatternForSign(pattern, sign2).replace(/([^\s;\-\+\d¤]+)/g, "{c:$1}").replace(/0+/, "0");
1787
4317
  return pattern;
1788
4318
  }
1789
4319
  function selectPlural(pl, x, rules) {
@@ -1810,66 +4340,71 @@
1810
4340
  var magnitude = 0;
1811
4341
  var exponent = 0;
1812
4342
  var n;
1813
- if (isNaN(x)) {
4343
+ if (x.isNaN()) {
1814
4344
  n = symbols.nan;
1815
- } else if (x == Number.POSITIVE_INFINITY || x == Number.NEGATIVE_INFINITY) {
4345
+ } else if (!x.isFinite()) {
1816
4346
  n = symbols.infinity;
1817
4347
  } else {
1818
- if (!SameValue(x, -0)) {
1819
- if (!isFinite(x)) {
1820
- throw new Error("Input must be a mathematical value");
1821
- }
4348
+ if (!x.isZero()) {
4349
+ invariant(x.isFinite(), "Input must be a mathematical value");
1822
4350
  if (internalSlots.style == "percent") {
1823
- x *= 100;
4351
+ x = x.times(100);
1824
4352
  }
1825
4353
  ;
1826
4354
  _b = ComputeExponent(numberFormat, x, {
1827
4355
  getInternalSlots: getInternalSlots2
1828
4356
  }), exponent = _b[0], magnitude = _b[1];
1829
- x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
4357
+ x = x.times(TEN.pow(-exponent));
1830
4358
  }
1831
4359
  var formatNumberResult = FormatNumericToString(internalSlots, x);
1832
4360
  n = formatNumberResult.formattedString;
1833
4361
  x = formatNumberResult.roundedNumber;
1834
4362
  }
1835
- var sign;
4363
+ var sign2;
1836
4364
  var signDisplay = internalSlots.signDisplay;
1837
4365
  switch (signDisplay) {
1838
4366
  case "never":
1839
- sign = 0;
4367
+ sign2 = 0;
1840
4368
  break;
1841
4369
  case "auto":
1842
- if (SameValue(x, 0) || x > 0 || isNaN(x)) {
1843
- sign = 0;
4370
+ if (x.isPositive() || x.isNaN()) {
4371
+ sign2 = 0;
1844
4372
  } else {
1845
- sign = -1;
4373
+ sign2 = -1;
1846
4374
  }
1847
4375
  break;
1848
4376
  case "always":
1849
- if (SameValue(x, 0) || x > 0 || isNaN(x)) {
1850
- sign = 1;
4377
+ if (x.isPositive() || x.isNaN()) {
4378
+ sign2 = 1;
4379
+ } else {
4380
+ sign2 = -1;
4381
+ }
4382
+ break;
4383
+ case "exceptZero":
4384
+ if (x.isZero()) {
4385
+ sign2 = 0;
4386
+ } else if (x.isNegative()) {
4387
+ sign2 = -1;
1851
4388
  } else {
1852
- sign = -1;
4389
+ sign2 = 1;
1853
4390
  }
1854
4391
  break;
1855
4392
  default:
1856
- if (x === 0 || isNaN(x)) {
1857
- sign = 0;
1858
- } else if (x > 0) {
1859
- sign = 1;
4393
+ invariant(signDisplay === "negative", 'signDisplay must be "negative"');
4394
+ if (x.isNegative() && !x.isZero()) {
4395
+ sign2 = -1;
1860
4396
  } else {
1861
- sign = -1;
4397
+ sign2 = 0;
1862
4398
  }
4399
+ break;
1863
4400
  }
1864
- return formatToParts({ roundedNumber: x, formattedString: n, exponent, magnitude, sign }, internalSlots.dataLocaleData, pl, internalSlots);
4401
+ return formatToParts({ roundedNumber: x, formattedString: n, exponent, magnitude, sign: sign2 }, internalSlots.dataLocaleData, pl, internalSlots);
1865
4402
  }
1866
4403
 
1867
4404
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/PartitionNumberRangePattern.js
1868
4405
  function PartitionNumberRangePattern(numberFormat, x, y, _a) {
1869
4406
  var getInternalSlots2 = _a.getInternalSlots;
1870
- if (isNaN(x) || isNaN(y)) {
1871
- throw new RangeError("Input must be a number");
1872
- }
4407
+ invariant(!x.isNaN() && !y.isNaN(), "Input must be a number");
1873
4408
  var result = [];
1874
4409
  var xResult = PartitionNumberPattern(numberFormat, x, { getInternalSlots: getInternalSlots2 });
1875
4410
  var yResult = PartitionNumberPattern(numberFormat, y, { getInternalSlots: getInternalSlots2 });
@@ -6306,6 +8841,23 @@
6306
8841
  }
6307
8842
 
6308
8843
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/SetNumberFormatDigitOptions.js
8844
+ var VALID_ROUNDING_INCREMENTS = /* @__PURE__ */ new Set([
8845
+ 1,
8846
+ 2,
8847
+ 5,
8848
+ 10,
8849
+ 20,
8850
+ 25,
8851
+ 50,
8852
+ 100,
8853
+ 200,
8854
+ 250,
8855
+ 500,
8856
+ 1e3,
8857
+ 2e3,
8858
+ 2500,
8859
+ 5e3
8860
+ ]);
6309
8861
  function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
6310
8862
  var mnid = GetNumberOption(opts, "minimumIntegerDigits", 1, 21, 1);
6311
8863
  var mnfd = opts.minimumFractionDigits;
@@ -6313,7 +8865,27 @@
6313
8865
  var mnsd = opts.minimumSignificantDigits;
6314
8866
  var mxsd = opts.maximumSignificantDigits;
6315
8867
  internalSlots.minimumIntegerDigits = mnid;
8868
+ var roundingIncrement = GetNumberOption(opts, "roundingIncrement", 1, 5e3, 1);
8869
+ invariant(VALID_ROUNDING_INCREMENTS.has(roundingIncrement), "Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(Array.from(VALID_ROUNDING_INCREMENTS).join(", "), "."));
8870
+ var roundingMode = GetOption(opts, "roundingMode", "string", [
8871
+ "ceil",
8872
+ "floor",
8873
+ "expand",
8874
+ "trunc",
8875
+ "halfCeil",
8876
+ "halfFloor",
8877
+ "halfExpand",
8878
+ "halfTrunc",
8879
+ "halfEven"
8880
+ ], "halfExpand");
6316
8881
  var roundingPriority = GetOption(opts, "roundingPriority", "string", ["auto", "morePrecision", "lessPrecision"], "auto");
8882
+ var trailingZeroDisplay = GetOption(opts, "trailingZeroDisplay", "string", ["auto", "stripIfInteger"], "auto");
8883
+ if (roundingIncrement !== 1) {
8884
+ mxfdDefault = mnfdDefault;
8885
+ }
8886
+ internalSlots.roundingIncrement = roundingIncrement;
8887
+ internalSlots.roundingMode = roundingMode;
8888
+ internalSlots.trailingZeroDisplay = trailingZeroDisplay;
6317
8889
  var hasSd = mnsd !== void 0 || mxsd !== void 0;
6318
8890
  var hasFd = mnfd !== void 0 || mxfd !== void 0;
6319
8891
  var needSd = true;
@@ -6326,10 +8898,8 @@
6326
8898
  }
6327
8899
  if (needSd) {
6328
8900
  if (hasSd) {
6329
- mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
6330
- mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
6331
- internalSlots.minimumSignificantDigits = mnsd;
6332
- internalSlots.maximumSignificantDigits = mxsd;
8901
+ internalSlots.minimumSignificantDigits = DefaultNumberOption(mnsd, 1, 21, 1);
8902
+ internalSlots.maximumSignificantDigits = DefaultNumberOption(mxsd, internalSlots.minimumSignificantDigits, 21, 21);
6333
8903
  } else {
6334
8904
  internalSlots.minimumSignificantDigits = 1;
6335
8905
  internalSlots.maximumSignificantDigits = 21;
@@ -6337,10 +8907,10 @@
6337
8907
  }
6338
8908
  if (needFd) {
6339
8909
  if (hasFd) {
6340
- mnfd = DefaultNumberOption(mnfd, 0, 20, void 0);
6341
- mxfd = DefaultNumberOption(mxfd, 0, 20, void 0);
8910
+ mnfd = DefaultNumberOption(mnfd, 0, 100, void 0);
8911
+ mxfd = DefaultNumberOption(mxfd, 0, 100, void 0);
6342
8912
  if (mnfd === void 0) {
6343
- mnfd = Math.min(mnfdDefault, mxfd);
8913
+ mnfd = Math.min(mnfdDefault, mxfd !== null && mxfd !== void 0 ? mxfd : 0);
6344
8914
  } else if (mxfd === void 0) {
6345
8915
  mxfd = Math.max(mxfdDefault, mnfd);
6346
8916
  } else if (mnfd > mxfd) {
@@ -6353,22 +8923,29 @@
6353
8923
  internalSlots.maximumFractionDigits = mxfdDefault;
6354
8924
  }
6355
8925
  }
6356
- if (needSd || needFd) {
6357
- if (roundingPriority === "morePrecision") {
6358
- internalSlots.roundingType = "morePrecision";
6359
- } else if (roundingPriority === "lessPrecision") {
6360
- internalSlots.roundingType = "lessPrecision";
6361
- } else if (hasSd) {
6362
- internalSlots.roundingType = "significantDigits";
6363
- } else {
6364
- internalSlots.roundingType = "fractionDigits";
6365
- }
6366
- } else {
6367
- internalSlots.roundingType = "morePrecision";
8926
+ if (!needSd && !needFd) {
6368
8927
  internalSlots.minimumFractionDigits = 0;
6369
8928
  internalSlots.maximumFractionDigits = 0;
6370
8929
  internalSlots.minimumSignificantDigits = 1;
6371
8930
  internalSlots.maximumSignificantDigits = 2;
8931
+ internalSlots.roundingType = "morePrecision";
8932
+ internalSlots.roundingPriority = "morePrecision";
8933
+ } else if (roundingPriority === "morePrecision") {
8934
+ internalSlots.roundingType = "morePrecision";
8935
+ internalSlots.roundingPriority = "morePrecision";
8936
+ } else if (roundingPriority === "lessPrecision") {
8937
+ internalSlots.roundingType = "lessPrecision";
8938
+ internalSlots.roundingPriority = "lessPrecision";
8939
+ } else if (hasSd) {
8940
+ internalSlots.roundingType = "significantDigits";
8941
+ internalSlots.roundingPriority = "auto";
8942
+ } else {
8943
+ internalSlots.roundingType = "fractionDigits";
8944
+ internalSlots.roundingPriority = "auto";
8945
+ }
8946
+ if (roundingIncrement !== 1) {
8947
+ invariant(internalSlots.roundingType === "fractionDigits", "Invalid roundingType");
8948
+ invariant(internalSlots.maximumFractionDigits === internalSlots.minimumFractionDigits, "With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.");
6372
8949
  }
6373
8950
  }
6374
8951
 
@@ -6410,21 +8987,6 @@
6410
8987
  }
6411
8988
 
6412
8989
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/InitializeNumberFormat.js
6413
- var VALID_ROUND_INCREMENT_VALUES = [
6414
- 1,
6415
- 2,
6416
- 5,
6417
- 10,
6418
- 20,
6419
- 25,
6420
- 50,
6421
- 100,
6422
- 200,
6423
- 250,
6424
- 500,
6425
- 1e3,
6426
- 2e3
6427
- ];
6428
8990
  function InitializeNumberFormat(nf, locales, opts, _a) {
6429
8991
  var getInternalSlots2 = _a.getInternalSlots, localeData = _a.localeData, availableLocales = _a.availableLocales, numberingSystemNames2 = _a.numberingSystemNames, getDefaultLocale = _a.getDefaultLocale, currencyDigitsData2 = _a.currencyDigitsData;
6430
8992
  var requestedLocales = CanonicalizeLocaleList(locales);
@@ -6455,9 +9017,11 @@
6455
9017
  internalSlots.dataLocaleData = dataLocaleData;
6456
9018
  SetNumberFormatUnitOptions(nf, options, { getInternalSlots: getInternalSlots2 });
6457
9019
  var style = internalSlots.style;
9020
+ var notation = GetOption(options, "notation", "string", ["standard", "scientific", "engineering", "compact"], "standard");
9021
+ internalSlots.notation = notation;
6458
9022
  var mnfdDefault;
6459
9023
  var mxfdDefault;
6460
- if (style === "currency") {
9024
+ if (style === "currency" && notation === "standard") {
6461
9025
  var currency = internalSlots.currency;
6462
9026
  var cDigits = CurrencyDigits(currency, { currencyDigitsData: currencyDigitsData2 });
6463
9027
  mnfdDefault = cDigits;
@@ -6466,41 +9030,17 @@
6466
9030
  mnfdDefault = 0;
6467
9031
  mxfdDefault = style === "percent" ? 0 : 3;
6468
9032
  }
6469
- var notation = GetOption(options, "notation", "string", ["standard", "scientific", "engineering", "compact"], "standard");
6470
- internalSlots.notation = notation;
6471
9033
  SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
6472
- var roundingIncrement = GetNumberOption(options, "roundingIncrement", 1, 5e3, 1);
6473
- if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
6474
- throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
6475
- }
6476
- if (roundingIncrement !== 1 && internalSlots.roundingType !== "fractionDigits") {
6477
- throw new TypeError("For roundingIncrement > 1 only fractionDigits is a valid roundingType");
6478
- }
6479
- if (roundingIncrement !== 1 && internalSlots.maximumFractionDigits !== internalSlots.minimumFractionDigits) {
6480
- throw new RangeError("With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.");
6481
- }
6482
- internalSlots.roundingIncrement = roundingIncrement;
6483
- var trailingZeroDisplay = GetOption(options, "trailingZeroDisplay", "string", ["auto", "stripIfInteger"], "auto");
6484
- internalSlots.trailingZeroDisplay = trailingZeroDisplay;
6485
9034
  var compactDisplay = GetOption(options, "compactDisplay", "string", ["short", "long"], "short");
6486
9035
  var defaultUseGrouping = "auto";
6487
9036
  if (notation === "compact") {
6488
9037
  internalSlots.compactDisplay = compactDisplay;
6489
9038
  defaultUseGrouping = "min2";
6490
9039
  }
6491
- internalSlots.useGrouping = GetStringOrBooleanOption(options, "useGrouping", ["min2", "auto", "always"], "always", false, defaultUseGrouping);
6492
- internalSlots.signDisplay = GetOption(options, "signDisplay", "string", ["auto", "never", "always", "exceptZero", "negative"], "auto");
6493
- internalSlots.roundingMode = GetOption(options, "roundingMode", "string", [
6494
- "ceil",
6495
- "floor",
6496
- "expand",
6497
- "trunc",
6498
- "halfCeil",
6499
- "halfFloor",
6500
- "halfExpand",
6501
- "halfTrunc",
6502
- "halfEven"
6503
- ], "halfExpand");
9040
+ var useGrouping = GetStringOrBooleanOption(options, "useGrouping", ["min2", "auto", "always"], "always", false, defaultUseGrouping);
9041
+ internalSlots.useGrouping = useGrouping;
9042
+ var signDisplay = GetOption(options, "signDisplay", "string", ["auto", "never", "always", "exceptZero", "negative"], "auto");
9043
+ internalSlots.signDisplay = signDisplay;
6504
9044
  return nf;
6505
9045
  }
6506
9046
 
@@ -6684,10 +9224,14 @@
6684
9224
  });
6685
9225
  }
6686
9226
  function formatRange(start, end) {
6687
- return FormatNumericRange(this, start, end, { getInternalSlots });
9227
+ return FormatNumericRange(this, toNumeric(start), toNumeric(end), {
9228
+ getInternalSlots
9229
+ });
6688
9230
  }
6689
9231
  function formatRangeToParts(start, end) {
6690
- return FormatNumericRangeToParts(this, start, end, { getInternalSlots });
9232
+ return FormatNumericRangeToParts(this, toNumeric(start), toNumeric(end), {
9233
+ getInternalSlots
9234
+ });
6691
9235
  }
6692
9236
  try {
6693
9237
  Object.defineProperty(formatToParts2, "name", {
@@ -6815,7 +9359,7 @@ Please __addLocaleData before adding additional unit data`);
6815
9359
  NumberFormat.polyfilled = true;
6816
9360
  function toNumeric(val) {
6817
9361
  if (typeof val === "bigint") {
6818
- return val;
9362
+ return new decimal_default(val.toString());
6819
9363
  }
6820
9364
  return ToNumber(val);
6821
9365
  }
@@ -6917,4 +9461,15 @@ Please __addLocaleData before adding additional unit data`);
6917
9461
  });
6918
9462
  }
6919
9463
  })();
9464
+ /*! Bundled license information:
9465
+
9466
+ decimal.js/decimal.mjs:
9467
+ (*!
9468
+ * decimal.js v10.4.3
9469
+ * An arbitrary-precision Decimal type for JavaScript.
9470
+ * https://github.com/MikeMcl/decimal.js
9471
+ * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
9472
+ * MIT Licence
9473
+ *)
9474
+ */
6920
9475
  //# sourceMappingURL=polyfill.iife.js.map