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