@formatjs/intl-locale 5.2.2 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/polyfill.iife.js +603 -2358
package/polyfill.iife.js
CHANGED
|
@@ -1,2393 +1,651 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
4
|
var __publicField = (obj, key, value) => {
|
|
22
5
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
6
|
return value;
|
|
24
7
|
};
|
|
25
8
|
|
|
26
|
-
// node_modules/.aspect_rules_js
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// ROUND_UP 0 Away from zero.
|
|
42
|
-
// ROUND_DOWN 1 Towards zero.
|
|
43
|
-
// ROUND_CEIL 2 Towards +Infinity.
|
|
44
|
-
// ROUND_FLOOR 3 Towards -Infinity.
|
|
45
|
-
// ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
|
|
46
|
-
// ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
|
|
47
|
-
// ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
|
|
48
|
-
// ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
|
|
49
|
-
// ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
|
|
50
|
-
//
|
|
51
|
-
// E.g.
|
|
52
|
-
// `Decimal.rounding = 4;`
|
|
53
|
-
// `Decimal.rounding = Decimal.ROUND_HALF_UP;`
|
|
54
|
-
rounding: 4,
|
|
55
|
-
// 0 to 8
|
|
56
|
-
// The modulo mode used when calculating the modulus: a mod n.
|
|
57
|
-
// The quotient (q = a / n) is calculated according to the corresponding rounding mode.
|
|
58
|
-
// The remainder (r) is calculated as: r = a - n * q.
|
|
59
|
-
//
|
|
60
|
-
// UP 0 The remainder is positive if the dividend is negative, else is negative.
|
|
61
|
-
// DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
|
|
62
|
-
// FLOOR 3 The remainder has the same sign as the divisor (Python %).
|
|
63
|
-
// HALF_EVEN 6 The IEEE 754 remainder function.
|
|
64
|
-
// EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
|
|
65
|
-
//
|
|
66
|
-
// Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
|
|
67
|
-
// division (9) are commonly used for the modulus operation. The other rounding modes can also
|
|
68
|
-
// be used, but they may not give useful results.
|
|
69
|
-
modulo: 1,
|
|
70
|
-
// 0 to 9
|
|
71
|
-
// The exponent value at and beneath which `toString` returns exponential notation.
|
|
72
|
-
// JavaScript numbers: -7
|
|
73
|
-
toExpNeg: -7,
|
|
74
|
-
// 0 to -EXP_LIMIT
|
|
75
|
-
// The exponent value at and above which `toString` returns exponential notation.
|
|
76
|
-
// JavaScript numbers: 21
|
|
77
|
-
toExpPos: 21,
|
|
78
|
-
// 0 to EXP_LIMIT
|
|
79
|
-
// The minimum exponent value, beneath which underflow to zero occurs.
|
|
80
|
-
// JavaScript numbers: -324 (5e-324)
|
|
81
|
-
minE: -EXP_LIMIT,
|
|
82
|
-
// -1 to -EXP_LIMIT
|
|
83
|
-
// The maximum exponent value, above which overflow to Infinity occurs.
|
|
84
|
-
// JavaScript numbers: 308 (1.7976931348623157e+308)
|
|
85
|
-
maxE: EXP_LIMIT,
|
|
86
|
-
// 1 to EXP_LIMIT
|
|
87
|
-
// Whether to use cryptographically-secure random number generation, if available.
|
|
88
|
-
crypto: false
|
|
89
|
-
// true/false
|
|
90
|
-
};
|
|
91
|
-
var inexact;
|
|
92
|
-
var quadrant;
|
|
93
|
-
var external = true;
|
|
94
|
-
var decimalError = "[DecimalError] ";
|
|
95
|
-
var invalidArgument = decimalError + "Invalid argument: ";
|
|
96
|
-
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
97
|
-
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
98
|
-
var tag = "[object Decimal]";
|
|
99
|
-
var mathfloor = Math.floor;
|
|
100
|
-
var mathpow = Math.pow;
|
|
101
|
-
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
102
|
-
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
103
|
-
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
104
|
-
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
105
|
-
var BASE = 1e7;
|
|
106
|
-
var LOG_BASE = 7;
|
|
107
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
108
|
-
var LN10_PRECISION = LN10.length - 1;
|
|
109
|
-
var PI_PRECISION = PI.length - 1;
|
|
110
|
-
var P = { toStringTag: tag };
|
|
111
|
-
P.absoluteValue = P.abs = function() {
|
|
112
|
-
var x = new this.constructor(this);
|
|
113
|
-
if (x.s < 0)
|
|
114
|
-
x.s = 1;
|
|
115
|
-
return finalise(x);
|
|
116
|
-
};
|
|
117
|
-
P.ceil = function() {
|
|
118
|
-
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
119
|
-
};
|
|
120
|
-
P.clampedTo = P.clamp = function(min2, max2) {
|
|
121
|
-
var k, x = this, Ctor = x.constructor;
|
|
122
|
-
min2 = new Ctor(min2);
|
|
123
|
-
max2 = new Ctor(max2);
|
|
124
|
-
if (!min2.s || !max2.s)
|
|
125
|
-
return new Ctor(NaN);
|
|
126
|
-
if (min2.gt(max2))
|
|
127
|
-
throw Error(invalidArgument + max2);
|
|
128
|
-
k = x.cmp(min2);
|
|
129
|
-
return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
|
|
130
|
-
};
|
|
131
|
-
P.comparedTo = P.cmp = function(y) {
|
|
132
|
-
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
|
133
|
-
if (!xd || !yd) {
|
|
134
|
-
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
9
|
+
// node_modules/.aspect_rules_js/@formatjs+bigdecimal@0.0.0/node_modules/@formatjs/bigdecimal/index.js
|
|
10
|
+
var DIV_PRECISION = 40;
|
|
11
|
+
var SpecialValue = function(SpecialValue2) {
|
|
12
|
+
SpecialValue2[SpecialValue2["NONE"] = 0] = "NONE";
|
|
13
|
+
SpecialValue2[SpecialValue2["NAN"] = 1] = "NAN";
|
|
14
|
+
SpecialValue2[SpecialValue2["POSITIVE_INFINITY"] = 2] = "POSITIVE_INFINITY";
|
|
15
|
+
SpecialValue2[SpecialValue2["NEGATIVE_INFINITY"] = 3] = "NEGATIVE_INFINITY";
|
|
16
|
+
return SpecialValue2;
|
|
17
|
+
}(SpecialValue || {});
|
|
18
|
+
function removeTrailingZeros(mantissa, exponent) {
|
|
19
|
+
if (mantissa === 0n)
|
|
20
|
+
return [0n, 0];
|
|
21
|
+
while (mantissa % 10n === 0n) {
|
|
22
|
+
mantissa /= 10n;
|
|
23
|
+
exponent++;
|
|
135
24
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
152
|
-
if (!x.d)
|
|
153
|
-
return new Ctor(NaN);
|
|
154
|
-
if (!x.d[0])
|
|
155
|
-
return new Ctor(1);
|
|
156
|
-
pr = Ctor.precision;
|
|
157
|
-
rm = Ctor.rounding;
|
|
158
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
159
|
-
Ctor.rounding = 1;
|
|
160
|
-
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
161
|
-
Ctor.precision = pr;
|
|
162
|
-
Ctor.rounding = rm;
|
|
163
|
-
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
|
164
|
-
};
|
|
165
|
-
P.cubeRoot = P.cbrt = function() {
|
|
166
|
-
var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
|
|
167
|
-
if (!x.isFinite() || x.isZero())
|
|
168
|
-
return new Ctor(x);
|
|
169
|
-
external = false;
|
|
170
|
-
s = x.s * mathpow(x.s * x, 1 / 3);
|
|
171
|
-
if (!s || Math.abs(s) == 1 / 0) {
|
|
172
|
-
n = digitsToString(x.d);
|
|
173
|
-
e = x.e;
|
|
174
|
-
if (s = (e - n.length + 1) % 3)
|
|
175
|
-
n += s == 1 || s == -2 ? "0" : "00";
|
|
176
|
-
s = mathpow(n, 1 / 3);
|
|
177
|
-
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
178
|
-
if (s == 1 / 0) {
|
|
179
|
-
n = "5e" + e;
|
|
180
|
-
} else {
|
|
181
|
-
n = s.toExponential();
|
|
182
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
183
|
-
}
|
|
184
|
-
r = new Ctor(n);
|
|
185
|
-
r.s = x.s;
|
|
186
|
-
} else {
|
|
187
|
-
r = new Ctor(s.toString());
|
|
188
|
-
}
|
|
189
|
-
sd = (e = Ctor.precision) + 3;
|
|
190
|
-
for (; ; ) {
|
|
191
|
-
t = r;
|
|
192
|
-
t3 = t.times(t).times(t);
|
|
193
|
-
t3plusx = t3.plus(x);
|
|
194
|
-
r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
|
|
195
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
196
|
-
n = n.slice(sd - 3, sd + 1);
|
|
197
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
198
|
-
if (!rep) {
|
|
199
|
-
finalise(t, e + 1, 0);
|
|
200
|
-
if (t.times(t).times(t).eq(x)) {
|
|
201
|
-
r = t;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
sd += 4;
|
|
206
|
-
rep = 1;
|
|
207
|
-
} else {
|
|
208
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
209
|
-
finalise(r, e + 1, 1);
|
|
210
|
-
m = !r.times(r).times(r).eq(x);
|
|
211
|
-
}
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
external = true;
|
|
217
|
-
return finalise(r, e, Ctor.rounding, m);
|
|
218
|
-
};
|
|
219
|
-
P.decimalPlaces = P.dp = function() {
|
|
220
|
-
var w, d = this.d, n = NaN;
|
|
221
|
-
if (d) {
|
|
222
|
-
w = d.length - 1;
|
|
223
|
-
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
224
|
-
w = d[w];
|
|
225
|
-
if (w)
|
|
226
|
-
for (; w % 10 == 0; w /= 10)
|
|
227
|
-
n--;
|
|
228
|
-
if (n < 0)
|
|
229
|
-
n = 0;
|
|
25
|
+
return [mantissa, exponent];
|
|
26
|
+
}
|
|
27
|
+
function bigintAbs(n) {
|
|
28
|
+
return n < 0n ? -n : n;
|
|
29
|
+
}
|
|
30
|
+
function digitCount(n) {
|
|
31
|
+
if (n === 0n)
|
|
32
|
+
return 1;
|
|
33
|
+
if (n < 0n)
|
|
34
|
+
n = -n;
|
|
35
|
+
let count = 0;
|
|
36
|
+
const big15 = 1000000000000000n;
|
|
37
|
+
while (n >= big15) {
|
|
38
|
+
n /= big15;
|
|
39
|
+
count += 15;
|
|
230
40
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
};
|
|
236
|
-
P.dividedToIntegerBy = P.divToInt = function(y) {
|
|
237
|
-
var x = this, Ctor = x.constructor;
|
|
238
|
-
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
239
|
-
};
|
|
240
|
-
P.equals = P.eq = function(y) {
|
|
241
|
-
return this.cmp(y) === 0;
|
|
242
|
-
};
|
|
243
|
-
P.floor = function() {
|
|
244
|
-
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
245
|
-
};
|
|
246
|
-
P.greaterThan = P.gt = function(y) {
|
|
247
|
-
return this.cmp(y) > 0;
|
|
248
|
-
};
|
|
249
|
-
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
250
|
-
var k = this.cmp(y);
|
|
251
|
-
return k == 1 || k === 0;
|
|
252
|
-
};
|
|
253
|
-
P.hyperbolicCosine = P.cosh = function() {
|
|
254
|
-
var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
|
255
|
-
if (!x.isFinite())
|
|
256
|
-
return new Ctor(x.s ? 1 / 0 : NaN);
|
|
257
|
-
if (x.isZero())
|
|
258
|
-
return one;
|
|
259
|
-
pr = Ctor.precision;
|
|
260
|
-
rm = Ctor.rounding;
|
|
261
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
262
|
-
Ctor.rounding = 1;
|
|
263
|
-
len = x.d.length;
|
|
264
|
-
if (len < 32) {
|
|
265
|
-
k = Math.ceil(len / 3);
|
|
266
|
-
n = (1 / tinyPow(4, k)).toString();
|
|
267
|
-
} else {
|
|
268
|
-
k = 16;
|
|
269
|
-
n = "2.3283064365386962890625e-10";
|
|
41
|
+
let r = Number(n);
|
|
42
|
+
while (r >= 1) {
|
|
43
|
+
r /= 10;
|
|
44
|
+
count++;
|
|
270
45
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
46
|
+
return count;
|
|
47
|
+
}
|
|
48
|
+
var TEN_BIGINT = 10n;
|
|
49
|
+
function bigintPow10(n) {
|
|
50
|
+
if (n <= 0)
|
|
51
|
+
return 1n;
|
|
52
|
+
let result = 1n;
|
|
53
|
+
let base = TEN_BIGINT;
|
|
54
|
+
let exp = n;
|
|
55
|
+
while (exp > 0) {
|
|
56
|
+
if (exp & 1)
|
|
57
|
+
result *= base;
|
|
58
|
+
base *= base;
|
|
59
|
+
exp >>= 1;
|
|
276
60
|
}
|
|
277
|
-
return
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (
|
|
282
|
-
return
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (len < 3) {
|
|
289
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
290
|
-
} else {
|
|
291
|
-
k = 1.4 * Math.sqrt(len);
|
|
292
|
-
k = k > 16 ? 16 : k | 0;
|
|
293
|
-
x = x.times(1 / tinyPow(5, k));
|
|
294
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
295
|
-
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
296
|
-
for (; k--; ) {
|
|
297
|
-
sinh2_x = x.times(x);
|
|
298
|
-
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
299
|
-
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
function parseDecimalString(s) {
|
|
64
|
+
s = s.trim();
|
|
65
|
+
if (s === "NaN") {
|
|
66
|
+
return {
|
|
67
|
+
mantissa: 0n,
|
|
68
|
+
exponent: 0,
|
|
69
|
+
special: SpecialValue.NAN,
|
|
70
|
+
negativeZero: false
|
|
71
|
+
};
|
|
300
72
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return new Ctor(x.s);
|
|
309
|
-
if (x.isZero())
|
|
310
|
-
return new Ctor(x);
|
|
311
|
-
pr = Ctor.precision;
|
|
312
|
-
rm = Ctor.rounding;
|
|
313
|
-
Ctor.precision = pr + 7;
|
|
314
|
-
Ctor.rounding = 1;
|
|
315
|
-
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
316
|
-
};
|
|
317
|
-
P.inverseCosine = P.acos = function() {
|
|
318
|
-
var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
319
|
-
if (k !== -1) {
|
|
320
|
-
return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
73
|
+
if (s === "Infinity" || s === "+Infinity") {
|
|
74
|
+
return {
|
|
75
|
+
mantissa: 0n,
|
|
76
|
+
exponent: 0,
|
|
77
|
+
special: SpecialValue.POSITIVE_INFINITY,
|
|
78
|
+
negativeZero: false
|
|
79
|
+
};
|
|
321
80
|
}
|
|
322
|
-
if (
|
|
323
|
-
return
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return x.times(2);
|
|
330
|
-
};
|
|
331
|
-
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
332
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
333
|
-
if (x.lte(1))
|
|
334
|
-
return new Ctor(x.eq(1) ? 0 : NaN);
|
|
335
|
-
if (!x.isFinite())
|
|
336
|
-
return new Ctor(x);
|
|
337
|
-
pr = Ctor.precision;
|
|
338
|
-
rm = Ctor.rounding;
|
|
339
|
-
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
340
|
-
Ctor.rounding = 1;
|
|
341
|
-
external = false;
|
|
342
|
-
x = x.times(x).minus(1).sqrt().plus(x);
|
|
343
|
-
external = true;
|
|
344
|
-
Ctor.precision = pr;
|
|
345
|
-
Ctor.rounding = rm;
|
|
346
|
-
return x.ln();
|
|
347
|
-
};
|
|
348
|
-
P.inverseHyperbolicSine = P.asinh = function() {
|
|
349
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
350
|
-
if (!x.isFinite() || x.isZero())
|
|
351
|
-
return new Ctor(x);
|
|
352
|
-
pr = Ctor.precision;
|
|
353
|
-
rm = Ctor.rounding;
|
|
354
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
355
|
-
Ctor.rounding = 1;
|
|
356
|
-
external = false;
|
|
357
|
-
x = x.times(x).plus(1).sqrt().plus(x);
|
|
358
|
-
external = true;
|
|
359
|
-
Ctor.precision = pr;
|
|
360
|
-
Ctor.rounding = rm;
|
|
361
|
-
return x.ln();
|
|
362
|
-
};
|
|
363
|
-
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
364
|
-
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
365
|
-
if (!x.isFinite())
|
|
366
|
-
return new Ctor(NaN);
|
|
367
|
-
if (x.e >= 0)
|
|
368
|
-
return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
369
|
-
pr = Ctor.precision;
|
|
370
|
-
rm = Ctor.rounding;
|
|
371
|
-
xsd = x.sd();
|
|
372
|
-
if (Math.max(xsd, pr) < 2 * -x.e - 1)
|
|
373
|
-
return finalise(new Ctor(x), pr, rm, true);
|
|
374
|
-
Ctor.precision = wpr = xsd - x.e;
|
|
375
|
-
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
376
|
-
Ctor.precision = pr + 4;
|
|
377
|
-
Ctor.rounding = 1;
|
|
378
|
-
x = x.ln();
|
|
379
|
-
Ctor.precision = pr;
|
|
380
|
-
Ctor.rounding = rm;
|
|
381
|
-
return x.times(0.5);
|
|
382
|
-
};
|
|
383
|
-
P.inverseSine = P.asin = function() {
|
|
384
|
-
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
385
|
-
if (x.isZero())
|
|
386
|
-
return new Ctor(x);
|
|
387
|
-
k = x.abs().cmp(1);
|
|
388
|
-
pr = Ctor.precision;
|
|
389
|
-
rm = Ctor.rounding;
|
|
390
|
-
if (k !== -1) {
|
|
391
|
-
if (k === 0) {
|
|
392
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
393
|
-
halfPi.s = x.s;
|
|
394
|
-
return halfPi;
|
|
395
|
-
}
|
|
396
|
-
return new Ctor(NaN);
|
|
81
|
+
if (s === "-Infinity") {
|
|
82
|
+
return {
|
|
83
|
+
mantissa: 0n,
|
|
84
|
+
exponent: 0,
|
|
85
|
+
special: SpecialValue.NEGATIVE_INFINITY,
|
|
86
|
+
negativeZero: false
|
|
87
|
+
};
|
|
397
88
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
P.inverseTangent = P.atan = function() {
|
|
406
|
-
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
407
|
-
if (!x.isFinite()) {
|
|
408
|
-
if (!x.s)
|
|
409
|
-
return new Ctor(NaN);
|
|
410
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
411
|
-
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
412
|
-
r.s = x.s;
|
|
413
|
-
return r;
|
|
414
|
-
}
|
|
415
|
-
} else if (x.isZero()) {
|
|
416
|
-
return new Ctor(x);
|
|
417
|
-
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
418
|
-
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
419
|
-
r.s = x.s;
|
|
420
|
-
return r;
|
|
89
|
+
let negative = false;
|
|
90
|
+
let idx = 0;
|
|
91
|
+
if (s[idx] === "-") {
|
|
92
|
+
negative = true;
|
|
93
|
+
idx++;
|
|
94
|
+
} else if (s[idx] === "+") {
|
|
95
|
+
idx++;
|
|
421
96
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
px = x;
|
|
433
|
-
for (; i !== -1; ) {
|
|
434
|
-
px = px.times(x2);
|
|
435
|
-
t = r.minus(px.div(n += 2));
|
|
436
|
-
px = px.times(x2);
|
|
437
|
-
r = t.plus(px.div(n += 2));
|
|
438
|
-
if (r.d[j] !== void 0)
|
|
439
|
-
for (i = j; r.d[i] === t.d[i] && i--; )
|
|
440
|
-
;
|
|
97
|
+
let eIdx = s.indexOf("e", idx);
|
|
98
|
+
if (eIdx === -1)
|
|
99
|
+
eIdx = s.indexOf("E", idx);
|
|
100
|
+
let sciExp = 0;
|
|
101
|
+
let numPart;
|
|
102
|
+
if (eIdx !== -1) {
|
|
103
|
+
sciExp = parseInt(s.substring(eIdx + 1), 10);
|
|
104
|
+
numPart = s.substring(idx, eIdx);
|
|
105
|
+
} else {
|
|
106
|
+
numPart = s.substring(idx);
|
|
441
107
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
return !!this.d;
|
|
449
|
-
};
|
|
450
|
-
P.isInteger = P.isInt = function() {
|
|
451
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
452
|
-
};
|
|
453
|
-
P.isNaN = function() {
|
|
454
|
-
return !this.s;
|
|
455
|
-
};
|
|
456
|
-
P.isNegative = P.isNeg = function() {
|
|
457
|
-
return this.s < 0;
|
|
458
|
-
};
|
|
459
|
-
P.isPositive = P.isPos = function() {
|
|
460
|
-
return this.s > 0;
|
|
461
|
-
};
|
|
462
|
-
P.isZero = function() {
|
|
463
|
-
return !!this.d && this.d[0] === 0;
|
|
464
|
-
};
|
|
465
|
-
P.lessThan = P.lt = function(y) {
|
|
466
|
-
return this.cmp(y) < 0;
|
|
467
|
-
};
|
|
468
|
-
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
469
|
-
return this.cmp(y) < 1;
|
|
470
|
-
};
|
|
471
|
-
P.logarithm = P.log = function(base) {
|
|
472
|
-
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
473
|
-
if (base == null) {
|
|
474
|
-
base = new Ctor(10);
|
|
475
|
-
isBase10 = true;
|
|
108
|
+
const dotIdx = numPart.indexOf(".");
|
|
109
|
+
let intPart;
|
|
110
|
+
let fracPart;
|
|
111
|
+
if (dotIdx !== -1) {
|
|
112
|
+
intPart = numPart.substring(0, dotIdx);
|
|
113
|
+
fracPart = numPart.substring(dotIdx + 1);
|
|
476
114
|
} else {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1))
|
|
480
|
-
return new Ctor(NaN);
|
|
481
|
-
isBase10 = base.eq(10);
|
|
115
|
+
intPart = numPart;
|
|
116
|
+
fracPart = "";
|
|
482
117
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
118
|
+
const combined = intPart + fracPart;
|
|
119
|
+
const exponent = sciExp - fracPart.length;
|
|
120
|
+
if (combined === "" || combined === "0" || /^0+$/.test(combined)) {
|
|
121
|
+
return {
|
|
122
|
+
mantissa: 0n,
|
|
123
|
+
exponent: 0,
|
|
124
|
+
special: SpecialValue.NONE,
|
|
125
|
+
negativeZero: negative
|
|
126
|
+
};
|
|
486
127
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
128
|
+
let mantissa = BigInt(combined);
|
|
129
|
+
if (negative)
|
|
130
|
+
mantissa = -mantissa;
|
|
131
|
+
const [normMantissa, normExponent] = removeTrailingZeros(mantissa, exponent);
|
|
132
|
+
return {
|
|
133
|
+
mantissa: normMantissa,
|
|
134
|
+
exponent: normExponent,
|
|
135
|
+
special: SpecialValue.NONE,
|
|
136
|
+
negativeZero: false
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
var BigDecimal = class _BigDecimal {
|
|
140
|
+
constructor(value) {
|
|
141
|
+
__publicField(this, "_mantissa");
|
|
142
|
+
__publicField(this, "_exponent");
|
|
143
|
+
__publicField(this, "_special");
|
|
144
|
+
__publicField(this, "_negativeZero");
|
|
145
|
+
if (typeof value === "bigint") {
|
|
146
|
+
const [m, e] = removeTrailingZeros(value, 0);
|
|
147
|
+
this._mantissa = m;
|
|
148
|
+
this._exponent = e;
|
|
149
|
+
this._special = SpecialValue.NONE;
|
|
150
|
+
this._negativeZero = false;
|
|
151
|
+
return;
|
|
494
152
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
do {
|
|
503
|
-
sd += 10;
|
|
504
|
-
num = naturalLogarithm(arg, sd);
|
|
505
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
506
|
-
r = divide(num, denominator, sd, 1);
|
|
507
|
-
if (!inf) {
|
|
508
|
-
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
|
509
|
-
r = finalise(r, pr + 1, 0);
|
|
510
|
-
}
|
|
511
|
-
break;
|
|
153
|
+
if (typeof value === "number") {
|
|
154
|
+
if (Number.isNaN(value)) {
|
|
155
|
+
this._mantissa = 0n;
|
|
156
|
+
this._exponent = 0;
|
|
157
|
+
this._special = SpecialValue.NAN;
|
|
158
|
+
this._negativeZero = false;
|
|
159
|
+
return;
|
|
512
160
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
|
520
|
-
y = new Ctor(y);
|
|
521
|
-
if (!x.d || !y.d) {
|
|
522
|
-
if (!x.s || !y.s)
|
|
523
|
-
y = new Ctor(NaN);
|
|
524
|
-
else if (x.d)
|
|
525
|
-
y.s = -y.s;
|
|
526
|
-
else
|
|
527
|
-
y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
|
528
|
-
return y;
|
|
529
|
-
}
|
|
530
|
-
if (x.s != y.s) {
|
|
531
|
-
y.s = -y.s;
|
|
532
|
-
return x.plus(y);
|
|
533
|
-
}
|
|
534
|
-
xd = x.d;
|
|
535
|
-
yd = y.d;
|
|
536
|
-
pr = Ctor.precision;
|
|
537
|
-
rm = Ctor.rounding;
|
|
538
|
-
if (!xd[0] || !yd[0]) {
|
|
539
|
-
if (yd[0])
|
|
540
|
-
y.s = -y.s;
|
|
541
|
-
else if (xd[0])
|
|
542
|
-
y = new Ctor(x);
|
|
543
|
-
else
|
|
544
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
545
|
-
return external ? finalise(y, pr, rm) : y;
|
|
546
|
-
}
|
|
547
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
548
|
-
xe = mathfloor(x.e / LOG_BASE);
|
|
549
|
-
xd = xd.slice();
|
|
550
|
-
k = xe - e;
|
|
551
|
-
if (k) {
|
|
552
|
-
xLTy = k < 0;
|
|
553
|
-
if (xLTy) {
|
|
554
|
-
d = xd;
|
|
555
|
-
k = -k;
|
|
556
|
-
len = yd.length;
|
|
557
|
-
} else {
|
|
558
|
-
d = yd;
|
|
559
|
-
e = xe;
|
|
560
|
-
len = xd.length;
|
|
561
|
-
}
|
|
562
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
563
|
-
if (k > i) {
|
|
564
|
-
k = i;
|
|
565
|
-
d.length = 1;
|
|
566
|
-
}
|
|
567
|
-
d.reverse();
|
|
568
|
-
for (i = k; i--; )
|
|
569
|
-
d.push(0);
|
|
570
|
-
d.reverse();
|
|
571
|
-
} else {
|
|
572
|
-
i = xd.length;
|
|
573
|
-
len = yd.length;
|
|
574
|
-
xLTy = i < len;
|
|
575
|
-
if (xLTy)
|
|
576
|
-
len = i;
|
|
577
|
-
for (i = 0; i < len; i++) {
|
|
578
|
-
if (xd[i] != yd[i]) {
|
|
579
|
-
xLTy = xd[i] < yd[i];
|
|
580
|
-
break;
|
|
161
|
+
if (value === Infinity) {
|
|
162
|
+
this._mantissa = 0n;
|
|
163
|
+
this._exponent = 0;
|
|
164
|
+
this._special = SpecialValue.POSITIVE_INFINITY;
|
|
165
|
+
this._negativeZero = false;
|
|
166
|
+
return;
|
|
581
167
|
}
|
|
168
|
+
if (value === -Infinity) {
|
|
169
|
+
this._mantissa = 0n;
|
|
170
|
+
this._exponent = 0;
|
|
171
|
+
this._special = SpecialValue.NEGATIVE_INFINITY;
|
|
172
|
+
this._negativeZero = false;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (value === 0) {
|
|
176
|
+
this._mantissa = 0n;
|
|
177
|
+
this._exponent = 0;
|
|
178
|
+
this._special = SpecialValue.NONE;
|
|
179
|
+
this._negativeZero = Object.is(value, -0);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
value = String(value);
|
|
582
183
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
yd = d;
|
|
589
|
-
y.s = -y.s;
|
|
590
|
-
}
|
|
591
|
-
len = xd.length;
|
|
592
|
-
for (i = yd.length - len; i > 0; --i)
|
|
593
|
-
xd[len++] = 0;
|
|
594
|
-
for (i = yd.length; i > k; ) {
|
|
595
|
-
if (xd[--i] < yd[i]) {
|
|
596
|
-
for (j = i; j && xd[--j] === 0; )
|
|
597
|
-
xd[j] = BASE - 1;
|
|
598
|
-
--xd[j];
|
|
599
|
-
xd[i] += BASE;
|
|
600
|
-
}
|
|
601
|
-
xd[i] -= yd[i];
|
|
602
|
-
}
|
|
603
|
-
for (; xd[--len] === 0; )
|
|
604
|
-
xd.pop();
|
|
605
|
-
for (; xd[0] === 0; xd.shift())
|
|
606
|
-
--e;
|
|
607
|
-
if (!xd[0])
|
|
608
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
609
|
-
y.d = xd;
|
|
610
|
-
y.e = getBase10Exponent(xd, e);
|
|
611
|
-
return external ? finalise(y, pr, rm) : y;
|
|
612
|
-
};
|
|
613
|
-
P.modulo = P.mod = function(y) {
|
|
614
|
-
var q, x = this, Ctor = x.constructor;
|
|
615
|
-
y = new Ctor(y);
|
|
616
|
-
if (!x.d || !y.s || y.d && !y.d[0])
|
|
617
|
-
return new Ctor(NaN);
|
|
618
|
-
if (!y.d || x.d && !x.d[0]) {
|
|
619
|
-
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
620
|
-
}
|
|
621
|
-
external = false;
|
|
622
|
-
if (Ctor.modulo == 9) {
|
|
623
|
-
q = divide(x, y.abs(), 0, 3, 1);
|
|
624
|
-
q.s *= y.s;
|
|
625
|
-
} else {
|
|
626
|
-
q = divide(x, y, 0, Ctor.modulo, 1);
|
|
627
|
-
}
|
|
628
|
-
q = q.times(y);
|
|
629
|
-
external = true;
|
|
630
|
-
return x.minus(q);
|
|
631
|
-
};
|
|
632
|
-
P.naturalExponential = P.exp = function() {
|
|
633
|
-
return naturalExponential(this);
|
|
634
|
-
};
|
|
635
|
-
P.naturalLogarithm = P.ln = function() {
|
|
636
|
-
return naturalLogarithm(this);
|
|
637
|
-
};
|
|
638
|
-
P.negated = P.neg = function() {
|
|
639
|
-
var x = new this.constructor(this);
|
|
640
|
-
x.s = -x.s;
|
|
641
|
-
return finalise(x);
|
|
642
|
-
};
|
|
643
|
-
P.plus = P.add = function(y) {
|
|
644
|
-
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
645
|
-
y = new Ctor(y);
|
|
646
|
-
if (!x.d || !y.d) {
|
|
647
|
-
if (!x.s || !y.s)
|
|
648
|
-
y = new Ctor(NaN);
|
|
649
|
-
else if (!x.d)
|
|
650
|
-
y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
651
|
-
return y;
|
|
184
|
+
const parsed = parseDecimalString(value);
|
|
185
|
+
this._mantissa = parsed.mantissa;
|
|
186
|
+
this._exponent = parsed.exponent;
|
|
187
|
+
this._special = parsed.special;
|
|
188
|
+
this._negativeZero = parsed.negativeZero;
|
|
652
189
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
190
|
+
// Private constructor for internal use
|
|
191
|
+
static _create(mantissa, exponent, special, negativeZero) {
|
|
192
|
+
const bd = Object.create(_BigDecimal.prototype);
|
|
193
|
+
bd._mantissa = mantissa;
|
|
194
|
+
bd._exponent = exponent;
|
|
195
|
+
bd._special = special;
|
|
196
|
+
bd._negativeZero = negativeZero;
|
|
197
|
+
return bd;
|
|
656
198
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
rm = Ctor.rounding;
|
|
661
|
-
if (!xd[0] || !yd[0]) {
|
|
662
|
-
if (!yd[0])
|
|
663
|
-
y = new Ctor(x);
|
|
664
|
-
return external ? finalise(y, pr, rm) : y;
|
|
199
|
+
// Auto-coerce to BigDecimal for decimal.js compat
|
|
200
|
+
static _coerce(v) {
|
|
201
|
+
return v instanceof _BigDecimal ? v : new _BigDecimal(v);
|
|
665
202
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (i < 0) {
|
|
672
|
-
d = xd;
|
|
673
|
-
i = -i;
|
|
674
|
-
len = yd.length;
|
|
675
|
-
} else {
|
|
676
|
-
d = yd;
|
|
677
|
-
e = k;
|
|
678
|
-
len = xd.length;
|
|
203
|
+
// --- Arithmetic ---
|
|
204
|
+
times(y) {
|
|
205
|
+
const other = _BigDecimal._coerce(y);
|
|
206
|
+
if (this._special || other._special) {
|
|
207
|
+
return this._specialArith(other, "times");
|
|
679
208
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
i = len;
|
|
684
|
-
d.length = 1;
|
|
209
|
+
if (this._mantissa === 0n || other._mantissa === 0n) {
|
|
210
|
+
const negZero = this._isSignNegative() ? !other._isSignNegative() : other._isSignNegative();
|
|
211
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
685
212
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
691
|
-
len = xd.length;
|
|
692
|
-
i = yd.length;
|
|
693
|
-
if (len - i < 0) {
|
|
694
|
-
i = len;
|
|
695
|
-
d = yd;
|
|
696
|
-
yd = xd;
|
|
697
|
-
xd = d;
|
|
698
|
-
}
|
|
699
|
-
for (carry = 0; i; ) {
|
|
700
|
-
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
701
|
-
xd[i] %= BASE;
|
|
702
|
-
}
|
|
703
|
-
if (carry) {
|
|
704
|
-
xd.unshift(carry);
|
|
705
|
-
++e;
|
|
213
|
+
const m = this._mantissa * other._mantissa;
|
|
214
|
+
const e = this._exponent + other._exponent;
|
|
215
|
+
const [nm, ne] = removeTrailingZeros(m, e);
|
|
216
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
706
217
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return external ? finalise(y, pr, rm) : y;
|
|
712
|
-
};
|
|
713
|
-
P.precision = P.sd = function(z) {
|
|
714
|
-
var k, x = this;
|
|
715
|
-
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
|
|
716
|
-
throw Error(invalidArgument + z);
|
|
717
|
-
if (x.d) {
|
|
718
|
-
k = getPrecision(x.d);
|
|
719
|
-
if (z && x.e + 1 > k)
|
|
720
|
-
k = x.e + 1;
|
|
721
|
-
} else {
|
|
722
|
-
k = NaN;
|
|
723
|
-
}
|
|
724
|
-
return k;
|
|
725
|
-
};
|
|
726
|
-
P.round = function() {
|
|
727
|
-
var x = this, Ctor = x.constructor;
|
|
728
|
-
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
|
729
|
-
};
|
|
730
|
-
P.sine = P.sin = function() {
|
|
731
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
732
|
-
if (!x.isFinite())
|
|
733
|
-
return new Ctor(NaN);
|
|
734
|
-
if (x.isZero())
|
|
735
|
-
return new Ctor(x);
|
|
736
|
-
pr = Ctor.precision;
|
|
737
|
-
rm = Ctor.rounding;
|
|
738
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
739
|
-
Ctor.rounding = 1;
|
|
740
|
-
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
741
|
-
Ctor.precision = pr;
|
|
742
|
-
Ctor.rounding = rm;
|
|
743
|
-
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
|
744
|
-
};
|
|
745
|
-
P.squareRoot = P.sqrt = function() {
|
|
746
|
-
var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
|
|
747
|
-
if (s !== 1 || !d || !d[0]) {
|
|
748
|
-
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
749
|
-
}
|
|
750
|
-
external = false;
|
|
751
|
-
s = Math.sqrt(+x);
|
|
752
|
-
if (s == 0 || s == 1 / 0) {
|
|
753
|
-
n = digitsToString(d);
|
|
754
|
-
if ((n.length + e) % 2 == 0)
|
|
755
|
-
n += "0";
|
|
756
|
-
s = Math.sqrt(n);
|
|
757
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
758
|
-
if (s == 1 / 0) {
|
|
759
|
-
n = "5e" + e;
|
|
760
|
-
} else {
|
|
761
|
-
n = s.toExponential();
|
|
762
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
218
|
+
div(y) {
|
|
219
|
+
const other = _BigDecimal._coerce(y);
|
|
220
|
+
if (this._special || other._special) {
|
|
221
|
+
return this._specialArith(other, "div");
|
|
763
222
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
768
|
-
sd = (e = Ctor.precision) + 3;
|
|
769
|
-
for (; ; ) {
|
|
770
|
-
t = r;
|
|
771
|
-
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
|
772
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
773
|
-
n = n.slice(sd - 3, sd + 1);
|
|
774
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
775
|
-
if (!rep) {
|
|
776
|
-
finalise(t, e + 1, 0);
|
|
777
|
-
if (t.times(t).eq(x)) {
|
|
778
|
-
r = t;
|
|
779
|
-
break;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
sd += 4;
|
|
783
|
-
rep = 1;
|
|
784
|
-
} else {
|
|
785
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
786
|
-
finalise(r, e + 1, 1);
|
|
787
|
-
m = !r.times(r).eq(x);
|
|
788
|
-
}
|
|
789
|
-
break;
|
|
223
|
+
if (other._mantissa === 0n) {
|
|
224
|
+
if (this._mantissa === 0n) {
|
|
225
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
790
226
|
}
|
|
227
|
+
const neg = this._isSignNegative() !== other._isSignNegative();
|
|
228
|
+
return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
|
|
791
229
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
};
|
|
796
|
-
P.tangent = P.tan = function() {
|
|
797
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
798
|
-
if (!x.isFinite())
|
|
799
|
-
return new Ctor(NaN);
|
|
800
|
-
if (x.isZero())
|
|
801
|
-
return new Ctor(x);
|
|
802
|
-
pr = Ctor.precision;
|
|
803
|
-
rm = Ctor.rounding;
|
|
804
|
-
Ctor.precision = pr + 10;
|
|
805
|
-
Ctor.rounding = 1;
|
|
806
|
-
x = x.sin();
|
|
807
|
-
x.s = 1;
|
|
808
|
-
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
|
809
|
-
Ctor.precision = pr;
|
|
810
|
-
Ctor.rounding = rm;
|
|
811
|
-
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
|
812
|
-
};
|
|
813
|
-
P.times = P.mul = function(y) {
|
|
814
|
-
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
815
|
-
y.s *= x.s;
|
|
816
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
817
|
-
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
818
|
-
}
|
|
819
|
-
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
820
|
-
xdL = xd.length;
|
|
821
|
-
ydL = yd.length;
|
|
822
|
-
if (xdL < ydL) {
|
|
823
|
-
r = xd;
|
|
824
|
-
xd = yd;
|
|
825
|
-
yd = r;
|
|
826
|
-
rL = xdL;
|
|
827
|
-
xdL = ydL;
|
|
828
|
-
ydL = rL;
|
|
829
|
-
}
|
|
830
|
-
r = [];
|
|
831
|
-
rL = xdL + ydL;
|
|
832
|
-
for (i = rL; i--; )
|
|
833
|
-
r.push(0);
|
|
834
|
-
for (i = ydL; --i >= 0; ) {
|
|
835
|
-
carry = 0;
|
|
836
|
-
for (k = xdL + i; k > i; ) {
|
|
837
|
-
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
838
|
-
r[k--] = t % BASE | 0;
|
|
839
|
-
carry = t / BASE | 0;
|
|
230
|
+
if (this._mantissa === 0n) {
|
|
231
|
+
const negZero = this._isSignNegative() !== other._isSignNegative();
|
|
232
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
840
233
|
}
|
|
841
|
-
|
|
234
|
+
const scaledNumerator = this._mantissa * bigintPow10(DIV_PRECISION);
|
|
235
|
+
const quotient = scaledNumerator / other._mantissa;
|
|
236
|
+
const newExponent = this._exponent - other._exponent - DIV_PRECISION;
|
|
237
|
+
const [nm, ne] = removeTrailingZeros(quotient, newExponent);
|
|
238
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
842
239
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
else
|
|
848
|
-
r.shift();
|
|
849
|
-
y.d = r;
|
|
850
|
-
y.e = getBase10Exponent(r, e);
|
|
851
|
-
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
852
|
-
};
|
|
853
|
-
P.toBinary = function(sd, rm) {
|
|
854
|
-
return toStringBinary(this, 2, sd, rm);
|
|
855
|
-
};
|
|
856
|
-
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
857
|
-
var x = this, Ctor = x.constructor;
|
|
858
|
-
x = new Ctor(x);
|
|
859
|
-
if (dp === void 0)
|
|
860
|
-
return x;
|
|
861
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
862
|
-
if (rm === void 0)
|
|
863
|
-
rm = Ctor.rounding;
|
|
864
|
-
else
|
|
865
|
-
checkInt32(rm, 0, 8);
|
|
866
|
-
return finalise(x, dp + x.e + 1, rm);
|
|
867
|
-
};
|
|
868
|
-
P.toExponential = function(dp, rm) {
|
|
869
|
-
var str, x = this, Ctor = x.constructor;
|
|
870
|
-
if (dp === void 0) {
|
|
871
|
-
str = finiteToString(x, true);
|
|
872
|
-
} else {
|
|
873
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
874
|
-
if (rm === void 0)
|
|
875
|
-
rm = Ctor.rounding;
|
|
876
|
-
else
|
|
877
|
-
checkInt32(rm, 0, 8);
|
|
878
|
-
x = finalise(new Ctor(x), dp + 1, rm);
|
|
879
|
-
str = finiteToString(x, true, dp + 1);
|
|
880
|
-
}
|
|
881
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
882
|
-
};
|
|
883
|
-
P.toFixed = function(dp, rm) {
|
|
884
|
-
var str, y, x = this, Ctor = x.constructor;
|
|
885
|
-
if (dp === void 0) {
|
|
886
|
-
str = finiteToString(x);
|
|
887
|
-
} else {
|
|
888
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
889
|
-
if (rm === void 0)
|
|
890
|
-
rm = Ctor.rounding;
|
|
891
|
-
else
|
|
892
|
-
checkInt32(rm, 0, 8);
|
|
893
|
-
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
894
|
-
str = finiteToString(y, false, dp + y.e + 1);
|
|
895
|
-
}
|
|
896
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
897
|
-
};
|
|
898
|
-
P.toFraction = function(maxD) {
|
|
899
|
-
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
900
|
-
if (!xd)
|
|
901
|
-
return new Ctor(x);
|
|
902
|
-
n1 = d0 = new Ctor(1);
|
|
903
|
-
d1 = n0 = new Ctor(0);
|
|
904
|
-
d = new Ctor(d1);
|
|
905
|
-
e = d.e = getPrecision(xd) - x.e - 1;
|
|
906
|
-
k = e % LOG_BASE;
|
|
907
|
-
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
908
|
-
if (maxD == null) {
|
|
909
|
-
maxD = e > 0 ? d : n1;
|
|
910
|
-
} else {
|
|
911
|
-
n = new Ctor(maxD);
|
|
912
|
-
if (!n.isInt() || n.lt(n1))
|
|
913
|
-
throw Error(invalidArgument + n);
|
|
914
|
-
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
915
|
-
}
|
|
916
|
-
external = false;
|
|
917
|
-
n = new Ctor(digitsToString(xd));
|
|
918
|
-
pr = Ctor.precision;
|
|
919
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
920
|
-
for (; ; ) {
|
|
921
|
-
q = divide(n, d, 0, 1, 1);
|
|
922
|
-
d2 = d0.plus(q.times(d1));
|
|
923
|
-
if (d2.cmp(maxD) == 1)
|
|
924
|
-
break;
|
|
925
|
-
d0 = d1;
|
|
926
|
-
d1 = d2;
|
|
927
|
-
d2 = n1;
|
|
928
|
-
n1 = n0.plus(q.times(d2));
|
|
929
|
-
n0 = d2;
|
|
930
|
-
d2 = d;
|
|
931
|
-
d = n.minus(q.times(d2));
|
|
932
|
-
n = d2;
|
|
933
|
-
}
|
|
934
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
935
|
-
n0 = n0.plus(d2.times(n1));
|
|
936
|
-
d0 = d0.plus(d2.times(d1));
|
|
937
|
-
n0.s = n1.s = x.s;
|
|
938
|
-
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
939
|
-
Ctor.precision = pr;
|
|
940
|
-
external = true;
|
|
941
|
-
return r;
|
|
942
|
-
};
|
|
943
|
-
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
944
|
-
return toStringBinary(this, 16, sd, rm);
|
|
945
|
-
};
|
|
946
|
-
P.toNearest = function(y, rm) {
|
|
947
|
-
var x = this, Ctor = x.constructor;
|
|
948
|
-
x = new Ctor(x);
|
|
949
|
-
if (y == null) {
|
|
950
|
-
if (!x.d)
|
|
951
|
-
return x;
|
|
952
|
-
y = new Ctor(1);
|
|
953
|
-
rm = Ctor.rounding;
|
|
954
|
-
} else {
|
|
955
|
-
y = new Ctor(y);
|
|
956
|
-
if (rm === void 0) {
|
|
957
|
-
rm = Ctor.rounding;
|
|
958
|
-
} else {
|
|
959
|
-
checkInt32(rm, 0, 8);
|
|
240
|
+
plus(y) {
|
|
241
|
+
const other = _BigDecimal._coerce(y);
|
|
242
|
+
if (this._special || other._special) {
|
|
243
|
+
return this._specialArith(other, "plus");
|
|
960
244
|
}
|
|
961
|
-
if (
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
if (y.s)
|
|
965
|
-
y.s = x.s;
|
|
966
|
-
return y;
|
|
245
|
+
if (this._mantissa === 0n && other._mantissa === 0n) {
|
|
246
|
+
const negZero = this._negativeZero && other._negativeZero;
|
|
247
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
967
248
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
return toStringBinary(this, 8, sd, rm);
|
|
985
|
-
};
|
|
986
|
-
P.toPower = P.pow = function(y) {
|
|
987
|
-
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
988
|
-
if (!x.d || !y.d || !x.d[0] || !y.d[0])
|
|
989
|
-
return new Ctor(mathpow(+x, yn));
|
|
990
|
-
x = new Ctor(x);
|
|
991
|
-
if (x.eq(1))
|
|
992
|
-
return x;
|
|
993
|
-
pr = Ctor.precision;
|
|
994
|
-
rm = Ctor.rounding;
|
|
995
|
-
if (y.eq(1))
|
|
996
|
-
return finalise(x, pr, rm);
|
|
997
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
998
|
-
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
999
|
-
r = intPow(Ctor, x, k, pr);
|
|
1000
|
-
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
1001
|
-
}
|
|
1002
|
-
s = x.s;
|
|
1003
|
-
if (s < 0) {
|
|
1004
|
-
if (e < y.d.length - 1)
|
|
1005
|
-
return new Ctor(NaN);
|
|
1006
|
-
if ((y.d[e] & 1) == 0)
|
|
1007
|
-
s = 1;
|
|
1008
|
-
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
1009
|
-
x.s = s;
|
|
1010
|
-
return x;
|
|
249
|
+
if (this._mantissa === 0n)
|
|
250
|
+
return other;
|
|
251
|
+
if (other._mantissa === 0n)
|
|
252
|
+
return this;
|
|
253
|
+
let m1 = this._mantissa;
|
|
254
|
+
let m2 = other._mantissa;
|
|
255
|
+
const e1 = this._exponent;
|
|
256
|
+
const e2 = other._exponent;
|
|
257
|
+
const minE = Math.min(e1, e2);
|
|
258
|
+
if (e1 > minE)
|
|
259
|
+
m1 *= bigintPow10(e1 - minE);
|
|
260
|
+
if (e2 > minE)
|
|
261
|
+
m2 *= bigintPow10(e2 - minE);
|
|
262
|
+
const sum = m1 + m2;
|
|
263
|
+
if (sum === 0n) {
|
|
264
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
|
|
1011
265
|
}
|
|
266
|
+
const [nm, ne] = removeTrailingZeros(sum, minE);
|
|
267
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
268
|
+
}
|
|
269
|
+
minus(y) {
|
|
270
|
+
return this.plus(_BigDecimal._coerce(y).negated());
|
|
1012
271
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
e = pr + 10;
|
|
1025
|
-
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
1026
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
|
1027
|
-
r = finalise(r, pr + 1, 0);
|
|
272
|
+
mod(y) {
|
|
273
|
+
const other = _BigDecimal._coerce(y);
|
|
274
|
+
if (this._special || other._special) {
|
|
275
|
+
if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN) {
|
|
276
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
277
|
+
}
|
|
278
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY || this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
279
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
280
|
+
}
|
|
281
|
+
if (other._special === SpecialValue.POSITIVE_INFINITY || other._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
282
|
+
return this;
|
|
1028
283
|
}
|
|
1029
284
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
external = true;
|
|
1033
|
-
Ctor.rounding = rm;
|
|
1034
|
-
return finalise(r, pr, rm);
|
|
1035
|
-
};
|
|
1036
|
-
P.toPrecision = function(sd, rm) {
|
|
1037
|
-
var str, x = this, Ctor = x.constructor;
|
|
1038
|
-
if (sd === void 0) {
|
|
1039
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1040
|
-
} else {
|
|
1041
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
1042
|
-
if (rm === void 0)
|
|
1043
|
-
rm = Ctor.rounding;
|
|
1044
|
-
else
|
|
1045
|
-
checkInt32(rm, 0, 8);
|
|
1046
|
-
x = finalise(new Ctor(x), sd, rm);
|
|
1047
|
-
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
1048
|
-
}
|
|
1049
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
1050
|
-
};
|
|
1051
|
-
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
1052
|
-
var x = this, Ctor = x.constructor;
|
|
1053
|
-
if (sd === void 0) {
|
|
1054
|
-
sd = Ctor.precision;
|
|
1055
|
-
rm = Ctor.rounding;
|
|
1056
|
-
} else {
|
|
1057
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
1058
|
-
if (rm === void 0)
|
|
1059
|
-
rm = Ctor.rounding;
|
|
1060
|
-
else
|
|
1061
|
-
checkInt32(rm, 0, 8);
|
|
1062
|
-
}
|
|
1063
|
-
return finalise(new Ctor(x), sd, rm);
|
|
1064
|
-
};
|
|
1065
|
-
P.toString = function() {
|
|
1066
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1067
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
1068
|
-
};
|
|
1069
|
-
P.truncated = P.trunc = function() {
|
|
1070
|
-
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
1071
|
-
};
|
|
1072
|
-
P.valueOf = P.toJSON = function() {
|
|
1073
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1074
|
-
return x.isNeg() ? "-" + str : str;
|
|
1075
|
-
};
|
|
1076
|
-
function digitsToString(d) {
|
|
1077
|
-
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
1078
|
-
if (indexOfLastWord > 0) {
|
|
1079
|
-
str += w;
|
|
1080
|
-
for (i = 1; i < indexOfLastWord; i++) {
|
|
1081
|
-
ws = d[i] + "";
|
|
1082
|
-
k = LOG_BASE - ws.length;
|
|
1083
|
-
if (k)
|
|
1084
|
-
str += getZeroString(k);
|
|
1085
|
-
str += ws;
|
|
285
|
+
if (other._mantissa === 0n) {
|
|
286
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1086
287
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
k = LOG_BASE - ws.length;
|
|
1090
|
-
if (k)
|
|
1091
|
-
str += getZeroString(k);
|
|
1092
|
-
} else if (w === 0) {
|
|
1093
|
-
return "0";
|
|
1094
|
-
}
|
|
1095
|
-
for (; w % 10 === 0; )
|
|
1096
|
-
w /= 10;
|
|
1097
|
-
return str + w;
|
|
1098
|
-
}
|
|
1099
|
-
function checkInt32(i, min2, max2) {
|
|
1100
|
-
if (i !== ~~i || i < min2 || i > max2) {
|
|
1101
|
-
throw Error(invalidArgument + i);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
1105
|
-
var di, k, r, rd;
|
|
1106
|
-
for (k = d[0]; k >= 10; k /= 10)
|
|
1107
|
-
--i;
|
|
1108
|
-
if (--i < 0) {
|
|
1109
|
-
i += LOG_BASE;
|
|
1110
|
-
di = 0;
|
|
1111
|
-
} else {
|
|
1112
|
-
di = Math.ceil((i + 1) / LOG_BASE);
|
|
1113
|
-
i %= LOG_BASE;
|
|
1114
|
-
}
|
|
1115
|
-
k = mathpow(10, LOG_BASE - i);
|
|
1116
|
-
rd = d[di] % k | 0;
|
|
1117
|
-
if (repeating == null) {
|
|
1118
|
-
if (i < 3) {
|
|
1119
|
-
if (i == 0)
|
|
1120
|
-
rd = rd / 100 | 0;
|
|
1121
|
-
else if (i == 1)
|
|
1122
|
-
rd = rd / 10 | 0;
|
|
1123
|
-
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
|
1124
|
-
} else {
|
|
1125
|
-
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;
|
|
288
|
+
if (this._mantissa === 0n) {
|
|
289
|
+
return this;
|
|
1126
290
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
291
|
+
let m1 = this._mantissa;
|
|
292
|
+
let m2 = other._mantissa;
|
|
293
|
+
const e1 = this._exponent;
|
|
294
|
+
const e2 = other._exponent;
|
|
295
|
+
const minE = Math.min(e1, e2);
|
|
296
|
+
if (e1 > minE)
|
|
297
|
+
m1 *= bigintPow10(e1 - minE);
|
|
298
|
+
if (e2 > minE)
|
|
299
|
+
m2 *= bigintPow10(e2 - minE);
|
|
300
|
+
const remainder = m1 % m2;
|
|
301
|
+
if (remainder === 0n) {
|
|
302
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
|
|
1138
303
|
}
|
|
304
|
+
const [nm, ne] = removeTrailingZeros(remainder, minE);
|
|
305
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
1139
306
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
for (arrL = arr.length; arrL--; )
|
|
1146
|
-
arr[arrL] *= baseIn;
|
|
1147
|
-
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
1148
|
-
for (j = 0; j < arr.length; j++) {
|
|
1149
|
-
if (arr[j] > baseOut - 1) {
|
|
1150
|
-
if (arr[j + 1] === void 0)
|
|
1151
|
-
arr[j + 1] = 0;
|
|
1152
|
-
arr[j + 1] += arr[j] / baseOut | 0;
|
|
1153
|
-
arr[j] %= baseOut;
|
|
1154
|
-
}
|
|
307
|
+
abs() {
|
|
308
|
+
if (this._special === SpecialValue.NAN)
|
|
309
|
+
return this;
|
|
310
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
311
|
+
return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
|
|
1155
312
|
}
|
|
313
|
+
return _BigDecimal._create(bigintAbs(this._mantissa), this._exponent, this._special, false);
|
|
1156
314
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
return x;
|
|
1163
|
-
len = x.d.length;
|
|
1164
|
-
if (len < 32) {
|
|
1165
|
-
k = Math.ceil(len / 3);
|
|
1166
|
-
y = (1 / tinyPow(4, k)).toString();
|
|
1167
|
-
} else {
|
|
1168
|
-
k = 16;
|
|
1169
|
-
y = "2.3283064365386962890625e-10";
|
|
1170
|
-
}
|
|
1171
|
-
Ctor.precision += k;
|
|
1172
|
-
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
|
1173
|
-
for (var i = k; i--; ) {
|
|
1174
|
-
var cos2x = x.times(x);
|
|
1175
|
-
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
1176
|
-
}
|
|
1177
|
-
Ctor.precision -= k;
|
|
1178
|
-
return x;
|
|
1179
|
-
}
|
|
1180
|
-
var divide = /* @__PURE__ */ function() {
|
|
1181
|
-
function multiplyInteger(x, k, base) {
|
|
1182
|
-
var temp, carry = 0, i = x.length;
|
|
1183
|
-
for (x = x.slice(); i--; ) {
|
|
1184
|
-
temp = x[i] * k + carry;
|
|
1185
|
-
x[i] = temp % base | 0;
|
|
1186
|
-
carry = temp / base | 0;
|
|
315
|
+
negated() {
|
|
316
|
+
if (this._special === SpecialValue.NAN)
|
|
317
|
+
return this;
|
|
318
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY) {
|
|
319
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false);
|
|
1187
320
|
}
|
|
1188
|
-
if (
|
|
1189
|
-
|
|
1190
|
-
return x;
|
|
1191
|
-
}
|
|
1192
|
-
function compare(a, b, aL, bL) {
|
|
1193
|
-
var i, r;
|
|
1194
|
-
if (aL != bL) {
|
|
1195
|
-
r = aL > bL ? 1 : -1;
|
|
1196
|
-
} else {
|
|
1197
|
-
for (i = r = 0; i < aL; i++) {
|
|
1198
|
-
if (a[i] != b[i]) {
|
|
1199
|
-
r = a[i] > b[i] ? 1 : -1;
|
|
1200
|
-
break;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
321
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
322
|
+
return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
|
|
1203
323
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
function subtract(a, b, aL, base) {
|
|
1207
|
-
var i = 0;
|
|
1208
|
-
for (; aL--; ) {
|
|
1209
|
-
a[aL] -= i;
|
|
1210
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
1211
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
324
|
+
if (this._mantissa === 0n) {
|
|
325
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, !this._negativeZero);
|
|
1212
326
|
}
|
|
1213
|
-
|
|
1214
|
-
a.shift();
|
|
327
|
+
return _BigDecimal._create(-this._mantissa, this._exponent, SpecialValue.NONE, false);
|
|
1215
328
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
|
|
1224
|
-
)
|
|
1225
|
-
);
|
|
329
|
+
pow(n) {
|
|
330
|
+
if (this._special === SpecialValue.NAN)
|
|
331
|
+
return this;
|
|
332
|
+
if (n === 0)
|
|
333
|
+
return new _BigDecimal(1);
|
|
334
|
+
if (n < 0) {
|
|
335
|
+
return new _BigDecimal(1).div(this.pow(-n));
|
|
1226
336
|
}
|
|
1227
|
-
if (
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
base = BASE;
|
|
1232
|
-
logBase = LOG_BASE;
|
|
1233
|
-
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
|
337
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
338
|
+
return this;
|
|
339
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
340
|
+
return n % 2 === 0 ? _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false) : this;
|
|
1234
341
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
if (
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
} else {
|
|
1255
|
-
sd = sd / logBase + 2 | 0;
|
|
1256
|
-
i = 0;
|
|
1257
|
-
if (yL == 1) {
|
|
1258
|
-
k = 0;
|
|
1259
|
-
yd = yd[0];
|
|
1260
|
-
sd++;
|
|
1261
|
-
for (; (i < xL || k) && sd--; i++) {
|
|
1262
|
-
t = k * base + (xd[i] || 0);
|
|
1263
|
-
qd[i] = t / yd | 0;
|
|
1264
|
-
k = t % yd | 0;
|
|
1265
|
-
}
|
|
1266
|
-
more = k || i < xL;
|
|
1267
|
-
} else {
|
|
1268
|
-
k = base / (yd[0] + 1) | 0;
|
|
1269
|
-
if (k > 1) {
|
|
1270
|
-
yd = multiplyInteger(yd, k, base);
|
|
1271
|
-
xd = multiplyInteger(xd, k, base);
|
|
1272
|
-
yL = yd.length;
|
|
1273
|
-
xL = xd.length;
|
|
1274
|
-
}
|
|
1275
|
-
xi = yL;
|
|
1276
|
-
rem = xd.slice(0, yL);
|
|
1277
|
-
remL = rem.length;
|
|
1278
|
-
for (; remL < yL; )
|
|
1279
|
-
rem[remL++] = 0;
|
|
1280
|
-
yz = yd.slice();
|
|
1281
|
-
yz.unshift(0);
|
|
1282
|
-
yd0 = yd[0];
|
|
1283
|
-
if (yd[1] >= base / 2)
|
|
1284
|
-
++yd0;
|
|
1285
|
-
do {
|
|
1286
|
-
k = 0;
|
|
1287
|
-
cmp = compare(yd, rem, yL, remL);
|
|
1288
|
-
if (cmp < 0) {
|
|
1289
|
-
rem0 = rem[0];
|
|
1290
|
-
if (yL != remL)
|
|
1291
|
-
rem0 = rem0 * base + (rem[1] || 0);
|
|
1292
|
-
k = rem0 / yd0 | 0;
|
|
1293
|
-
if (k > 1) {
|
|
1294
|
-
if (k >= base)
|
|
1295
|
-
k = base - 1;
|
|
1296
|
-
prod = multiplyInteger(yd, k, base);
|
|
1297
|
-
prodL = prod.length;
|
|
1298
|
-
remL = rem.length;
|
|
1299
|
-
cmp = compare(prod, rem, prodL, remL);
|
|
1300
|
-
if (cmp == 1) {
|
|
1301
|
-
k--;
|
|
1302
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
1303
|
-
}
|
|
1304
|
-
} else {
|
|
1305
|
-
if (k == 0)
|
|
1306
|
-
cmp = k = 1;
|
|
1307
|
-
prod = yd.slice();
|
|
1308
|
-
}
|
|
1309
|
-
prodL = prod.length;
|
|
1310
|
-
if (prodL < remL)
|
|
1311
|
-
prod.unshift(0);
|
|
1312
|
-
subtract(rem, prod, remL, base);
|
|
1313
|
-
if (cmp == -1) {
|
|
1314
|
-
remL = rem.length;
|
|
1315
|
-
cmp = compare(yd, rem, yL, remL);
|
|
1316
|
-
if (cmp < 1) {
|
|
1317
|
-
k++;
|
|
1318
|
-
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
remL = rem.length;
|
|
1322
|
-
} else if (cmp === 0) {
|
|
1323
|
-
k++;
|
|
1324
|
-
rem = [0];
|
|
1325
|
-
}
|
|
1326
|
-
qd[i++] = k;
|
|
1327
|
-
if (cmp && rem[0]) {
|
|
1328
|
-
rem[remL++] = xd[xi] || 0;
|
|
1329
|
-
} else {
|
|
1330
|
-
rem = [xd[xi]];
|
|
1331
|
-
remL = 1;
|
|
1332
|
-
}
|
|
1333
|
-
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
1334
|
-
more = rem[0] !== void 0;
|
|
1335
|
-
}
|
|
1336
|
-
if (!qd[0])
|
|
1337
|
-
qd.shift();
|
|
1338
|
-
}
|
|
1339
|
-
if (logBase == 1) {
|
|
1340
|
-
q.e = e;
|
|
1341
|
-
inexact = more;
|
|
1342
|
-
} else {
|
|
1343
|
-
for (i = 1, k = qd[0]; k >= 10; k /= 10)
|
|
1344
|
-
i++;
|
|
1345
|
-
q.e = i + e * logBase - 1;
|
|
1346
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
1347
|
-
}
|
|
1348
|
-
return q;
|
|
1349
|
-
};
|
|
1350
|
-
}();
|
|
1351
|
-
function finalise(x, sd, rm, isTruncated) {
|
|
1352
|
-
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
1353
|
-
out:
|
|
1354
|
-
if (sd != null) {
|
|
1355
|
-
xd = x.d;
|
|
1356
|
-
if (!xd)
|
|
1357
|
-
return x;
|
|
1358
|
-
for (digits = 1, k = xd[0]; k >= 10; k /= 10)
|
|
1359
|
-
digits++;
|
|
1360
|
-
i = sd - digits;
|
|
1361
|
-
if (i < 0) {
|
|
1362
|
-
i += LOG_BASE;
|
|
1363
|
-
j = sd;
|
|
1364
|
-
w = xd[xdi = 0];
|
|
1365
|
-
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
1366
|
-
} else {
|
|
1367
|
-
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
1368
|
-
k = xd.length;
|
|
1369
|
-
if (xdi >= k) {
|
|
1370
|
-
if (isTruncated) {
|
|
1371
|
-
for (; k++ <= xdi; )
|
|
1372
|
-
xd.push(0);
|
|
1373
|
-
w = rd = 0;
|
|
1374
|
-
digits = 1;
|
|
1375
|
-
i %= LOG_BASE;
|
|
1376
|
-
j = i - LOG_BASE + 1;
|
|
1377
|
-
} else {
|
|
1378
|
-
break out;
|
|
1379
|
-
}
|
|
1380
|
-
} else {
|
|
1381
|
-
w = k = xd[xdi];
|
|
1382
|
-
for (digits = 1; k >= 10; k /= 10)
|
|
1383
|
-
digits++;
|
|
1384
|
-
i %= LOG_BASE;
|
|
1385
|
-
j = i - LOG_BASE + digits;
|
|
1386
|
-
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
1390
|
-
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.
|
|
1391
|
-
(i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
1392
|
-
if (sd < 1 || !xd[0]) {
|
|
1393
|
-
xd.length = 0;
|
|
1394
|
-
if (roundUp) {
|
|
1395
|
-
sd -= x.e + 1;
|
|
1396
|
-
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
1397
|
-
x.e = -sd || 0;
|
|
1398
|
-
} else {
|
|
1399
|
-
xd[0] = x.e = 0;
|
|
1400
|
-
}
|
|
1401
|
-
return x;
|
|
1402
|
-
}
|
|
1403
|
-
if (i == 0) {
|
|
1404
|
-
xd.length = xdi;
|
|
1405
|
-
k = 1;
|
|
1406
|
-
xdi--;
|
|
1407
|
-
} else {
|
|
1408
|
-
xd.length = xdi + 1;
|
|
1409
|
-
k = mathpow(10, LOG_BASE - i);
|
|
1410
|
-
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
1411
|
-
}
|
|
1412
|
-
if (roundUp) {
|
|
1413
|
-
for (; ; ) {
|
|
1414
|
-
if (xdi == 0) {
|
|
1415
|
-
for (i = 1, j = xd[0]; j >= 10; j /= 10)
|
|
1416
|
-
i++;
|
|
1417
|
-
j = xd[0] += k;
|
|
1418
|
-
for (k = 1; j >= 10; j /= 10)
|
|
1419
|
-
k++;
|
|
1420
|
-
if (i != k) {
|
|
1421
|
-
x.e++;
|
|
1422
|
-
if (xd[0] == BASE)
|
|
1423
|
-
xd[0] = 1;
|
|
1424
|
-
}
|
|
1425
|
-
break;
|
|
1426
|
-
} else {
|
|
1427
|
-
xd[xdi] += k;
|
|
1428
|
-
if (xd[xdi] != BASE)
|
|
1429
|
-
break;
|
|
1430
|
-
xd[xdi--] = 0;
|
|
1431
|
-
k = 1;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
for (i = xd.length; xd[--i] === 0; )
|
|
1436
|
-
xd.pop();
|
|
342
|
+
if (this._mantissa === 0n)
|
|
343
|
+
return new _BigDecimal(0);
|
|
344
|
+
const m = this._mantissa ** BigInt(n);
|
|
345
|
+
const e = this._exponent * n;
|
|
346
|
+
const [nm, ne] = removeTrailingZeros(m, e);
|
|
347
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
348
|
+
}
|
|
349
|
+
floor() {
|
|
350
|
+
if (this._special !== SpecialValue.NONE)
|
|
351
|
+
return this;
|
|
352
|
+
if (this._mantissa === 0n)
|
|
353
|
+
return this;
|
|
354
|
+
if (this._exponent >= 0)
|
|
355
|
+
return this;
|
|
356
|
+
const divisor = bigintPow10(-this._exponent);
|
|
357
|
+
const m = this._mantissa;
|
|
358
|
+
let q = m / divisor;
|
|
359
|
+
if (m < 0n && m % divisor !== 0n) {
|
|
360
|
+
q -= 1n;
|
|
1437
361
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
x.e = NaN;
|
|
1442
|
-
} else if (x.e < Ctor.minE) {
|
|
1443
|
-
x.e = 0;
|
|
1444
|
-
x.d = [0];
|
|
362
|
+
if (q === 0n) {
|
|
363
|
+
const negZero = this._mantissa < 0n;
|
|
364
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
1445
365
|
}
|
|
366
|
+
const [nm, ne] = removeTrailingZeros(q, 0);
|
|
367
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
1446
368
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
369
|
+
ceil() {
|
|
370
|
+
if (this._special !== SpecialValue.NONE)
|
|
371
|
+
return this;
|
|
372
|
+
if (this._mantissa === 0n)
|
|
373
|
+
return this;
|
|
374
|
+
if (this._exponent >= 0)
|
|
375
|
+
return this;
|
|
376
|
+
const divisor = bigintPow10(-this._exponent);
|
|
377
|
+
const m = this._mantissa;
|
|
378
|
+
let q = m / divisor;
|
|
379
|
+
if (m > 0n && m % divisor !== 0n) {
|
|
380
|
+
q += 1n;
|
|
1458
381
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
str = "0." + getZeroString(-e - 1) + str;
|
|
1462
|
-
if (sd && (k = sd - len) > 0)
|
|
1463
|
-
str += getZeroString(k);
|
|
1464
|
-
} else if (e >= len) {
|
|
1465
|
-
str += getZeroString(e + 1 - len);
|
|
1466
|
-
if (sd && (k = sd - e - 1) > 0)
|
|
1467
|
-
str = str + "." + getZeroString(k);
|
|
1468
|
-
} else {
|
|
1469
|
-
if ((k = e + 1) < len)
|
|
1470
|
-
str = str.slice(0, k) + "." + str.slice(k);
|
|
1471
|
-
if (sd && (k = sd - len) > 0) {
|
|
1472
|
-
if (e + 1 === len)
|
|
1473
|
-
str += ".";
|
|
1474
|
-
str += getZeroString(k);
|
|
382
|
+
if (q === 0n) {
|
|
383
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
|
|
1475
384
|
}
|
|
385
|
+
const [nm, ne] = removeTrailingZeros(q, 0);
|
|
386
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
1476
387
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
e++;
|
|
1483
|
-
return e;
|
|
1484
|
-
}
|
|
1485
|
-
function getLn10(Ctor, sd, pr) {
|
|
1486
|
-
if (sd > LN10_PRECISION) {
|
|
1487
|
-
external = true;
|
|
1488
|
-
if (pr)
|
|
1489
|
-
Ctor.precision = pr;
|
|
1490
|
-
throw Error(precisionLimitExceeded);
|
|
1491
|
-
}
|
|
1492
|
-
return finalise(new Ctor(LN10), sd, 1, true);
|
|
1493
|
-
}
|
|
1494
|
-
function getPi(Ctor, sd, rm) {
|
|
1495
|
-
if (sd > PI_PRECISION)
|
|
1496
|
-
throw Error(precisionLimitExceeded);
|
|
1497
|
-
return finalise(new Ctor(PI), sd, rm, true);
|
|
1498
|
-
}
|
|
1499
|
-
function getPrecision(digits) {
|
|
1500
|
-
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
1501
|
-
w = digits[w];
|
|
1502
|
-
if (w) {
|
|
1503
|
-
for (; w % 10 == 0; w /= 10)
|
|
1504
|
-
len--;
|
|
1505
|
-
for (w = digits[0]; w >= 10; w /= 10)
|
|
1506
|
-
len++;
|
|
1507
|
-
}
|
|
1508
|
-
return len;
|
|
1509
|
-
}
|
|
1510
|
-
function getZeroString(k) {
|
|
1511
|
-
var zs = "";
|
|
1512
|
-
for (; k--; )
|
|
1513
|
-
zs += "0";
|
|
1514
|
-
return zs;
|
|
1515
|
-
}
|
|
1516
|
-
function intPow(Ctor, x, n, pr) {
|
|
1517
|
-
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
1518
|
-
external = false;
|
|
1519
|
-
for (; ; ) {
|
|
1520
|
-
if (n % 2) {
|
|
1521
|
-
r = r.times(x);
|
|
1522
|
-
if (truncate(r.d, k))
|
|
1523
|
-
isTruncated = true;
|
|
388
|
+
log(base) {
|
|
389
|
+
if (this._special === SpecialValue.NAN)
|
|
390
|
+
return this;
|
|
391
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
392
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1524
393
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
n = r.d.length - 1;
|
|
1528
|
-
if (isTruncated && r.d[n] === 0)
|
|
1529
|
-
++r.d[n];
|
|
1530
|
-
break;
|
|
394
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY) {
|
|
395
|
+
return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
|
|
1531
396
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
}
|
|
1535
|
-
external = true;
|
|
1536
|
-
return r;
|
|
1537
|
-
}
|
|
1538
|
-
function isOdd(n) {
|
|
1539
|
-
return n.d[n.d.length - 1] & 1;
|
|
1540
|
-
}
|
|
1541
|
-
function maxOrMin(Ctor, args, n) {
|
|
1542
|
-
var k, y, x = new Ctor(args[0]), i = 0;
|
|
1543
|
-
for (; ++i < args.length; ) {
|
|
1544
|
-
y = new Ctor(args[i]);
|
|
1545
|
-
if (!y.s) {
|
|
1546
|
-
x = y;
|
|
1547
|
-
break;
|
|
397
|
+
if (this._mantissa < 0n) {
|
|
398
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1548
399
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
x = y;
|
|
400
|
+
if (this._mantissa === 0n) {
|
|
401
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false);
|
|
1552
402
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
}
|
|
1556
|
-
function naturalExponential(x, sd) {
|
|
1557
|
-
var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
1558
|
-
if (!x.d || !x.d[0] || x.e > 17) {
|
|
1559
|
-
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
|
1560
|
-
}
|
|
1561
|
-
if (sd == null) {
|
|
1562
|
-
external = false;
|
|
1563
|
-
wpr = pr;
|
|
1564
|
-
} else {
|
|
1565
|
-
wpr = sd;
|
|
1566
|
-
}
|
|
1567
|
-
t = new Ctor(0.03125);
|
|
1568
|
-
while (x.e > -2) {
|
|
1569
|
-
x = x.times(t);
|
|
1570
|
-
k += 5;
|
|
1571
|
-
}
|
|
1572
|
-
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
1573
|
-
wpr += guard;
|
|
1574
|
-
denominator = pow2 = sum2 = new Ctor(1);
|
|
1575
|
-
Ctor.precision = wpr;
|
|
1576
|
-
for (; ; ) {
|
|
1577
|
-
pow2 = finalise(pow2.times(x), wpr, 1);
|
|
1578
|
-
denominator = denominator.times(++i);
|
|
1579
|
-
t = sum2.plus(divide(pow2, denominator, wpr, 1));
|
|
1580
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1581
|
-
j = k;
|
|
1582
|
-
while (j--)
|
|
1583
|
-
sum2 = finalise(sum2.times(sum2), wpr, 1);
|
|
1584
|
-
if (sd == null) {
|
|
1585
|
-
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1586
|
-
Ctor.precision = wpr += 10;
|
|
1587
|
-
denominator = pow2 = t = new Ctor(1);
|
|
1588
|
-
i = 0;
|
|
1589
|
-
rep++;
|
|
1590
|
-
} else {
|
|
1591
|
-
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
1592
|
-
}
|
|
1593
|
-
} else {
|
|
1594
|
-
Ctor.precision = pr;
|
|
1595
|
-
return sum2;
|
|
1596
|
-
}
|
|
403
|
+
if (base === 10) {
|
|
404
|
+
return this._log10();
|
|
1597
405
|
}
|
|
1598
|
-
|
|
406
|
+
const log10x = this._log10();
|
|
407
|
+
const log10b = new _BigDecimal(Math.log10(base));
|
|
408
|
+
return log10x.div(log10b);
|
|
1599
409
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
410
|
+
_log10() {
|
|
411
|
+
const absMantissa = bigintAbs(this._mantissa);
|
|
412
|
+
const digits = digitCount(absMantissa);
|
|
413
|
+
let log10Mantissa;
|
|
414
|
+
if (digits <= 15) {
|
|
415
|
+
log10Mantissa = Math.log10(Number(absMantissa));
|
|
416
|
+
} else {
|
|
417
|
+
const shift = digits - 17;
|
|
418
|
+
const leading = absMantissa / bigintPow10(shift);
|
|
419
|
+
log10Mantissa = Math.log10(Number(leading)) + shift;
|
|
420
|
+
}
|
|
421
|
+
const totalLog10 = log10Mantissa + this._exponent;
|
|
422
|
+
return new _BigDecimal(totalLog10);
|
|
1605
423
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
424
|
+
// --- Comparison ---
|
|
425
|
+
eq(y) {
|
|
426
|
+
const other = _BigDecimal._coerce(y);
|
|
427
|
+
if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN)
|
|
428
|
+
return false;
|
|
429
|
+
if (this._special !== other._special)
|
|
430
|
+
return false;
|
|
431
|
+
if (this._special !== SpecialValue.NONE)
|
|
432
|
+
return true;
|
|
433
|
+
if (this._mantissa === 0n && other._mantissa === 0n)
|
|
434
|
+
return true;
|
|
435
|
+
return this._mantissa === other._mantissa && this._exponent === other._exponent;
|
|
1611
436
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
if (Math.abs(e = x.e) < 15e14) {
|
|
1616
|
-
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
1617
|
-
x = x.times(y);
|
|
1618
|
-
c = digitsToString(x.d);
|
|
1619
|
-
c0 = c.charAt(0);
|
|
1620
|
-
n++;
|
|
437
|
+
_compareTo(other) {
|
|
438
|
+
if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN) {
|
|
439
|
+
return NaN;
|
|
1621
440
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
x = new Ctor("0." + c);
|
|
1625
|
-
e++;
|
|
1626
|
-
} else {
|
|
1627
|
-
x = new Ctor(c0 + "." + c.slice(1));
|
|
441
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY) {
|
|
442
|
+
return other._special === SpecialValue.POSITIVE_INFINITY ? 0 : 1;
|
|
1628
443
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
1632
|
-
Ctor.precision = pr;
|
|
1633
|
-
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
|
1634
|
-
}
|
|
1635
|
-
x1 = x;
|
|
1636
|
-
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
1637
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
1638
|
-
denominator = 3;
|
|
1639
|
-
for (; ; ) {
|
|
1640
|
-
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
1641
|
-
t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
1642
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1643
|
-
sum2 = sum2.times(2);
|
|
1644
|
-
if (e !== 0)
|
|
1645
|
-
sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
1646
|
-
sum2 = divide(sum2, new Ctor(n), wpr, 1);
|
|
1647
|
-
if (sd == null) {
|
|
1648
|
-
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1649
|
-
Ctor.precision = wpr += guard;
|
|
1650
|
-
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
1651
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
1652
|
-
denominator = rep = 1;
|
|
1653
|
-
} else {
|
|
1654
|
-
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
1655
|
-
}
|
|
1656
|
-
} else {
|
|
1657
|
-
Ctor.precision = pr;
|
|
1658
|
-
return sum2;
|
|
1659
|
-
}
|
|
444
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
445
|
+
return other._special === SpecialValue.NEGATIVE_INFINITY ? 0 : -1;
|
|
1660
446
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
447
|
+
if (other._special === SpecialValue.POSITIVE_INFINITY)
|
|
448
|
+
return -1;
|
|
449
|
+
if (other._special === SpecialValue.NEGATIVE_INFINITY)
|
|
450
|
+
return 1;
|
|
451
|
+
const thisZero = this._mantissa === 0n;
|
|
452
|
+
const otherZero = other._mantissa === 0n;
|
|
453
|
+
if (thisZero && otherZero)
|
|
454
|
+
return 0;
|
|
455
|
+
if (thisZero)
|
|
456
|
+
return other._mantissa > 0n ? -1 : 1;
|
|
457
|
+
if (otherZero)
|
|
458
|
+
return this._mantissa > 0n ? 1 : -1;
|
|
459
|
+
const thisNeg = this._mantissa < 0n;
|
|
460
|
+
const otherNeg = other._mantissa < 0n;
|
|
461
|
+
if (thisNeg !== otherNeg)
|
|
462
|
+
return thisNeg ? -1 : 1;
|
|
463
|
+
let m1 = this._mantissa;
|
|
464
|
+
let m2 = other._mantissa;
|
|
465
|
+
const e1 = this._exponent;
|
|
466
|
+
const e2 = other._exponent;
|
|
467
|
+
const minE = Math.min(e1, e2);
|
|
468
|
+
if (e1 > minE)
|
|
469
|
+
m1 *= bigintPow10(e1 - minE);
|
|
470
|
+
if (e2 > minE)
|
|
471
|
+
m2 *= bigintPow10(e2 - minE);
|
|
472
|
+
if (m1 < m2)
|
|
473
|
+
return -1;
|
|
474
|
+
if (m1 > m2)
|
|
475
|
+
return 1;
|
|
476
|
+
return 0;
|
|
1663
477
|
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
}
|
|
1668
|
-
function parseDecimal(x, str) {
|
|
1669
|
-
var e, i, len;
|
|
1670
|
-
if ((e = str.indexOf(".")) > -1)
|
|
1671
|
-
str = str.replace(".", "");
|
|
1672
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
1673
|
-
if (e < 0)
|
|
1674
|
-
e = i;
|
|
1675
|
-
e += +str.slice(i + 1);
|
|
1676
|
-
str = str.substring(0, i);
|
|
1677
|
-
} else if (e < 0) {
|
|
1678
|
-
e = str.length;
|
|
478
|
+
lessThan(y) {
|
|
479
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
480
|
+
return c === -1;
|
|
1679
481
|
}
|
|
1680
|
-
|
|
1681
|
-
;
|
|
1682
|
-
|
|
1683
|
-
;
|
|
1684
|
-
str = str.slice(i, len);
|
|
1685
|
-
if (str) {
|
|
1686
|
-
len -= i;
|
|
1687
|
-
x.e = e = e - i - 1;
|
|
1688
|
-
x.d = [];
|
|
1689
|
-
i = (e + 1) % LOG_BASE;
|
|
1690
|
-
if (e < 0)
|
|
1691
|
-
i += LOG_BASE;
|
|
1692
|
-
if (i < len) {
|
|
1693
|
-
if (i)
|
|
1694
|
-
x.d.push(+str.slice(0, i));
|
|
1695
|
-
for (len -= LOG_BASE; i < len; )
|
|
1696
|
-
x.d.push(+str.slice(i, i += LOG_BASE));
|
|
1697
|
-
str = str.slice(i);
|
|
1698
|
-
i = LOG_BASE - str.length;
|
|
1699
|
-
} else {
|
|
1700
|
-
i -= len;
|
|
1701
|
-
}
|
|
1702
|
-
for (; i--; )
|
|
1703
|
-
str += "0";
|
|
1704
|
-
x.d.push(+str);
|
|
1705
|
-
if (external) {
|
|
1706
|
-
if (x.e > x.constructor.maxE) {
|
|
1707
|
-
x.d = null;
|
|
1708
|
-
x.e = NaN;
|
|
1709
|
-
} else if (x.e < x.constructor.minE) {
|
|
1710
|
-
x.e = 0;
|
|
1711
|
-
x.d = [0];
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
} else {
|
|
1715
|
-
x.e = 0;
|
|
1716
|
-
x.d = [0];
|
|
482
|
+
greaterThan(y) {
|
|
483
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
484
|
+
return c === 1;
|
|
1717
485
|
}
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
1722
|
-
if (str.indexOf("_") > -1) {
|
|
1723
|
-
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
1724
|
-
if (isDecimal.test(str))
|
|
1725
|
-
return parseDecimal(x, str);
|
|
1726
|
-
} else if (str === "Infinity" || str === "NaN") {
|
|
1727
|
-
if (!+str)
|
|
1728
|
-
x.s = NaN;
|
|
1729
|
-
x.e = NaN;
|
|
1730
|
-
x.d = null;
|
|
1731
|
-
return x;
|
|
486
|
+
lessThanOrEqualTo(y) {
|
|
487
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
488
|
+
return c === 0 || c === -1;
|
|
1732
489
|
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
} else if (isBinary.test(str)) {
|
|
1737
|
-
base = 2;
|
|
1738
|
-
} else if (isOctal.test(str)) {
|
|
1739
|
-
base = 8;
|
|
1740
|
-
} else {
|
|
1741
|
-
throw Error(invalidArgument + str);
|
|
490
|
+
greaterThanOrEqualTo(y) {
|
|
491
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
492
|
+
return c === 0 || c === 1;
|
|
1742
493
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
str = str.substring(2, i);
|
|
1747
|
-
} else {
|
|
1748
|
-
str = str.slice(2);
|
|
494
|
+
// --- Queries ---
|
|
495
|
+
isZero() {
|
|
496
|
+
return this._special === SpecialValue.NONE && this._mantissa === 0n;
|
|
1749
497
|
}
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
Ctor = x.constructor;
|
|
1753
|
-
if (isFloat) {
|
|
1754
|
-
str = str.replace(".", "");
|
|
1755
|
-
len = str.length;
|
|
1756
|
-
i = len - i;
|
|
1757
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
498
|
+
isNaN() {
|
|
499
|
+
return this._special === SpecialValue.NAN;
|
|
1758
500
|
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
for (i = xe; xd[i] === 0; --i)
|
|
1762
|
-
xd.pop();
|
|
1763
|
-
if (i < 0)
|
|
1764
|
-
return new Ctor(x.s * 0);
|
|
1765
|
-
x.e = getBase10Exponent(xd, xe);
|
|
1766
|
-
x.d = xd;
|
|
1767
|
-
external = false;
|
|
1768
|
-
if (isFloat)
|
|
1769
|
-
x = divide(x, divisor, len * 4);
|
|
1770
|
-
if (p)
|
|
1771
|
-
x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
1772
|
-
external = true;
|
|
1773
|
-
return x;
|
|
1774
|
-
}
|
|
1775
|
-
function sine(Ctor, x) {
|
|
1776
|
-
var k, len = x.d.length;
|
|
1777
|
-
if (len < 3) {
|
|
1778
|
-
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
501
|
+
isFinite() {
|
|
502
|
+
return this._special === SpecialValue.NONE;
|
|
1779
503
|
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
504
|
+
isNegative() {
|
|
505
|
+
if (this._special === SpecialValue.NAN)
|
|
506
|
+
return false;
|
|
507
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
508
|
+
return true;
|
|
509
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
510
|
+
return false;
|
|
511
|
+
if (this._mantissa === 0n)
|
|
512
|
+
return this._negativeZero;
|
|
513
|
+
return this._mantissa < 0n;
|
|
1788
514
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
1800
|
-
t = u.plus(y);
|
|
1801
|
-
if (t.d[k] !== void 0) {
|
|
1802
|
-
for (j = k; t.d[j] === u.d[j] && j--; )
|
|
1803
|
-
;
|
|
1804
|
-
if (j == -1)
|
|
1805
|
-
break;
|
|
1806
|
-
}
|
|
1807
|
-
j = u;
|
|
1808
|
-
u = y;
|
|
1809
|
-
y = t;
|
|
1810
|
-
t = j;
|
|
1811
|
-
i++;
|
|
515
|
+
isPositive() {
|
|
516
|
+
if (this._special === SpecialValue.NAN)
|
|
517
|
+
return false;
|
|
518
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
519
|
+
return true;
|
|
520
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
521
|
+
return false;
|
|
522
|
+
if (this._mantissa === 0n)
|
|
523
|
+
return !this._negativeZero;
|
|
524
|
+
return this._mantissa > 0n;
|
|
1812
525
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
while (--e)
|
|
1820
|
-
n *= b;
|
|
1821
|
-
return n;
|
|
1822
|
-
}
|
|
1823
|
-
function toLessThanHalfPi(Ctor, x) {
|
|
1824
|
-
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
1825
|
-
x = x.abs();
|
|
1826
|
-
if (x.lte(halfPi)) {
|
|
1827
|
-
quadrant = isNeg ? 4 : 1;
|
|
1828
|
-
return x;
|
|
526
|
+
isInteger() {
|
|
527
|
+
if (this._special !== SpecialValue.NONE)
|
|
528
|
+
return false;
|
|
529
|
+
if (this._mantissa === 0n)
|
|
530
|
+
return true;
|
|
531
|
+
return this._exponent >= 0;
|
|
1829
532
|
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
} else {
|
|
1834
|
-
x = x.minus(t.times(pi));
|
|
1835
|
-
if (x.lte(halfPi)) {
|
|
1836
|
-
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
1837
|
-
return x;
|
|
1838
|
-
}
|
|
1839
|
-
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
533
|
+
// --- Conversion ---
|
|
534
|
+
toJSON() {
|
|
535
|
+
return this.toString();
|
|
1840
536
|
}
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
} else {
|
|
1852
|
-
sd = Ctor.precision;
|
|
1853
|
-
rm = Ctor.rounding;
|
|
537
|
+
toNumber() {
|
|
538
|
+
if (this._special === SpecialValue.NAN)
|
|
539
|
+
return NaN;
|
|
540
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
541
|
+
return Infinity;
|
|
542
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
543
|
+
return -Infinity;
|
|
544
|
+
if (this._mantissa === 0n)
|
|
545
|
+
return this._negativeZero ? -0 : 0;
|
|
546
|
+
return Number(this.toString());
|
|
1854
547
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
if (
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
548
|
+
toString() {
|
|
549
|
+
if (this._special === SpecialValue.NAN)
|
|
550
|
+
return "NaN";
|
|
551
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
552
|
+
return "Infinity";
|
|
553
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
554
|
+
return "-Infinity";
|
|
555
|
+
if (this._mantissa === 0n)
|
|
556
|
+
return "0";
|
|
557
|
+
const negative = this._mantissa < 0n;
|
|
558
|
+
const absStr = bigintAbs(this._mantissa).toString();
|
|
559
|
+
const prefix = negative ? "-" : "";
|
|
560
|
+
if (this._exponent === 0) {
|
|
561
|
+
return prefix + absStr;
|
|
1869
562
|
}
|
|
1870
|
-
if (
|
|
1871
|
-
|
|
1872
|
-
y = new Ctor(1);
|
|
1873
|
-
y.e = str.length - i;
|
|
1874
|
-
y.d = convertBase(finiteToString(y), 10, base);
|
|
1875
|
-
y.e = y.d.length;
|
|
563
|
+
if (this._exponent > 0) {
|
|
564
|
+
return prefix + absStr + "0".repeat(this._exponent);
|
|
1876
565
|
}
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
str = isExp ? "0p+0" : "0";
|
|
566
|
+
const decimalPlaces = -this._exponent;
|
|
567
|
+
if (decimalPlaces < absStr.length) {
|
|
568
|
+
const intPart = absStr.slice(0, absStr.length - decimalPlaces);
|
|
569
|
+
const fracPart = absStr.slice(absStr.length - decimalPlaces);
|
|
570
|
+
return prefix + intPart + "." + fracPart;
|
|
1883
571
|
} else {
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
} else {
|
|
1887
|
-
x = new Ctor(x);
|
|
1888
|
-
x.d = xd;
|
|
1889
|
-
x.e = e;
|
|
1890
|
-
x = divide(x, y, sd, rm, 0, base);
|
|
1891
|
-
xd = x.d;
|
|
1892
|
-
e = x.e;
|
|
1893
|
-
roundUp = inexact;
|
|
1894
|
-
}
|
|
1895
|
-
i = xd[sd];
|
|
1896
|
-
k = base / 2;
|
|
1897
|
-
roundUp = roundUp || xd[sd + 1] !== void 0;
|
|
1898
|
-
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));
|
|
1899
|
-
xd.length = sd;
|
|
1900
|
-
if (roundUp) {
|
|
1901
|
-
for (; ++xd[--sd] > base - 1; ) {
|
|
1902
|
-
xd[sd] = 0;
|
|
1903
|
-
if (!sd) {
|
|
1904
|
-
++e;
|
|
1905
|
-
xd.unshift(1);
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
for (len = xd.length; !xd[len - 1]; --len)
|
|
1910
|
-
;
|
|
1911
|
-
for (i = 0, str = ""; i < len; i++)
|
|
1912
|
-
str += NUMERALS.charAt(xd[i]);
|
|
1913
|
-
if (isExp) {
|
|
1914
|
-
if (len > 1) {
|
|
1915
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
1916
|
-
i = baseOut == 16 ? 4 : 3;
|
|
1917
|
-
for (--len; len % i; len++)
|
|
1918
|
-
str += "0";
|
|
1919
|
-
xd = convertBase(str, base, baseOut);
|
|
1920
|
-
for (len = xd.length; !xd[len - 1]; --len)
|
|
1921
|
-
;
|
|
1922
|
-
for (i = 1, str = "1."; i < len; i++)
|
|
1923
|
-
str += NUMERALS.charAt(xd[i]);
|
|
1924
|
-
} else {
|
|
1925
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
str = str + (e < 0 ? "p" : "p+") + e;
|
|
1929
|
-
} else if (e < 0) {
|
|
1930
|
-
for (; ++e; )
|
|
1931
|
-
str = "0" + str;
|
|
1932
|
-
str = "0." + str;
|
|
1933
|
-
} else {
|
|
1934
|
-
if (++e > len)
|
|
1935
|
-
for (e -= len; e--; )
|
|
1936
|
-
str += "0";
|
|
1937
|
-
else if (e < len)
|
|
1938
|
-
str = str.slice(0, e) + "." + str.slice(e);
|
|
1939
|
-
}
|
|
572
|
+
const leadingZeros = decimalPlaces - absStr.length;
|
|
573
|
+
return prefix + "0." + "0".repeat(leadingZeros) + absStr;
|
|
1940
574
|
}
|
|
1941
|
-
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
1942
575
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
return true;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
function abs(x) {
|
|
1952
|
-
return new this(x).abs();
|
|
1953
|
-
}
|
|
1954
|
-
function acos(x) {
|
|
1955
|
-
return new this(x).acos();
|
|
1956
|
-
}
|
|
1957
|
-
function acosh(x) {
|
|
1958
|
-
return new this(x).acosh();
|
|
1959
|
-
}
|
|
1960
|
-
function add(x, y) {
|
|
1961
|
-
return new this(x).plus(y);
|
|
1962
|
-
}
|
|
1963
|
-
function asin(x) {
|
|
1964
|
-
return new this(x).asin();
|
|
1965
|
-
}
|
|
1966
|
-
function asinh(x) {
|
|
1967
|
-
return new this(x).asinh();
|
|
1968
|
-
}
|
|
1969
|
-
function atan(x) {
|
|
1970
|
-
return new this(x).atan();
|
|
1971
|
-
}
|
|
1972
|
-
function atanh(x) {
|
|
1973
|
-
return new this(x).atanh();
|
|
1974
|
-
}
|
|
1975
|
-
function atan2(y, x) {
|
|
1976
|
-
y = new this(y);
|
|
1977
|
-
x = new this(x);
|
|
1978
|
-
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
1979
|
-
if (!y.s || !x.s) {
|
|
1980
|
-
r = new this(NaN);
|
|
1981
|
-
} else if (!y.d && !x.d) {
|
|
1982
|
-
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
|
1983
|
-
r.s = y.s;
|
|
1984
|
-
} else if (!x.d || y.isZero()) {
|
|
1985
|
-
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
1986
|
-
r.s = y.s;
|
|
1987
|
-
} else if (!y.d || x.isZero()) {
|
|
1988
|
-
r = getPi(this, wpr, 1).times(0.5);
|
|
1989
|
-
r.s = y.s;
|
|
1990
|
-
} else if (x.s < 0) {
|
|
1991
|
-
this.precision = wpr;
|
|
1992
|
-
this.rounding = 1;
|
|
1993
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
1994
|
-
x = getPi(this, wpr, 1);
|
|
1995
|
-
this.precision = pr;
|
|
1996
|
-
this.rounding = rm;
|
|
1997
|
-
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
1998
|
-
} else {
|
|
1999
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
2000
|
-
}
|
|
2001
|
-
return r;
|
|
2002
|
-
}
|
|
2003
|
-
function cbrt(x) {
|
|
2004
|
-
return new this(x).cbrt();
|
|
2005
|
-
}
|
|
2006
|
-
function ceil(x) {
|
|
2007
|
-
return finalise(x = new this(x), x.e + 1, 2);
|
|
2008
|
-
}
|
|
2009
|
-
function clamp(x, min2, max2) {
|
|
2010
|
-
return new this(x).clamp(min2, max2);
|
|
2011
|
-
}
|
|
2012
|
-
function config(obj) {
|
|
2013
|
-
if (!obj || typeof obj !== "object")
|
|
2014
|
-
throw Error(decimalError + "Object expected");
|
|
2015
|
-
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
2016
|
-
"precision",
|
|
2017
|
-
1,
|
|
2018
|
-
MAX_DIGITS,
|
|
2019
|
-
"rounding",
|
|
2020
|
-
0,
|
|
2021
|
-
8,
|
|
2022
|
-
"toExpNeg",
|
|
2023
|
-
-EXP_LIMIT,
|
|
2024
|
-
0,
|
|
2025
|
-
"toExpPos",
|
|
2026
|
-
0,
|
|
2027
|
-
EXP_LIMIT,
|
|
2028
|
-
"maxE",
|
|
2029
|
-
0,
|
|
2030
|
-
EXP_LIMIT,
|
|
2031
|
-
"minE",
|
|
2032
|
-
-EXP_LIMIT,
|
|
2033
|
-
0,
|
|
2034
|
-
"modulo",
|
|
2035
|
-
0,
|
|
2036
|
-
9
|
|
2037
|
-
];
|
|
2038
|
-
for (i = 0; i < ps.length; i += 3) {
|
|
2039
|
-
if (p = ps[i], useDefaults)
|
|
2040
|
-
this[p] = DEFAULTS[p];
|
|
2041
|
-
if ((v = obj[p]) !== void 0) {
|
|
2042
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
|
|
2043
|
-
this[p] = v;
|
|
2044
|
-
else
|
|
2045
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
576
|
+
// --- Static ---
|
|
577
|
+
static pow(base, exp) {
|
|
578
|
+
const n = typeof exp === "number" ? exp : exp.toNumber();
|
|
579
|
+
if (typeof base === "number" && base === 10) {
|
|
580
|
+
return _BigDecimal._create(1n, n, SpecialValue.NONE, false);
|
|
2046
581
|
}
|
|
582
|
+
const bd = base instanceof _BigDecimal ? base : new _BigDecimal(base);
|
|
583
|
+
return bd.pow(n);
|
|
2047
584
|
}
|
|
2048
|
-
|
|
2049
|
-
this[p] = DEFAULTS[p];
|
|
2050
|
-
if ((v = obj[p]) !== void 0) {
|
|
2051
|
-
if (v === true || v === false || v === 0 || v === 1) {
|
|
2052
|
-
if (v) {
|
|
2053
|
-
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
2054
|
-
this[p] = true;
|
|
2055
|
-
} else {
|
|
2056
|
-
throw Error(cryptoUnavailable);
|
|
2057
|
-
}
|
|
2058
|
-
} else {
|
|
2059
|
-
this[p] = false;
|
|
2060
|
-
}
|
|
2061
|
-
} else {
|
|
2062
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
2063
|
-
}
|
|
585
|
+
static set(_config) {
|
|
2064
586
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
if (isDecimalInstance(v)) {
|
|
2081
|
-
x.s = v.s;
|
|
2082
|
-
if (external) {
|
|
2083
|
-
if (!v.d || v.e > Decimal2.maxE) {
|
|
2084
|
-
x.e = NaN;
|
|
2085
|
-
x.d = null;
|
|
2086
|
-
} else if (v.e < Decimal2.minE) {
|
|
2087
|
-
x.e = 0;
|
|
2088
|
-
x.d = [0];
|
|
2089
|
-
} else {
|
|
2090
|
-
x.e = v.e;
|
|
2091
|
-
x.d = v.d.slice();
|
|
2092
|
-
}
|
|
2093
|
-
} else {
|
|
2094
|
-
x.e = v.e;
|
|
2095
|
-
x.d = v.d ? v.d.slice() : v.d;
|
|
2096
|
-
}
|
|
2097
|
-
return;
|
|
587
|
+
// --- Internal helpers ---
|
|
588
|
+
_isSignNegative() {
|
|
589
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
590
|
+
return true;
|
|
591
|
+
if (this._mantissa < 0n)
|
|
592
|
+
return true;
|
|
593
|
+
if (this._mantissa === 0n)
|
|
594
|
+
return this._negativeZero;
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
_specialArith(other, op) {
|
|
598
|
+
const a = this._special;
|
|
599
|
+
const b = other._special;
|
|
600
|
+
if (a === SpecialValue.NAN || b === SpecialValue.NAN) {
|
|
601
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2098
602
|
}
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
if (v < 0) {
|
|
2108
|
-
v = -v;
|
|
2109
|
-
x.s = -1;
|
|
2110
|
-
} else {
|
|
2111
|
-
x.s = 1;
|
|
2112
|
-
}
|
|
2113
|
-
if (v === ~~v && v < 1e7) {
|
|
2114
|
-
for (e = 0, i2 = v; i2 >= 10; i2 /= 10)
|
|
2115
|
-
e++;
|
|
2116
|
-
if (external) {
|
|
2117
|
-
if (e > Decimal2.maxE) {
|
|
2118
|
-
x.e = NaN;
|
|
2119
|
-
x.d = null;
|
|
2120
|
-
} else if (e < Decimal2.minE) {
|
|
2121
|
-
x.e = 0;
|
|
2122
|
-
x.d = [0];
|
|
2123
|
-
} else {
|
|
2124
|
-
x.e = e;
|
|
2125
|
-
x.d = [v];
|
|
2126
|
-
}
|
|
2127
|
-
} else {
|
|
2128
|
-
x.e = e;
|
|
2129
|
-
x.d = [v];
|
|
603
|
+
const aNeg = this._isSignNegative();
|
|
604
|
+
const bNeg = other._isSignNegative();
|
|
605
|
+
const aInf = a === SpecialValue.POSITIVE_INFINITY || a === SpecialValue.NEGATIVE_INFINITY;
|
|
606
|
+
const bInf = b === SpecialValue.POSITIVE_INFINITY || b === SpecialValue.NEGATIVE_INFINITY;
|
|
607
|
+
if (op === "times") {
|
|
608
|
+
if (aInf || bInf) {
|
|
609
|
+
if (aInf && other._mantissa === 0n && !bInf || bInf && this._mantissa === 0n && !aInf) {
|
|
610
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2130
611
|
}
|
|
2131
|
-
|
|
612
|
+
const neg = aNeg !== bNeg;
|
|
613
|
+
return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
|
|
2132
614
|
}
|
|
2133
|
-
if (v * 0 !== 0) {
|
|
2134
|
-
if (!v)
|
|
2135
|
-
x.s = NaN;
|
|
2136
|
-
x.e = NaN;
|
|
2137
|
-
x.d = null;
|
|
2138
|
-
return;
|
|
2139
|
-
}
|
|
2140
|
-
return parseDecimal(x, v.toString());
|
|
2141
615
|
}
|
|
2142
|
-
if (
|
|
2143
|
-
if (
|
|
2144
|
-
|
|
2145
|
-
x.s = -1;
|
|
2146
|
-
} else {
|
|
2147
|
-
if (i2 === 43)
|
|
2148
|
-
v = v.slice(1);
|
|
2149
|
-
x.s = 1;
|
|
616
|
+
if (op === "div") {
|
|
617
|
+
if (aInf && bInf) {
|
|
618
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2150
619
|
}
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
if (v < 0) {
|
|
2155
|
-
v = -v;
|
|
2156
|
-
x.s = -1;
|
|
2157
|
-
} else {
|
|
2158
|
-
x.s = 1;
|
|
620
|
+
if (aInf) {
|
|
621
|
+
const neg = aNeg !== bNeg;
|
|
622
|
+
return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
|
|
2159
623
|
}
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
}
|
|
2164
|
-
Decimal2.prototype = P;
|
|
2165
|
-
Decimal2.ROUND_UP = 0;
|
|
2166
|
-
Decimal2.ROUND_DOWN = 1;
|
|
2167
|
-
Decimal2.ROUND_CEIL = 2;
|
|
2168
|
-
Decimal2.ROUND_FLOOR = 3;
|
|
2169
|
-
Decimal2.ROUND_HALF_UP = 4;
|
|
2170
|
-
Decimal2.ROUND_HALF_DOWN = 5;
|
|
2171
|
-
Decimal2.ROUND_HALF_EVEN = 6;
|
|
2172
|
-
Decimal2.ROUND_HALF_CEIL = 7;
|
|
2173
|
-
Decimal2.ROUND_HALF_FLOOR = 8;
|
|
2174
|
-
Decimal2.EUCLID = 9;
|
|
2175
|
-
Decimal2.config = Decimal2.set = config;
|
|
2176
|
-
Decimal2.clone = clone;
|
|
2177
|
-
Decimal2.isDecimal = isDecimalInstance;
|
|
2178
|
-
Decimal2.abs = abs;
|
|
2179
|
-
Decimal2.acos = acos;
|
|
2180
|
-
Decimal2.acosh = acosh;
|
|
2181
|
-
Decimal2.add = add;
|
|
2182
|
-
Decimal2.asin = asin;
|
|
2183
|
-
Decimal2.asinh = asinh;
|
|
2184
|
-
Decimal2.atan = atan;
|
|
2185
|
-
Decimal2.atanh = atanh;
|
|
2186
|
-
Decimal2.atan2 = atan2;
|
|
2187
|
-
Decimal2.cbrt = cbrt;
|
|
2188
|
-
Decimal2.ceil = ceil;
|
|
2189
|
-
Decimal2.clamp = clamp;
|
|
2190
|
-
Decimal2.cos = cos;
|
|
2191
|
-
Decimal2.cosh = cosh;
|
|
2192
|
-
Decimal2.div = div;
|
|
2193
|
-
Decimal2.exp = exp;
|
|
2194
|
-
Decimal2.floor = floor;
|
|
2195
|
-
Decimal2.hypot = hypot;
|
|
2196
|
-
Decimal2.ln = ln;
|
|
2197
|
-
Decimal2.log = log;
|
|
2198
|
-
Decimal2.log10 = log10;
|
|
2199
|
-
Decimal2.log2 = log2;
|
|
2200
|
-
Decimal2.max = max;
|
|
2201
|
-
Decimal2.min = min;
|
|
2202
|
-
Decimal2.mod = mod;
|
|
2203
|
-
Decimal2.mul = mul;
|
|
2204
|
-
Decimal2.pow = pow;
|
|
2205
|
-
Decimal2.random = random;
|
|
2206
|
-
Decimal2.round = round;
|
|
2207
|
-
Decimal2.sign = sign;
|
|
2208
|
-
Decimal2.sin = sin;
|
|
2209
|
-
Decimal2.sinh = sinh;
|
|
2210
|
-
Decimal2.sqrt = sqrt;
|
|
2211
|
-
Decimal2.sub = sub;
|
|
2212
|
-
Decimal2.sum = sum;
|
|
2213
|
-
Decimal2.tan = tan;
|
|
2214
|
-
Decimal2.tanh = tanh;
|
|
2215
|
-
Decimal2.trunc = trunc;
|
|
2216
|
-
if (obj === void 0)
|
|
2217
|
-
obj = {};
|
|
2218
|
-
if (obj) {
|
|
2219
|
-
if (obj.defaults !== true) {
|
|
2220
|
-
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
2221
|
-
for (i = 0; i < ps.length; )
|
|
2222
|
-
if (!obj.hasOwnProperty(p = ps[i++]))
|
|
2223
|
-
obj[p] = this[p];
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
Decimal2.config(obj);
|
|
2227
|
-
return Decimal2;
|
|
2228
|
-
}
|
|
2229
|
-
function div(x, y) {
|
|
2230
|
-
return new this(x).div(y);
|
|
2231
|
-
}
|
|
2232
|
-
function exp(x) {
|
|
2233
|
-
return new this(x).exp();
|
|
2234
|
-
}
|
|
2235
|
-
function floor(x) {
|
|
2236
|
-
return finalise(x = new this(x), x.e + 1, 3);
|
|
2237
|
-
}
|
|
2238
|
-
function hypot() {
|
|
2239
|
-
var i, n, t = new this(0);
|
|
2240
|
-
external = false;
|
|
2241
|
-
for (i = 0; i < arguments.length; ) {
|
|
2242
|
-
n = new this(arguments[i++]);
|
|
2243
|
-
if (!n.d) {
|
|
2244
|
-
if (n.s) {
|
|
2245
|
-
external = true;
|
|
2246
|
-
return new this(1 / 0);
|
|
624
|
+
if (bInf) {
|
|
625
|
+
const negZero = aNeg !== bNeg;
|
|
626
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
2247
627
|
}
|
|
2248
|
-
t = n;
|
|
2249
|
-
} else if (t.d) {
|
|
2250
|
-
t = t.plus(n.times(n));
|
|
2251
628
|
}
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
}
|
|
2259
|
-
function ln(x) {
|
|
2260
|
-
return new this(x).ln();
|
|
2261
|
-
}
|
|
2262
|
-
function log(x, y) {
|
|
2263
|
-
return new this(x).log(y);
|
|
2264
|
-
}
|
|
2265
|
-
function log2(x) {
|
|
2266
|
-
return new this(x).log(2);
|
|
2267
|
-
}
|
|
2268
|
-
function log10(x) {
|
|
2269
|
-
return new this(x).log(10);
|
|
2270
|
-
}
|
|
2271
|
-
function max() {
|
|
2272
|
-
return maxOrMin(this, arguments, -1);
|
|
2273
|
-
}
|
|
2274
|
-
function min() {
|
|
2275
|
-
return maxOrMin(this, arguments, 1);
|
|
2276
|
-
}
|
|
2277
|
-
function mod(x, y) {
|
|
2278
|
-
return new this(x).mod(y);
|
|
2279
|
-
}
|
|
2280
|
-
function mul(x, y) {
|
|
2281
|
-
return new this(x).mul(y);
|
|
2282
|
-
}
|
|
2283
|
-
function pow(x, y) {
|
|
2284
|
-
return new this(x).pow(y);
|
|
2285
|
-
}
|
|
2286
|
-
function random(sd) {
|
|
2287
|
-
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
2288
|
-
if (sd === void 0)
|
|
2289
|
-
sd = this.precision;
|
|
2290
|
-
else
|
|
2291
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
2292
|
-
k = Math.ceil(sd / LOG_BASE);
|
|
2293
|
-
if (!this.crypto) {
|
|
2294
|
-
for (; i < k; )
|
|
2295
|
-
rd[i++] = Math.random() * 1e7 | 0;
|
|
2296
|
-
} else if (crypto.getRandomValues) {
|
|
2297
|
-
d = crypto.getRandomValues(new Uint32Array(k));
|
|
2298
|
-
for (; i < k; ) {
|
|
2299
|
-
n = d[i];
|
|
2300
|
-
if (n >= 429e7) {
|
|
2301
|
-
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
2302
|
-
} else {
|
|
2303
|
-
rd[i++] = n % 1e7;
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
} else if (crypto.randomBytes) {
|
|
2307
|
-
d = crypto.randomBytes(k *= 4);
|
|
2308
|
-
for (; i < k; ) {
|
|
2309
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
2310
|
-
if (n >= 214e7) {
|
|
2311
|
-
crypto.randomBytes(4).copy(d, i);
|
|
2312
|
-
} else {
|
|
2313
|
-
rd.push(n % 1e7);
|
|
2314
|
-
i += 4;
|
|
629
|
+
if (op === "plus") {
|
|
630
|
+
if (aInf && bInf) {
|
|
631
|
+
if (aNeg !== bNeg) {
|
|
632
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
633
|
+
}
|
|
634
|
+
return this;
|
|
2315
635
|
}
|
|
636
|
+
if (aInf)
|
|
637
|
+
return this;
|
|
638
|
+
if (bInf)
|
|
639
|
+
return other;
|
|
2316
640
|
}
|
|
2317
|
-
|
|
2318
|
-
} else {
|
|
2319
|
-
throw Error(cryptoUnavailable);
|
|
2320
|
-
}
|
|
2321
|
-
k = rd[--i];
|
|
2322
|
-
sd %= LOG_BASE;
|
|
2323
|
-
if (k && sd) {
|
|
2324
|
-
n = mathpow(10, LOG_BASE - sd);
|
|
2325
|
-
rd[i] = (k / n | 0) * n;
|
|
2326
|
-
}
|
|
2327
|
-
for (; rd[i] === 0; i--)
|
|
2328
|
-
rd.pop();
|
|
2329
|
-
if (i < 0) {
|
|
2330
|
-
e = 0;
|
|
2331
|
-
rd = [0];
|
|
2332
|
-
} else {
|
|
2333
|
-
e = -1;
|
|
2334
|
-
for (; rd[0] === 0; e -= LOG_BASE)
|
|
2335
|
-
rd.shift();
|
|
2336
|
-
for (k = 1, n = rd[0]; n >= 10; n /= 10)
|
|
2337
|
-
k++;
|
|
2338
|
-
if (k < LOG_BASE)
|
|
2339
|
-
e -= LOG_BASE - k;
|
|
641
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2340
642
|
}
|
|
2341
|
-
|
|
2342
|
-
r.d = rd;
|
|
2343
|
-
return r;
|
|
2344
|
-
}
|
|
2345
|
-
function round(x) {
|
|
2346
|
-
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
2347
|
-
}
|
|
2348
|
-
function sign(x) {
|
|
2349
|
-
x = new this(x);
|
|
2350
|
-
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
2351
|
-
}
|
|
2352
|
-
function sin(x) {
|
|
2353
|
-
return new this(x).sin();
|
|
2354
|
-
}
|
|
2355
|
-
function sinh(x) {
|
|
2356
|
-
return new this(x).sinh();
|
|
2357
|
-
}
|
|
2358
|
-
function sqrt(x) {
|
|
2359
|
-
return new this(x).sqrt();
|
|
2360
|
-
}
|
|
2361
|
-
function sub(x, y) {
|
|
2362
|
-
return new this(x).sub(y);
|
|
2363
|
-
}
|
|
2364
|
-
function sum() {
|
|
2365
|
-
var i = 0, args = arguments, x = new this(args[i]);
|
|
2366
|
-
external = false;
|
|
2367
|
-
for (; x.s && ++i < args.length; )
|
|
2368
|
-
x = x.plus(args[i]);
|
|
2369
|
-
external = true;
|
|
2370
|
-
return finalise(x, this.precision, this.rounding);
|
|
2371
|
-
}
|
|
2372
|
-
function tan(x) {
|
|
2373
|
-
return new this(x).tan();
|
|
2374
|
-
}
|
|
2375
|
-
function tanh(x) {
|
|
2376
|
-
return new this(x).tanh();
|
|
2377
|
-
}
|
|
2378
|
-
function trunc(x) {
|
|
2379
|
-
return finalise(x = new this(x), x.e + 1, 1);
|
|
2380
|
-
}
|
|
2381
|
-
P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
2382
|
-
P[Symbol.toStringTag] = "Decimal";
|
|
2383
|
-
var Decimal = P.constructor = clone(DEFAULTS);
|
|
2384
|
-
LN10 = new Decimal(LN10);
|
|
2385
|
-
PI = new Decimal(PI);
|
|
643
|
+
};
|
|
2386
644
|
|
|
2387
645
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/constants.js
|
|
2388
|
-
var TEN = new
|
|
2389
|
-
var ZERO = new
|
|
2390
|
-
var NEGATIVE_ZERO = new
|
|
646
|
+
var TEN = new BigDecimal(10);
|
|
647
|
+
var ZERO = new BigDecimal(0);
|
|
648
|
+
var NEGATIVE_ZERO = new BigDecimal(-0);
|
|
2391
649
|
|
|
2392
650
|
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
2393
651
|
function memoize(fn, options) {
|
|
@@ -2592,15 +850,9 @@
|
|
|
2592
850
|
|
|
2593
851
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/decimal-cache.js
|
|
2594
852
|
var getPowerOf10 = memoize((exponent) => {
|
|
2595
|
-
return
|
|
853
|
+
return BigDecimal.pow(10, exponent);
|
|
2596
854
|
});
|
|
2597
855
|
|
|
2598
|
-
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
|
|
2599
|
-
Decimal.set({ toExpPos: 100 });
|
|
2600
|
-
|
|
2601
|
-
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ToRawFixed.js
|
|
2602
|
-
Decimal.set({ toExpPos: 100 });
|
|
2603
|
-
|
|
2604
856
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/regex.generated.js
|
|
2605
857
|
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]/;
|
|
2606
858
|
|
|
@@ -5794,9 +4046,8 @@
|
|
|
5794
4046
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/utils.js
|
|
5795
4047
|
var PROCESSED_DATA;
|
|
5796
4048
|
function processData() {
|
|
5797
|
-
var _a, _b;
|
|
5798
4049
|
if (!PROCESSED_DATA) {
|
|
5799
|
-
const paradigmLocales =
|
|
4050
|
+
const paradigmLocales = data.supplemental.languageMatching["written-new"][0]?.paradigmLocales?._locales.split(" ");
|
|
5800
4051
|
const matchVariables = data.supplemental.languageMatching["written-new"].slice(1, 5);
|
|
5801
4052
|
const data2 = data.supplemental.languageMatching["written-new"].slice(5);
|
|
5802
4053
|
const matches = data2.map((d) => {
|
|
@@ -5944,7 +4195,7 @@
|
|
|
5944
4195
|
const dateTimeFormat = createMemoizedDateTimeFormat(`en-u-ca-${item}`);
|
|
5945
4196
|
const options = dateTimeFormat.resolvedOptions().calendar;
|
|
5946
4197
|
return options === item;
|
|
5947
|
-
} catch
|
|
4198
|
+
} catch {
|
|
5948
4199
|
}
|
|
5949
4200
|
return false;
|
|
5950
4201
|
}
|
|
@@ -5979,7 +4230,7 @@
|
|
|
5979
4230
|
function isSupportedCollation(collation) {
|
|
5980
4231
|
try {
|
|
5981
4232
|
return Intl.Collator(`en-u-co-${collation}`).resolvedOptions().collation === collation;
|
|
5982
|
-
} catch
|
|
4233
|
+
} catch {
|
|
5983
4234
|
}
|
|
5984
4235
|
return false;
|
|
5985
4236
|
}
|
|
@@ -6310,7 +4561,7 @@
|
|
|
6310
4561
|
if (format.substring(0, 3) !== currency && format.substring(format.length - 3) !== currency) {
|
|
6311
4562
|
return true;
|
|
6312
4563
|
}
|
|
6313
|
-
} catch
|
|
4564
|
+
} catch {
|
|
6314
4565
|
}
|
|
6315
4566
|
return false;
|
|
6316
4567
|
}
|
|
@@ -6445,7 +4696,7 @@
|
|
|
6445
4696
|
if (options === system && system === "latn" || numberFormat.format(123) !== "123") {
|
|
6446
4697
|
return true;
|
|
6447
4698
|
}
|
|
6448
|
-
} catch
|
|
4699
|
+
} catch {
|
|
6449
4700
|
}
|
|
6450
4701
|
return false;
|
|
6451
4702
|
}
|
|
@@ -6889,7 +5140,7 @@
|
|
|
6889
5140
|
try {
|
|
6890
5141
|
const formatter = createMemoizedDateTimeFormat("en", { timeZone });
|
|
6891
5142
|
return formatter.resolvedOptions().timeZone === timeZone;
|
|
6892
|
-
} catch
|
|
5143
|
+
} catch {
|
|
6893
5144
|
}
|
|
6894
5145
|
return false;
|
|
6895
5146
|
}
|
|
@@ -6952,7 +5203,7 @@
|
|
|
6952
5203
|
unit
|
|
6953
5204
|
});
|
|
6954
5205
|
return formatter.resolvedOptions().unit === unit;
|
|
6955
|
-
} catch
|
|
5206
|
+
} catch {
|
|
6956
5207
|
}
|
|
6957
5208
|
return false;
|
|
6958
5209
|
}
|
|
@@ -14819,10 +13070,10 @@
|
|
|
14819
13070
|
function isUnicodeLanguageSubtag(lang) {
|
|
14820
13071
|
return UNICODE_LANGUAGE_SUBTAG_REGEX.test(lang);
|
|
14821
13072
|
}
|
|
14822
|
-
function isStructurallyValidLanguageTag(
|
|
13073
|
+
function isStructurallyValidLanguageTag(tag) {
|
|
14823
13074
|
try {
|
|
14824
|
-
parseUnicodeLanguageId(
|
|
14825
|
-
} catch
|
|
13075
|
+
parseUnicodeLanguageId(tag.split(SEPARATOR));
|
|
13076
|
+
} catch {
|
|
14826
13077
|
return false;
|
|
14827
13078
|
}
|
|
14828
13079
|
return true;
|
|
@@ -14925,7 +13176,7 @@
|
|
|
14925
13176
|
let lang;
|
|
14926
13177
|
try {
|
|
14927
13178
|
lang = parseUnicodeLanguageId(chunks);
|
|
14928
|
-
} catch
|
|
13179
|
+
} catch {
|
|
14929
13180
|
}
|
|
14930
13181
|
const fields = [];
|
|
14931
13182
|
while (chunks.length && TKEY_REGEX.test(chunks[0])) {
|
|
@@ -15028,9 +13279,10 @@
|
|
|
15028
13279
|
function parseUnicodeLocaleId(locale) {
|
|
15029
13280
|
const chunks = locale.split(SEPARATOR);
|
|
15030
13281
|
const lang = parseUnicodeLanguageId(chunks);
|
|
15031
|
-
return
|
|
15032
|
-
lang
|
|
15033
|
-
|
|
13282
|
+
return {
|
|
13283
|
+
lang,
|
|
13284
|
+
...parseExtensions(chunks)
|
|
13285
|
+
};
|
|
15034
13286
|
}
|
|
15035
13287
|
|
|
15036
13288
|
// packages/intl-locale/character-orders.generated.ts
|
|
@@ -22676,10 +20928,10 @@
|
|
|
22676
20928
|
"fw"
|
|
22677
20929
|
];
|
|
22678
20930
|
var UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
|
|
22679
|
-
function applyOptionsToTag(
|
|
22680
|
-
invariant(typeof
|
|
20931
|
+
function applyOptionsToTag(tag, options) {
|
|
20932
|
+
invariant(typeof tag === "string", "language tag must be a string");
|
|
22681
20933
|
invariant(
|
|
22682
|
-
isStructurallyValidLanguageTag(
|
|
20934
|
+
isStructurallyValidLanguageTag(tag),
|
|
22683
20935
|
"malformed language tag",
|
|
22684
20936
|
RangeError
|
|
22685
20937
|
);
|
|
@@ -22713,7 +20965,7 @@
|
|
|
22713
20965
|
RangeError
|
|
22714
20966
|
);
|
|
22715
20967
|
}
|
|
22716
|
-
const languageId = parseUnicodeLanguageId(
|
|
20968
|
+
const languageId = parseUnicodeLanguageId(tag);
|
|
22717
20969
|
if (language !== void 0) {
|
|
22718
20970
|
languageId.lang = language;
|
|
22719
20971
|
}
|
|
@@ -22724,15 +20976,16 @@
|
|
|
22724
20976
|
languageId.region = region;
|
|
22725
20977
|
}
|
|
22726
20978
|
return Intl.getCanonicalLocales(
|
|
22727
|
-
emitUnicodeLocaleId(
|
|
20979
|
+
emitUnicodeLocaleId({
|
|
20980
|
+
...parseUnicodeLocaleId(tag),
|
|
22728
20981
|
lang: languageId
|
|
22729
|
-
})
|
|
20982
|
+
})
|
|
22730
20983
|
)[0];
|
|
22731
20984
|
}
|
|
22732
|
-
function applyUnicodeExtensionToTag(
|
|
20985
|
+
function applyUnicodeExtensionToTag(tag, options, relevantExtensionKeys) {
|
|
22733
20986
|
let unicodeExtension;
|
|
22734
20987
|
let keywords = [];
|
|
22735
|
-
const ast = parseUnicodeLocaleId(
|
|
20988
|
+
const ast = parseUnicodeLocaleId(tag);
|
|
22736
20989
|
for (const ext of ast.extensions) {
|
|
22737
20990
|
if (ext.type === "u") {
|
|
22738
20991
|
unicodeExtension = ext;
|
|
@@ -22795,8 +21048,8 @@
|
|
|
22795
21048
|
variants: [...variants, ...replacement.variants]
|
|
22796
21049
|
};
|
|
22797
21050
|
}
|
|
22798
|
-
function addLikelySubtags(
|
|
22799
|
-
const ast = parseUnicodeLocaleId(
|
|
21051
|
+
function addLikelySubtags(tag) {
|
|
21052
|
+
const ast = parseUnicodeLocaleId(tag);
|
|
22800
21053
|
const unicodeLangId = ast.lang;
|
|
22801
21054
|
const { lang, script, region, variants } = unicodeLangId;
|
|
22802
21055
|
if (script && region) {
|
|
@@ -22849,32 +21102,35 @@
|
|
|
22849
21102
|
ast.lang = mergeUnicodeLanguageId(void 0, script, region, variants, parts);
|
|
22850
21103
|
return emitUnicodeLocaleId(ast);
|
|
22851
21104
|
}
|
|
22852
|
-
function removeLikelySubtags(
|
|
22853
|
-
let maxLocale = addLikelySubtags(
|
|
21105
|
+
function removeLikelySubtags(tag) {
|
|
21106
|
+
let maxLocale = addLikelySubtags(tag);
|
|
22854
21107
|
if (!maxLocale) {
|
|
22855
|
-
return
|
|
21108
|
+
return tag;
|
|
22856
21109
|
}
|
|
22857
|
-
maxLocale = emitUnicodeLanguageId(
|
|
21110
|
+
maxLocale = emitUnicodeLanguageId({
|
|
21111
|
+
...parseUnicodeLanguageId(maxLocale),
|
|
22858
21112
|
variants: []
|
|
22859
|
-
})
|
|
22860
|
-
const ast = parseUnicodeLocaleId(
|
|
21113
|
+
});
|
|
21114
|
+
const ast = parseUnicodeLocaleId(tag);
|
|
22861
21115
|
const {
|
|
22862
21116
|
lang: { lang, script, region, variants }
|
|
22863
21117
|
} = ast;
|
|
22864
21118
|
const trial = addLikelySubtags(emitUnicodeLanguageId({ lang, variants: [] }));
|
|
22865
21119
|
if (trial === maxLocale) {
|
|
22866
|
-
return emitUnicodeLocaleId(
|
|
21120
|
+
return emitUnicodeLocaleId({
|
|
21121
|
+
...ast,
|
|
22867
21122
|
lang: mergeUnicodeLanguageId(lang, void 0, void 0, variants)
|
|
22868
|
-
})
|
|
21123
|
+
});
|
|
22869
21124
|
}
|
|
22870
21125
|
if (region) {
|
|
22871
21126
|
const trial2 = addLikelySubtags(
|
|
22872
21127
|
emitUnicodeLanguageId({ lang, region, variants: [] })
|
|
22873
21128
|
);
|
|
22874
21129
|
if (trial2 === maxLocale) {
|
|
22875
|
-
return emitUnicodeLocaleId(
|
|
21130
|
+
return emitUnicodeLocaleId({
|
|
21131
|
+
...ast,
|
|
22876
21132
|
lang: mergeUnicodeLanguageId(lang, void 0, region, variants)
|
|
22877
|
-
})
|
|
21133
|
+
});
|
|
22878
21134
|
}
|
|
22879
21135
|
}
|
|
22880
21136
|
if (script) {
|
|
@@ -22882,12 +21138,13 @@
|
|
|
22882
21138
|
emitUnicodeLanguageId({ lang, script, variants: [] })
|
|
22883
21139
|
);
|
|
22884
21140
|
if (trial2 === maxLocale) {
|
|
22885
|
-
return emitUnicodeLocaleId(
|
|
21141
|
+
return emitUnicodeLocaleId({
|
|
21142
|
+
...ast,
|
|
22886
21143
|
lang: mergeUnicodeLanguageId(lang, script, void 0, variants)
|
|
22887
|
-
})
|
|
21144
|
+
});
|
|
22888
21145
|
}
|
|
22889
21146
|
}
|
|
22890
|
-
return
|
|
21147
|
+
return tag;
|
|
22891
21148
|
}
|
|
22892
21149
|
function createArrayFromListOrRestricted(list, restricted) {
|
|
22893
21150
|
let result = list;
|
|
@@ -22931,12 +21188,11 @@
|
|
|
22931
21188
|
return createArrayFromListOrRestricted(preferredHourCycles, restricted);
|
|
22932
21189
|
}
|
|
22933
21190
|
function numberingSystemsOfLocale(loc) {
|
|
22934
|
-
var _a;
|
|
22935
21191
|
const locInternalSlots = getInternalSlots(loc);
|
|
22936
21192
|
const restricted = locInternalSlots.numberingSystem;
|
|
22937
21193
|
const locale = locInternalSlots.locale;
|
|
22938
21194
|
const language = loc.language;
|
|
22939
|
-
const localeNumberingSystems =
|
|
21195
|
+
const localeNumberingSystems = numberingSystems[locale] ?? numberingSystems[language];
|
|
22940
21196
|
if (localeNumberingSystems) {
|
|
22941
21197
|
return createArrayFromListOrRestricted(
|
|
22942
21198
|
[...localeNumberingSystems],
|
|
@@ -22980,7 +21236,7 @@
|
|
|
22980
21236
|
return TABLE_1[+fw];
|
|
22981
21237
|
}
|
|
22982
21238
|
var _Locale = class _Locale {
|
|
22983
|
-
constructor(
|
|
21239
|
+
constructor(tag, opts) {
|
|
22984
21240
|
const newTarget = this && this instanceof _Locale ? this.constructor : void 0;
|
|
22985
21241
|
if (!newTarget) {
|
|
22986
21242
|
throw new TypeError("Intl.Locale must be called with 'new'");
|
|
@@ -23000,23 +21256,23 @@
|
|
|
23000
21256
|
if (relevantExtensionKeys.indexOf("kn") > -1) {
|
|
23001
21257
|
internalSlotsList.push("numeric");
|
|
23002
21258
|
}
|
|
23003
|
-
if (
|
|
21259
|
+
if (tag === void 0) {
|
|
23004
21260
|
throw new TypeError(
|
|
23005
21261
|
"First argument to Intl.Locale constructor can't be empty or missing"
|
|
23006
21262
|
);
|
|
23007
21263
|
}
|
|
23008
|
-
if (typeof
|
|
21264
|
+
if (typeof tag !== "string" && typeof tag !== "object") {
|
|
23009
21265
|
throw new TypeError("tag must be a string or object");
|
|
23010
21266
|
}
|
|
23011
21267
|
let tagInternalSlots;
|
|
23012
|
-
if (typeof
|
|
23013
|
-
|
|
21268
|
+
if (typeof tag === "object" && (tagInternalSlots = getInternalSlots(tag)) && HasOwnProperty(tagInternalSlots, "initializedLocale")) {
|
|
21269
|
+
tag = tagInternalSlots.locale;
|
|
23014
21270
|
} else {
|
|
23015
|
-
|
|
21271
|
+
tag = tag.toString();
|
|
23016
21272
|
}
|
|
23017
21273
|
let internalSlots = getInternalSlots(this, internalSlotsList);
|
|
23018
21274
|
let options = CoerceOptionsToObject(opts);
|
|
23019
|
-
|
|
21275
|
+
tag = applyOptionsToTag(tag, options);
|
|
23020
21276
|
const opt = /* @__PURE__ */ Object.create(null);
|
|
23021
21277
|
const calendar = GetOption(
|
|
23022
21278
|
options,
|
|
@@ -23093,7 +21349,7 @@
|
|
|
23093
21349
|
}
|
|
23094
21350
|
}
|
|
23095
21351
|
opt.nu = numberingSystem;
|
|
23096
|
-
const r = applyUnicodeExtensionToTag(
|
|
21352
|
+
const r = applyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys);
|
|
23097
21353
|
internalSlots.locale = r.locale;
|
|
23098
21354
|
internalSlots.calendar = r.ca;
|
|
23099
21355
|
internalSlots.collation = r.co;
|
|
@@ -23115,7 +21371,7 @@
|
|
|
23115
21371
|
try {
|
|
23116
21372
|
const maximizedLocale = addLikelySubtags(locale);
|
|
23117
21373
|
return new _Locale(maximizedLocale);
|
|
23118
|
-
} catch
|
|
21374
|
+
} catch {
|
|
23119
21375
|
return new _Locale(locale);
|
|
23120
21376
|
}
|
|
23121
21377
|
}
|
|
@@ -23127,7 +21383,7 @@
|
|
|
23127
21383
|
try {
|
|
23128
21384
|
const minimizedLocale = removeLikelySubtags(locale);
|
|
23129
21385
|
return new _Locale(minimizedLocale);
|
|
23130
|
-
} catch
|
|
21386
|
+
} catch {
|
|
23131
21387
|
return new _Locale(locale);
|
|
23132
21388
|
}
|
|
23133
21389
|
}
|
|
@@ -23294,14 +21550,14 @@
|
|
|
23294
21550
|
enumerable: false,
|
|
23295
21551
|
configurable: true
|
|
23296
21552
|
});
|
|
23297
|
-
} catch
|
|
21553
|
+
} catch {
|
|
23298
21554
|
}
|
|
23299
21555
|
|
|
23300
21556
|
// packages/intl-locale/should-polyfill.ts
|
|
23301
21557
|
function hasIntlGetCanonicalLocalesBug() {
|
|
23302
21558
|
try {
|
|
23303
21559
|
return new Intl.Locale("und-x-private").toString() === "x-private";
|
|
23304
|
-
} catch
|
|
21560
|
+
} catch {
|
|
23305
21561
|
return true;
|
|
23306
21562
|
}
|
|
23307
21563
|
}
|
|
@@ -23313,7 +21569,7 @@
|
|
|
23313
21569
|
"variants"
|
|
23314
21570
|
);
|
|
23315
21571
|
return descriptor !== void 0 && typeof descriptor.get === "function";
|
|
23316
|
-
} catch
|
|
21572
|
+
} catch {
|
|
23317
21573
|
return false;
|
|
23318
21574
|
}
|
|
23319
21575
|
}
|
|
@@ -23327,7 +21583,7 @@
|
|
|
23327
21583
|
return true;
|
|
23328
21584
|
}
|
|
23329
21585
|
return false;
|
|
23330
|
-
} catch
|
|
21586
|
+
} catch {
|
|
23331
21587
|
return true;
|
|
23332
21588
|
}
|
|
23333
21589
|
}
|
|
@@ -23345,15 +21601,4 @@
|
|
|
23345
21601
|
});
|
|
23346
21602
|
}
|
|
23347
21603
|
})();
|
|
23348
|
-
/*! Bundled license information:
|
|
23349
|
-
|
|
23350
|
-
decimal.js/decimal.mjs:
|
|
23351
|
-
(*!
|
|
23352
|
-
* decimal.js v10.6.0
|
|
23353
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
23354
|
-
* https://github.com/MikeMcl/decimal.js
|
|
23355
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
23356
|
-
* MIT Licence
|
|
23357
|
-
*)
|
|
23358
|
-
*/
|
|
23359
21604
|
//# sourceMappingURL=polyfill.iife.js.map
|