@formatjs/intl-supportedvaluesof 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/polyfill.iife.js +552 -2295
package/polyfill.iife.js CHANGED
@@ -96,7 +96,7 @@
96
96
  const dateTimeFormat = createMemoizedDateTimeFormat(`en-u-ca-${item}`);
97
97
  const options = dateTimeFormat.resolvedOptions().calendar;
98
98
  return options === item;
99
- } catch (e) {
99
+ } catch {
100
100
  }
101
101
  return false;
102
102
  }
@@ -111,7 +111,7 @@
111
111
  function isSupportedCollation(collation) {
112
112
  try {
113
113
  return Intl.Collator(`en-u-co-${collation}`).resolvedOptions().collation === collation;
114
- } catch (e) {
114
+ } catch {
115
115
  }
116
116
  return false;
117
117
  }
@@ -119,2371 +119,646 @@
119
119
  return collations.filter(isSupportedCollation).sort();
120
120
  }
121
121
 
122
- // node_modules/.aspect_rules_js/decimal.js@10.6.0/node_modules/decimal.js/decimal.mjs
123
- var EXP_LIMIT = 9e15;
124
- var MAX_DIGITS = 1e9;
125
- var NUMERALS = "0123456789abcdef";
126
- var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
127
- var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
128
- var DEFAULTS = {
129
- // These values must be integers within the stated ranges (inclusive).
130
- // Most of these values can be changed at run-time using the `Decimal.config` method.
131
- // The maximum number of significant digits of the result of a calculation or base conversion.
132
- // E.g. `Decimal.config({ precision: 20 });`
133
- precision: 20,
134
- // 1 to MAX_DIGITS
135
- // The rounding mode used when rounding to `precision`.
136
- //
137
- // ROUND_UP 0 Away from zero.
138
- // ROUND_DOWN 1 Towards zero.
139
- // ROUND_CEIL 2 Towards +Infinity.
140
- // ROUND_FLOOR 3 Towards -Infinity.
141
- // ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
142
- // ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
143
- // ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
144
- // ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
145
- // ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
146
- //
147
- // E.g.
148
- // `Decimal.rounding = 4;`
149
- // `Decimal.rounding = Decimal.ROUND_HALF_UP;`
150
- rounding: 4,
151
- // 0 to 8
152
- // The modulo mode used when calculating the modulus: a mod n.
153
- // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
154
- // The remainder (r) is calculated as: r = a - n * q.
155
- //
156
- // UP 0 The remainder is positive if the dividend is negative, else is negative.
157
- // DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
158
- // FLOOR 3 The remainder has the same sign as the divisor (Python %).
159
- // HALF_EVEN 6 The IEEE 754 remainder function.
160
- // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
161
- //
162
- // Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
163
- // division (9) are commonly used for the modulus operation. The other rounding modes can also
164
- // be used, but they may not give useful results.
165
- modulo: 1,
166
- // 0 to 9
167
- // The exponent value at and beneath which `toString` returns exponential notation.
168
- // JavaScript numbers: -7
169
- toExpNeg: -7,
170
- // 0 to -EXP_LIMIT
171
- // The exponent value at and above which `toString` returns exponential notation.
172
- // JavaScript numbers: 21
173
- toExpPos: 21,
174
- // 0 to EXP_LIMIT
175
- // The minimum exponent value, beneath which underflow to zero occurs.
176
- // JavaScript numbers: -324 (5e-324)
177
- minE: -EXP_LIMIT,
178
- // -1 to -EXP_LIMIT
179
- // The maximum exponent value, above which overflow to Infinity occurs.
180
- // JavaScript numbers: 308 (1.7976931348623157e+308)
181
- maxE: EXP_LIMIT,
182
- // 1 to EXP_LIMIT
183
- // Whether to use cryptographically-secure random number generation, if available.
184
- crypto: false
185
- // true/false
186
- };
187
- var inexact;
188
- var quadrant;
189
- var external = true;
190
- var decimalError = "[DecimalError] ";
191
- var invalidArgument = decimalError + "Invalid argument: ";
192
- var precisionLimitExceeded = decimalError + "Precision limit exceeded";
193
- var cryptoUnavailable = decimalError + "crypto unavailable";
194
- var tag = "[object Decimal]";
195
- var mathfloor = Math.floor;
196
- var mathpow = Math.pow;
197
- var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
198
- var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
199
- var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
200
- var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
201
- var BASE = 1e7;
202
- var LOG_BASE = 7;
203
- var MAX_SAFE_INTEGER = 9007199254740991;
204
- var LN10_PRECISION = LN10.length - 1;
205
- var PI_PRECISION = PI.length - 1;
206
- var P = { toStringTag: tag };
207
- P.absoluteValue = P.abs = function() {
208
- var x = new this.constructor(this);
209
- if (x.s < 0)
210
- x.s = 1;
211
- return finalise(x);
212
- };
213
- P.ceil = function() {
214
- return finalise(new this.constructor(this), this.e + 1, 2);
215
- };
216
- P.clampedTo = P.clamp = function(min2, max2) {
217
- var k, x = this, Ctor = x.constructor;
218
- min2 = new Ctor(min2);
219
- max2 = new Ctor(max2);
220
- if (!min2.s || !max2.s)
221
- return new Ctor(NaN);
222
- if (min2.gt(max2))
223
- throw Error(invalidArgument + max2);
224
- k = x.cmp(min2);
225
- return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
226
- };
227
- P.comparedTo = P.cmp = function(y) {
228
- var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
229
- if (!xd || !yd) {
230
- return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
231
- }
232
- if (!xd[0] || !yd[0])
233
- return xd[0] ? xs : yd[0] ? -ys : 0;
234
- if (xs !== ys)
235
- return xs;
236
- if (x.e !== y.e)
237
- return x.e > y.e ^ xs < 0 ? 1 : -1;
238
- xdL = xd.length;
239
- ydL = yd.length;
240
- for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
241
- if (xd[i] !== yd[i])
242
- return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
243
- }
244
- return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
245
- };
246
- P.cosine = P.cos = function() {
247
- var pr, rm, x = this, Ctor = x.constructor;
248
- if (!x.d)
249
- return new Ctor(NaN);
250
- if (!x.d[0])
251
- return new Ctor(1);
252
- pr = Ctor.precision;
253
- rm = Ctor.rounding;
254
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
255
- Ctor.rounding = 1;
256
- x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
257
- Ctor.precision = pr;
258
- Ctor.rounding = rm;
259
- return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
260
- };
261
- P.cubeRoot = P.cbrt = function() {
262
- var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
263
- if (!x.isFinite() || x.isZero())
264
- return new Ctor(x);
265
- external = false;
266
- s = x.s * mathpow(x.s * x, 1 / 3);
267
- if (!s || Math.abs(s) == 1 / 0) {
268
- n = digitsToString(x.d);
269
- e = x.e;
270
- if (s = (e - n.length + 1) % 3)
271
- n += s == 1 || s == -2 ? "0" : "00";
272
- s = mathpow(n, 1 / 3);
273
- e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
274
- if (s == 1 / 0) {
275
- n = "5e" + e;
276
- } else {
277
- n = s.toExponential();
278
- n = n.slice(0, n.indexOf("e") + 1) + e;
279
- }
280
- r = new Ctor(n);
281
- r.s = x.s;
282
- } else {
283
- r = new Ctor(s.toString());
122
+ // node_modules/.aspect_rules_js/@formatjs+bigdecimal@0.0.0/node_modules/@formatjs/bigdecimal/index.js
123
+ var DIV_PRECISION = 40;
124
+ var SpecialValue = function(SpecialValue2) {
125
+ SpecialValue2[SpecialValue2["NONE"] = 0] = "NONE";
126
+ SpecialValue2[SpecialValue2["NAN"] = 1] = "NAN";
127
+ SpecialValue2[SpecialValue2["POSITIVE_INFINITY"] = 2] = "POSITIVE_INFINITY";
128
+ SpecialValue2[SpecialValue2["NEGATIVE_INFINITY"] = 3] = "NEGATIVE_INFINITY";
129
+ return SpecialValue2;
130
+ }(SpecialValue || {});
131
+ function removeTrailingZeros(mantissa, exponent) {
132
+ if (mantissa === 0n)
133
+ return [0n, 0];
134
+ while (mantissa % 10n === 0n) {
135
+ mantissa /= 10n;
136
+ exponent++;
284
137
  }
285
- sd = (e = Ctor.precision) + 3;
286
- for (; ; ) {
287
- t = r;
288
- t3 = t.times(t).times(t);
289
- t3plusx = t3.plus(x);
290
- r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
291
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
292
- n = n.slice(sd - 3, sd + 1);
293
- if (n == "9999" || !rep && n == "4999") {
294
- if (!rep) {
295
- finalise(t, e + 1, 0);
296
- if (t.times(t).times(t).eq(x)) {
297
- r = t;
298
- break;
299
- }
300
- }
301
- sd += 4;
302
- rep = 1;
303
- } else {
304
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
305
- finalise(r, e + 1, 1);
306
- m = !r.times(r).times(r).eq(x);
307
- }
308
- break;
309
- }
310
- }
138
+ return [mantissa, exponent];
139
+ }
140
+ function bigintAbs(n) {
141
+ return n < 0n ? -n : n;
142
+ }
143
+ function digitCount(n) {
144
+ if (n === 0n)
145
+ return 1;
146
+ if (n < 0n)
147
+ n = -n;
148
+ let count = 0;
149
+ const big15 = 1000000000000000n;
150
+ while (n >= big15) {
151
+ n /= big15;
152
+ count += 15;
311
153
  }
312
- external = true;
313
- return finalise(r, e, Ctor.rounding, m);
314
- };
315
- P.decimalPlaces = P.dp = function() {
316
- var w, d = this.d, n = NaN;
317
- if (d) {
318
- w = d.length - 1;
319
- n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
320
- w = d[w];
321
- if (w)
322
- for (; w % 10 == 0; w /= 10)
323
- n--;
324
- if (n < 0)
325
- n = 0;
154
+ let r = Number(n);
155
+ while (r >= 1) {
156
+ r /= 10;
157
+ count++;
326
158
  }
327
- return n;
328
- };
329
- P.dividedBy = P.div = function(y) {
330
- return divide(this, new this.constructor(y));
331
- };
332
- P.dividedToIntegerBy = P.divToInt = function(y) {
333
- var x = this, Ctor = x.constructor;
334
- return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
335
- };
336
- P.equals = P.eq = function(y) {
337
- return this.cmp(y) === 0;
338
- };
339
- P.floor = function() {
340
- return finalise(new this.constructor(this), this.e + 1, 3);
341
- };
342
- P.greaterThan = P.gt = function(y) {
343
- return this.cmp(y) > 0;
344
- };
345
- P.greaterThanOrEqualTo = P.gte = function(y) {
346
- var k = this.cmp(y);
347
- return k == 1 || k === 0;
348
- };
349
- P.hyperbolicCosine = P.cosh = function() {
350
- var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
351
- if (!x.isFinite())
352
- return new Ctor(x.s ? 1 / 0 : NaN);
353
- if (x.isZero())
354
- return one;
355
- pr = Ctor.precision;
356
- rm = Ctor.rounding;
357
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
358
- Ctor.rounding = 1;
359
- len = x.d.length;
360
- if (len < 32) {
361
- k = Math.ceil(len / 3);
362
- n = (1 / tinyPow(4, k)).toString();
363
- } else {
364
- k = 16;
365
- n = "2.3283064365386962890625e-10";
366
- }
367
- x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
368
- var cosh2_x, i = k, d8 = new Ctor(8);
369
- for (; i--; ) {
370
- cosh2_x = x.times(x);
371
- x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
159
+ return count;
160
+ }
161
+ var TEN_BIGINT = 10n;
162
+ function bigintPow10(n) {
163
+ if (n <= 0)
164
+ return 1n;
165
+ let result = 1n;
166
+ let base = TEN_BIGINT;
167
+ let exp = n;
168
+ while (exp > 0) {
169
+ if (exp & 1)
170
+ result *= base;
171
+ base *= base;
172
+ exp >>= 1;
372
173
  }
373
- return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
374
- };
375
- P.hyperbolicSine = P.sinh = function() {
376
- var k, pr, rm, len, x = this, Ctor = x.constructor;
377
- if (!x.isFinite() || x.isZero())
378
- return new Ctor(x);
379
- pr = Ctor.precision;
380
- rm = Ctor.rounding;
381
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
382
- Ctor.rounding = 1;
383
- len = x.d.length;
384
- if (len < 3) {
385
- x = taylorSeries(Ctor, 2, x, x, true);
386
- } else {
387
- k = 1.4 * Math.sqrt(len);
388
- k = k > 16 ? 16 : k | 0;
389
- x = x.times(1 / tinyPow(5, k));
390
- x = taylorSeries(Ctor, 2, x, x, true);
391
- var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
392
- for (; k--; ) {
393
- sinh2_x = x.times(x);
394
- x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
395
- }
174
+ return result;
175
+ }
176
+ function parseDecimalString(s) {
177
+ s = s.trim();
178
+ if (s === "NaN") {
179
+ return {
180
+ mantissa: 0n,
181
+ exponent: 0,
182
+ special: SpecialValue.NAN,
183
+ negativeZero: false
184
+ };
396
185
  }
397
- Ctor.precision = pr;
398
- Ctor.rounding = rm;
399
- return finalise(x, pr, rm, true);
400
- };
401
- P.hyperbolicTangent = P.tanh = function() {
402
- var pr, rm, x = this, Ctor = x.constructor;
403
- if (!x.isFinite())
404
- return new Ctor(x.s);
405
- if (x.isZero())
406
- return new Ctor(x);
407
- pr = Ctor.precision;
408
- rm = Ctor.rounding;
409
- Ctor.precision = pr + 7;
410
- Ctor.rounding = 1;
411
- return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
412
- };
413
- P.inverseCosine = P.acos = function() {
414
- var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
415
- if (k !== -1) {
416
- return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
186
+ if (s === "Infinity" || s === "+Infinity") {
187
+ return {
188
+ mantissa: 0n,
189
+ exponent: 0,
190
+ special: SpecialValue.POSITIVE_INFINITY,
191
+ negativeZero: false
192
+ };
417
193
  }
418
- if (x.isZero())
419
- return getPi(Ctor, pr + 4, rm).times(0.5);
420
- Ctor.precision = pr + 6;
421
- Ctor.rounding = 1;
422
- x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
423
- Ctor.precision = pr;
424
- Ctor.rounding = rm;
425
- return x.times(2);
426
- };
427
- P.inverseHyperbolicCosine = P.acosh = function() {
428
- var pr, rm, x = this, Ctor = x.constructor;
429
- if (x.lte(1))
430
- return new Ctor(x.eq(1) ? 0 : NaN);
431
- if (!x.isFinite())
432
- return new Ctor(x);
433
- pr = Ctor.precision;
434
- rm = Ctor.rounding;
435
- Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
436
- Ctor.rounding = 1;
437
- external = false;
438
- x = x.times(x).minus(1).sqrt().plus(x);
439
- external = true;
440
- Ctor.precision = pr;
441
- Ctor.rounding = rm;
442
- return x.ln();
443
- };
444
- P.inverseHyperbolicSine = P.asinh = function() {
445
- var pr, rm, x = this, Ctor = x.constructor;
446
- if (!x.isFinite() || x.isZero())
447
- return new Ctor(x);
448
- pr = Ctor.precision;
449
- rm = Ctor.rounding;
450
- Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
451
- Ctor.rounding = 1;
452
- external = false;
453
- x = x.times(x).plus(1).sqrt().plus(x);
454
- external = true;
455
- Ctor.precision = pr;
456
- Ctor.rounding = rm;
457
- return x.ln();
458
- };
459
- P.inverseHyperbolicTangent = P.atanh = function() {
460
- var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
461
- if (!x.isFinite())
462
- return new Ctor(NaN);
463
- if (x.e >= 0)
464
- return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
465
- pr = Ctor.precision;
466
- rm = Ctor.rounding;
467
- xsd = x.sd();
468
- if (Math.max(xsd, pr) < 2 * -x.e - 1)
469
- return finalise(new Ctor(x), pr, rm, true);
470
- Ctor.precision = wpr = xsd - x.e;
471
- x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
472
- Ctor.precision = pr + 4;
473
- Ctor.rounding = 1;
474
- x = x.ln();
475
- Ctor.precision = pr;
476
- Ctor.rounding = rm;
477
- return x.times(0.5);
478
- };
479
- P.inverseSine = P.asin = function() {
480
- var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
481
- if (x.isZero())
482
- return new Ctor(x);
483
- k = x.abs().cmp(1);
484
- pr = Ctor.precision;
485
- rm = Ctor.rounding;
486
- if (k !== -1) {
487
- if (k === 0) {
488
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
489
- halfPi.s = x.s;
490
- return halfPi;
491
- }
492
- return new Ctor(NaN);
194
+ if (s === "-Infinity") {
195
+ return {
196
+ mantissa: 0n,
197
+ exponent: 0,
198
+ special: SpecialValue.NEGATIVE_INFINITY,
199
+ negativeZero: false
200
+ };
493
201
  }
494
- Ctor.precision = pr + 6;
495
- Ctor.rounding = 1;
496
- x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
497
- Ctor.precision = pr;
498
- Ctor.rounding = rm;
499
- return x.times(2);
500
- };
501
- P.inverseTangent = P.atan = function() {
502
- var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
503
- if (!x.isFinite()) {
504
- if (!x.s)
505
- return new Ctor(NaN);
506
- if (pr + 4 <= PI_PRECISION) {
507
- r = getPi(Ctor, pr + 4, rm).times(0.5);
508
- r.s = x.s;
509
- return r;
510
- }
511
- } else if (x.isZero()) {
512
- return new Ctor(x);
513
- } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
514
- r = getPi(Ctor, pr + 4, rm).times(0.25);
515
- r.s = x.s;
516
- return r;
202
+ let negative = false;
203
+ let idx = 0;
204
+ if (s[idx] === "-") {
205
+ negative = true;
206
+ idx++;
207
+ } else if (s[idx] === "+") {
208
+ idx++;
517
209
  }
518
- Ctor.precision = wpr = pr + 10;
519
- Ctor.rounding = 1;
520
- k = Math.min(28, wpr / LOG_BASE + 2 | 0);
521
- for (i = k; i; --i)
522
- x = x.div(x.times(x).plus(1).sqrt().plus(1));
523
- external = false;
524
- j = Math.ceil(wpr / LOG_BASE);
525
- n = 1;
526
- x2 = x.times(x);
527
- r = new Ctor(x);
528
- px = x;
529
- for (; i !== -1; ) {
530
- px = px.times(x2);
531
- t = r.minus(px.div(n += 2));
532
- px = px.times(x2);
533
- r = t.plus(px.div(n += 2));
534
- if (r.d[j] !== void 0)
535
- for (i = j; r.d[i] === t.d[i] && i--; )
536
- ;
210
+ let eIdx = s.indexOf("e", idx);
211
+ if (eIdx === -1)
212
+ eIdx = s.indexOf("E", idx);
213
+ let sciExp = 0;
214
+ let numPart;
215
+ if (eIdx !== -1) {
216
+ sciExp = parseInt(s.substring(eIdx + 1), 10);
217
+ numPart = s.substring(idx, eIdx);
218
+ } else {
219
+ numPart = s.substring(idx);
537
220
  }
538
- if (k)
539
- r = r.times(2 << k - 1);
540
- external = true;
541
- return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
542
- };
543
- P.isFinite = function() {
544
- return !!this.d;
545
- };
546
- P.isInteger = P.isInt = function() {
547
- return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
548
- };
549
- P.isNaN = function() {
550
- return !this.s;
551
- };
552
- P.isNegative = P.isNeg = function() {
553
- return this.s < 0;
554
- };
555
- P.isPositive = P.isPos = function() {
556
- return this.s > 0;
557
- };
558
- P.isZero = function() {
559
- return !!this.d && this.d[0] === 0;
560
- };
561
- P.lessThan = P.lt = function(y) {
562
- return this.cmp(y) < 0;
563
- };
564
- P.lessThanOrEqualTo = P.lte = function(y) {
565
- return this.cmp(y) < 1;
566
- };
567
- P.logarithm = P.log = function(base) {
568
- var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
569
- if (base == null) {
570
- base = new Ctor(10);
571
- isBase10 = true;
221
+ const dotIdx = numPart.indexOf(".");
222
+ let intPart;
223
+ let fracPart;
224
+ if (dotIdx !== -1) {
225
+ intPart = numPart.substring(0, dotIdx);
226
+ fracPart = numPart.substring(dotIdx + 1);
572
227
  } else {
573
- base = new Ctor(base);
574
- d = base.d;
575
- if (base.s < 0 || !d || !d[0] || base.eq(1))
576
- return new Ctor(NaN);
577
- isBase10 = base.eq(10);
228
+ intPart = numPart;
229
+ fracPart = "";
578
230
  }
579
- d = arg.d;
580
- if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
581
- return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
231
+ const combined = intPart + fracPart;
232
+ const exponent = sciExp - fracPart.length;
233
+ if (combined === "" || combined === "0" || /^0+$/.test(combined)) {
234
+ return {
235
+ mantissa: 0n,
236
+ exponent: 0,
237
+ special: SpecialValue.NONE,
238
+ negativeZero: negative
239
+ };
582
240
  }
583
- if (isBase10) {
584
- if (d.length > 1) {
585
- inf = true;
586
- } else {
587
- for (k = d[0]; k % 10 === 0; )
588
- k /= 10;
589
- inf = k !== 1;
241
+ let mantissa = BigInt(combined);
242
+ if (negative)
243
+ mantissa = -mantissa;
244
+ const [normMantissa, normExponent] = removeTrailingZeros(mantissa, exponent);
245
+ return {
246
+ mantissa: normMantissa,
247
+ exponent: normExponent,
248
+ special: SpecialValue.NONE,
249
+ negativeZero: false
250
+ };
251
+ }
252
+ var BigDecimal = class _BigDecimal {
253
+ constructor(value) {
254
+ __publicField(this, "_mantissa");
255
+ __publicField(this, "_exponent");
256
+ __publicField(this, "_special");
257
+ __publicField(this, "_negativeZero");
258
+ if (typeof value === "bigint") {
259
+ const [m, e] = removeTrailingZeros(value, 0);
260
+ this._mantissa = m;
261
+ this._exponent = e;
262
+ this._special = SpecialValue.NONE;
263
+ this._negativeZero = false;
264
+ return;
590
265
  }
591
- }
592
- external = false;
593
- sd = pr + guard;
594
- num = naturalLogarithm(arg, sd);
595
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
596
- r = divide(num, denominator, sd, 1);
597
- if (checkRoundingDigits(r.d, k = pr, rm)) {
598
- do {
599
- sd += 10;
600
- num = naturalLogarithm(arg, sd);
601
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
602
- r = divide(num, denominator, sd, 1);
603
- if (!inf) {
604
- if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
605
- r = finalise(r, pr + 1, 0);
606
- }
607
- break;
266
+ if (typeof value === "number") {
267
+ if (Number.isNaN(value)) {
268
+ this._mantissa = 0n;
269
+ this._exponent = 0;
270
+ this._special = SpecialValue.NAN;
271
+ this._negativeZero = false;
272
+ return;
608
273
  }
609
- } while (checkRoundingDigits(r.d, k += 10, rm));
610
- }
611
- external = true;
612
- return finalise(r, pr, rm);
613
- };
614
- P.minus = P.sub = function(y) {
615
- var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
616
- y = new Ctor(y);
617
- if (!x.d || !y.d) {
618
- if (!x.s || !y.s)
619
- y = new Ctor(NaN);
620
- else if (x.d)
621
- y.s = -y.s;
622
- else
623
- y = new Ctor(y.d || x.s !== y.s ? x : NaN);
624
- return y;
625
- }
626
- if (x.s != y.s) {
627
- y.s = -y.s;
628
- return x.plus(y);
629
- }
630
- xd = x.d;
631
- yd = y.d;
632
- pr = Ctor.precision;
633
- rm = Ctor.rounding;
634
- if (!xd[0] || !yd[0]) {
635
- if (yd[0])
636
- y.s = -y.s;
637
- else if (xd[0])
638
- y = new Ctor(x);
639
- else
640
- return new Ctor(rm === 3 ? -0 : 0);
641
- return external ? finalise(y, pr, rm) : y;
642
- }
643
- e = mathfloor(y.e / LOG_BASE);
644
- xe = mathfloor(x.e / LOG_BASE);
645
- xd = xd.slice();
646
- k = xe - e;
647
- if (k) {
648
- xLTy = k < 0;
649
- if (xLTy) {
650
- d = xd;
651
- k = -k;
652
- len = yd.length;
653
- } else {
654
- d = yd;
655
- e = xe;
656
- len = xd.length;
657
- }
658
- i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
659
- if (k > i) {
660
- k = i;
661
- d.length = 1;
662
- }
663
- d.reverse();
664
- for (i = k; i--; )
665
- d.push(0);
666
- d.reverse();
667
- } else {
668
- i = xd.length;
669
- len = yd.length;
670
- xLTy = i < len;
671
- if (xLTy)
672
- len = i;
673
- for (i = 0; i < len; i++) {
674
- if (xd[i] != yd[i]) {
675
- xLTy = xd[i] < yd[i];
676
- break;
274
+ if (value === Infinity) {
275
+ this._mantissa = 0n;
276
+ this._exponent = 0;
277
+ this._special = SpecialValue.POSITIVE_INFINITY;
278
+ this._negativeZero = false;
279
+ return;
677
280
  }
281
+ if (value === -Infinity) {
282
+ this._mantissa = 0n;
283
+ this._exponent = 0;
284
+ this._special = SpecialValue.NEGATIVE_INFINITY;
285
+ this._negativeZero = false;
286
+ return;
287
+ }
288
+ if (value === 0) {
289
+ this._mantissa = 0n;
290
+ this._exponent = 0;
291
+ this._special = SpecialValue.NONE;
292
+ this._negativeZero = Object.is(value, -0);
293
+ return;
294
+ }
295
+ value = String(value);
678
296
  }
679
- k = 0;
680
- }
681
- if (xLTy) {
682
- d = xd;
683
- xd = yd;
684
- yd = d;
685
- y.s = -y.s;
686
- }
687
- len = xd.length;
688
- for (i = yd.length - len; i > 0; --i)
689
- xd[len++] = 0;
690
- for (i = yd.length; i > k; ) {
691
- if (xd[--i] < yd[i]) {
692
- for (j = i; j && xd[--j] === 0; )
693
- xd[j] = BASE - 1;
694
- --xd[j];
695
- xd[i] += BASE;
696
- }
697
- xd[i] -= yd[i];
698
- }
699
- for (; xd[--len] === 0; )
700
- xd.pop();
701
- for (; xd[0] === 0; xd.shift())
702
- --e;
703
- if (!xd[0])
704
- return new Ctor(rm === 3 ? -0 : 0);
705
- y.d = xd;
706
- y.e = getBase10Exponent(xd, e);
707
- return external ? finalise(y, pr, rm) : y;
708
- };
709
- P.modulo = P.mod = function(y) {
710
- var q, x = this, Ctor = x.constructor;
711
- y = new Ctor(y);
712
- if (!x.d || !y.s || y.d && !y.d[0])
713
- return new Ctor(NaN);
714
- if (!y.d || x.d && !x.d[0]) {
715
- return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
716
- }
717
- external = false;
718
- if (Ctor.modulo == 9) {
719
- q = divide(x, y.abs(), 0, 3, 1);
720
- q.s *= y.s;
721
- } else {
722
- q = divide(x, y, 0, Ctor.modulo, 1);
723
- }
724
- q = q.times(y);
725
- external = true;
726
- return x.minus(q);
727
- };
728
- P.naturalExponential = P.exp = function() {
729
- return naturalExponential(this);
730
- };
731
- P.naturalLogarithm = P.ln = function() {
732
- return naturalLogarithm(this);
733
- };
734
- P.negated = P.neg = function() {
735
- var x = new this.constructor(this);
736
- x.s = -x.s;
737
- return finalise(x);
738
- };
739
- P.plus = P.add = function(y) {
740
- var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
741
- y = new Ctor(y);
742
- if (!x.d || !y.d) {
743
- if (!x.s || !y.s)
744
- y = new Ctor(NaN);
745
- else if (!x.d)
746
- y = new Ctor(y.d || x.s === y.s ? x : NaN);
747
- return y;
297
+ const parsed = parseDecimalString(value);
298
+ this._mantissa = parsed.mantissa;
299
+ this._exponent = parsed.exponent;
300
+ this._special = parsed.special;
301
+ this._negativeZero = parsed.negativeZero;
748
302
  }
749
- if (x.s != y.s) {
750
- y.s = -y.s;
751
- return x.minus(y);
303
+ // Private constructor for internal use
304
+ static _create(mantissa, exponent, special, negativeZero) {
305
+ const bd = Object.create(_BigDecimal.prototype);
306
+ bd._mantissa = mantissa;
307
+ bd._exponent = exponent;
308
+ bd._special = special;
309
+ bd._negativeZero = negativeZero;
310
+ return bd;
752
311
  }
753
- xd = x.d;
754
- yd = y.d;
755
- pr = Ctor.precision;
756
- rm = Ctor.rounding;
757
- if (!xd[0] || !yd[0]) {
758
- if (!yd[0])
759
- y = new Ctor(x);
760
- return external ? finalise(y, pr, rm) : y;
312
+ // Auto-coerce to BigDecimal for decimal.js compat
313
+ static _coerce(v) {
314
+ return v instanceof _BigDecimal ? v : new _BigDecimal(v);
761
315
  }
762
- k = mathfloor(x.e / LOG_BASE);
763
- e = mathfloor(y.e / LOG_BASE);
764
- xd = xd.slice();
765
- i = k - e;
766
- if (i) {
767
- if (i < 0) {
768
- d = xd;
769
- i = -i;
770
- len = yd.length;
771
- } else {
772
- d = yd;
773
- e = k;
774
- len = xd.length;
316
+ // --- Arithmetic ---
317
+ times(y) {
318
+ const other = _BigDecimal._coerce(y);
319
+ if (this._special || other._special) {
320
+ return this._specialArith(other, "times");
775
321
  }
776
- k = Math.ceil(pr / LOG_BASE);
777
- len = k > len ? k + 1 : len + 1;
778
- if (i > len) {
779
- i = len;
780
- d.length = 1;
322
+ if (this._mantissa === 0n || other._mantissa === 0n) {
323
+ const negZero = this._isSignNegative() ? !other._isSignNegative() : other._isSignNegative();
324
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
781
325
  }
782
- d.reverse();
783
- for (; i--; )
784
- d.push(0);
785
- d.reverse();
786
- }
787
- len = xd.length;
788
- i = yd.length;
789
- if (len - i < 0) {
790
- i = len;
791
- d = yd;
792
- yd = xd;
793
- xd = d;
794
- }
795
- for (carry = 0; i; ) {
796
- carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
797
- xd[i] %= BASE;
326
+ const m = this._mantissa * other._mantissa;
327
+ const e = this._exponent + other._exponent;
328
+ const [nm, ne] = removeTrailingZeros(m, e);
329
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
798
330
  }
799
- if (carry) {
800
- xd.unshift(carry);
801
- ++e;
802
- }
803
- for (len = xd.length; xd[--len] == 0; )
804
- xd.pop();
805
- y.d = xd;
806
- y.e = getBase10Exponent(xd, e);
807
- return external ? finalise(y, pr, rm) : y;
808
- };
809
- P.precision = P.sd = function(z) {
810
- var k, x = this;
811
- if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
812
- throw Error(invalidArgument + z);
813
- if (x.d) {
814
- k = getPrecision(x.d);
815
- if (z && x.e + 1 > k)
816
- k = x.e + 1;
817
- } else {
818
- k = NaN;
819
- }
820
- return k;
821
- };
822
- P.round = function() {
823
- var x = this, Ctor = x.constructor;
824
- return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
825
- };
826
- P.sine = P.sin = function() {
827
- var pr, rm, x = this, Ctor = x.constructor;
828
- if (!x.isFinite())
829
- return new Ctor(NaN);
830
- if (x.isZero())
831
- return new Ctor(x);
832
- pr = Ctor.precision;
833
- rm = Ctor.rounding;
834
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
835
- Ctor.rounding = 1;
836
- x = sine(Ctor, toLessThanHalfPi(Ctor, x));
837
- Ctor.precision = pr;
838
- Ctor.rounding = rm;
839
- return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
840
- };
841
- P.squareRoot = P.sqrt = function() {
842
- var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
843
- if (s !== 1 || !d || !d[0]) {
844
- return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
845
- }
846
- external = false;
847
- s = Math.sqrt(+x);
848
- if (s == 0 || s == 1 / 0) {
849
- n = digitsToString(d);
850
- if ((n.length + e) % 2 == 0)
851
- n += "0";
852
- s = Math.sqrt(n);
853
- e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
854
- if (s == 1 / 0) {
855
- n = "5e" + e;
856
- } else {
857
- n = s.toExponential();
858
- n = n.slice(0, n.indexOf("e") + 1) + e;
331
+ div(y) {
332
+ const other = _BigDecimal._coerce(y);
333
+ if (this._special || other._special) {
334
+ return this._specialArith(other, "div");
859
335
  }
860
- r = new Ctor(n);
861
- } else {
862
- r = new Ctor(s.toString());
863
- }
864
- sd = (e = Ctor.precision) + 3;
865
- for (; ; ) {
866
- t = r;
867
- r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
868
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
869
- n = n.slice(sd - 3, sd + 1);
870
- if (n == "9999" || !rep && n == "4999") {
871
- if (!rep) {
872
- finalise(t, e + 1, 0);
873
- if (t.times(t).eq(x)) {
874
- r = t;
875
- break;
876
- }
877
- }
878
- sd += 4;
879
- rep = 1;
880
- } else {
881
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
882
- finalise(r, e + 1, 1);
883
- m = !r.times(r).eq(x);
884
- }
885
- break;
336
+ if (other._mantissa === 0n) {
337
+ if (this._mantissa === 0n) {
338
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
886
339
  }
340
+ const neg = this._isSignNegative() !== other._isSignNegative();
341
+ return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
887
342
  }
888
- }
889
- external = true;
890
- return finalise(r, e, Ctor.rounding, m);
891
- };
892
- P.tangent = P.tan = function() {
893
- var pr, rm, x = this, Ctor = x.constructor;
894
- if (!x.isFinite())
895
- return new Ctor(NaN);
896
- if (x.isZero())
897
- return new Ctor(x);
898
- pr = Ctor.precision;
899
- rm = Ctor.rounding;
900
- Ctor.precision = pr + 10;
901
- Ctor.rounding = 1;
902
- x = x.sin();
903
- x.s = 1;
904
- x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
905
- Ctor.precision = pr;
906
- Ctor.rounding = rm;
907
- return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
908
- };
909
- P.times = P.mul = function(y) {
910
- var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
911
- y.s *= x.s;
912
- if (!xd || !xd[0] || !yd || !yd[0]) {
913
- return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
914
- }
915
- e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
916
- xdL = xd.length;
917
- ydL = yd.length;
918
- if (xdL < ydL) {
919
- r = xd;
920
- xd = yd;
921
- yd = r;
922
- rL = xdL;
923
- xdL = ydL;
924
- ydL = rL;
925
- }
926
- r = [];
927
- rL = xdL + ydL;
928
- for (i = rL; i--; )
929
- r.push(0);
930
- for (i = ydL; --i >= 0; ) {
931
- carry = 0;
932
- for (k = xdL + i; k > i; ) {
933
- t = r[k] + yd[i] * xd[k - i - 1] + carry;
934
- r[k--] = t % BASE | 0;
935
- carry = t / BASE | 0;
343
+ if (this._mantissa === 0n) {
344
+ const negZero = this._isSignNegative() !== other._isSignNegative();
345
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
936
346
  }
937
- r[k] = (r[k] + carry) % BASE | 0;
938
- }
939
- for (; !r[--rL]; )
940
- r.pop();
941
- if (carry)
942
- ++e;
943
- else
944
- r.shift();
945
- y.d = r;
946
- y.e = getBase10Exponent(r, e);
947
- return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
948
- };
949
- P.toBinary = function(sd, rm) {
950
- return toStringBinary(this, 2, sd, rm);
951
- };
952
- P.toDecimalPlaces = P.toDP = function(dp, rm) {
953
- var x = this, Ctor = x.constructor;
954
- x = new Ctor(x);
955
- if (dp === void 0)
956
- return x;
957
- checkInt32(dp, 0, MAX_DIGITS);
958
- if (rm === void 0)
959
- rm = Ctor.rounding;
960
- else
961
- checkInt32(rm, 0, 8);
962
- return finalise(x, dp + x.e + 1, rm);
963
- };
964
- P.toExponential = function(dp, rm) {
965
- var str, x = this, Ctor = x.constructor;
966
- if (dp === void 0) {
967
- str = finiteToString(x, true);
968
- } else {
969
- checkInt32(dp, 0, MAX_DIGITS);
970
- if (rm === void 0)
971
- rm = Ctor.rounding;
972
- else
973
- checkInt32(rm, 0, 8);
974
- x = finalise(new Ctor(x), dp + 1, rm);
975
- str = finiteToString(x, true, dp + 1);
976
- }
977
- return x.isNeg() && !x.isZero() ? "-" + str : str;
978
- };
979
- P.toFixed = function(dp, rm) {
980
- var str, y, x = this, Ctor = x.constructor;
981
- if (dp === void 0) {
982
- str = finiteToString(x);
983
- } else {
984
- checkInt32(dp, 0, MAX_DIGITS);
985
- if (rm === void 0)
986
- rm = Ctor.rounding;
987
- else
988
- checkInt32(rm, 0, 8);
989
- y = finalise(new Ctor(x), dp + x.e + 1, rm);
990
- str = finiteToString(y, false, dp + y.e + 1);
991
- }
992
- return x.isNeg() && !x.isZero() ? "-" + str : str;
993
- };
994
- P.toFraction = function(maxD) {
995
- var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
996
- if (!xd)
997
- return new Ctor(x);
998
- n1 = d0 = new Ctor(1);
999
- d1 = n0 = new Ctor(0);
1000
- d = new Ctor(d1);
1001
- e = d.e = getPrecision(xd) - x.e - 1;
1002
- k = e % LOG_BASE;
1003
- d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
1004
- if (maxD == null) {
1005
- maxD = e > 0 ? d : n1;
1006
- } else {
1007
- n = new Ctor(maxD);
1008
- if (!n.isInt() || n.lt(n1))
1009
- throw Error(invalidArgument + n);
1010
- maxD = n.gt(d) ? e > 0 ? d : n1 : n;
1011
- }
1012
- external = false;
1013
- n = new Ctor(digitsToString(xd));
1014
- pr = Ctor.precision;
1015
- Ctor.precision = e = xd.length * LOG_BASE * 2;
1016
- for (; ; ) {
1017
- q = divide(n, d, 0, 1, 1);
1018
- d2 = d0.plus(q.times(d1));
1019
- if (d2.cmp(maxD) == 1)
1020
- break;
1021
- d0 = d1;
1022
- d1 = d2;
1023
- d2 = n1;
1024
- n1 = n0.plus(q.times(d2));
1025
- n0 = d2;
1026
- d2 = d;
1027
- d = n.minus(q.times(d2));
1028
- n = d2;
347
+ const scaledNumerator = this._mantissa * bigintPow10(DIV_PRECISION);
348
+ const quotient = scaledNumerator / other._mantissa;
349
+ const newExponent = this._exponent - other._exponent - DIV_PRECISION;
350
+ const [nm, ne] = removeTrailingZeros(quotient, newExponent);
351
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
1029
352
  }
1030
- d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
1031
- n0 = n0.plus(d2.times(n1));
1032
- d0 = d0.plus(d2.times(d1));
1033
- n0.s = n1.s = x.s;
1034
- r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
1035
- Ctor.precision = pr;
1036
- external = true;
1037
- return r;
1038
- };
1039
- P.toHexadecimal = P.toHex = function(sd, rm) {
1040
- return toStringBinary(this, 16, sd, rm);
1041
- };
1042
- P.toNearest = function(y, rm) {
1043
- var x = this, Ctor = x.constructor;
1044
- x = new Ctor(x);
1045
- if (y == null) {
1046
- if (!x.d)
1047
- return x;
1048
- y = new Ctor(1);
1049
- rm = Ctor.rounding;
1050
- } else {
1051
- y = new Ctor(y);
1052
- if (rm === void 0) {
1053
- rm = Ctor.rounding;
1054
- } else {
1055
- checkInt32(rm, 0, 8);
353
+ plus(y) {
354
+ const other = _BigDecimal._coerce(y);
355
+ if (this._special || other._special) {
356
+ return this._specialArith(other, "plus");
1056
357
  }
1057
- if (!x.d)
1058
- return y.s ? x : y;
1059
- if (!y.d) {
1060
- if (y.s)
1061
- y.s = x.s;
1062
- return y;
358
+ if (this._mantissa === 0n && other._mantissa === 0n) {
359
+ const negZero = this._negativeZero && other._negativeZero;
360
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
1063
361
  }
1064
- }
1065
- if (y.d[0]) {
1066
- external = false;
1067
- x = divide(x, y, 0, rm, 1).times(y);
1068
- external = true;
1069
- finalise(x);
1070
- } else {
1071
- y.s = x.s;
1072
- x = y;
1073
- }
1074
- return x;
1075
- };
1076
- P.toNumber = function() {
1077
- return +this;
1078
- };
1079
- P.toOctal = function(sd, rm) {
1080
- return toStringBinary(this, 8, sd, rm);
1081
- };
1082
- P.toPower = P.pow = function(y) {
1083
- var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
1084
- if (!x.d || !y.d || !x.d[0] || !y.d[0])
1085
- return new Ctor(mathpow(+x, yn));
1086
- x = new Ctor(x);
1087
- if (x.eq(1))
1088
- return x;
1089
- pr = Ctor.precision;
1090
- rm = Ctor.rounding;
1091
- if (y.eq(1))
1092
- return finalise(x, pr, rm);
1093
- e = mathfloor(y.e / LOG_BASE);
1094
- if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
1095
- r = intPow(Ctor, x, k, pr);
1096
- return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
1097
- }
1098
- s = x.s;
1099
- if (s < 0) {
1100
- if (e < y.d.length - 1)
1101
- return new Ctor(NaN);
1102
- if ((y.d[e] & 1) == 0)
1103
- s = 1;
1104
- if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
1105
- x.s = s;
1106
- return x;
362
+ if (this._mantissa === 0n)
363
+ return other;
364
+ if (other._mantissa === 0n)
365
+ return this;
366
+ let m1 = this._mantissa;
367
+ let m2 = other._mantissa;
368
+ const e1 = this._exponent;
369
+ const e2 = other._exponent;
370
+ const minE = Math.min(e1, e2);
371
+ if (e1 > minE)
372
+ m1 *= bigintPow10(e1 - minE);
373
+ if (e2 > minE)
374
+ m2 *= bigintPow10(e2 - minE);
375
+ const sum = m1 + m2;
376
+ if (sum === 0n) {
377
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
1107
378
  }
379
+ const [nm, ne] = removeTrailingZeros(sum, minE);
380
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
1108
381
  }
1109
- k = mathpow(+x, yn);
1110
- e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
1111
- if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
1112
- return new Ctor(e > 0 ? s / 0 : 0);
1113
- external = false;
1114
- Ctor.rounding = x.s = 1;
1115
- k = Math.min(12, (e + "").length);
1116
- r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
1117
- if (r.d) {
1118
- r = finalise(r, pr + 5, 1);
1119
- if (checkRoundingDigits(r.d, pr, rm)) {
1120
- e = pr + 10;
1121
- r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
1122
- if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
1123
- r = finalise(r, pr + 1, 0);
382
+ minus(y) {
383
+ return this.plus(_BigDecimal._coerce(y).negated());
384
+ }
385
+ mod(y) {
386
+ const other = _BigDecimal._coerce(y);
387
+ if (this._special || other._special) {
388
+ if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN) {
389
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
390
+ }
391
+ if (this._special === SpecialValue.POSITIVE_INFINITY || this._special === SpecialValue.NEGATIVE_INFINITY) {
392
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
393
+ }
394
+ if (other._special === SpecialValue.POSITIVE_INFINITY || other._special === SpecialValue.NEGATIVE_INFINITY) {
395
+ return this;
1124
396
  }
1125
397
  }
1126
- }
1127
- r.s = s;
1128
- external = true;
1129
- Ctor.rounding = rm;
1130
- return finalise(r, pr, rm);
1131
- };
1132
- P.toPrecision = function(sd, rm) {
1133
- var str, x = this, Ctor = x.constructor;
1134
- if (sd === void 0) {
1135
- str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1136
- } else {
1137
- checkInt32(sd, 1, MAX_DIGITS);
1138
- if (rm === void 0)
1139
- rm = Ctor.rounding;
1140
- else
1141
- checkInt32(rm, 0, 8);
1142
- x = finalise(new Ctor(x), sd, rm);
1143
- str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
1144
- }
1145
- return x.isNeg() && !x.isZero() ? "-" + str : str;
1146
- };
1147
- P.toSignificantDigits = P.toSD = function(sd, rm) {
1148
- var x = this, Ctor = x.constructor;
1149
- if (sd === void 0) {
1150
- sd = Ctor.precision;
1151
- rm = Ctor.rounding;
1152
- } else {
1153
- checkInt32(sd, 1, MAX_DIGITS);
1154
- if (rm === void 0)
1155
- rm = Ctor.rounding;
1156
- else
1157
- checkInt32(rm, 0, 8);
1158
- }
1159
- return finalise(new Ctor(x), sd, rm);
1160
- };
1161
- P.toString = function() {
1162
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1163
- return x.isNeg() && !x.isZero() ? "-" + str : str;
1164
- };
1165
- P.truncated = P.trunc = function() {
1166
- return finalise(new this.constructor(this), this.e + 1, 1);
1167
- };
1168
- P.valueOf = P.toJSON = function() {
1169
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1170
- return x.isNeg() ? "-" + str : str;
1171
- };
1172
- function digitsToString(d) {
1173
- var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
1174
- if (indexOfLastWord > 0) {
1175
- str += w;
1176
- for (i = 1; i < indexOfLastWord; i++) {
1177
- ws = d[i] + "";
1178
- k = LOG_BASE - ws.length;
1179
- if (k)
1180
- str += getZeroString(k);
1181
- str += ws;
398
+ if (other._mantissa === 0n) {
399
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
1182
400
  }
1183
- w = d[i];
1184
- ws = w + "";
1185
- k = LOG_BASE - ws.length;
1186
- if (k)
1187
- str += getZeroString(k);
1188
- } else if (w === 0) {
1189
- return "0";
1190
- }
1191
- for (; w % 10 === 0; )
1192
- w /= 10;
1193
- return str + w;
1194
- }
1195
- function checkInt32(i, min2, max2) {
1196
- if (i !== ~~i || i < min2 || i > max2) {
1197
- throw Error(invalidArgument + i);
1198
- }
1199
- }
1200
- function checkRoundingDigits(d, i, rm, repeating) {
1201
- var di, k, r, rd;
1202
- for (k = d[0]; k >= 10; k /= 10)
1203
- --i;
1204
- if (--i < 0) {
1205
- i += LOG_BASE;
1206
- di = 0;
1207
- } else {
1208
- di = Math.ceil((i + 1) / LOG_BASE);
1209
- i %= LOG_BASE;
1210
- }
1211
- k = mathpow(10, LOG_BASE - i);
1212
- rd = d[di] % k | 0;
1213
- if (repeating == null) {
1214
- if (i < 3) {
1215
- if (i == 0)
1216
- rd = rd / 100 | 0;
1217
- else if (i == 1)
1218
- rd = rd / 10 | 0;
1219
- r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
1220
- } else {
1221
- 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;
401
+ if (this._mantissa === 0n) {
402
+ return this;
1222
403
  }
1223
- } else {
1224
- if (i < 4) {
1225
- if (i == 0)
1226
- rd = rd / 1e3 | 0;
1227
- else if (i == 1)
1228
- rd = rd / 100 | 0;
1229
- else if (i == 2)
1230
- rd = rd / 10 | 0;
1231
- r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
1232
- } else {
1233
- 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;
404
+ let m1 = this._mantissa;
405
+ let m2 = other._mantissa;
406
+ const e1 = this._exponent;
407
+ const e2 = other._exponent;
408
+ const minE = Math.min(e1, e2);
409
+ if (e1 > minE)
410
+ m1 *= bigintPow10(e1 - minE);
411
+ if (e2 > minE)
412
+ m2 *= bigintPow10(e2 - minE);
413
+ const remainder = m1 % m2;
414
+ if (remainder === 0n) {
415
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
1234
416
  }
417
+ const [nm, ne] = removeTrailingZeros(remainder, minE);
418
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
1235
419
  }
1236
- return r;
1237
- }
1238
- function convertBase(str, baseIn, baseOut) {
1239
- var j, arr = [0], arrL, i = 0, strL = str.length;
1240
- for (; i < strL; ) {
1241
- for (arrL = arr.length; arrL--; )
1242
- arr[arrL] *= baseIn;
1243
- arr[0] += NUMERALS.indexOf(str.charAt(i++));
1244
- for (j = 0; j < arr.length; j++) {
1245
- if (arr[j] > baseOut - 1) {
1246
- if (arr[j + 1] === void 0)
1247
- arr[j + 1] = 0;
1248
- arr[j + 1] += arr[j] / baseOut | 0;
1249
- arr[j] %= baseOut;
1250
- }
420
+ abs() {
421
+ if (this._special === SpecialValue.NAN)
422
+ return this;
423
+ if (this._special === SpecialValue.NEGATIVE_INFINITY) {
424
+ return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
1251
425
  }
426
+ return _BigDecimal._create(bigintAbs(this._mantissa), this._exponent, this._special, false);
1252
427
  }
1253
- return arr.reverse();
1254
- }
1255
- function cosine(Ctor, x) {
1256
- var k, len, y;
1257
- if (x.isZero())
1258
- return x;
1259
- len = x.d.length;
1260
- if (len < 32) {
1261
- k = Math.ceil(len / 3);
1262
- y = (1 / tinyPow(4, k)).toString();
1263
- } else {
1264
- k = 16;
1265
- y = "2.3283064365386962890625e-10";
1266
- }
1267
- Ctor.precision += k;
1268
- x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
1269
- for (var i = k; i--; ) {
1270
- var cos2x = x.times(x);
1271
- x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
1272
- }
1273
- Ctor.precision -= k;
1274
- return x;
1275
- }
1276
- var divide = /* @__PURE__ */ function() {
1277
- function multiplyInteger(x, k, base) {
1278
- var temp, carry = 0, i = x.length;
1279
- for (x = x.slice(); i--; ) {
1280
- temp = x[i] * k + carry;
1281
- x[i] = temp % base | 0;
1282
- carry = temp / base | 0;
428
+ negated() {
429
+ if (this._special === SpecialValue.NAN)
430
+ return this;
431
+ if (this._special === SpecialValue.POSITIVE_INFINITY) {
432
+ return _BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false);
1283
433
  }
1284
- if (carry)
1285
- x.unshift(carry);
1286
- return x;
1287
- }
1288
- function compare(a, b, aL, bL) {
1289
- var i, r;
1290
- if (aL != bL) {
1291
- r = aL > bL ? 1 : -1;
1292
- } else {
1293
- for (i = r = 0; i < aL; i++) {
1294
- if (a[i] != b[i]) {
1295
- r = a[i] > b[i] ? 1 : -1;
1296
- break;
1297
- }
1298
- }
434
+ if (this._special === SpecialValue.NEGATIVE_INFINITY) {
435
+ return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
1299
436
  }
1300
- return r;
1301
- }
1302
- function subtract(a, b, aL, base) {
1303
- var i = 0;
1304
- for (; aL--; ) {
1305
- a[aL] -= i;
1306
- i = a[aL] < b[aL] ? 1 : 0;
1307
- a[aL] = i * base + a[aL] - b[aL];
437
+ if (this._mantissa === 0n) {
438
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, !this._negativeZero);
1308
439
  }
1309
- for (; !a[0] && a.length > 1; )
1310
- a.shift();
440
+ return _BigDecimal._create(-this._mantissa, this._exponent, SpecialValue.NONE, false);
1311
441
  }
1312
- return function(x, y, pr, rm, dp, base) {
1313
- 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;
1314
- if (!xd || !xd[0] || !yd || !yd[0]) {
1315
- return new Ctor(
1316
- // Return NaN if either NaN, or both Infinity or 0.
1317
- !x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
1318
- // Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
1319
- xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
1320
- )
1321
- );
442
+ pow(n) {
443
+ if (this._special === SpecialValue.NAN)
444
+ return this;
445
+ if (n === 0)
446
+ return new _BigDecimal(1);
447
+ if (n < 0) {
448
+ return new _BigDecimal(1).div(this.pow(-n));
1322
449
  }
1323
- if (base) {
1324
- logBase = 1;
1325
- e = x.e - y.e;
1326
- } else {
1327
- base = BASE;
1328
- logBase = LOG_BASE;
1329
- e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
1330
- }
1331
- yL = yd.length;
1332
- xL = xd.length;
1333
- q = new Ctor(sign2);
1334
- qd = q.d = [];
1335
- for (i = 0; yd[i] == (xd[i] || 0); i++)
1336
- ;
1337
- if (yd[i] > (xd[i] || 0))
1338
- e--;
1339
- if (pr == null) {
1340
- sd = pr = Ctor.precision;
1341
- rm = Ctor.rounding;
1342
- } else if (dp) {
1343
- sd = pr + (x.e - y.e) + 1;
1344
- } else {
1345
- sd = pr;
1346
- }
1347
- if (sd < 0) {
1348
- qd.push(1);
1349
- more = true;
1350
- } else {
1351
- sd = sd / logBase + 2 | 0;
1352
- i = 0;
1353
- if (yL == 1) {
1354
- k = 0;
1355
- yd = yd[0];
1356
- sd++;
1357
- for (; (i < xL || k) && sd--; i++) {
1358
- t = k * base + (xd[i] || 0);
1359
- qd[i] = t / yd | 0;
1360
- k = t % yd | 0;
1361
- }
1362
- more = k || i < xL;
1363
- } else {
1364
- k = base / (yd[0] + 1) | 0;
1365
- if (k > 1) {
1366
- yd = multiplyInteger(yd, k, base);
1367
- xd = multiplyInteger(xd, k, base);
1368
- yL = yd.length;
1369
- xL = xd.length;
1370
- }
1371
- xi = yL;
1372
- rem = xd.slice(0, yL);
1373
- remL = rem.length;
1374
- for (; remL < yL; )
1375
- rem[remL++] = 0;
1376
- yz = yd.slice();
1377
- yz.unshift(0);
1378
- yd0 = yd[0];
1379
- if (yd[1] >= base / 2)
1380
- ++yd0;
1381
- do {
1382
- k = 0;
1383
- cmp = compare(yd, rem, yL, remL);
1384
- if (cmp < 0) {
1385
- rem0 = rem[0];
1386
- if (yL != remL)
1387
- rem0 = rem0 * base + (rem[1] || 0);
1388
- k = rem0 / yd0 | 0;
1389
- if (k > 1) {
1390
- if (k >= base)
1391
- k = base - 1;
1392
- prod = multiplyInteger(yd, k, base);
1393
- prodL = prod.length;
1394
- remL = rem.length;
1395
- cmp = compare(prod, rem, prodL, remL);
1396
- if (cmp == 1) {
1397
- k--;
1398
- subtract(prod, yL < prodL ? yz : yd, prodL, base);
1399
- }
1400
- } else {
1401
- if (k == 0)
1402
- cmp = k = 1;
1403
- prod = yd.slice();
1404
- }
1405
- prodL = prod.length;
1406
- if (prodL < remL)
1407
- prod.unshift(0);
1408
- subtract(rem, prod, remL, base);
1409
- if (cmp == -1) {
1410
- remL = rem.length;
1411
- cmp = compare(yd, rem, yL, remL);
1412
- if (cmp < 1) {
1413
- k++;
1414
- subtract(rem, yL < remL ? yz : yd, remL, base);
1415
- }
1416
- }
1417
- remL = rem.length;
1418
- } else if (cmp === 0) {
1419
- k++;
1420
- rem = [0];
1421
- }
1422
- qd[i++] = k;
1423
- if (cmp && rem[0]) {
1424
- rem[remL++] = xd[xi] || 0;
1425
- } else {
1426
- rem = [xd[xi]];
1427
- remL = 1;
1428
- }
1429
- } while ((xi++ < xL || rem[0] !== void 0) && sd--);
1430
- more = rem[0] !== void 0;
1431
- }
1432
- if (!qd[0])
1433
- qd.shift();
450
+ if (this._special === SpecialValue.POSITIVE_INFINITY)
451
+ return this;
452
+ if (this._special === SpecialValue.NEGATIVE_INFINITY) {
453
+ return n % 2 === 0 ? _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false) : this;
1434
454
  }
1435
- if (logBase == 1) {
1436
- q.e = e;
1437
- inexact = more;
1438
- } else {
1439
- for (i = 1, k = qd[0]; k >= 10; k /= 10)
1440
- i++;
1441
- q.e = i + e * logBase - 1;
1442
- finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
1443
- }
1444
- return q;
1445
- };
1446
- }();
1447
- function finalise(x, sd, rm, isTruncated) {
1448
- var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
1449
- out:
1450
- if (sd != null) {
1451
- xd = x.d;
1452
- if (!xd)
1453
- return x;
1454
- for (digits = 1, k = xd[0]; k >= 10; k /= 10)
1455
- digits++;
1456
- i = sd - digits;
1457
- if (i < 0) {
1458
- i += LOG_BASE;
1459
- j = sd;
1460
- w = xd[xdi = 0];
1461
- rd = w / mathpow(10, digits - j - 1) % 10 | 0;
1462
- } else {
1463
- xdi = Math.ceil((i + 1) / LOG_BASE);
1464
- k = xd.length;
1465
- if (xdi >= k) {
1466
- if (isTruncated) {
1467
- for (; k++ <= xdi; )
1468
- xd.push(0);
1469
- w = rd = 0;
1470
- digits = 1;
1471
- i %= LOG_BASE;
1472
- j = i - LOG_BASE + 1;
1473
- } else {
1474
- break out;
1475
- }
1476
- } else {
1477
- w = k = xd[xdi];
1478
- for (digits = 1; k >= 10; k /= 10)
1479
- digits++;
1480
- i %= LOG_BASE;
1481
- j = i - LOG_BASE + digits;
1482
- rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
1483
- }
1484
- }
1485
- isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
1486
- 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.
1487
- (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
1488
- if (sd < 1 || !xd[0]) {
1489
- xd.length = 0;
1490
- if (roundUp) {
1491
- sd -= x.e + 1;
1492
- xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
1493
- x.e = -sd || 0;
1494
- } else {
1495
- xd[0] = x.e = 0;
1496
- }
1497
- return x;
1498
- }
1499
- if (i == 0) {
1500
- xd.length = xdi;
1501
- k = 1;
1502
- xdi--;
1503
- } else {
1504
- xd.length = xdi + 1;
1505
- k = mathpow(10, LOG_BASE - i);
1506
- xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
1507
- }
1508
- if (roundUp) {
1509
- for (; ; ) {
1510
- if (xdi == 0) {
1511
- for (i = 1, j = xd[0]; j >= 10; j /= 10)
1512
- i++;
1513
- j = xd[0] += k;
1514
- for (k = 1; j >= 10; j /= 10)
1515
- k++;
1516
- if (i != k) {
1517
- x.e++;
1518
- if (xd[0] == BASE)
1519
- xd[0] = 1;
1520
- }
1521
- break;
1522
- } else {
1523
- xd[xdi] += k;
1524
- if (xd[xdi] != BASE)
1525
- break;
1526
- xd[xdi--] = 0;
1527
- k = 1;
1528
- }
1529
- }
1530
- }
1531
- for (i = xd.length; xd[--i] === 0; )
1532
- xd.pop();
455
+ if (this._mantissa === 0n)
456
+ return new _BigDecimal(0);
457
+ const m = this._mantissa ** BigInt(n);
458
+ const e = this._exponent * n;
459
+ const [nm, ne] = removeTrailingZeros(m, e);
460
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
461
+ }
462
+ floor() {
463
+ if (this._special !== SpecialValue.NONE)
464
+ return this;
465
+ if (this._mantissa === 0n)
466
+ return this;
467
+ if (this._exponent >= 0)
468
+ return this;
469
+ const divisor = bigintPow10(-this._exponent);
470
+ const m = this._mantissa;
471
+ let q = m / divisor;
472
+ if (m < 0n && m % divisor !== 0n) {
473
+ q -= 1n;
1533
474
  }
1534
- if (external) {
1535
- if (x.e > Ctor.maxE) {
1536
- x.d = null;
1537
- x.e = NaN;
1538
- } else if (x.e < Ctor.minE) {
1539
- x.e = 0;
1540
- x.d = [0];
475
+ if (q === 0n) {
476
+ const negZero = this._mantissa < 0n;
477
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
1541
478
  }
479
+ const [nm, ne] = removeTrailingZeros(q, 0);
480
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
1542
481
  }
1543
- return x;
1544
- }
1545
- function finiteToString(x, isExp, sd) {
1546
- if (!x.isFinite())
1547
- return nonFiniteToString(x);
1548
- var k, e = x.e, str = digitsToString(x.d), len = str.length;
1549
- if (isExp) {
1550
- if (sd && (k = sd - len) > 0) {
1551
- str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
1552
- } else if (len > 1) {
1553
- str = str.charAt(0) + "." + str.slice(1);
482
+ ceil() {
483
+ if (this._special !== SpecialValue.NONE)
484
+ return this;
485
+ if (this._mantissa === 0n)
486
+ return this;
487
+ if (this._exponent >= 0)
488
+ return this;
489
+ const divisor = bigintPow10(-this._exponent);
490
+ const m = this._mantissa;
491
+ let q = m / divisor;
492
+ if (m > 0n && m % divisor !== 0n) {
493
+ q += 1n;
1554
494
  }
1555
- str = str + (x.e < 0 ? "e" : "e+") + x.e;
1556
- } else if (e < 0) {
1557
- str = "0." + getZeroString(-e - 1) + str;
1558
- if (sd && (k = sd - len) > 0)
1559
- str += getZeroString(k);
1560
- } else if (e >= len) {
1561
- str += getZeroString(e + 1 - len);
1562
- if (sd && (k = sd - e - 1) > 0)
1563
- str = str + "." + getZeroString(k);
1564
- } else {
1565
- if ((k = e + 1) < len)
1566
- str = str.slice(0, k) + "." + str.slice(k);
1567
- if (sd && (k = sd - len) > 0) {
1568
- if (e + 1 === len)
1569
- str += ".";
1570
- str += getZeroString(k);
495
+ if (q === 0n) {
496
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
1571
497
  }
498
+ const [nm, ne] = removeTrailingZeros(q, 0);
499
+ return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
1572
500
  }
1573
- return str;
1574
- }
1575
- function getBase10Exponent(digits, e) {
1576
- var w = digits[0];
1577
- for (e *= LOG_BASE; w >= 10; w /= 10)
1578
- e++;
1579
- return e;
1580
- }
1581
- function getLn10(Ctor, sd, pr) {
1582
- if (sd > LN10_PRECISION) {
1583
- external = true;
1584
- if (pr)
1585
- Ctor.precision = pr;
1586
- throw Error(precisionLimitExceeded);
1587
- }
1588
- return finalise(new Ctor(LN10), sd, 1, true);
1589
- }
1590
- function getPi(Ctor, sd, rm) {
1591
- if (sd > PI_PRECISION)
1592
- throw Error(precisionLimitExceeded);
1593
- return finalise(new Ctor(PI), sd, rm, true);
1594
- }
1595
- function getPrecision(digits) {
1596
- var w = digits.length - 1, len = w * LOG_BASE + 1;
1597
- w = digits[w];
1598
- if (w) {
1599
- for (; w % 10 == 0; w /= 10)
1600
- len--;
1601
- for (w = digits[0]; w >= 10; w /= 10)
1602
- len++;
1603
- }
1604
- return len;
1605
- }
1606
- function getZeroString(k) {
1607
- var zs = "";
1608
- for (; k--; )
1609
- zs += "0";
1610
- return zs;
1611
- }
1612
- function intPow(Ctor, x, n, pr) {
1613
- var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
1614
- external = false;
1615
- for (; ; ) {
1616
- if (n % 2) {
1617
- r = r.times(x);
1618
- if (truncate(r.d, k))
1619
- isTruncated = true;
501
+ log(base) {
502
+ if (this._special === SpecialValue.NAN)
503
+ return this;
504
+ if (this._special === SpecialValue.NEGATIVE_INFINITY) {
505
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
1620
506
  }
1621
- n = mathfloor(n / 2);
1622
- if (n === 0) {
1623
- n = r.d.length - 1;
1624
- if (isTruncated && r.d[n] === 0)
1625
- ++r.d[n];
1626
- break;
507
+ if (this._special === SpecialValue.POSITIVE_INFINITY) {
508
+ return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
1627
509
  }
1628
- x = x.times(x);
1629
- truncate(x.d, k);
1630
- }
1631
- external = true;
1632
- return r;
1633
- }
1634
- function isOdd(n) {
1635
- return n.d[n.d.length - 1] & 1;
1636
- }
1637
- function maxOrMin(Ctor, args, n) {
1638
- var k, y, x = new Ctor(args[0]), i = 0;
1639
- for (; ++i < args.length; ) {
1640
- y = new Ctor(args[i]);
1641
- if (!y.s) {
1642
- x = y;
1643
- break;
510
+ if (this._mantissa < 0n) {
511
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
1644
512
  }
1645
- k = x.cmp(y);
1646
- if (k === n || k === 0 && x.s === n) {
1647
- x = y;
513
+ if (this._mantissa === 0n) {
514
+ return _BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false);
1648
515
  }
1649
- }
1650
- return x;
1651
- }
1652
- function naturalExponential(x, sd) {
1653
- var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1654
- if (!x.d || !x.d[0] || x.e > 17) {
1655
- return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
1656
- }
1657
- if (sd == null) {
1658
- external = false;
1659
- wpr = pr;
1660
- } else {
1661
- wpr = sd;
1662
- }
1663
- t = new Ctor(0.03125);
1664
- while (x.e > -2) {
1665
- x = x.times(t);
1666
- k += 5;
1667
- }
1668
- guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1669
- wpr += guard;
1670
- denominator = pow2 = sum2 = new Ctor(1);
1671
- Ctor.precision = wpr;
1672
- for (; ; ) {
1673
- pow2 = finalise(pow2.times(x), wpr, 1);
1674
- denominator = denominator.times(++i);
1675
- t = sum2.plus(divide(pow2, denominator, wpr, 1));
1676
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1677
- j = k;
1678
- while (j--)
1679
- sum2 = finalise(sum2.times(sum2), wpr, 1);
1680
- if (sd == null) {
1681
- if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1682
- Ctor.precision = wpr += 10;
1683
- denominator = pow2 = t = new Ctor(1);
1684
- i = 0;
1685
- rep++;
1686
- } else {
1687
- return finalise(sum2, Ctor.precision = pr, rm, external = true);
1688
- }
1689
- } else {
1690
- Ctor.precision = pr;
1691
- return sum2;
1692
- }
516
+ if (base === 10) {
517
+ return this._log10();
1693
518
  }
1694
- sum2 = t;
519
+ const log10x = this._log10();
520
+ const log10b = new _BigDecimal(Math.log10(base));
521
+ return log10x.div(log10b);
1695
522
  }
1696
- }
1697
- function naturalLogarithm(y, sd) {
1698
- 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;
1699
- if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
1700
- return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
523
+ _log10() {
524
+ const absMantissa = bigintAbs(this._mantissa);
525
+ const digits = digitCount(absMantissa);
526
+ let log10Mantissa;
527
+ if (digits <= 15) {
528
+ log10Mantissa = Math.log10(Number(absMantissa));
529
+ } else {
530
+ const shift = digits - 17;
531
+ const leading = absMantissa / bigintPow10(shift);
532
+ log10Mantissa = Math.log10(Number(leading)) + shift;
533
+ }
534
+ const totalLog10 = log10Mantissa + this._exponent;
535
+ return new _BigDecimal(totalLog10);
1701
536
  }
1702
- if (sd == null) {
1703
- external = false;
1704
- wpr = pr;
1705
- } else {
1706
- wpr = sd;
537
+ // --- Comparison ---
538
+ eq(y) {
539
+ const other = _BigDecimal._coerce(y);
540
+ if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN)
541
+ return false;
542
+ if (this._special !== other._special)
543
+ return false;
544
+ if (this._special !== SpecialValue.NONE)
545
+ return true;
546
+ if (this._mantissa === 0n && other._mantissa === 0n)
547
+ return true;
548
+ return this._mantissa === other._mantissa && this._exponent === other._exponent;
1707
549
  }
1708
- Ctor.precision = wpr += guard;
1709
- c = digitsToString(xd);
1710
- c0 = c.charAt(0);
1711
- if (Math.abs(e = x.e) < 15e14) {
1712
- while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
1713
- x = x.times(y);
1714
- c = digitsToString(x.d);
1715
- c0 = c.charAt(0);
1716
- n++;
550
+ _compareTo(other) {
551
+ if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN) {
552
+ return NaN;
1717
553
  }
1718
- e = x.e;
1719
- if (c0 > 1) {
1720
- x = new Ctor("0." + c);
1721
- e++;
1722
- } else {
1723
- x = new Ctor(c0 + "." + c.slice(1));
554
+ if (this._special === SpecialValue.POSITIVE_INFINITY) {
555
+ return other._special === SpecialValue.POSITIVE_INFINITY ? 0 : 1;
1724
556
  }
1725
- } else {
1726
- t = getLn10(Ctor, wpr + 2, pr).times(e + "");
1727
- x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
1728
- Ctor.precision = pr;
1729
- return sd == null ? finalise(x, pr, rm, external = true) : x;
1730
- }
1731
- x1 = x;
1732
- sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
1733
- x2 = finalise(x.times(x), wpr, 1);
1734
- denominator = 3;
1735
- for (; ; ) {
1736
- numerator = finalise(numerator.times(x2), wpr, 1);
1737
- t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
1738
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1739
- sum2 = sum2.times(2);
1740
- if (e !== 0)
1741
- sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
1742
- sum2 = divide(sum2, new Ctor(n), wpr, 1);
1743
- if (sd == null) {
1744
- if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1745
- Ctor.precision = wpr += guard;
1746
- t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
1747
- x2 = finalise(x.times(x), wpr, 1);
1748
- denominator = rep = 1;
1749
- } else {
1750
- return finalise(sum2, Ctor.precision = pr, rm, external = true);
1751
- }
1752
- } else {
1753
- Ctor.precision = pr;
1754
- return sum2;
1755
- }
557
+ if (this._special === SpecialValue.NEGATIVE_INFINITY) {
558
+ return other._special === SpecialValue.NEGATIVE_INFINITY ? 0 : -1;
1756
559
  }
1757
- sum2 = t;
1758
- denominator += 2;
560
+ if (other._special === SpecialValue.POSITIVE_INFINITY)
561
+ return -1;
562
+ if (other._special === SpecialValue.NEGATIVE_INFINITY)
563
+ return 1;
564
+ const thisZero = this._mantissa === 0n;
565
+ const otherZero = other._mantissa === 0n;
566
+ if (thisZero && otherZero)
567
+ return 0;
568
+ if (thisZero)
569
+ return other._mantissa > 0n ? -1 : 1;
570
+ if (otherZero)
571
+ return this._mantissa > 0n ? 1 : -1;
572
+ const thisNeg = this._mantissa < 0n;
573
+ const otherNeg = other._mantissa < 0n;
574
+ if (thisNeg !== otherNeg)
575
+ return thisNeg ? -1 : 1;
576
+ let m1 = this._mantissa;
577
+ let m2 = other._mantissa;
578
+ const e1 = this._exponent;
579
+ const e2 = other._exponent;
580
+ const minE = Math.min(e1, e2);
581
+ if (e1 > minE)
582
+ m1 *= bigintPow10(e1 - minE);
583
+ if (e2 > minE)
584
+ m2 *= bigintPow10(e2 - minE);
585
+ if (m1 < m2)
586
+ return -1;
587
+ if (m1 > m2)
588
+ return 1;
589
+ return 0;
1759
590
  }
1760
- }
1761
- function nonFiniteToString(x) {
1762
- return String(x.s * x.s / 0);
1763
- }
1764
- function parseDecimal(x, str) {
1765
- var e, i, len;
1766
- if ((e = str.indexOf(".")) > -1)
1767
- str = str.replace(".", "");
1768
- if ((i = str.search(/e/i)) > 0) {
1769
- if (e < 0)
1770
- e = i;
1771
- e += +str.slice(i + 1);
1772
- str = str.substring(0, i);
1773
- } else if (e < 0) {
1774
- e = str.length;
591
+ lessThan(y) {
592
+ const c = this._compareTo(_BigDecimal._coerce(y));
593
+ return c === -1;
1775
594
  }
1776
- for (i = 0; str.charCodeAt(i) === 48; i++)
1777
- ;
1778
- for (len = str.length; str.charCodeAt(len - 1) === 48; --len)
1779
- ;
1780
- str = str.slice(i, len);
1781
- if (str) {
1782
- len -= i;
1783
- x.e = e = e - i - 1;
1784
- x.d = [];
1785
- i = (e + 1) % LOG_BASE;
1786
- if (e < 0)
1787
- i += LOG_BASE;
1788
- if (i < len) {
1789
- if (i)
1790
- x.d.push(+str.slice(0, i));
1791
- for (len -= LOG_BASE; i < len; )
1792
- x.d.push(+str.slice(i, i += LOG_BASE));
1793
- str = str.slice(i);
1794
- i = LOG_BASE - str.length;
1795
- } else {
1796
- i -= len;
1797
- }
1798
- for (; i--; )
1799
- str += "0";
1800
- x.d.push(+str);
1801
- if (external) {
1802
- if (x.e > x.constructor.maxE) {
1803
- x.d = null;
1804
- x.e = NaN;
1805
- } else if (x.e < x.constructor.minE) {
1806
- x.e = 0;
1807
- x.d = [0];
1808
- }
1809
- }
1810
- } else {
1811
- x.e = 0;
1812
- x.d = [0];
595
+ greaterThan(y) {
596
+ const c = this._compareTo(_BigDecimal._coerce(y));
597
+ return c === 1;
1813
598
  }
1814
- return x;
1815
- }
1816
- function parseOther(x, str) {
1817
- var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
1818
- if (str.indexOf("_") > -1) {
1819
- str = str.replace(/(\d)_(?=\d)/g, "$1");
1820
- if (isDecimal.test(str))
1821
- return parseDecimal(x, str);
1822
- } else if (str === "Infinity" || str === "NaN") {
1823
- if (!+str)
1824
- x.s = NaN;
1825
- x.e = NaN;
1826
- x.d = null;
1827
- return x;
599
+ lessThanOrEqualTo(y) {
600
+ const c = this._compareTo(_BigDecimal._coerce(y));
601
+ return c === 0 || c === -1;
1828
602
  }
1829
- if (isHex.test(str)) {
1830
- base = 16;
1831
- str = str.toLowerCase();
1832
- } else if (isBinary.test(str)) {
1833
- base = 2;
1834
- } else if (isOctal.test(str)) {
1835
- base = 8;
1836
- } else {
1837
- throw Error(invalidArgument + str);
603
+ greaterThanOrEqualTo(y) {
604
+ const c = this._compareTo(_BigDecimal._coerce(y));
605
+ return c === 0 || c === 1;
1838
606
  }
1839
- i = str.search(/p/i);
1840
- if (i > 0) {
1841
- p = +str.slice(i + 1);
1842
- str = str.substring(2, i);
1843
- } else {
1844
- str = str.slice(2);
607
+ // --- Queries ---
608
+ isZero() {
609
+ return this._special === SpecialValue.NONE && this._mantissa === 0n;
1845
610
  }
1846
- i = str.indexOf(".");
1847
- isFloat = i >= 0;
1848
- Ctor = x.constructor;
1849
- if (isFloat) {
1850
- str = str.replace(".", "");
1851
- len = str.length;
1852
- i = len - i;
1853
- divisor = intPow(Ctor, new Ctor(base), i, i * 2);
611
+ isNaN() {
612
+ return this._special === SpecialValue.NAN;
1854
613
  }
1855
- xd = convertBase(str, base, BASE);
1856
- xe = xd.length - 1;
1857
- for (i = xe; xd[i] === 0; --i)
1858
- xd.pop();
1859
- if (i < 0)
1860
- return new Ctor(x.s * 0);
1861
- x.e = getBase10Exponent(xd, xe);
1862
- x.d = xd;
1863
- external = false;
1864
- if (isFloat)
1865
- x = divide(x, divisor, len * 4);
1866
- if (p)
1867
- x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
1868
- external = true;
1869
- return x;
1870
- }
1871
- function sine(Ctor, x) {
1872
- var k, len = x.d.length;
1873
- if (len < 3) {
1874
- return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
614
+ isFinite() {
615
+ return this._special === SpecialValue.NONE;
1875
616
  }
1876
- k = 1.4 * Math.sqrt(len);
1877
- k = k > 16 ? 16 : k | 0;
1878
- x = x.times(1 / tinyPow(5, k));
1879
- x = taylorSeries(Ctor, 2, x, x);
1880
- var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
1881
- for (; k--; ) {
1882
- sin2_x = x.times(x);
1883
- x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
617
+ isNegative() {
618
+ if (this._special === SpecialValue.NAN)
619
+ return false;
620
+ if (this._special === SpecialValue.NEGATIVE_INFINITY)
621
+ return true;
622
+ if (this._special === SpecialValue.POSITIVE_INFINITY)
623
+ return false;
624
+ if (this._mantissa === 0n)
625
+ return this._negativeZero;
626
+ return this._mantissa < 0n;
1884
627
  }
1885
- return x;
1886
- }
1887
- function taylorSeries(Ctor, n, x, y, isHyperbolic) {
1888
- var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
1889
- external = false;
1890
- x2 = x.times(x);
1891
- u = new Ctor(y);
1892
- for (; ; ) {
1893
- t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
1894
- u = isHyperbolic ? y.plus(t) : y.minus(t);
1895
- y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
1896
- t = u.plus(y);
1897
- if (t.d[k] !== void 0) {
1898
- for (j = k; t.d[j] === u.d[j] && j--; )
1899
- ;
1900
- if (j == -1)
1901
- break;
1902
- }
1903
- j = u;
1904
- u = y;
1905
- y = t;
1906
- t = j;
1907
- i++;
628
+ isPositive() {
629
+ if (this._special === SpecialValue.NAN)
630
+ return false;
631
+ if (this._special === SpecialValue.POSITIVE_INFINITY)
632
+ return true;
633
+ if (this._special === SpecialValue.NEGATIVE_INFINITY)
634
+ return false;
635
+ if (this._mantissa === 0n)
636
+ return !this._negativeZero;
637
+ return this._mantissa > 0n;
1908
638
  }
1909
- external = true;
1910
- t.d.length = k + 1;
1911
- return t;
1912
- }
1913
- function tinyPow(b, e) {
1914
- var n = b;
1915
- while (--e)
1916
- n *= b;
1917
- return n;
1918
- }
1919
- function toLessThanHalfPi(Ctor, x) {
1920
- var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
1921
- x = x.abs();
1922
- if (x.lte(halfPi)) {
1923
- quadrant = isNeg ? 4 : 1;
1924
- return x;
639
+ isInteger() {
640
+ if (this._special !== SpecialValue.NONE)
641
+ return false;
642
+ if (this._mantissa === 0n)
643
+ return true;
644
+ return this._exponent >= 0;
1925
645
  }
1926
- t = x.divToInt(pi);
1927
- if (t.isZero()) {
1928
- quadrant = isNeg ? 3 : 2;
1929
- } else {
1930
- x = x.minus(t.times(pi));
1931
- if (x.lte(halfPi)) {
1932
- quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
1933
- return x;
1934
- }
1935
- quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
646
+ // --- Conversion ---
647
+ toJSON() {
648
+ return this.toString();
1936
649
  }
1937
- return x.minus(pi).abs();
1938
- }
1939
- function toStringBinary(x, baseOut, sd, rm) {
1940
- var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
1941
- if (isExp) {
1942
- checkInt32(sd, 1, MAX_DIGITS);
1943
- if (rm === void 0)
1944
- rm = Ctor.rounding;
1945
- else
1946
- checkInt32(rm, 0, 8);
1947
- } else {
1948
- sd = Ctor.precision;
1949
- rm = Ctor.rounding;
650
+ toNumber() {
651
+ if (this._special === SpecialValue.NAN)
652
+ return NaN;
653
+ if (this._special === SpecialValue.POSITIVE_INFINITY)
654
+ return Infinity;
655
+ if (this._special === SpecialValue.NEGATIVE_INFINITY)
656
+ return -Infinity;
657
+ if (this._mantissa === 0n)
658
+ return this._negativeZero ? -0 : 0;
659
+ return Number(this.toString());
1950
660
  }
1951
- if (!x.isFinite()) {
1952
- str = nonFiniteToString(x);
1953
- } else {
1954
- str = finiteToString(x);
1955
- i = str.indexOf(".");
1956
- if (isExp) {
1957
- base = 2;
1958
- if (baseOut == 16) {
1959
- sd = sd * 4 - 3;
1960
- } else if (baseOut == 8) {
1961
- sd = sd * 3 - 2;
1962
- }
1963
- } else {
1964
- base = baseOut;
661
+ toString() {
662
+ if (this._special === SpecialValue.NAN)
663
+ return "NaN";
664
+ if (this._special === SpecialValue.POSITIVE_INFINITY)
665
+ return "Infinity";
666
+ if (this._special === SpecialValue.NEGATIVE_INFINITY)
667
+ return "-Infinity";
668
+ if (this._mantissa === 0n)
669
+ return "0";
670
+ const negative = this._mantissa < 0n;
671
+ const absStr = bigintAbs(this._mantissa).toString();
672
+ const prefix = negative ? "-" : "";
673
+ if (this._exponent === 0) {
674
+ return prefix + absStr;
1965
675
  }
1966
- if (i >= 0) {
1967
- str = str.replace(".", "");
1968
- y = new Ctor(1);
1969
- y.e = str.length - i;
1970
- y.d = convertBase(finiteToString(y), 10, base);
1971
- y.e = y.d.length;
676
+ if (this._exponent > 0) {
677
+ return prefix + absStr + "0".repeat(this._exponent);
1972
678
  }
1973
- xd = convertBase(str, 10, base);
1974
- e = len = xd.length;
1975
- for (; xd[--len] == 0; )
1976
- xd.pop();
1977
- if (!xd[0]) {
1978
- str = isExp ? "0p+0" : "0";
679
+ const decimalPlaces = -this._exponent;
680
+ if (decimalPlaces < absStr.length) {
681
+ const intPart = absStr.slice(0, absStr.length - decimalPlaces);
682
+ const fracPart = absStr.slice(absStr.length - decimalPlaces);
683
+ return prefix + intPart + "." + fracPart;
1979
684
  } else {
1980
- if (i < 0) {
1981
- e--;
1982
- } else {
1983
- x = new Ctor(x);
1984
- x.d = xd;
1985
- x.e = e;
1986
- x = divide(x, y, sd, rm, 0, base);
1987
- xd = x.d;
1988
- e = x.e;
1989
- roundUp = inexact;
1990
- }
1991
- i = xd[sd];
1992
- k = base / 2;
1993
- roundUp = roundUp || xd[sd + 1] !== void 0;
1994
- 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));
1995
- xd.length = sd;
1996
- if (roundUp) {
1997
- for (; ++xd[--sd] > base - 1; ) {
1998
- xd[sd] = 0;
1999
- if (!sd) {
2000
- ++e;
2001
- xd.unshift(1);
2002
- }
2003
- }
2004
- }
2005
- for (len = xd.length; !xd[len - 1]; --len)
2006
- ;
2007
- for (i = 0, str = ""; i < len; i++)
2008
- str += NUMERALS.charAt(xd[i]);
2009
- if (isExp) {
2010
- if (len > 1) {
2011
- if (baseOut == 16 || baseOut == 8) {
2012
- i = baseOut == 16 ? 4 : 3;
2013
- for (--len; len % i; len++)
2014
- str += "0";
2015
- xd = convertBase(str, base, baseOut);
2016
- for (len = xd.length; !xd[len - 1]; --len)
2017
- ;
2018
- for (i = 1, str = "1."; i < len; i++)
2019
- str += NUMERALS.charAt(xd[i]);
2020
- } else {
2021
- str = str.charAt(0) + "." + str.slice(1);
2022
- }
2023
- }
2024
- str = str + (e < 0 ? "p" : "p+") + e;
2025
- } else if (e < 0) {
2026
- for (; ++e; )
2027
- str = "0" + str;
2028
- str = "0." + str;
2029
- } else {
2030
- if (++e > len)
2031
- for (e -= len; e--; )
2032
- str += "0";
2033
- else if (e < len)
2034
- str = str.slice(0, e) + "." + str.slice(e);
2035
- }
685
+ const leadingZeros = decimalPlaces - absStr.length;
686
+ return prefix + "0." + "0".repeat(leadingZeros) + absStr;
2036
687
  }
2037
- str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
2038
688
  }
2039
- return x.s < 0 ? "-" + str : str;
2040
- }
2041
- function truncate(arr, len) {
2042
- if (arr.length > len) {
2043
- arr.length = len;
2044
- return true;
689
+ // --- Static ---
690
+ static pow(base, exp) {
691
+ const n = typeof exp === "number" ? exp : exp.toNumber();
692
+ if (typeof base === "number" && base === 10) {
693
+ return _BigDecimal._create(1n, n, SpecialValue.NONE, false);
694
+ }
695
+ const bd = base instanceof _BigDecimal ? base : new _BigDecimal(base);
696
+ return bd.pow(n);
2045
697
  }
2046
- }
2047
- function abs(x) {
2048
- return new this(x).abs();
2049
- }
2050
- function acos(x) {
2051
- return new this(x).acos();
2052
- }
2053
- function acosh(x) {
2054
- return new this(x).acosh();
2055
- }
2056
- function add(x, y) {
2057
- return new this(x).plus(y);
2058
- }
2059
- function asin(x) {
2060
- return new this(x).asin();
2061
- }
2062
- function asinh(x) {
2063
- return new this(x).asinh();
2064
- }
2065
- function atan(x) {
2066
- return new this(x).atan();
2067
- }
2068
- function atanh(x) {
2069
- return new this(x).atanh();
2070
- }
2071
- function atan2(y, x) {
2072
- y = new this(y);
2073
- x = new this(x);
2074
- var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
2075
- if (!y.s || !x.s) {
2076
- r = new this(NaN);
2077
- } else if (!y.d && !x.d) {
2078
- r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
2079
- r.s = y.s;
2080
- } else if (!x.d || y.isZero()) {
2081
- r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
2082
- r.s = y.s;
2083
- } else if (!y.d || x.isZero()) {
2084
- r = getPi(this, wpr, 1).times(0.5);
2085
- r.s = y.s;
2086
- } else if (x.s < 0) {
2087
- this.precision = wpr;
2088
- this.rounding = 1;
2089
- r = this.atan(divide(y, x, wpr, 1));
2090
- x = getPi(this, wpr, 1);
2091
- this.precision = pr;
2092
- this.rounding = rm;
2093
- r = y.s < 0 ? r.minus(x) : r.plus(x);
2094
- } else {
2095
- r = this.atan(divide(y, x, wpr, 1));
698
+ static set(_config) {
2096
699
  }
2097
- return r;
2098
- }
2099
- function cbrt(x) {
2100
- return new this(x).cbrt();
2101
- }
2102
- function ceil(x) {
2103
- return finalise(x = new this(x), x.e + 1, 2);
2104
- }
2105
- function clamp(x, min2, max2) {
2106
- return new this(x).clamp(min2, max2);
2107
- }
2108
- function config(obj) {
2109
- if (!obj || typeof obj !== "object")
2110
- throw Error(decimalError + "Object expected");
2111
- var i, p, v, useDefaults = obj.defaults === true, ps = [
2112
- "precision",
2113
- 1,
2114
- MAX_DIGITS,
2115
- "rounding",
2116
- 0,
2117
- 8,
2118
- "toExpNeg",
2119
- -EXP_LIMIT,
2120
- 0,
2121
- "toExpPos",
2122
- 0,
2123
- EXP_LIMIT,
2124
- "maxE",
2125
- 0,
2126
- EXP_LIMIT,
2127
- "minE",
2128
- -EXP_LIMIT,
2129
- 0,
2130
- "modulo",
2131
- 0,
2132
- 9
2133
- ];
2134
- for (i = 0; i < ps.length; i += 3) {
2135
- if (p = ps[i], useDefaults)
2136
- this[p] = DEFAULTS[p];
2137
- if ((v = obj[p]) !== void 0) {
2138
- if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
2139
- this[p] = v;
2140
- else
2141
- throw Error(invalidArgument + p + ": " + v);
2142
- }
700
+ // --- Internal helpers ---
701
+ _isSignNegative() {
702
+ if (this._special === SpecialValue.NEGATIVE_INFINITY)
703
+ return true;
704
+ if (this._mantissa < 0n)
705
+ return true;
706
+ if (this._mantissa === 0n)
707
+ return this._negativeZero;
708
+ return false;
2143
709
  }
2144
- if (p = "crypto", useDefaults)
2145
- this[p] = DEFAULTS[p];
2146
- if ((v = obj[p]) !== void 0) {
2147
- if (v === true || v === false || v === 0 || v === 1) {
2148
- if (v) {
2149
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
2150
- this[p] = true;
2151
- } else {
2152
- throw Error(cryptoUnavailable);
2153
- }
2154
- } else {
2155
- this[p] = false;
2156
- }
2157
- } else {
2158
- throw Error(invalidArgument + p + ": " + v);
710
+ _specialArith(other, op) {
711
+ const a = this._special;
712
+ const b = other._special;
713
+ if (a === SpecialValue.NAN || b === SpecialValue.NAN) {
714
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
2159
715
  }
2160
- }
2161
- return this;
2162
- }
2163
- function cos(x) {
2164
- return new this(x).cos();
2165
- }
2166
- function cosh(x) {
2167
- return new this(x).cosh();
2168
- }
2169
- function clone(obj) {
2170
- var i, p, ps;
2171
- function Decimal2(v) {
2172
- var e, i2, t, x = this;
2173
- if (!(x instanceof Decimal2))
2174
- return new Decimal2(v);
2175
- x.constructor = Decimal2;
2176
- if (isDecimalInstance(v)) {
2177
- x.s = v.s;
2178
- if (external) {
2179
- if (!v.d || v.e > Decimal2.maxE) {
2180
- x.e = NaN;
2181
- x.d = null;
2182
- } else if (v.e < Decimal2.minE) {
2183
- x.e = 0;
2184
- x.d = [0];
2185
- } else {
2186
- x.e = v.e;
2187
- x.d = v.d.slice();
716
+ const aNeg = this._isSignNegative();
717
+ const bNeg = other._isSignNegative();
718
+ const aInf = a === SpecialValue.POSITIVE_INFINITY || a === SpecialValue.NEGATIVE_INFINITY;
719
+ const bInf = b === SpecialValue.POSITIVE_INFINITY || b === SpecialValue.NEGATIVE_INFINITY;
720
+ if (op === "times") {
721
+ if (aInf || bInf) {
722
+ if (aInf && other._mantissa === 0n && !bInf || bInf && this._mantissa === 0n && !aInf) {
723
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
2188
724
  }
2189
- } else {
2190
- x.e = v.e;
2191
- x.d = v.d ? v.d.slice() : v.d;
725
+ const neg = aNeg !== bNeg;
726
+ return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
2192
727
  }
2193
- return;
2194
728
  }
2195
- t = typeof v;
2196
- if (t === "number") {
2197
- if (v === 0) {
2198
- x.s = 1 / v < 0 ? -1 : 1;
2199
- x.e = 0;
2200
- x.d = [0];
2201
- return;
2202
- }
2203
- if (v < 0) {
2204
- v = -v;
2205
- x.s = -1;
2206
- } else {
2207
- x.s = 1;
729
+ if (op === "div") {
730
+ if (aInf && bInf) {
731
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
2208
732
  }
2209
- if (v === ~~v && v < 1e7) {
2210
- for (e = 0, i2 = v; i2 >= 10; i2 /= 10)
2211
- e++;
2212
- if (external) {
2213
- if (e > Decimal2.maxE) {
2214
- x.e = NaN;
2215
- x.d = null;
2216
- } else if (e < Decimal2.minE) {
2217
- x.e = 0;
2218
- x.d = [0];
2219
- } else {
2220
- x.e = e;
2221
- x.d = [v];
2222
- }
2223
- } else {
2224
- x.e = e;
2225
- x.d = [v];
2226
- }
2227
- return;
2228
- }
2229
- if (v * 0 !== 0) {
2230
- if (!v)
2231
- x.s = NaN;
2232
- x.e = NaN;
2233
- x.d = null;
2234
- return;
2235
- }
2236
- return parseDecimal(x, v.toString());
2237
- }
2238
- if (t === "string") {
2239
- if ((i2 = v.charCodeAt(0)) === 45) {
2240
- v = v.slice(1);
2241
- x.s = -1;
2242
- } else {
2243
- if (i2 === 43)
2244
- v = v.slice(1);
2245
- x.s = 1;
733
+ if (aInf) {
734
+ const neg = aNeg !== bNeg;
735
+ return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
2246
736
  }
2247
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
2248
- }
2249
- if (t === "bigint") {
2250
- if (v < 0) {
2251
- v = -v;
2252
- x.s = -1;
2253
- } else {
2254
- x.s = 1;
737
+ if (bInf) {
738
+ const negZero = aNeg !== bNeg;
739
+ return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
2255
740
  }
2256
- return parseDecimal(x, v.toString());
2257
741
  }
2258
- throw Error(invalidArgument + v);
2259
- }
2260
- Decimal2.prototype = P;
2261
- Decimal2.ROUND_UP = 0;
2262
- Decimal2.ROUND_DOWN = 1;
2263
- Decimal2.ROUND_CEIL = 2;
2264
- Decimal2.ROUND_FLOOR = 3;
2265
- Decimal2.ROUND_HALF_UP = 4;
2266
- Decimal2.ROUND_HALF_DOWN = 5;
2267
- Decimal2.ROUND_HALF_EVEN = 6;
2268
- Decimal2.ROUND_HALF_CEIL = 7;
2269
- Decimal2.ROUND_HALF_FLOOR = 8;
2270
- Decimal2.EUCLID = 9;
2271
- Decimal2.config = Decimal2.set = config;
2272
- Decimal2.clone = clone;
2273
- Decimal2.isDecimal = isDecimalInstance;
2274
- Decimal2.abs = abs;
2275
- Decimal2.acos = acos;
2276
- Decimal2.acosh = acosh;
2277
- Decimal2.add = add;
2278
- Decimal2.asin = asin;
2279
- Decimal2.asinh = asinh;
2280
- Decimal2.atan = atan;
2281
- Decimal2.atanh = atanh;
2282
- Decimal2.atan2 = atan2;
2283
- Decimal2.cbrt = cbrt;
2284
- Decimal2.ceil = ceil;
2285
- Decimal2.clamp = clamp;
2286
- Decimal2.cos = cos;
2287
- Decimal2.cosh = cosh;
2288
- Decimal2.div = div;
2289
- Decimal2.exp = exp;
2290
- Decimal2.floor = floor;
2291
- Decimal2.hypot = hypot;
2292
- Decimal2.ln = ln;
2293
- Decimal2.log = log;
2294
- Decimal2.log10 = log10;
2295
- Decimal2.log2 = log2;
2296
- Decimal2.max = max;
2297
- Decimal2.min = min;
2298
- Decimal2.mod = mod;
2299
- Decimal2.mul = mul;
2300
- Decimal2.pow = pow;
2301
- Decimal2.random = random;
2302
- Decimal2.round = round;
2303
- Decimal2.sign = sign;
2304
- Decimal2.sin = sin;
2305
- Decimal2.sinh = sinh;
2306
- Decimal2.sqrt = sqrt;
2307
- Decimal2.sub = sub;
2308
- Decimal2.sum = sum;
2309
- Decimal2.tan = tan;
2310
- Decimal2.tanh = tanh;
2311
- Decimal2.trunc = trunc;
2312
- if (obj === void 0)
2313
- obj = {};
2314
- if (obj) {
2315
- if (obj.defaults !== true) {
2316
- ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
2317
- for (i = 0; i < ps.length; )
2318
- if (!obj.hasOwnProperty(p = ps[i++]))
2319
- obj[p] = this[p];
2320
- }
2321
- }
2322
- Decimal2.config(obj);
2323
- return Decimal2;
2324
- }
2325
- function div(x, y) {
2326
- return new this(x).div(y);
2327
- }
2328
- function exp(x) {
2329
- return new this(x).exp();
2330
- }
2331
- function floor(x) {
2332
- return finalise(x = new this(x), x.e + 1, 3);
2333
- }
2334
- function hypot() {
2335
- var i, n, t = new this(0);
2336
- external = false;
2337
- for (i = 0; i < arguments.length; ) {
2338
- n = new this(arguments[i++]);
2339
- if (!n.d) {
2340
- if (n.s) {
2341
- external = true;
2342
- return new this(1 / 0);
2343
- }
2344
- t = n;
2345
- } else if (t.d) {
2346
- t = t.plus(n.times(n));
2347
- }
2348
- }
2349
- external = true;
2350
- return t.sqrt();
2351
- }
2352
- function isDecimalInstance(obj) {
2353
- return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
2354
- }
2355
- function ln(x) {
2356
- return new this(x).ln();
2357
- }
2358
- function log(x, y) {
2359
- return new this(x).log(y);
2360
- }
2361
- function log2(x) {
2362
- return new this(x).log(2);
2363
- }
2364
- function log10(x) {
2365
- return new this(x).log(10);
2366
- }
2367
- function max() {
2368
- return maxOrMin(this, arguments, -1);
2369
- }
2370
- function min() {
2371
- return maxOrMin(this, arguments, 1);
2372
- }
2373
- function mod(x, y) {
2374
- return new this(x).mod(y);
2375
- }
2376
- function mul(x, y) {
2377
- return new this(x).mul(y);
2378
- }
2379
- function pow(x, y) {
2380
- return new this(x).pow(y);
2381
- }
2382
- function random(sd) {
2383
- var d, e, k, n, i = 0, r = new this(1), rd = [];
2384
- if (sd === void 0)
2385
- sd = this.precision;
2386
- else
2387
- checkInt32(sd, 1, MAX_DIGITS);
2388
- k = Math.ceil(sd / LOG_BASE);
2389
- if (!this.crypto) {
2390
- for (; i < k; )
2391
- rd[i++] = Math.random() * 1e7 | 0;
2392
- } else if (crypto.getRandomValues) {
2393
- d = crypto.getRandomValues(new Uint32Array(k));
2394
- for (; i < k; ) {
2395
- n = d[i];
2396
- if (n >= 429e7) {
2397
- d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
2398
- } else {
2399
- rd[i++] = n % 1e7;
2400
- }
2401
- }
2402
- } else if (crypto.randomBytes) {
2403
- d = crypto.randomBytes(k *= 4);
2404
- for (; i < k; ) {
2405
- n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
2406
- if (n >= 214e7) {
2407
- crypto.randomBytes(4).copy(d, i);
2408
- } else {
2409
- rd.push(n % 1e7);
2410
- i += 4;
742
+ if (op === "plus") {
743
+ if (aInf && bInf) {
744
+ if (aNeg !== bNeg) {
745
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
746
+ }
747
+ return this;
2411
748
  }
749
+ if (aInf)
750
+ return this;
751
+ if (bInf)
752
+ return other;
2412
753
  }
2413
- i = k / 4;
2414
- } else {
2415
- throw Error(cryptoUnavailable);
2416
- }
2417
- k = rd[--i];
2418
- sd %= LOG_BASE;
2419
- if (k && sd) {
2420
- n = mathpow(10, LOG_BASE - sd);
2421
- rd[i] = (k / n | 0) * n;
2422
- }
2423
- for (; rd[i] === 0; i--)
2424
- rd.pop();
2425
- if (i < 0) {
2426
- e = 0;
2427
- rd = [0];
2428
- } else {
2429
- e = -1;
2430
- for (; rd[0] === 0; e -= LOG_BASE)
2431
- rd.shift();
2432
- for (k = 1, n = rd[0]; n >= 10; n /= 10)
2433
- k++;
2434
- if (k < LOG_BASE)
2435
- e -= LOG_BASE - k;
754
+ return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
2436
755
  }
2437
- r.e = e;
2438
- r.d = rd;
2439
- return r;
2440
- }
2441
- function round(x) {
2442
- return finalise(x = new this(x), x.e + 1, this.rounding);
2443
- }
2444
- function sign(x) {
2445
- x = new this(x);
2446
- return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
2447
- }
2448
- function sin(x) {
2449
- return new this(x).sin();
2450
- }
2451
- function sinh(x) {
2452
- return new this(x).sinh();
2453
- }
2454
- function sqrt(x) {
2455
- return new this(x).sqrt();
2456
- }
2457
- function sub(x, y) {
2458
- return new this(x).sub(y);
2459
- }
2460
- function sum() {
2461
- var i = 0, args = arguments, x = new this(args[i]);
2462
- external = false;
2463
- for (; x.s && ++i < args.length; )
2464
- x = x.plus(args[i]);
2465
- external = true;
2466
- return finalise(x, this.precision, this.rounding);
2467
- }
2468
- function tan(x) {
2469
- return new this(x).tan();
2470
- }
2471
- function tanh(x) {
2472
- return new this(x).tanh();
2473
- }
2474
- function trunc(x) {
2475
- return finalise(x = new this(x), x.e + 1, 1);
2476
- }
2477
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
2478
- P[Symbol.toStringTag] = "Decimal";
2479
- var Decimal = P.constructor = clone(DEFAULTS);
2480
- LN10 = new Decimal(LN10);
2481
- PI = new Decimal(PI);
756
+ };
2482
757
 
2483
758
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/constants.js
2484
- var TEN = new Decimal(10);
2485
- var ZERO = new Decimal(0);
2486
- var NEGATIVE_ZERO = new Decimal(-0);
759
+ var TEN = new BigDecimal(10);
760
+ var ZERO = new BigDecimal(0);
761
+ var NEGATIVE_ZERO = new BigDecimal(-0);
2487
762
 
2488
763
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/utils.js
2489
764
  var createMemoizedNumberFormat = memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
@@ -2551,15 +826,9 @@
2551
826
 
2552
827
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/decimal-cache.js
2553
828
  var getPowerOf10 = memoize((exponent) => {
2554
- return Decimal.pow(10, exponent);
829
+ return BigDecimal.pow(10, exponent);
2555
830
  });
2556
831
 
2557
- // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
2558
- Decimal.set({ toExpPos: 100 });
2559
-
2560
- // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ToRawFixed.js
2561
- Decimal.set({ toExpPos: 100 });
2562
-
2563
832
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/regex.generated.js
2564
833
  var S_UNICODE_REGEX = /[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u0888\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20C1\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2429\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E5\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDCF\uFDFC-\uFDFF\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD803[\uDD8E\uDD8F\uDED1-\uDED8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD833[\uDC00-\uDCEF\uDCFA-\uDCFC\uDD00-\uDEB3\uDEBA-\uDED0\uDEE0-\uDEF0\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED8\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0-\uDCBB\uDCC0\uDCC1\uDCD0-\uDCD8\uDD00-\uDE57\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE8A\uDE8E-\uDEC6\uDEC8\uDECD-\uDEDC\uDEDF-\uDEEA\uDEEF-\uDEF8\uDF00-\uDF92\uDF94-\uDFEF\uDFFA]/;
2565
834
 
@@ -5753,9 +4022,8 @@
5753
4022
  // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/utils.js
5754
4023
  var PROCESSED_DATA;
5755
4024
  function processData() {
5756
- var _a, _b;
5757
4025
  if (!PROCESSED_DATA) {
5758
- const paradigmLocales = (_b = (_a = data.supplemental.languageMatching["written-new"][0]) == null ? void 0 : _a.paradigmLocales) == null ? void 0 : _b._locales.split(" ");
4026
+ const paradigmLocales = data.supplemental.languageMatching["written-new"][0]?.paradigmLocales?._locales.split(" ");
5759
4027
  const matchVariables = data.supplemental.languageMatching["written-new"].slice(1, 5);
5760
4028
  const data2 = data.supplemental.languageMatching["written-new"].slice(5);
5761
4029
  const matches = data2.map((d) => {
@@ -5886,7 +4154,7 @@
5886
4154
  if (format.substring(0, 3) !== currency && format.substring(format.length - 3) !== currency) {
5887
4155
  return true;
5888
4156
  }
5889
- } catch (e) {
4157
+ } catch {
5890
4158
  }
5891
4159
  return false;
5892
4160
  }
@@ -6021,7 +4289,7 @@
6021
4289
  if (options === system && system === "latn" || numberFormat.format(123) !== "123") {
6022
4290
  return true;
6023
4291
  }
6024
- } catch (e) {
4292
+ } catch {
6025
4293
  }
6026
4294
  return false;
6027
4295
  }
@@ -6037,7 +4305,7 @@
6037
4305
  try {
6038
4306
  const formatter = createMemoizedDateTimeFormat("en", { timeZone });
6039
4307
  return formatter.resolvedOptions().timeZone === timeZone;
6040
- } catch (e) {
4308
+ } catch {
6041
4309
  }
6042
4310
  return false;
6043
4311
  }
@@ -6053,7 +4321,7 @@
6053
4321
  try {
6054
4322
  const formatter = createMemoizedNumberFormat("en", { style: "unit", unit });
6055
4323
  return formatter.resolvedOptions().unit === unit;
6056
- } catch (e) {
4324
+ } catch {
6057
4325
  }
6058
4326
  return false;
6059
4327
  }
@@ -6091,15 +4359,4 @@
6091
4359
  });
6092
4360
  }
6093
4361
  })();
6094
- /*! Bundled license information:
6095
-
6096
- decimal.js/decimal.mjs:
6097
- (*!
6098
- * decimal.js v10.6.0
6099
- * An arbitrary-precision Decimal type for JavaScript.
6100
- * https://github.com/MikeMcl/decimal.js
6101
- * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
6102
- * MIT Licence
6103
- *)
6104
- */
6105
4362
  //# sourceMappingURL=polyfill.iife.js.map