@formatjs/intl-pluralrules 5.3.5 → 5.4.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/abstract/GetOperands.d.ts +2 -1
- package/abstract/GetOperands.js +8 -8
- package/abstract/InitializePluralRules.d.ts +1 -1
- package/abstract/InitializePluralRules.js +2 -2
- package/abstract/ResolvePlural.d.ts +4 -3
- package/abstract/ResolvePlural.js +1 -2
- package/index.d.ts +1 -1
- package/lib/abstract/GetOperands.d.ts +2 -1
- package/lib/abstract/GetOperands.js +9 -9
- package/lib/abstract/InitializePluralRules.d.ts +1 -1
- package/lib/abstract/InitializePluralRules.js +2 -2
- package/lib/abstract/ResolvePlural.d.ts +4 -3
- package/lib/abstract/ResolvePlural.js +2 -3
- package/lib/index.d.ts +1 -1
- package/package.json +6 -5
- package/polyfill.iife.js +2723 -146
- package/abstract/GetOperands.js.map +0 -1
- package/abstract/InitializePluralRules.js.map +0 -1
- package/abstract/ResolvePlural.js.map +0 -1
- package/get_internal_slots.js.map +0 -1
- package/index.js.map +0 -1
- package/lib/abstract/GetOperands.js.map +0 -1
- package/lib/abstract/InitializePluralRules.js.map +0 -1
- package/lib/abstract/ResolvePlural.js.map +0 -1
- package/lib/get_internal_slots.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/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/supported-locales.generated.js.map +0 -1
package/polyfill.iife.js
CHANGED
|
@@ -11,6 +11,2361 @@
|
|
|
11
11
|
return Intl.getCanonicalLocales(locales);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// node_modules/.aspect_rules_js/decimal.js@10.4.3/node_modules/decimal.js/decimal.mjs
|
|
15
|
+
var EXP_LIMIT = 9e15;
|
|
16
|
+
var MAX_DIGITS = 1e9;
|
|
17
|
+
var NUMERALS = "0123456789abcdef";
|
|
18
|
+
var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
|
|
19
|
+
var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
|
|
20
|
+
var DEFAULTS = {
|
|
21
|
+
// These values must be integers within the stated ranges (inclusive).
|
|
22
|
+
// Most of these values can be changed at run-time using the `Decimal.config` method.
|
|
23
|
+
// The maximum number of significant digits of the result of a calculation or base conversion.
|
|
24
|
+
// E.g. `Decimal.config({ precision: 20 });`
|
|
25
|
+
precision: 20,
|
|
26
|
+
// 1 to MAX_DIGITS
|
|
27
|
+
// The rounding mode used when rounding to `precision`.
|
|
28
|
+
//
|
|
29
|
+
// ROUND_UP 0 Away from zero.
|
|
30
|
+
// ROUND_DOWN 1 Towards zero.
|
|
31
|
+
// ROUND_CEIL 2 Towards +Infinity.
|
|
32
|
+
// ROUND_FLOOR 3 Towards -Infinity.
|
|
33
|
+
// ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
|
|
34
|
+
// ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
|
|
35
|
+
// ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
|
|
36
|
+
// ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
|
|
37
|
+
// ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
|
|
38
|
+
//
|
|
39
|
+
// E.g.
|
|
40
|
+
// `Decimal.rounding = 4;`
|
|
41
|
+
// `Decimal.rounding = Decimal.ROUND_HALF_UP;`
|
|
42
|
+
rounding: 4,
|
|
43
|
+
// 0 to 8
|
|
44
|
+
// The modulo mode used when calculating the modulus: a mod n.
|
|
45
|
+
// The quotient (q = a / n) is calculated according to the corresponding rounding mode.
|
|
46
|
+
// The remainder (r) is calculated as: r = a - n * q.
|
|
47
|
+
//
|
|
48
|
+
// UP 0 The remainder is positive if the dividend is negative, else is negative.
|
|
49
|
+
// DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
|
|
50
|
+
// FLOOR 3 The remainder has the same sign as the divisor (Python %).
|
|
51
|
+
// HALF_EVEN 6 The IEEE 754 remainder function.
|
|
52
|
+
// EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
|
|
53
|
+
//
|
|
54
|
+
// Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
|
|
55
|
+
// division (9) are commonly used for the modulus operation. The other rounding modes can also
|
|
56
|
+
// be used, but they may not give useful results.
|
|
57
|
+
modulo: 1,
|
|
58
|
+
// 0 to 9
|
|
59
|
+
// The exponent value at and beneath which `toString` returns exponential notation.
|
|
60
|
+
// JavaScript numbers: -7
|
|
61
|
+
toExpNeg: -7,
|
|
62
|
+
// 0 to -EXP_LIMIT
|
|
63
|
+
// The exponent value at and above which `toString` returns exponential notation.
|
|
64
|
+
// JavaScript numbers: 21
|
|
65
|
+
toExpPos: 21,
|
|
66
|
+
// 0 to EXP_LIMIT
|
|
67
|
+
// The minimum exponent value, beneath which underflow to zero occurs.
|
|
68
|
+
// JavaScript numbers: -324 (5e-324)
|
|
69
|
+
minE: -EXP_LIMIT,
|
|
70
|
+
// -1 to -EXP_LIMIT
|
|
71
|
+
// The maximum exponent value, above which overflow to Infinity occurs.
|
|
72
|
+
// JavaScript numbers: 308 (1.7976931348623157e+308)
|
|
73
|
+
maxE: EXP_LIMIT,
|
|
74
|
+
// 1 to EXP_LIMIT
|
|
75
|
+
// Whether to use cryptographically-secure random number generation, if available.
|
|
76
|
+
crypto: false
|
|
77
|
+
// true/false
|
|
78
|
+
};
|
|
79
|
+
var inexact;
|
|
80
|
+
var quadrant;
|
|
81
|
+
var external = true;
|
|
82
|
+
var decimalError = "[DecimalError] ";
|
|
83
|
+
var invalidArgument = decimalError + "Invalid argument: ";
|
|
84
|
+
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
85
|
+
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
86
|
+
var tag = "[object Decimal]";
|
|
87
|
+
var mathfloor = Math.floor;
|
|
88
|
+
var mathpow = Math.pow;
|
|
89
|
+
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
90
|
+
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
91
|
+
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
92
|
+
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
93
|
+
var BASE = 1e7;
|
|
94
|
+
var LOG_BASE = 7;
|
|
95
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
96
|
+
var LN10_PRECISION = LN10.length - 1;
|
|
97
|
+
var PI_PRECISION = PI.length - 1;
|
|
98
|
+
var P = { toStringTag: tag };
|
|
99
|
+
P.absoluteValue = P.abs = function() {
|
|
100
|
+
var x = new this.constructor(this);
|
|
101
|
+
if (x.s < 0)
|
|
102
|
+
x.s = 1;
|
|
103
|
+
return finalise(x);
|
|
104
|
+
};
|
|
105
|
+
P.ceil = function() {
|
|
106
|
+
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
107
|
+
};
|
|
108
|
+
P.clampedTo = P.clamp = function(min2, max2) {
|
|
109
|
+
var k, x = this, Ctor = x.constructor;
|
|
110
|
+
min2 = new Ctor(min2);
|
|
111
|
+
max2 = new Ctor(max2);
|
|
112
|
+
if (!min2.s || !max2.s)
|
|
113
|
+
return new Ctor(NaN);
|
|
114
|
+
if (min2.gt(max2))
|
|
115
|
+
throw Error(invalidArgument + max2);
|
|
116
|
+
k = x.cmp(min2);
|
|
117
|
+
return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
|
|
118
|
+
};
|
|
119
|
+
P.comparedTo = P.cmp = function(y) {
|
|
120
|
+
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
|
121
|
+
if (!xd || !yd) {
|
|
122
|
+
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
123
|
+
}
|
|
124
|
+
if (!xd[0] || !yd[0])
|
|
125
|
+
return xd[0] ? xs : yd[0] ? -ys : 0;
|
|
126
|
+
if (xs !== ys)
|
|
127
|
+
return xs;
|
|
128
|
+
if (x.e !== y.e)
|
|
129
|
+
return x.e > y.e ^ xs < 0 ? 1 : -1;
|
|
130
|
+
xdL = xd.length;
|
|
131
|
+
ydL = yd.length;
|
|
132
|
+
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
|
|
133
|
+
if (xd[i] !== yd[i])
|
|
134
|
+
return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
|
135
|
+
}
|
|
136
|
+
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
|
137
|
+
};
|
|
138
|
+
P.cosine = P.cos = function() {
|
|
139
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
140
|
+
if (!x.d)
|
|
141
|
+
return new Ctor(NaN);
|
|
142
|
+
if (!x.d[0])
|
|
143
|
+
return new Ctor(1);
|
|
144
|
+
pr = Ctor.precision;
|
|
145
|
+
rm = Ctor.rounding;
|
|
146
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
147
|
+
Ctor.rounding = 1;
|
|
148
|
+
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
149
|
+
Ctor.precision = pr;
|
|
150
|
+
Ctor.rounding = rm;
|
|
151
|
+
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
|
152
|
+
};
|
|
153
|
+
P.cubeRoot = P.cbrt = function() {
|
|
154
|
+
var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
|
|
155
|
+
if (!x.isFinite() || x.isZero())
|
|
156
|
+
return new Ctor(x);
|
|
157
|
+
external = false;
|
|
158
|
+
s = x.s * mathpow(x.s * x, 1 / 3);
|
|
159
|
+
if (!s || Math.abs(s) == 1 / 0) {
|
|
160
|
+
n = digitsToString(x.d);
|
|
161
|
+
e = x.e;
|
|
162
|
+
if (s = (e - n.length + 1) % 3)
|
|
163
|
+
n += s == 1 || s == -2 ? "0" : "00";
|
|
164
|
+
s = mathpow(n, 1 / 3);
|
|
165
|
+
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
166
|
+
if (s == 1 / 0) {
|
|
167
|
+
n = "5e" + e;
|
|
168
|
+
} else {
|
|
169
|
+
n = s.toExponential();
|
|
170
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
171
|
+
}
|
|
172
|
+
r = new Ctor(n);
|
|
173
|
+
r.s = x.s;
|
|
174
|
+
} else {
|
|
175
|
+
r = new Ctor(s.toString());
|
|
176
|
+
}
|
|
177
|
+
sd = (e = Ctor.precision) + 3;
|
|
178
|
+
for (; ; ) {
|
|
179
|
+
t = r;
|
|
180
|
+
t3 = t.times(t).times(t);
|
|
181
|
+
t3plusx = t3.plus(x);
|
|
182
|
+
r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
|
|
183
|
+
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
184
|
+
n = n.slice(sd - 3, sd + 1);
|
|
185
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
186
|
+
if (!rep) {
|
|
187
|
+
finalise(t, e + 1, 0);
|
|
188
|
+
if (t.times(t).times(t).eq(x)) {
|
|
189
|
+
r = t;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
sd += 4;
|
|
194
|
+
rep = 1;
|
|
195
|
+
} else {
|
|
196
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
197
|
+
finalise(r, e + 1, 1);
|
|
198
|
+
m = !r.times(r).times(r).eq(x);
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
external = true;
|
|
205
|
+
return finalise(r, e, Ctor.rounding, m);
|
|
206
|
+
};
|
|
207
|
+
P.decimalPlaces = P.dp = function() {
|
|
208
|
+
var w, d = this.d, n = NaN;
|
|
209
|
+
if (d) {
|
|
210
|
+
w = d.length - 1;
|
|
211
|
+
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
212
|
+
w = d[w];
|
|
213
|
+
if (w)
|
|
214
|
+
for (; w % 10 == 0; w /= 10)
|
|
215
|
+
n--;
|
|
216
|
+
if (n < 0)
|
|
217
|
+
n = 0;
|
|
218
|
+
}
|
|
219
|
+
return n;
|
|
220
|
+
};
|
|
221
|
+
P.dividedBy = P.div = function(y) {
|
|
222
|
+
return divide(this, new this.constructor(y));
|
|
223
|
+
};
|
|
224
|
+
P.dividedToIntegerBy = P.divToInt = function(y) {
|
|
225
|
+
var x = this, Ctor = x.constructor;
|
|
226
|
+
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
227
|
+
};
|
|
228
|
+
P.equals = P.eq = function(y) {
|
|
229
|
+
return this.cmp(y) === 0;
|
|
230
|
+
};
|
|
231
|
+
P.floor = function() {
|
|
232
|
+
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
233
|
+
};
|
|
234
|
+
P.greaterThan = P.gt = function(y) {
|
|
235
|
+
return this.cmp(y) > 0;
|
|
236
|
+
};
|
|
237
|
+
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
238
|
+
var k = this.cmp(y);
|
|
239
|
+
return k == 1 || k === 0;
|
|
240
|
+
};
|
|
241
|
+
P.hyperbolicCosine = P.cosh = function() {
|
|
242
|
+
var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
|
243
|
+
if (!x.isFinite())
|
|
244
|
+
return new Ctor(x.s ? 1 / 0 : NaN);
|
|
245
|
+
if (x.isZero())
|
|
246
|
+
return one;
|
|
247
|
+
pr = Ctor.precision;
|
|
248
|
+
rm = Ctor.rounding;
|
|
249
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
250
|
+
Ctor.rounding = 1;
|
|
251
|
+
len = x.d.length;
|
|
252
|
+
if (len < 32) {
|
|
253
|
+
k = Math.ceil(len / 3);
|
|
254
|
+
n = (1 / tinyPow(4, k)).toString();
|
|
255
|
+
} else {
|
|
256
|
+
k = 16;
|
|
257
|
+
n = "2.3283064365386962890625e-10";
|
|
258
|
+
}
|
|
259
|
+
x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
|
|
260
|
+
var cosh2_x, i = k, d8 = new Ctor(8);
|
|
261
|
+
for (; i--; ) {
|
|
262
|
+
cosh2_x = x.times(x);
|
|
263
|
+
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
|
264
|
+
}
|
|
265
|
+
return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
266
|
+
};
|
|
267
|
+
P.hyperbolicSine = P.sinh = function() {
|
|
268
|
+
var k, pr, rm, len, x = this, Ctor = x.constructor;
|
|
269
|
+
if (!x.isFinite() || x.isZero())
|
|
270
|
+
return new Ctor(x);
|
|
271
|
+
pr = Ctor.precision;
|
|
272
|
+
rm = Ctor.rounding;
|
|
273
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
274
|
+
Ctor.rounding = 1;
|
|
275
|
+
len = x.d.length;
|
|
276
|
+
if (len < 3) {
|
|
277
|
+
x = taylorSeries(Ctor, 2, x, x, true);
|
|
278
|
+
} else {
|
|
279
|
+
k = 1.4 * Math.sqrt(len);
|
|
280
|
+
k = k > 16 ? 16 : k | 0;
|
|
281
|
+
x = x.times(1 / tinyPow(5, k));
|
|
282
|
+
x = taylorSeries(Ctor, 2, x, x, true);
|
|
283
|
+
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
284
|
+
for (; k--; ) {
|
|
285
|
+
sinh2_x = x.times(x);
|
|
286
|
+
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
Ctor.precision = pr;
|
|
290
|
+
Ctor.rounding = rm;
|
|
291
|
+
return finalise(x, pr, rm, true);
|
|
292
|
+
};
|
|
293
|
+
P.hyperbolicTangent = P.tanh = function() {
|
|
294
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
295
|
+
if (!x.isFinite())
|
|
296
|
+
return new Ctor(x.s);
|
|
297
|
+
if (x.isZero())
|
|
298
|
+
return new Ctor(x);
|
|
299
|
+
pr = Ctor.precision;
|
|
300
|
+
rm = Ctor.rounding;
|
|
301
|
+
Ctor.precision = pr + 7;
|
|
302
|
+
Ctor.rounding = 1;
|
|
303
|
+
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
304
|
+
};
|
|
305
|
+
P.inverseCosine = P.acos = function() {
|
|
306
|
+
var halfPi, x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
307
|
+
if (k !== -1) {
|
|
308
|
+
return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
309
|
+
}
|
|
310
|
+
if (x.isZero())
|
|
311
|
+
return getPi(Ctor, pr + 4, rm).times(0.5);
|
|
312
|
+
Ctor.precision = pr + 6;
|
|
313
|
+
Ctor.rounding = 1;
|
|
314
|
+
x = x.asin();
|
|
315
|
+
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
316
|
+
Ctor.precision = pr;
|
|
317
|
+
Ctor.rounding = rm;
|
|
318
|
+
return halfPi.minus(x);
|
|
319
|
+
};
|
|
320
|
+
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
321
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
322
|
+
if (x.lte(1))
|
|
323
|
+
return new Ctor(x.eq(1) ? 0 : NaN);
|
|
324
|
+
if (!x.isFinite())
|
|
325
|
+
return new Ctor(x);
|
|
326
|
+
pr = Ctor.precision;
|
|
327
|
+
rm = Ctor.rounding;
|
|
328
|
+
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
329
|
+
Ctor.rounding = 1;
|
|
330
|
+
external = false;
|
|
331
|
+
x = x.times(x).minus(1).sqrt().plus(x);
|
|
332
|
+
external = true;
|
|
333
|
+
Ctor.precision = pr;
|
|
334
|
+
Ctor.rounding = rm;
|
|
335
|
+
return x.ln();
|
|
336
|
+
};
|
|
337
|
+
P.inverseHyperbolicSine = P.asinh = function() {
|
|
338
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
339
|
+
if (!x.isFinite() || x.isZero())
|
|
340
|
+
return new Ctor(x);
|
|
341
|
+
pr = Ctor.precision;
|
|
342
|
+
rm = Ctor.rounding;
|
|
343
|
+
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
344
|
+
Ctor.rounding = 1;
|
|
345
|
+
external = false;
|
|
346
|
+
x = x.times(x).plus(1).sqrt().plus(x);
|
|
347
|
+
external = true;
|
|
348
|
+
Ctor.precision = pr;
|
|
349
|
+
Ctor.rounding = rm;
|
|
350
|
+
return x.ln();
|
|
351
|
+
};
|
|
352
|
+
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
353
|
+
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
354
|
+
if (!x.isFinite())
|
|
355
|
+
return new Ctor(NaN);
|
|
356
|
+
if (x.e >= 0)
|
|
357
|
+
return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
358
|
+
pr = Ctor.precision;
|
|
359
|
+
rm = Ctor.rounding;
|
|
360
|
+
xsd = x.sd();
|
|
361
|
+
if (Math.max(xsd, pr) < 2 * -x.e - 1)
|
|
362
|
+
return finalise(new Ctor(x), pr, rm, true);
|
|
363
|
+
Ctor.precision = wpr = xsd - x.e;
|
|
364
|
+
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
365
|
+
Ctor.precision = pr + 4;
|
|
366
|
+
Ctor.rounding = 1;
|
|
367
|
+
x = x.ln();
|
|
368
|
+
Ctor.precision = pr;
|
|
369
|
+
Ctor.rounding = rm;
|
|
370
|
+
return x.times(0.5);
|
|
371
|
+
};
|
|
372
|
+
P.inverseSine = P.asin = function() {
|
|
373
|
+
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
374
|
+
if (x.isZero())
|
|
375
|
+
return new Ctor(x);
|
|
376
|
+
k = x.abs().cmp(1);
|
|
377
|
+
pr = Ctor.precision;
|
|
378
|
+
rm = Ctor.rounding;
|
|
379
|
+
if (k !== -1) {
|
|
380
|
+
if (k === 0) {
|
|
381
|
+
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
382
|
+
halfPi.s = x.s;
|
|
383
|
+
return halfPi;
|
|
384
|
+
}
|
|
385
|
+
return new Ctor(NaN);
|
|
386
|
+
}
|
|
387
|
+
Ctor.precision = pr + 6;
|
|
388
|
+
Ctor.rounding = 1;
|
|
389
|
+
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
|
390
|
+
Ctor.precision = pr;
|
|
391
|
+
Ctor.rounding = rm;
|
|
392
|
+
return x.times(2);
|
|
393
|
+
};
|
|
394
|
+
P.inverseTangent = P.atan = function() {
|
|
395
|
+
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
396
|
+
if (!x.isFinite()) {
|
|
397
|
+
if (!x.s)
|
|
398
|
+
return new Ctor(NaN);
|
|
399
|
+
if (pr + 4 <= PI_PRECISION) {
|
|
400
|
+
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
401
|
+
r.s = x.s;
|
|
402
|
+
return r;
|
|
403
|
+
}
|
|
404
|
+
} else if (x.isZero()) {
|
|
405
|
+
return new Ctor(x);
|
|
406
|
+
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
407
|
+
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
408
|
+
r.s = x.s;
|
|
409
|
+
return r;
|
|
410
|
+
}
|
|
411
|
+
Ctor.precision = wpr = pr + 10;
|
|
412
|
+
Ctor.rounding = 1;
|
|
413
|
+
k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
|
414
|
+
for (i = k; i; --i)
|
|
415
|
+
x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
|
416
|
+
external = false;
|
|
417
|
+
j = Math.ceil(wpr / LOG_BASE);
|
|
418
|
+
n = 1;
|
|
419
|
+
x2 = x.times(x);
|
|
420
|
+
r = new Ctor(x);
|
|
421
|
+
px = x;
|
|
422
|
+
for (; i !== -1; ) {
|
|
423
|
+
px = px.times(x2);
|
|
424
|
+
t = r.minus(px.div(n += 2));
|
|
425
|
+
px = px.times(x2);
|
|
426
|
+
r = t.plus(px.div(n += 2));
|
|
427
|
+
if (r.d[j] !== void 0)
|
|
428
|
+
for (i = j; r.d[i] === t.d[i] && i--; )
|
|
429
|
+
;
|
|
430
|
+
}
|
|
431
|
+
if (k)
|
|
432
|
+
r = r.times(2 << k - 1);
|
|
433
|
+
external = true;
|
|
434
|
+
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
435
|
+
};
|
|
436
|
+
P.isFinite = function() {
|
|
437
|
+
return !!this.d;
|
|
438
|
+
};
|
|
439
|
+
P.isInteger = P.isInt = function() {
|
|
440
|
+
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
441
|
+
};
|
|
442
|
+
P.isNaN = function() {
|
|
443
|
+
return !this.s;
|
|
444
|
+
};
|
|
445
|
+
P.isNegative = P.isNeg = function() {
|
|
446
|
+
return this.s < 0;
|
|
447
|
+
};
|
|
448
|
+
P.isPositive = P.isPos = function() {
|
|
449
|
+
return this.s > 0;
|
|
450
|
+
};
|
|
451
|
+
P.isZero = function() {
|
|
452
|
+
return !!this.d && this.d[0] === 0;
|
|
453
|
+
};
|
|
454
|
+
P.lessThan = P.lt = function(y) {
|
|
455
|
+
return this.cmp(y) < 0;
|
|
456
|
+
};
|
|
457
|
+
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
458
|
+
return this.cmp(y) < 1;
|
|
459
|
+
};
|
|
460
|
+
P.logarithm = P.log = function(base) {
|
|
461
|
+
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
462
|
+
if (base == null) {
|
|
463
|
+
base = new Ctor(10);
|
|
464
|
+
isBase10 = true;
|
|
465
|
+
} else {
|
|
466
|
+
base = new Ctor(base);
|
|
467
|
+
d = base.d;
|
|
468
|
+
if (base.s < 0 || !d || !d[0] || base.eq(1))
|
|
469
|
+
return new Ctor(NaN);
|
|
470
|
+
isBase10 = base.eq(10);
|
|
471
|
+
}
|
|
472
|
+
d = arg.d;
|
|
473
|
+
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
474
|
+
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
475
|
+
}
|
|
476
|
+
if (isBase10) {
|
|
477
|
+
if (d.length > 1) {
|
|
478
|
+
inf = true;
|
|
479
|
+
} else {
|
|
480
|
+
for (k = d[0]; k % 10 === 0; )
|
|
481
|
+
k /= 10;
|
|
482
|
+
inf = k !== 1;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
external = false;
|
|
486
|
+
sd = pr + guard;
|
|
487
|
+
num = naturalLogarithm(arg, sd);
|
|
488
|
+
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
489
|
+
r = divide(num, denominator, sd, 1);
|
|
490
|
+
if (checkRoundingDigits(r.d, k = pr, rm)) {
|
|
491
|
+
do {
|
|
492
|
+
sd += 10;
|
|
493
|
+
num = naturalLogarithm(arg, sd);
|
|
494
|
+
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
495
|
+
r = divide(num, denominator, sd, 1);
|
|
496
|
+
if (!inf) {
|
|
497
|
+
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
|
498
|
+
r = finalise(r, pr + 1, 0);
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
} while (checkRoundingDigits(r.d, k += 10, rm));
|
|
503
|
+
}
|
|
504
|
+
external = true;
|
|
505
|
+
return finalise(r, pr, rm);
|
|
506
|
+
};
|
|
507
|
+
P.minus = P.sub = function(y) {
|
|
508
|
+
var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
|
509
|
+
y = new Ctor(y);
|
|
510
|
+
if (!x.d || !y.d) {
|
|
511
|
+
if (!x.s || !y.s)
|
|
512
|
+
y = new Ctor(NaN);
|
|
513
|
+
else if (x.d)
|
|
514
|
+
y.s = -y.s;
|
|
515
|
+
else
|
|
516
|
+
y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
|
517
|
+
return y;
|
|
518
|
+
}
|
|
519
|
+
if (x.s != y.s) {
|
|
520
|
+
y.s = -y.s;
|
|
521
|
+
return x.plus(y);
|
|
522
|
+
}
|
|
523
|
+
xd = x.d;
|
|
524
|
+
yd = y.d;
|
|
525
|
+
pr = Ctor.precision;
|
|
526
|
+
rm = Ctor.rounding;
|
|
527
|
+
if (!xd[0] || !yd[0]) {
|
|
528
|
+
if (yd[0])
|
|
529
|
+
y.s = -y.s;
|
|
530
|
+
else if (xd[0])
|
|
531
|
+
y = new Ctor(x);
|
|
532
|
+
else
|
|
533
|
+
return new Ctor(rm === 3 ? -0 : 0);
|
|
534
|
+
return external ? finalise(y, pr, rm) : y;
|
|
535
|
+
}
|
|
536
|
+
e = mathfloor(y.e / LOG_BASE);
|
|
537
|
+
xe = mathfloor(x.e / LOG_BASE);
|
|
538
|
+
xd = xd.slice();
|
|
539
|
+
k = xe - e;
|
|
540
|
+
if (k) {
|
|
541
|
+
xLTy = k < 0;
|
|
542
|
+
if (xLTy) {
|
|
543
|
+
d = xd;
|
|
544
|
+
k = -k;
|
|
545
|
+
len = yd.length;
|
|
546
|
+
} else {
|
|
547
|
+
d = yd;
|
|
548
|
+
e = xe;
|
|
549
|
+
len = xd.length;
|
|
550
|
+
}
|
|
551
|
+
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
552
|
+
if (k > i) {
|
|
553
|
+
k = i;
|
|
554
|
+
d.length = 1;
|
|
555
|
+
}
|
|
556
|
+
d.reverse();
|
|
557
|
+
for (i = k; i--; )
|
|
558
|
+
d.push(0);
|
|
559
|
+
d.reverse();
|
|
560
|
+
} else {
|
|
561
|
+
i = xd.length;
|
|
562
|
+
len = yd.length;
|
|
563
|
+
xLTy = i < len;
|
|
564
|
+
if (xLTy)
|
|
565
|
+
len = i;
|
|
566
|
+
for (i = 0; i < len; i++) {
|
|
567
|
+
if (xd[i] != yd[i]) {
|
|
568
|
+
xLTy = xd[i] < yd[i];
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
k = 0;
|
|
573
|
+
}
|
|
574
|
+
if (xLTy) {
|
|
575
|
+
d = xd;
|
|
576
|
+
xd = yd;
|
|
577
|
+
yd = d;
|
|
578
|
+
y.s = -y.s;
|
|
579
|
+
}
|
|
580
|
+
len = xd.length;
|
|
581
|
+
for (i = yd.length - len; i > 0; --i)
|
|
582
|
+
xd[len++] = 0;
|
|
583
|
+
for (i = yd.length; i > k; ) {
|
|
584
|
+
if (xd[--i] < yd[i]) {
|
|
585
|
+
for (j = i; j && xd[--j] === 0; )
|
|
586
|
+
xd[j] = BASE - 1;
|
|
587
|
+
--xd[j];
|
|
588
|
+
xd[i] += BASE;
|
|
589
|
+
}
|
|
590
|
+
xd[i] -= yd[i];
|
|
591
|
+
}
|
|
592
|
+
for (; xd[--len] === 0; )
|
|
593
|
+
xd.pop();
|
|
594
|
+
for (; xd[0] === 0; xd.shift())
|
|
595
|
+
--e;
|
|
596
|
+
if (!xd[0])
|
|
597
|
+
return new Ctor(rm === 3 ? -0 : 0);
|
|
598
|
+
y.d = xd;
|
|
599
|
+
y.e = getBase10Exponent(xd, e);
|
|
600
|
+
return external ? finalise(y, pr, rm) : y;
|
|
601
|
+
};
|
|
602
|
+
P.modulo = P.mod = function(y) {
|
|
603
|
+
var q, x = this, Ctor = x.constructor;
|
|
604
|
+
y = new Ctor(y);
|
|
605
|
+
if (!x.d || !y.s || y.d && !y.d[0])
|
|
606
|
+
return new Ctor(NaN);
|
|
607
|
+
if (!y.d || x.d && !x.d[0]) {
|
|
608
|
+
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
609
|
+
}
|
|
610
|
+
external = false;
|
|
611
|
+
if (Ctor.modulo == 9) {
|
|
612
|
+
q = divide(x, y.abs(), 0, 3, 1);
|
|
613
|
+
q.s *= y.s;
|
|
614
|
+
} else {
|
|
615
|
+
q = divide(x, y, 0, Ctor.modulo, 1);
|
|
616
|
+
}
|
|
617
|
+
q = q.times(y);
|
|
618
|
+
external = true;
|
|
619
|
+
return x.minus(q);
|
|
620
|
+
};
|
|
621
|
+
P.naturalExponential = P.exp = function() {
|
|
622
|
+
return naturalExponential(this);
|
|
623
|
+
};
|
|
624
|
+
P.naturalLogarithm = P.ln = function() {
|
|
625
|
+
return naturalLogarithm(this);
|
|
626
|
+
};
|
|
627
|
+
P.negated = P.neg = function() {
|
|
628
|
+
var x = new this.constructor(this);
|
|
629
|
+
x.s = -x.s;
|
|
630
|
+
return finalise(x);
|
|
631
|
+
};
|
|
632
|
+
P.plus = P.add = function(y) {
|
|
633
|
+
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
634
|
+
y = new Ctor(y);
|
|
635
|
+
if (!x.d || !y.d) {
|
|
636
|
+
if (!x.s || !y.s)
|
|
637
|
+
y = new Ctor(NaN);
|
|
638
|
+
else if (!x.d)
|
|
639
|
+
y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
640
|
+
return y;
|
|
641
|
+
}
|
|
642
|
+
if (x.s != y.s) {
|
|
643
|
+
y.s = -y.s;
|
|
644
|
+
return x.minus(y);
|
|
645
|
+
}
|
|
646
|
+
xd = x.d;
|
|
647
|
+
yd = y.d;
|
|
648
|
+
pr = Ctor.precision;
|
|
649
|
+
rm = Ctor.rounding;
|
|
650
|
+
if (!xd[0] || !yd[0]) {
|
|
651
|
+
if (!yd[0])
|
|
652
|
+
y = new Ctor(x);
|
|
653
|
+
return external ? finalise(y, pr, rm) : y;
|
|
654
|
+
}
|
|
655
|
+
k = mathfloor(x.e / LOG_BASE);
|
|
656
|
+
e = mathfloor(y.e / LOG_BASE);
|
|
657
|
+
xd = xd.slice();
|
|
658
|
+
i = k - e;
|
|
659
|
+
if (i) {
|
|
660
|
+
if (i < 0) {
|
|
661
|
+
d = xd;
|
|
662
|
+
i = -i;
|
|
663
|
+
len = yd.length;
|
|
664
|
+
} else {
|
|
665
|
+
d = yd;
|
|
666
|
+
e = k;
|
|
667
|
+
len = xd.length;
|
|
668
|
+
}
|
|
669
|
+
k = Math.ceil(pr / LOG_BASE);
|
|
670
|
+
len = k > len ? k + 1 : len + 1;
|
|
671
|
+
if (i > len) {
|
|
672
|
+
i = len;
|
|
673
|
+
d.length = 1;
|
|
674
|
+
}
|
|
675
|
+
d.reverse();
|
|
676
|
+
for (; i--; )
|
|
677
|
+
d.push(0);
|
|
678
|
+
d.reverse();
|
|
679
|
+
}
|
|
680
|
+
len = xd.length;
|
|
681
|
+
i = yd.length;
|
|
682
|
+
if (len - i < 0) {
|
|
683
|
+
i = len;
|
|
684
|
+
d = yd;
|
|
685
|
+
yd = xd;
|
|
686
|
+
xd = d;
|
|
687
|
+
}
|
|
688
|
+
for (carry = 0; i; ) {
|
|
689
|
+
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
690
|
+
xd[i] %= BASE;
|
|
691
|
+
}
|
|
692
|
+
if (carry) {
|
|
693
|
+
xd.unshift(carry);
|
|
694
|
+
++e;
|
|
695
|
+
}
|
|
696
|
+
for (len = xd.length; xd[--len] == 0; )
|
|
697
|
+
xd.pop();
|
|
698
|
+
y.d = xd;
|
|
699
|
+
y.e = getBase10Exponent(xd, e);
|
|
700
|
+
return external ? finalise(y, pr, rm) : y;
|
|
701
|
+
};
|
|
702
|
+
P.precision = P.sd = function(z) {
|
|
703
|
+
var k, x = this;
|
|
704
|
+
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
|
|
705
|
+
throw Error(invalidArgument + z);
|
|
706
|
+
if (x.d) {
|
|
707
|
+
k = getPrecision(x.d);
|
|
708
|
+
if (z && x.e + 1 > k)
|
|
709
|
+
k = x.e + 1;
|
|
710
|
+
} else {
|
|
711
|
+
k = NaN;
|
|
712
|
+
}
|
|
713
|
+
return k;
|
|
714
|
+
};
|
|
715
|
+
P.round = function() {
|
|
716
|
+
var x = this, Ctor = x.constructor;
|
|
717
|
+
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
|
718
|
+
};
|
|
719
|
+
P.sine = P.sin = function() {
|
|
720
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
721
|
+
if (!x.isFinite())
|
|
722
|
+
return new Ctor(NaN);
|
|
723
|
+
if (x.isZero())
|
|
724
|
+
return new Ctor(x);
|
|
725
|
+
pr = Ctor.precision;
|
|
726
|
+
rm = Ctor.rounding;
|
|
727
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
728
|
+
Ctor.rounding = 1;
|
|
729
|
+
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
730
|
+
Ctor.precision = pr;
|
|
731
|
+
Ctor.rounding = rm;
|
|
732
|
+
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
|
733
|
+
};
|
|
734
|
+
P.squareRoot = P.sqrt = function() {
|
|
735
|
+
var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
|
|
736
|
+
if (s !== 1 || !d || !d[0]) {
|
|
737
|
+
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
738
|
+
}
|
|
739
|
+
external = false;
|
|
740
|
+
s = Math.sqrt(+x);
|
|
741
|
+
if (s == 0 || s == 1 / 0) {
|
|
742
|
+
n = digitsToString(d);
|
|
743
|
+
if ((n.length + e) % 2 == 0)
|
|
744
|
+
n += "0";
|
|
745
|
+
s = Math.sqrt(n);
|
|
746
|
+
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
747
|
+
if (s == 1 / 0) {
|
|
748
|
+
n = "5e" + e;
|
|
749
|
+
} else {
|
|
750
|
+
n = s.toExponential();
|
|
751
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
752
|
+
}
|
|
753
|
+
r = new Ctor(n);
|
|
754
|
+
} else {
|
|
755
|
+
r = new Ctor(s.toString());
|
|
756
|
+
}
|
|
757
|
+
sd = (e = Ctor.precision) + 3;
|
|
758
|
+
for (; ; ) {
|
|
759
|
+
t = r;
|
|
760
|
+
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
|
761
|
+
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
762
|
+
n = n.slice(sd - 3, sd + 1);
|
|
763
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
764
|
+
if (!rep) {
|
|
765
|
+
finalise(t, e + 1, 0);
|
|
766
|
+
if (t.times(t).eq(x)) {
|
|
767
|
+
r = t;
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
sd += 4;
|
|
772
|
+
rep = 1;
|
|
773
|
+
} else {
|
|
774
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
775
|
+
finalise(r, e + 1, 1);
|
|
776
|
+
m = !r.times(r).eq(x);
|
|
777
|
+
}
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
external = true;
|
|
783
|
+
return finalise(r, e, Ctor.rounding, m);
|
|
784
|
+
};
|
|
785
|
+
P.tangent = P.tan = function() {
|
|
786
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
787
|
+
if (!x.isFinite())
|
|
788
|
+
return new Ctor(NaN);
|
|
789
|
+
if (x.isZero())
|
|
790
|
+
return new Ctor(x);
|
|
791
|
+
pr = Ctor.precision;
|
|
792
|
+
rm = Ctor.rounding;
|
|
793
|
+
Ctor.precision = pr + 10;
|
|
794
|
+
Ctor.rounding = 1;
|
|
795
|
+
x = x.sin();
|
|
796
|
+
x.s = 1;
|
|
797
|
+
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
|
798
|
+
Ctor.precision = pr;
|
|
799
|
+
Ctor.rounding = rm;
|
|
800
|
+
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
|
801
|
+
};
|
|
802
|
+
P.times = P.mul = function(y) {
|
|
803
|
+
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
804
|
+
y.s *= x.s;
|
|
805
|
+
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
806
|
+
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
807
|
+
}
|
|
808
|
+
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
809
|
+
xdL = xd.length;
|
|
810
|
+
ydL = yd.length;
|
|
811
|
+
if (xdL < ydL) {
|
|
812
|
+
r = xd;
|
|
813
|
+
xd = yd;
|
|
814
|
+
yd = r;
|
|
815
|
+
rL = xdL;
|
|
816
|
+
xdL = ydL;
|
|
817
|
+
ydL = rL;
|
|
818
|
+
}
|
|
819
|
+
r = [];
|
|
820
|
+
rL = xdL + ydL;
|
|
821
|
+
for (i = rL; i--; )
|
|
822
|
+
r.push(0);
|
|
823
|
+
for (i = ydL; --i >= 0; ) {
|
|
824
|
+
carry = 0;
|
|
825
|
+
for (k = xdL + i; k > i; ) {
|
|
826
|
+
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
827
|
+
r[k--] = t % BASE | 0;
|
|
828
|
+
carry = t / BASE | 0;
|
|
829
|
+
}
|
|
830
|
+
r[k] = (r[k] + carry) % BASE | 0;
|
|
831
|
+
}
|
|
832
|
+
for (; !r[--rL]; )
|
|
833
|
+
r.pop();
|
|
834
|
+
if (carry)
|
|
835
|
+
++e;
|
|
836
|
+
else
|
|
837
|
+
r.shift();
|
|
838
|
+
y.d = r;
|
|
839
|
+
y.e = getBase10Exponent(r, e);
|
|
840
|
+
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
841
|
+
};
|
|
842
|
+
P.toBinary = function(sd, rm) {
|
|
843
|
+
return toStringBinary(this, 2, sd, rm);
|
|
844
|
+
};
|
|
845
|
+
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
846
|
+
var x = this, Ctor = x.constructor;
|
|
847
|
+
x = new Ctor(x);
|
|
848
|
+
if (dp === void 0)
|
|
849
|
+
return x;
|
|
850
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
851
|
+
if (rm === void 0)
|
|
852
|
+
rm = Ctor.rounding;
|
|
853
|
+
else
|
|
854
|
+
checkInt32(rm, 0, 8);
|
|
855
|
+
return finalise(x, dp + x.e + 1, rm);
|
|
856
|
+
};
|
|
857
|
+
P.toExponential = function(dp, rm) {
|
|
858
|
+
var str, x = this, Ctor = x.constructor;
|
|
859
|
+
if (dp === void 0) {
|
|
860
|
+
str = finiteToString(x, true);
|
|
861
|
+
} else {
|
|
862
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
863
|
+
if (rm === void 0)
|
|
864
|
+
rm = Ctor.rounding;
|
|
865
|
+
else
|
|
866
|
+
checkInt32(rm, 0, 8);
|
|
867
|
+
x = finalise(new Ctor(x), dp + 1, rm);
|
|
868
|
+
str = finiteToString(x, true, dp + 1);
|
|
869
|
+
}
|
|
870
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
871
|
+
};
|
|
872
|
+
P.toFixed = function(dp, rm) {
|
|
873
|
+
var str, y, x = this, Ctor = x.constructor;
|
|
874
|
+
if (dp === void 0) {
|
|
875
|
+
str = finiteToString(x);
|
|
876
|
+
} else {
|
|
877
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
878
|
+
if (rm === void 0)
|
|
879
|
+
rm = Ctor.rounding;
|
|
880
|
+
else
|
|
881
|
+
checkInt32(rm, 0, 8);
|
|
882
|
+
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
883
|
+
str = finiteToString(y, false, dp + y.e + 1);
|
|
884
|
+
}
|
|
885
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
886
|
+
};
|
|
887
|
+
P.toFraction = function(maxD) {
|
|
888
|
+
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
889
|
+
if (!xd)
|
|
890
|
+
return new Ctor(x);
|
|
891
|
+
n1 = d0 = new Ctor(1);
|
|
892
|
+
d1 = n0 = new Ctor(0);
|
|
893
|
+
d = new Ctor(d1);
|
|
894
|
+
e = d.e = getPrecision(xd) - x.e - 1;
|
|
895
|
+
k = e % LOG_BASE;
|
|
896
|
+
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
897
|
+
if (maxD == null) {
|
|
898
|
+
maxD = e > 0 ? d : n1;
|
|
899
|
+
} else {
|
|
900
|
+
n = new Ctor(maxD);
|
|
901
|
+
if (!n.isInt() || n.lt(n1))
|
|
902
|
+
throw Error(invalidArgument + n);
|
|
903
|
+
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
904
|
+
}
|
|
905
|
+
external = false;
|
|
906
|
+
n = new Ctor(digitsToString(xd));
|
|
907
|
+
pr = Ctor.precision;
|
|
908
|
+
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
909
|
+
for (; ; ) {
|
|
910
|
+
q = divide(n, d, 0, 1, 1);
|
|
911
|
+
d2 = d0.plus(q.times(d1));
|
|
912
|
+
if (d2.cmp(maxD) == 1)
|
|
913
|
+
break;
|
|
914
|
+
d0 = d1;
|
|
915
|
+
d1 = d2;
|
|
916
|
+
d2 = n1;
|
|
917
|
+
n1 = n0.plus(q.times(d2));
|
|
918
|
+
n0 = d2;
|
|
919
|
+
d2 = d;
|
|
920
|
+
d = n.minus(q.times(d2));
|
|
921
|
+
n = d2;
|
|
922
|
+
}
|
|
923
|
+
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
924
|
+
n0 = n0.plus(d2.times(n1));
|
|
925
|
+
d0 = d0.plus(d2.times(d1));
|
|
926
|
+
n0.s = n1.s = x.s;
|
|
927
|
+
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
928
|
+
Ctor.precision = pr;
|
|
929
|
+
external = true;
|
|
930
|
+
return r;
|
|
931
|
+
};
|
|
932
|
+
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
933
|
+
return toStringBinary(this, 16, sd, rm);
|
|
934
|
+
};
|
|
935
|
+
P.toNearest = function(y, rm) {
|
|
936
|
+
var x = this, Ctor = x.constructor;
|
|
937
|
+
x = new Ctor(x);
|
|
938
|
+
if (y == null) {
|
|
939
|
+
if (!x.d)
|
|
940
|
+
return x;
|
|
941
|
+
y = new Ctor(1);
|
|
942
|
+
rm = Ctor.rounding;
|
|
943
|
+
} else {
|
|
944
|
+
y = new Ctor(y);
|
|
945
|
+
if (rm === void 0) {
|
|
946
|
+
rm = Ctor.rounding;
|
|
947
|
+
} else {
|
|
948
|
+
checkInt32(rm, 0, 8);
|
|
949
|
+
}
|
|
950
|
+
if (!x.d)
|
|
951
|
+
return y.s ? x : y;
|
|
952
|
+
if (!y.d) {
|
|
953
|
+
if (y.s)
|
|
954
|
+
y.s = x.s;
|
|
955
|
+
return y;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if (y.d[0]) {
|
|
959
|
+
external = false;
|
|
960
|
+
x = divide(x, y, 0, rm, 1).times(y);
|
|
961
|
+
external = true;
|
|
962
|
+
finalise(x);
|
|
963
|
+
} else {
|
|
964
|
+
y.s = x.s;
|
|
965
|
+
x = y;
|
|
966
|
+
}
|
|
967
|
+
return x;
|
|
968
|
+
};
|
|
969
|
+
P.toNumber = function() {
|
|
970
|
+
return +this;
|
|
971
|
+
};
|
|
972
|
+
P.toOctal = function(sd, rm) {
|
|
973
|
+
return toStringBinary(this, 8, sd, rm);
|
|
974
|
+
};
|
|
975
|
+
P.toPower = P.pow = function(y) {
|
|
976
|
+
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
977
|
+
if (!x.d || !y.d || !x.d[0] || !y.d[0])
|
|
978
|
+
return new Ctor(mathpow(+x, yn));
|
|
979
|
+
x = new Ctor(x);
|
|
980
|
+
if (x.eq(1))
|
|
981
|
+
return x;
|
|
982
|
+
pr = Ctor.precision;
|
|
983
|
+
rm = Ctor.rounding;
|
|
984
|
+
if (y.eq(1))
|
|
985
|
+
return finalise(x, pr, rm);
|
|
986
|
+
e = mathfloor(y.e / LOG_BASE);
|
|
987
|
+
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
988
|
+
r = intPow(Ctor, x, k, pr);
|
|
989
|
+
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
990
|
+
}
|
|
991
|
+
s = x.s;
|
|
992
|
+
if (s < 0) {
|
|
993
|
+
if (e < y.d.length - 1)
|
|
994
|
+
return new Ctor(NaN);
|
|
995
|
+
if ((y.d[e] & 1) == 0)
|
|
996
|
+
s = 1;
|
|
997
|
+
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
998
|
+
x.s = s;
|
|
999
|
+
return x;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
k = mathpow(+x, yn);
|
|
1003
|
+
e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
|
|
1004
|
+
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
|
|
1005
|
+
return new Ctor(e > 0 ? s / 0 : 0);
|
|
1006
|
+
external = false;
|
|
1007
|
+
Ctor.rounding = x.s = 1;
|
|
1008
|
+
k = Math.min(12, (e + "").length);
|
|
1009
|
+
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
|
1010
|
+
if (r.d) {
|
|
1011
|
+
r = finalise(r, pr + 5, 1);
|
|
1012
|
+
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
1013
|
+
e = pr + 10;
|
|
1014
|
+
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
1015
|
+
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
|
1016
|
+
r = finalise(r, pr + 1, 0);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
r.s = s;
|
|
1021
|
+
external = true;
|
|
1022
|
+
Ctor.rounding = rm;
|
|
1023
|
+
return finalise(r, pr, rm);
|
|
1024
|
+
};
|
|
1025
|
+
P.toPrecision = function(sd, rm) {
|
|
1026
|
+
var str, x = this, Ctor = x.constructor;
|
|
1027
|
+
if (sd === void 0) {
|
|
1028
|
+
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1029
|
+
} else {
|
|
1030
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
1031
|
+
if (rm === void 0)
|
|
1032
|
+
rm = Ctor.rounding;
|
|
1033
|
+
else
|
|
1034
|
+
checkInt32(rm, 0, 8);
|
|
1035
|
+
x = finalise(new Ctor(x), sd, rm);
|
|
1036
|
+
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
1037
|
+
}
|
|
1038
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
1039
|
+
};
|
|
1040
|
+
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
1041
|
+
var x = this, Ctor = x.constructor;
|
|
1042
|
+
if (sd === void 0) {
|
|
1043
|
+
sd = Ctor.precision;
|
|
1044
|
+
rm = Ctor.rounding;
|
|
1045
|
+
} else {
|
|
1046
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
1047
|
+
if (rm === void 0)
|
|
1048
|
+
rm = Ctor.rounding;
|
|
1049
|
+
else
|
|
1050
|
+
checkInt32(rm, 0, 8);
|
|
1051
|
+
}
|
|
1052
|
+
return finalise(new Ctor(x), sd, rm);
|
|
1053
|
+
};
|
|
1054
|
+
P.toString = function() {
|
|
1055
|
+
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1056
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
1057
|
+
};
|
|
1058
|
+
P.truncated = P.trunc = function() {
|
|
1059
|
+
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
1060
|
+
};
|
|
1061
|
+
P.valueOf = P.toJSON = function() {
|
|
1062
|
+
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1063
|
+
return x.isNeg() ? "-" + str : str;
|
|
1064
|
+
};
|
|
1065
|
+
function digitsToString(d) {
|
|
1066
|
+
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
1067
|
+
if (indexOfLastWord > 0) {
|
|
1068
|
+
str += w;
|
|
1069
|
+
for (i = 1; i < indexOfLastWord; i++) {
|
|
1070
|
+
ws = d[i] + "";
|
|
1071
|
+
k = LOG_BASE - ws.length;
|
|
1072
|
+
if (k)
|
|
1073
|
+
str += getZeroString(k);
|
|
1074
|
+
str += ws;
|
|
1075
|
+
}
|
|
1076
|
+
w = d[i];
|
|
1077
|
+
ws = w + "";
|
|
1078
|
+
k = LOG_BASE - ws.length;
|
|
1079
|
+
if (k)
|
|
1080
|
+
str += getZeroString(k);
|
|
1081
|
+
} else if (w === 0) {
|
|
1082
|
+
return "0";
|
|
1083
|
+
}
|
|
1084
|
+
for (; w % 10 === 0; )
|
|
1085
|
+
w /= 10;
|
|
1086
|
+
return str + w;
|
|
1087
|
+
}
|
|
1088
|
+
function checkInt32(i, min2, max2) {
|
|
1089
|
+
if (i !== ~~i || i < min2 || i > max2) {
|
|
1090
|
+
throw Error(invalidArgument + i);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function checkRoundingDigits(d, i, rm, repeating) {
|
|
1094
|
+
var di, k, r, rd;
|
|
1095
|
+
for (k = d[0]; k >= 10; k /= 10)
|
|
1096
|
+
--i;
|
|
1097
|
+
if (--i < 0) {
|
|
1098
|
+
i += LOG_BASE;
|
|
1099
|
+
di = 0;
|
|
1100
|
+
} else {
|
|
1101
|
+
di = Math.ceil((i + 1) / LOG_BASE);
|
|
1102
|
+
i %= LOG_BASE;
|
|
1103
|
+
}
|
|
1104
|
+
k = mathpow(10, LOG_BASE - i);
|
|
1105
|
+
rd = d[di] % k | 0;
|
|
1106
|
+
if (repeating == null) {
|
|
1107
|
+
if (i < 3) {
|
|
1108
|
+
if (i == 0)
|
|
1109
|
+
rd = rd / 100 | 0;
|
|
1110
|
+
else if (i == 1)
|
|
1111
|
+
rd = rd / 10 | 0;
|
|
1112
|
+
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
|
1113
|
+
} else {
|
|
1114
|
+
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;
|
|
1115
|
+
}
|
|
1116
|
+
} else {
|
|
1117
|
+
if (i < 4) {
|
|
1118
|
+
if (i == 0)
|
|
1119
|
+
rd = rd / 1e3 | 0;
|
|
1120
|
+
else if (i == 1)
|
|
1121
|
+
rd = rd / 100 | 0;
|
|
1122
|
+
else if (i == 2)
|
|
1123
|
+
rd = rd / 10 | 0;
|
|
1124
|
+
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
1125
|
+
} else {
|
|
1126
|
+
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;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
return r;
|
|
1130
|
+
}
|
|
1131
|
+
function convertBase(str, baseIn, baseOut) {
|
|
1132
|
+
var j, arr = [0], arrL, i = 0, strL = str.length;
|
|
1133
|
+
for (; i < strL; ) {
|
|
1134
|
+
for (arrL = arr.length; arrL--; )
|
|
1135
|
+
arr[arrL] *= baseIn;
|
|
1136
|
+
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
1137
|
+
for (j = 0; j < arr.length; j++) {
|
|
1138
|
+
if (arr[j] > baseOut - 1) {
|
|
1139
|
+
if (arr[j + 1] === void 0)
|
|
1140
|
+
arr[j + 1] = 0;
|
|
1141
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
1142
|
+
arr[j] %= baseOut;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return arr.reverse();
|
|
1147
|
+
}
|
|
1148
|
+
function cosine(Ctor, x) {
|
|
1149
|
+
var k, len, y;
|
|
1150
|
+
if (x.isZero())
|
|
1151
|
+
return x;
|
|
1152
|
+
len = x.d.length;
|
|
1153
|
+
if (len < 32) {
|
|
1154
|
+
k = Math.ceil(len / 3);
|
|
1155
|
+
y = (1 / tinyPow(4, k)).toString();
|
|
1156
|
+
} else {
|
|
1157
|
+
k = 16;
|
|
1158
|
+
y = "2.3283064365386962890625e-10";
|
|
1159
|
+
}
|
|
1160
|
+
Ctor.precision += k;
|
|
1161
|
+
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
|
1162
|
+
for (var i = k; i--; ) {
|
|
1163
|
+
var cos2x = x.times(x);
|
|
1164
|
+
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
1165
|
+
}
|
|
1166
|
+
Ctor.precision -= k;
|
|
1167
|
+
return x;
|
|
1168
|
+
}
|
|
1169
|
+
var divide = /* @__PURE__ */ function() {
|
|
1170
|
+
function multiplyInteger(x, k, base) {
|
|
1171
|
+
var temp, carry = 0, i = x.length;
|
|
1172
|
+
for (x = x.slice(); i--; ) {
|
|
1173
|
+
temp = x[i] * k + carry;
|
|
1174
|
+
x[i] = temp % base | 0;
|
|
1175
|
+
carry = temp / base | 0;
|
|
1176
|
+
}
|
|
1177
|
+
if (carry)
|
|
1178
|
+
x.unshift(carry);
|
|
1179
|
+
return x;
|
|
1180
|
+
}
|
|
1181
|
+
function compare(a, b, aL, bL) {
|
|
1182
|
+
var i, r;
|
|
1183
|
+
if (aL != bL) {
|
|
1184
|
+
r = aL > bL ? 1 : -1;
|
|
1185
|
+
} else {
|
|
1186
|
+
for (i = r = 0; i < aL; i++) {
|
|
1187
|
+
if (a[i] != b[i]) {
|
|
1188
|
+
r = a[i] > b[i] ? 1 : -1;
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return r;
|
|
1194
|
+
}
|
|
1195
|
+
function subtract(a, b, aL, base) {
|
|
1196
|
+
var i = 0;
|
|
1197
|
+
for (; aL--; ) {
|
|
1198
|
+
a[aL] -= i;
|
|
1199
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
1200
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
1201
|
+
}
|
|
1202
|
+
for (; !a[0] && a.length > 1; )
|
|
1203
|
+
a.shift();
|
|
1204
|
+
}
|
|
1205
|
+
return function(x, y, pr, rm, dp, base) {
|
|
1206
|
+
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;
|
|
1207
|
+
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
1208
|
+
return new Ctor(
|
|
1209
|
+
// Return NaN if either NaN, or both Infinity or 0.
|
|
1210
|
+
!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
|
|
1211
|
+
// Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
|
|
1212
|
+
xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
|
|
1213
|
+
)
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
if (base) {
|
|
1217
|
+
logBase = 1;
|
|
1218
|
+
e = x.e - y.e;
|
|
1219
|
+
} else {
|
|
1220
|
+
base = BASE;
|
|
1221
|
+
logBase = LOG_BASE;
|
|
1222
|
+
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
|
1223
|
+
}
|
|
1224
|
+
yL = yd.length;
|
|
1225
|
+
xL = xd.length;
|
|
1226
|
+
q = new Ctor(sign2);
|
|
1227
|
+
qd = q.d = [];
|
|
1228
|
+
for (i = 0; yd[i] == (xd[i] || 0); i++)
|
|
1229
|
+
;
|
|
1230
|
+
if (yd[i] > (xd[i] || 0))
|
|
1231
|
+
e--;
|
|
1232
|
+
if (pr == null) {
|
|
1233
|
+
sd = pr = Ctor.precision;
|
|
1234
|
+
rm = Ctor.rounding;
|
|
1235
|
+
} else if (dp) {
|
|
1236
|
+
sd = pr + (x.e - y.e) + 1;
|
|
1237
|
+
} else {
|
|
1238
|
+
sd = pr;
|
|
1239
|
+
}
|
|
1240
|
+
if (sd < 0) {
|
|
1241
|
+
qd.push(1);
|
|
1242
|
+
more = true;
|
|
1243
|
+
} else {
|
|
1244
|
+
sd = sd / logBase + 2 | 0;
|
|
1245
|
+
i = 0;
|
|
1246
|
+
if (yL == 1) {
|
|
1247
|
+
k = 0;
|
|
1248
|
+
yd = yd[0];
|
|
1249
|
+
sd++;
|
|
1250
|
+
for (; (i < xL || k) && sd--; i++) {
|
|
1251
|
+
t = k * base + (xd[i] || 0);
|
|
1252
|
+
qd[i] = t / yd | 0;
|
|
1253
|
+
k = t % yd | 0;
|
|
1254
|
+
}
|
|
1255
|
+
more = k || i < xL;
|
|
1256
|
+
} else {
|
|
1257
|
+
k = base / (yd[0] + 1) | 0;
|
|
1258
|
+
if (k > 1) {
|
|
1259
|
+
yd = multiplyInteger(yd, k, base);
|
|
1260
|
+
xd = multiplyInteger(xd, k, base);
|
|
1261
|
+
yL = yd.length;
|
|
1262
|
+
xL = xd.length;
|
|
1263
|
+
}
|
|
1264
|
+
xi = yL;
|
|
1265
|
+
rem = xd.slice(0, yL);
|
|
1266
|
+
remL = rem.length;
|
|
1267
|
+
for (; remL < yL; )
|
|
1268
|
+
rem[remL++] = 0;
|
|
1269
|
+
yz = yd.slice();
|
|
1270
|
+
yz.unshift(0);
|
|
1271
|
+
yd0 = yd[0];
|
|
1272
|
+
if (yd[1] >= base / 2)
|
|
1273
|
+
++yd0;
|
|
1274
|
+
do {
|
|
1275
|
+
k = 0;
|
|
1276
|
+
cmp = compare(yd, rem, yL, remL);
|
|
1277
|
+
if (cmp < 0) {
|
|
1278
|
+
rem0 = rem[0];
|
|
1279
|
+
if (yL != remL)
|
|
1280
|
+
rem0 = rem0 * base + (rem[1] || 0);
|
|
1281
|
+
k = rem0 / yd0 | 0;
|
|
1282
|
+
if (k > 1) {
|
|
1283
|
+
if (k >= base)
|
|
1284
|
+
k = base - 1;
|
|
1285
|
+
prod = multiplyInteger(yd, k, base);
|
|
1286
|
+
prodL = prod.length;
|
|
1287
|
+
remL = rem.length;
|
|
1288
|
+
cmp = compare(prod, rem, prodL, remL);
|
|
1289
|
+
if (cmp == 1) {
|
|
1290
|
+
k--;
|
|
1291
|
+
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
1292
|
+
}
|
|
1293
|
+
} else {
|
|
1294
|
+
if (k == 0)
|
|
1295
|
+
cmp = k = 1;
|
|
1296
|
+
prod = yd.slice();
|
|
1297
|
+
}
|
|
1298
|
+
prodL = prod.length;
|
|
1299
|
+
if (prodL < remL)
|
|
1300
|
+
prod.unshift(0);
|
|
1301
|
+
subtract(rem, prod, remL, base);
|
|
1302
|
+
if (cmp == -1) {
|
|
1303
|
+
remL = rem.length;
|
|
1304
|
+
cmp = compare(yd, rem, yL, remL);
|
|
1305
|
+
if (cmp < 1) {
|
|
1306
|
+
k++;
|
|
1307
|
+
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
remL = rem.length;
|
|
1311
|
+
} else if (cmp === 0) {
|
|
1312
|
+
k++;
|
|
1313
|
+
rem = [0];
|
|
1314
|
+
}
|
|
1315
|
+
qd[i++] = k;
|
|
1316
|
+
if (cmp && rem[0]) {
|
|
1317
|
+
rem[remL++] = xd[xi] || 0;
|
|
1318
|
+
} else {
|
|
1319
|
+
rem = [xd[xi]];
|
|
1320
|
+
remL = 1;
|
|
1321
|
+
}
|
|
1322
|
+
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
1323
|
+
more = rem[0] !== void 0;
|
|
1324
|
+
}
|
|
1325
|
+
if (!qd[0])
|
|
1326
|
+
qd.shift();
|
|
1327
|
+
}
|
|
1328
|
+
if (logBase == 1) {
|
|
1329
|
+
q.e = e;
|
|
1330
|
+
inexact = more;
|
|
1331
|
+
} else {
|
|
1332
|
+
for (i = 1, k = qd[0]; k >= 10; k /= 10)
|
|
1333
|
+
i++;
|
|
1334
|
+
q.e = i + e * logBase - 1;
|
|
1335
|
+
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
1336
|
+
}
|
|
1337
|
+
return q;
|
|
1338
|
+
};
|
|
1339
|
+
}();
|
|
1340
|
+
function finalise(x, sd, rm, isTruncated) {
|
|
1341
|
+
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
1342
|
+
out:
|
|
1343
|
+
if (sd != null) {
|
|
1344
|
+
xd = x.d;
|
|
1345
|
+
if (!xd)
|
|
1346
|
+
return x;
|
|
1347
|
+
for (digits = 1, k = xd[0]; k >= 10; k /= 10)
|
|
1348
|
+
digits++;
|
|
1349
|
+
i = sd - digits;
|
|
1350
|
+
if (i < 0) {
|
|
1351
|
+
i += LOG_BASE;
|
|
1352
|
+
j = sd;
|
|
1353
|
+
w = xd[xdi = 0];
|
|
1354
|
+
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
1355
|
+
} else {
|
|
1356
|
+
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
1357
|
+
k = xd.length;
|
|
1358
|
+
if (xdi >= k) {
|
|
1359
|
+
if (isTruncated) {
|
|
1360
|
+
for (; k++ <= xdi; )
|
|
1361
|
+
xd.push(0);
|
|
1362
|
+
w = rd = 0;
|
|
1363
|
+
digits = 1;
|
|
1364
|
+
i %= LOG_BASE;
|
|
1365
|
+
j = i - LOG_BASE + 1;
|
|
1366
|
+
} else {
|
|
1367
|
+
break out;
|
|
1368
|
+
}
|
|
1369
|
+
} else {
|
|
1370
|
+
w = k = xd[xdi];
|
|
1371
|
+
for (digits = 1; k >= 10; k /= 10)
|
|
1372
|
+
digits++;
|
|
1373
|
+
i %= LOG_BASE;
|
|
1374
|
+
j = i - LOG_BASE + digits;
|
|
1375
|
+
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
1379
|
+
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.
|
|
1380
|
+
(i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
1381
|
+
if (sd < 1 || !xd[0]) {
|
|
1382
|
+
xd.length = 0;
|
|
1383
|
+
if (roundUp) {
|
|
1384
|
+
sd -= x.e + 1;
|
|
1385
|
+
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
1386
|
+
x.e = -sd || 0;
|
|
1387
|
+
} else {
|
|
1388
|
+
xd[0] = x.e = 0;
|
|
1389
|
+
}
|
|
1390
|
+
return x;
|
|
1391
|
+
}
|
|
1392
|
+
if (i == 0) {
|
|
1393
|
+
xd.length = xdi;
|
|
1394
|
+
k = 1;
|
|
1395
|
+
xdi--;
|
|
1396
|
+
} else {
|
|
1397
|
+
xd.length = xdi + 1;
|
|
1398
|
+
k = mathpow(10, LOG_BASE - i);
|
|
1399
|
+
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
1400
|
+
}
|
|
1401
|
+
if (roundUp) {
|
|
1402
|
+
for (; ; ) {
|
|
1403
|
+
if (xdi == 0) {
|
|
1404
|
+
for (i = 1, j = xd[0]; j >= 10; j /= 10)
|
|
1405
|
+
i++;
|
|
1406
|
+
j = xd[0] += k;
|
|
1407
|
+
for (k = 1; j >= 10; j /= 10)
|
|
1408
|
+
k++;
|
|
1409
|
+
if (i != k) {
|
|
1410
|
+
x.e++;
|
|
1411
|
+
if (xd[0] == BASE)
|
|
1412
|
+
xd[0] = 1;
|
|
1413
|
+
}
|
|
1414
|
+
break;
|
|
1415
|
+
} else {
|
|
1416
|
+
xd[xdi] += k;
|
|
1417
|
+
if (xd[xdi] != BASE)
|
|
1418
|
+
break;
|
|
1419
|
+
xd[xdi--] = 0;
|
|
1420
|
+
k = 1;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
for (i = xd.length; xd[--i] === 0; )
|
|
1425
|
+
xd.pop();
|
|
1426
|
+
}
|
|
1427
|
+
if (external) {
|
|
1428
|
+
if (x.e > Ctor.maxE) {
|
|
1429
|
+
x.d = null;
|
|
1430
|
+
x.e = NaN;
|
|
1431
|
+
} else if (x.e < Ctor.minE) {
|
|
1432
|
+
x.e = 0;
|
|
1433
|
+
x.d = [0];
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
return x;
|
|
1437
|
+
}
|
|
1438
|
+
function finiteToString(x, isExp, sd) {
|
|
1439
|
+
if (!x.isFinite())
|
|
1440
|
+
return nonFiniteToString(x);
|
|
1441
|
+
var k, e = x.e, str = digitsToString(x.d), len = str.length;
|
|
1442
|
+
if (isExp) {
|
|
1443
|
+
if (sd && (k = sd - len) > 0) {
|
|
1444
|
+
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
1445
|
+
} else if (len > 1) {
|
|
1446
|
+
str = str.charAt(0) + "." + str.slice(1);
|
|
1447
|
+
}
|
|
1448
|
+
str = str + (x.e < 0 ? "e" : "e+") + x.e;
|
|
1449
|
+
} else if (e < 0) {
|
|
1450
|
+
str = "0." + getZeroString(-e - 1) + str;
|
|
1451
|
+
if (sd && (k = sd - len) > 0)
|
|
1452
|
+
str += getZeroString(k);
|
|
1453
|
+
} else if (e >= len) {
|
|
1454
|
+
str += getZeroString(e + 1 - len);
|
|
1455
|
+
if (sd && (k = sd - e - 1) > 0)
|
|
1456
|
+
str = str + "." + getZeroString(k);
|
|
1457
|
+
} else {
|
|
1458
|
+
if ((k = e + 1) < len)
|
|
1459
|
+
str = str.slice(0, k) + "." + str.slice(k);
|
|
1460
|
+
if (sd && (k = sd - len) > 0) {
|
|
1461
|
+
if (e + 1 === len)
|
|
1462
|
+
str += ".";
|
|
1463
|
+
str += getZeroString(k);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return str;
|
|
1467
|
+
}
|
|
1468
|
+
function getBase10Exponent(digits, e) {
|
|
1469
|
+
var w = digits[0];
|
|
1470
|
+
for (e *= LOG_BASE; w >= 10; w /= 10)
|
|
1471
|
+
e++;
|
|
1472
|
+
return e;
|
|
1473
|
+
}
|
|
1474
|
+
function getLn10(Ctor, sd, pr) {
|
|
1475
|
+
if (sd > LN10_PRECISION) {
|
|
1476
|
+
external = true;
|
|
1477
|
+
if (pr)
|
|
1478
|
+
Ctor.precision = pr;
|
|
1479
|
+
throw Error(precisionLimitExceeded);
|
|
1480
|
+
}
|
|
1481
|
+
return finalise(new Ctor(LN10), sd, 1, true);
|
|
1482
|
+
}
|
|
1483
|
+
function getPi(Ctor, sd, rm) {
|
|
1484
|
+
if (sd > PI_PRECISION)
|
|
1485
|
+
throw Error(precisionLimitExceeded);
|
|
1486
|
+
return finalise(new Ctor(PI), sd, rm, true);
|
|
1487
|
+
}
|
|
1488
|
+
function getPrecision(digits) {
|
|
1489
|
+
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
1490
|
+
w = digits[w];
|
|
1491
|
+
if (w) {
|
|
1492
|
+
for (; w % 10 == 0; w /= 10)
|
|
1493
|
+
len--;
|
|
1494
|
+
for (w = digits[0]; w >= 10; w /= 10)
|
|
1495
|
+
len++;
|
|
1496
|
+
}
|
|
1497
|
+
return len;
|
|
1498
|
+
}
|
|
1499
|
+
function getZeroString(k) {
|
|
1500
|
+
var zs = "";
|
|
1501
|
+
for (; k--; )
|
|
1502
|
+
zs += "0";
|
|
1503
|
+
return zs;
|
|
1504
|
+
}
|
|
1505
|
+
function intPow(Ctor, x, n, pr) {
|
|
1506
|
+
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
1507
|
+
external = false;
|
|
1508
|
+
for (; ; ) {
|
|
1509
|
+
if (n % 2) {
|
|
1510
|
+
r = r.times(x);
|
|
1511
|
+
if (truncate(r.d, k))
|
|
1512
|
+
isTruncated = true;
|
|
1513
|
+
}
|
|
1514
|
+
n = mathfloor(n / 2);
|
|
1515
|
+
if (n === 0) {
|
|
1516
|
+
n = r.d.length - 1;
|
|
1517
|
+
if (isTruncated && r.d[n] === 0)
|
|
1518
|
+
++r.d[n];
|
|
1519
|
+
break;
|
|
1520
|
+
}
|
|
1521
|
+
x = x.times(x);
|
|
1522
|
+
truncate(x.d, k);
|
|
1523
|
+
}
|
|
1524
|
+
external = true;
|
|
1525
|
+
return r;
|
|
1526
|
+
}
|
|
1527
|
+
function isOdd(n) {
|
|
1528
|
+
return n.d[n.d.length - 1] & 1;
|
|
1529
|
+
}
|
|
1530
|
+
function maxOrMin(Ctor, args, ltgt) {
|
|
1531
|
+
var y, x = new Ctor(args[0]), i = 0;
|
|
1532
|
+
for (; ++i < args.length; ) {
|
|
1533
|
+
y = new Ctor(args[i]);
|
|
1534
|
+
if (!y.s) {
|
|
1535
|
+
x = y;
|
|
1536
|
+
break;
|
|
1537
|
+
} else if (x[ltgt](y)) {
|
|
1538
|
+
x = y;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return x;
|
|
1542
|
+
}
|
|
1543
|
+
function naturalExponential(x, sd) {
|
|
1544
|
+
var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
1545
|
+
if (!x.d || !x.d[0] || x.e > 17) {
|
|
1546
|
+
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
|
1547
|
+
}
|
|
1548
|
+
if (sd == null) {
|
|
1549
|
+
external = false;
|
|
1550
|
+
wpr = pr;
|
|
1551
|
+
} else {
|
|
1552
|
+
wpr = sd;
|
|
1553
|
+
}
|
|
1554
|
+
t = new Ctor(0.03125);
|
|
1555
|
+
while (x.e > -2) {
|
|
1556
|
+
x = x.times(t);
|
|
1557
|
+
k += 5;
|
|
1558
|
+
}
|
|
1559
|
+
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
1560
|
+
wpr += guard;
|
|
1561
|
+
denominator = pow2 = sum2 = new Ctor(1);
|
|
1562
|
+
Ctor.precision = wpr;
|
|
1563
|
+
for (; ; ) {
|
|
1564
|
+
pow2 = finalise(pow2.times(x), wpr, 1);
|
|
1565
|
+
denominator = denominator.times(++i);
|
|
1566
|
+
t = sum2.plus(divide(pow2, denominator, wpr, 1));
|
|
1567
|
+
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1568
|
+
j = k;
|
|
1569
|
+
while (j--)
|
|
1570
|
+
sum2 = finalise(sum2.times(sum2), wpr, 1);
|
|
1571
|
+
if (sd == null) {
|
|
1572
|
+
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1573
|
+
Ctor.precision = wpr += 10;
|
|
1574
|
+
denominator = pow2 = t = new Ctor(1);
|
|
1575
|
+
i = 0;
|
|
1576
|
+
rep++;
|
|
1577
|
+
} else {
|
|
1578
|
+
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
1579
|
+
}
|
|
1580
|
+
} else {
|
|
1581
|
+
Ctor.precision = pr;
|
|
1582
|
+
return sum2;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
sum2 = t;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
function naturalLogarithm(y, sd) {
|
|
1589
|
+
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;
|
|
1590
|
+
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
|
1591
|
+
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
|
1592
|
+
}
|
|
1593
|
+
if (sd == null) {
|
|
1594
|
+
external = false;
|
|
1595
|
+
wpr = pr;
|
|
1596
|
+
} else {
|
|
1597
|
+
wpr = sd;
|
|
1598
|
+
}
|
|
1599
|
+
Ctor.precision = wpr += guard;
|
|
1600
|
+
c = digitsToString(xd);
|
|
1601
|
+
c0 = c.charAt(0);
|
|
1602
|
+
if (Math.abs(e = x.e) < 15e14) {
|
|
1603
|
+
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
1604
|
+
x = x.times(y);
|
|
1605
|
+
c = digitsToString(x.d);
|
|
1606
|
+
c0 = c.charAt(0);
|
|
1607
|
+
n++;
|
|
1608
|
+
}
|
|
1609
|
+
e = x.e;
|
|
1610
|
+
if (c0 > 1) {
|
|
1611
|
+
x = new Ctor("0." + c);
|
|
1612
|
+
e++;
|
|
1613
|
+
} else {
|
|
1614
|
+
x = new Ctor(c0 + "." + c.slice(1));
|
|
1615
|
+
}
|
|
1616
|
+
} else {
|
|
1617
|
+
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
1618
|
+
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
1619
|
+
Ctor.precision = pr;
|
|
1620
|
+
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
|
1621
|
+
}
|
|
1622
|
+
x1 = x;
|
|
1623
|
+
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
1624
|
+
x2 = finalise(x.times(x), wpr, 1);
|
|
1625
|
+
denominator = 3;
|
|
1626
|
+
for (; ; ) {
|
|
1627
|
+
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
1628
|
+
t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
1629
|
+
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1630
|
+
sum2 = sum2.times(2);
|
|
1631
|
+
if (e !== 0)
|
|
1632
|
+
sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
1633
|
+
sum2 = divide(sum2, new Ctor(n), wpr, 1);
|
|
1634
|
+
if (sd == null) {
|
|
1635
|
+
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1636
|
+
Ctor.precision = wpr += guard;
|
|
1637
|
+
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
1638
|
+
x2 = finalise(x.times(x), wpr, 1);
|
|
1639
|
+
denominator = rep = 1;
|
|
1640
|
+
} else {
|
|
1641
|
+
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
1642
|
+
}
|
|
1643
|
+
} else {
|
|
1644
|
+
Ctor.precision = pr;
|
|
1645
|
+
return sum2;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
sum2 = t;
|
|
1649
|
+
denominator += 2;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
function nonFiniteToString(x) {
|
|
1653
|
+
return String(x.s * x.s / 0);
|
|
1654
|
+
}
|
|
1655
|
+
function parseDecimal(x, str) {
|
|
1656
|
+
var e, i, len;
|
|
1657
|
+
if ((e = str.indexOf(".")) > -1)
|
|
1658
|
+
str = str.replace(".", "");
|
|
1659
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
1660
|
+
if (e < 0)
|
|
1661
|
+
e = i;
|
|
1662
|
+
e += +str.slice(i + 1);
|
|
1663
|
+
str = str.substring(0, i);
|
|
1664
|
+
} else if (e < 0) {
|
|
1665
|
+
e = str.length;
|
|
1666
|
+
}
|
|
1667
|
+
for (i = 0; str.charCodeAt(i) === 48; i++)
|
|
1668
|
+
;
|
|
1669
|
+
for (len = str.length; str.charCodeAt(len - 1) === 48; --len)
|
|
1670
|
+
;
|
|
1671
|
+
str = str.slice(i, len);
|
|
1672
|
+
if (str) {
|
|
1673
|
+
len -= i;
|
|
1674
|
+
x.e = e = e - i - 1;
|
|
1675
|
+
x.d = [];
|
|
1676
|
+
i = (e + 1) % LOG_BASE;
|
|
1677
|
+
if (e < 0)
|
|
1678
|
+
i += LOG_BASE;
|
|
1679
|
+
if (i < len) {
|
|
1680
|
+
if (i)
|
|
1681
|
+
x.d.push(+str.slice(0, i));
|
|
1682
|
+
for (len -= LOG_BASE; i < len; )
|
|
1683
|
+
x.d.push(+str.slice(i, i += LOG_BASE));
|
|
1684
|
+
str = str.slice(i);
|
|
1685
|
+
i = LOG_BASE - str.length;
|
|
1686
|
+
} else {
|
|
1687
|
+
i -= len;
|
|
1688
|
+
}
|
|
1689
|
+
for (; i--; )
|
|
1690
|
+
str += "0";
|
|
1691
|
+
x.d.push(+str);
|
|
1692
|
+
if (external) {
|
|
1693
|
+
if (x.e > x.constructor.maxE) {
|
|
1694
|
+
x.d = null;
|
|
1695
|
+
x.e = NaN;
|
|
1696
|
+
} else if (x.e < x.constructor.minE) {
|
|
1697
|
+
x.e = 0;
|
|
1698
|
+
x.d = [0];
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
} else {
|
|
1702
|
+
x.e = 0;
|
|
1703
|
+
x.d = [0];
|
|
1704
|
+
}
|
|
1705
|
+
return x;
|
|
1706
|
+
}
|
|
1707
|
+
function parseOther(x, str) {
|
|
1708
|
+
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
1709
|
+
if (str.indexOf("_") > -1) {
|
|
1710
|
+
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
1711
|
+
if (isDecimal.test(str))
|
|
1712
|
+
return parseDecimal(x, str);
|
|
1713
|
+
} else if (str === "Infinity" || str === "NaN") {
|
|
1714
|
+
if (!+str)
|
|
1715
|
+
x.s = NaN;
|
|
1716
|
+
x.e = NaN;
|
|
1717
|
+
x.d = null;
|
|
1718
|
+
return x;
|
|
1719
|
+
}
|
|
1720
|
+
if (isHex.test(str)) {
|
|
1721
|
+
base = 16;
|
|
1722
|
+
str = str.toLowerCase();
|
|
1723
|
+
} else if (isBinary.test(str)) {
|
|
1724
|
+
base = 2;
|
|
1725
|
+
} else if (isOctal.test(str)) {
|
|
1726
|
+
base = 8;
|
|
1727
|
+
} else {
|
|
1728
|
+
throw Error(invalidArgument + str);
|
|
1729
|
+
}
|
|
1730
|
+
i = str.search(/p/i);
|
|
1731
|
+
if (i > 0) {
|
|
1732
|
+
p = +str.slice(i + 1);
|
|
1733
|
+
str = str.substring(2, i);
|
|
1734
|
+
} else {
|
|
1735
|
+
str = str.slice(2);
|
|
1736
|
+
}
|
|
1737
|
+
i = str.indexOf(".");
|
|
1738
|
+
isFloat = i >= 0;
|
|
1739
|
+
Ctor = x.constructor;
|
|
1740
|
+
if (isFloat) {
|
|
1741
|
+
str = str.replace(".", "");
|
|
1742
|
+
len = str.length;
|
|
1743
|
+
i = len - i;
|
|
1744
|
+
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
1745
|
+
}
|
|
1746
|
+
xd = convertBase(str, base, BASE);
|
|
1747
|
+
xe = xd.length - 1;
|
|
1748
|
+
for (i = xe; xd[i] === 0; --i)
|
|
1749
|
+
xd.pop();
|
|
1750
|
+
if (i < 0)
|
|
1751
|
+
return new Ctor(x.s * 0);
|
|
1752
|
+
x.e = getBase10Exponent(xd, xe);
|
|
1753
|
+
x.d = xd;
|
|
1754
|
+
external = false;
|
|
1755
|
+
if (isFloat)
|
|
1756
|
+
x = divide(x, divisor, len * 4);
|
|
1757
|
+
if (p)
|
|
1758
|
+
x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
1759
|
+
external = true;
|
|
1760
|
+
return x;
|
|
1761
|
+
}
|
|
1762
|
+
function sine(Ctor, x) {
|
|
1763
|
+
var k, len = x.d.length;
|
|
1764
|
+
if (len < 3) {
|
|
1765
|
+
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
1766
|
+
}
|
|
1767
|
+
k = 1.4 * Math.sqrt(len);
|
|
1768
|
+
k = k > 16 ? 16 : k | 0;
|
|
1769
|
+
x = x.times(1 / tinyPow(5, k));
|
|
1770
|
+
x = taylorSeries(Ctor, 2, x, x);
|
|
1771
|
+
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
1772
|
+
for (; k--; ) {
|
|
1773
|
+
sin2_x = x.times(x);
|
|
1774
|
+
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
1775
|
+
}
|
|
1776
|
+
return x;
|
|
1777
|
+
}
|
|
1778
|
+
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
1779
|
+
var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
|
1780
|
+
external = false;
|
|
1781
|
+
x2 = x.times(x);
|
|
1782
|
+
u = new Ctor(y);
|
|
1783
|
+
for (; ; ) {
|
|
1784
|
+
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
1785
|
+
u = isHyperbolic ? y.plus(t) : y.minus(t);
|
|
1786
|
+
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
1787
|
+
t = u.plus(y);
|
|
1788
|
+
if (t.d[k] !== void 0) {
|
|
1789
|
+
for (j = k; t.d[j] === u.d[j] && j--; )
|
|
1790
|
+
;
|
|
1791
|
+
if (j == -1)
|
|
1792
|
+
break;
|
|
1793
|
+
}
|
|
1794
|
+
j = u;
|
|
1795
|
+
u = y;
|
|
1796
|
+
y = t;
|
|
1797
|
+
t = j;
|
|
1798
|
+
i++;
|
|
1799
|
+
}
|
|
1800
|
+
external = true;
|
|
1801
|
+
t.d.length = k + 1;
|
|
1802
|
+
return t;
|
|
1803
|
+
}
|
|
1804
|
+
function tinyPow(b, e) {
|
|
1805
|
+
var n = b;
|
|
1806
|
+
while (--e)
|
|
1807
|
+
n *= b;
|
|
1808
|
+
return n;
|
|
1809
|
+
}
|
|
1810
|
+
function toLessThanHalfPi(Ctor, x) {
|
|
1811
|
+
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
1812
|
+
x = x.abs();
|
|
1813
|
+
if (x.lte(halfPi)) {
|
|
1814
|
+
quadrant = isNeg ? 4 : 1;
|
|
1815
|
+
return x;
|
|
1816
|
+
}
|
|
1817
|
+
t = x.divToInt(pi);
|
|
1818
|
+
if (t.isZero()) {
|
|
1819
|
+
quadrant = isNeg ? 3 : 2;
|
|
1820
|
+
} else {
|
|
1821
|
+
x = x.minus(t.times(pi));
|
|
1822
|
+
if (x.lte(halfPi)) {
|
|
1823
|
+
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
1824
|
+
return x;
|
|
1825
|
+
}
|
|
1826
|
+
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
1827
|
+
}
|
|
1828
|
+
return x.minus(pi).abs();
|
|
1829
|
+
}
|
|
1830
|
+
function toStringBinary(x, baseOut, sd, rm) {
|
|
1831
|
+
var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
|
|
1832
|
+
if (isExp) {
|
|
1833
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
1834
|
+
if (rm === void 0)
|
|
1835
|
+
rm = Ctor.rounding;
|
|
1836
|
+
else
|
|
1837
|
+
checkInt32(rm, 0, 8);
|
|
1838
|
+
} else {
|
|
1839
|
+
sd = Ctor.precision;
|
|
1840
|
+
rm = Ctor.rounding;
|
|
1841
|
+
}
|
|
1842
|
+
if (!x.isFinite()) {
|
|
1843
|
+
str = nonFiniteToString(x);
|
|
1844
|
+
} else {
|
|
1845
|
+
str = finiteToString(x);
|
|
1846
|
+
i = str.indexOf(".");
|
|
1847
|
+
if (isExp) {
|
|
1848
|
+
base = 2;
|
|
1849
|
+
if (baseOut == 16) {
|
|
1850
|
+
sd = sd * 4 - 3;
|
|
1851
|
+
} else if (baseOut == 8) {
|
|
1852
|
+
sd = sd * 3 - 2;
|
|
1853
|
+
}
|
|
1854
|
+
} else {
|
|
1855
|
+
base = baseOut;
|
|
1856
|
+
}
|
|
1857
|
+
if (i >= 0) {
|
|
1858
|
+
str = str.replace(".", "");
|
|
1859
|
+
y = new Ctor(1);
|
|
1860
|
+
y.e = str.length - i;
|
|
1861
|
+
y.d = convertBase(finiteToString(y), 10, base);
|
|
1862
|
+
y.e = y.d.length;
|
|
1863
|
+
}
|
|
1864
|
+
xd = convertBase(str, 10, base);
|
|
1865
|
+
e = len = xd.length;
|
|
1866
|
+
for (; xd[--len] == 0; )
|
|
1867
|
+
xd.pop();
|
|
1868
|
+
if (!xd[0]) {
|
|
1869
|
+
str = isExp ? "0p+0" : "0";
|
|
1870
|
+
} else {
|
|
1871
|
+
if (i < 0) {
|
|
1872
|
+
e--;
|
|
1873
|
+
} else {
|
|
1874
|
+
x = new Ctor(x);
|
|
1875
|
+
x.d = xd;
|
|
1876
|
+
x.e = e;
|
|
1877
|
+
x = divide(x, y, sd, rm, 0, base);
|
|
1878
|
+
xd = x.d;
|
|
1879
|
+
e = x.e;
|
|
1880
|
+
roundUp = inexact;
|
|
1881
|
+
}
|
|
1882
|
+
i = xd[sd];
|
|
1883
|
+
k = base / 2;
|
|
1884
|
+
roundUp = roundUp || xd[sd + 1] !== void 0;
|
|
1885
|
+
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));
|
|
1886
|
+
xd.length = sd;
|
|
1887
|
+
if (roundUp) {
|
|
1888
|
+
for (; ++xd[--sd] > base - 1; ) {
|
|
1889
|
+
xd[sd] = 0;
|
|
1890
|
+
if (!sd) {
|
|
1891
|
+
++e;
|
|
1892
|
+
xd.unshift(1);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
for (len = xd.length; !xd[len - 1]; --len)
|
|
1897
|
+
;
|
|
1898
|
+
for (i = 0, str = ""; i < len; i++)
|
|
1899
|
+
str += NUMERALS.charAt(xd[i]);
|
|
1900
|
+
if (isExp) {
|
|
1901
|
+
if (len > 1) {
|
|
1902
|
+
if (baseOut == 16 || baseOut == 8) {
|
|
1903
|
+
i = baseOut == 16 ? 4 : 3;
|
|
1904
|
+
for (--len; len % i; len++)
|
|
1905
|
+
str += "0";
|
|
1906
|
+
xd = convertBase(str, base, baseOut);
|
|
1907
|
+
for (len = xd.length; !xd[len - 1]; --len)
|
|
1908
|
+
;
|
|
1909
|
+
for (i = 1, str = "1."; i < len; i++)
|
|
1910
|
+
str += NUMERALS.charAt(xd[i]);
|
|
1911
|
+
} else {
|
|
1912
|
+
str = str.charAt(0) + "." + str.slice(1);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
str = str + (e < 0 ? "p" : "p+") + e;
|
|
1916
|
+
} else if (e < 0) {
|
|
1917
|
+
for (; ++e; )
|
|
1918
|
+
str = "0" + str;
|
|
1919
|
+
str = "0." + str;
|
|
1920
|
+
} else {
|
|
1921
|
+
if (++e > len)
|
|
1922
|
+
for (e -= len; e--; )
|
|
1923
|
+
str += "0";
|
|
1924
|
+
else if (e < len)
|
|
1925
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
1929
|
+
}
|
|
1930
|
+
return x.s < 0 ? "-" + str : str;
|
|
1931
|
+
}
|
|
1932
|
+
function truncate(arr, len) {
|
|
1933
|
+
if (arr.length > len) {
|
|
1934
|
+
arr.length = len;
|
|
1935
|
+
return true;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function abs(x) {
|
|
1939
|
+
return new this(x).abs();
|
|
1940
|
+
}
|
|
1941
|
+
function acos(x) {
|
|
1942
|
+
return new this(x).acos();
|
|
1943
|
+
}
|
|
1944
|
+
function acosh(x) {
|
|
1945
|
+
return new this(x).acosh();
|
|
1946
|
+
}
|
|
1947
|
+
function add(x, y) {
|
|
1948
|
+
return new this(x).plus(y);
|
|
1949
|
+
}
|
|
1950
|
+
function asin(x) {
|
|
1951
|
+
return new this(x).asin();
|
|
1952
|
+
}
|
|
1953
|
+
function asinh(x) {
|
|
1954
|
+
return new this(x).asinh();
|
|
1955
|
+
}
|
|
1956
|
+
function atan(x) {
|
|
1957
|
+
return new this(x).atan();
|
|
1958
|
+
}
|
|
1959
|
+
function atanh(x) {
|
|
1960
|
+
return new this(x).atanh();
|
|
1961
|
+
}
|
|
1962
|
+
function atan2(y, x) {
|
|
1963
|
+
y = new this(y);
|
|
1964
|
+
x = new this(x);
|
|
1965
|
+
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
1966
|
+
if (!y.s || !x.s) {
|
|
1967
|
+
r = new this(NaN);
|
|
1968
|
+
} else if (!y.d && !x.d) {
|
|
1969
|
+
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
|
1970
|
+
r.s = y.s;
|
|
1971
|
+
} else if (!x.d || y.isZero()) {
|
|
1972
|
+
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
1973
|
+
r.s = y.s;
|
|
1974
|
+
} else if (!y.d || x.isZero()) {
|
|
1975
|
+
r = getPi(this, wpr, 1).times(0.5);
|
|
1976
|
+
r.s = y.s;
|
|
1977
|
+
} else if (x.s < 0) {
|
|
1978
|
+
this.precision = wpr;
|
|
1979
|
+
this.rounding = 1;
|
|
1980
|
+
r = this.atan(divide(y, x, wpr, 1));
|
|
1981
|
+
x = getPi(this, wpr, 1);
|
|
1982
|
+
this.precision = pr;
|
|
1983
|
+
this.rounding = rm;
|
|
1984
|
+
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
1985
|
+
} else {
|
|
1986
|
+
r = this.atan(divide(y, x, wpr, 1));
|
|
1987
|
+
}
|
|
1988
|
+
return r;
|
|
1989
|
+
}
|
|
1990
|
+
function cbrt(x) {
|
|
1991
|
+
return new this(x).cbrt();
|
|
1992
|
+
}
|
|
1993
|
+
function ceil(x) {
|
|
1994
|
+
return finalise(x = new this(x), x.e + 1, 2);
|
|
1995
|
+
}
|
|
1996
|
+
function clamp(x, min2, max2) {
|
|
1997
|
+
return new this(x).clamp(min2, max2);
|
|
1998
|
+
}
|
|
1999
|
+
function config(obj) {
|
|
2000
|
+
if (!obj || typeof obj !== "object")
|
|
2001
|
+
throw Error(decimalError + "Object expected");
|
|
2002
|
+
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
2003
|
+
"precision",
|
|
2004
|
+
1,
|
|
2005
|
+
MAX_DIGITS,
|
|
2006
|
+
"rounding",
|
|
2007
|
+
0,
|
|
2008
|
+
8,
|
|
2009
|
+
"toExpNeg",
|
|
2010
|
+
-EXP_LIMIT,
|
|
2011
|
+
0,
|
|
2012
|
+
"toExpPos",
|
|
2013
|
+
0,
|
|
2014
|
+
EXP_LIMIT,
|
|
2015
|
+
"maxE",
|
|
2016
|
+
0,
|
|
2017
|
+
EXP_LIMIT,
|
|
2018
|
+
"minE",
|
|
2019
|
+
-EXP_LIMIT,
|
|
2020
|
+
0,
|
|
2021
|
+
"modulo",
|
|
2022
|
+
0,
|
|
2023
|
+
9
|
|
2024
|
+
];
|
|
2025
|
+
for (i = 0; i < ps.length; i += 3) {
|
|
2026
|
+
if (p = ps[i], useDefaults)
|
|
2027
|
+
this[p] = DEFAULTS[p];
|
|
2028
|
+
if ((v = obj[p]) !== void 0) {
|
|
2029
|
+
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
|
|
2030
|
+
this[p] = v;
|
|
2031
|
+
else
|
|
2032
|
+
throw Error(invalidArgument + p + ": " + v);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (p = "crypto", useDefaults)
|
|
2036
|
+
this[p] = DEFAULTS[p];
|
|
2037
|
+
if ((v = obj[p]) !== void 0) {
|
|
2038
|
+
if (v === true || v === false || v === 0 || v === 1) {
|
|
2039
|
+
if (v) {
|
|
2040
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
2041
|
+
this[p] = true;
|
|
2042
|
+
} else {
|
|
2043
|
+
throw Error(cryptoUnavailable);
|
|
2044
|
+
}
|
|
2045
|
+
} else {
|
|
2046
|
+
this[p] = false;
|
|
2047
|
+
}
|
|
2048
|
+
} else {
|
|
2049
|
+
throw Error(invalidArgument + p + ": " + v);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
return this;
|
|
2053
|
+
}
|
|
2054
|
+
function cos(x) {
|
|
2055
|
+
return new this(x).cos();
|
|
2056
|
+
}
|
|
2057
|
+
function cosh(x) {
|
|
2058
|
+
return new this(x).cosh();
|
|
2059
|
+
}
|
|
2060
|
+
function clone(obj) {
|
|
2061
|
+
var i, p, ps;
|
|
2062
|
+
function Decimal2(v) {
|
|
2063
|
+
var e, i2, t, x = this;
|
|
2064
|
+
if (!(x instanceof Decimal2))
|
|
2065
|
+
return new Decimal2(v);
|
|
2066
|
+
x.constructor = Decimal2;
|
|
2067
|
+
if (isDecimalInstance(v)) {
|
|
2068
|
+
x.s = v.s;
|
|
2069
|
+
if (external) {
|
|
2070
|
+
if (!v.d || v.e > Decimal2.maxE) {
|
|
2071
|
+
x.e = NaN;
|
|
2072
|
+
x.d = null;
|
|
2073
|
+
} else if (v.e < Decimal2.minE) {
|
|
2074
|
+
x.e = 0;
|
|
2075
|
+
x.d = [0];
|
|
2076
|
+
} else {
|
|
2077
|
+
x.e = v.e;
|
|
2078
|
+
x.d = v.d.slice();
|
|
2079
|
+
}
|
|
2080
|
+
} else {
|
|
2081
|
+
x.e = v.e;
|
|
2082
|
+
x.d = v.d ? v.d.slice() : v.d;
|
|
2083
|
+
}
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
t = typeof v;
|
|
2087
|
+
if (t === "number") {
|
|
2088
|
+
if (v === 0) {
|
|
2089
|
+
x.s = 1 / v < 0 ? -1 : 1;
|
|
2090
|
+
x.e = 0;
|
|
2091
|
+
x.d = [0];
|
|
2092
|
+
return;
|
|
2093
|
+
}
|
|
2094
|
+
if (v < 0) {
|
|
2095
|
+
v = -v;
|
|
2096
|
+
x.s = -1;
|
|
2097
|
+
} else {
|
|
2098
|
+
x.s = 1;
|
|
2099
|
+
}
|
|
2100
|
+
if (v === ~~v && v < 1e7) {
|
|
2101
|
+
for (e = 0, i2 = v; i2 >= 10; i2 /= 10)
|
|
2102
|
+
e++;
|
|
2103
|
+
if (external) {
|
|
2104
|
+
if (e > Decimal2.maxE) {
|
|
2105
|
+
x.e = NaN;
|
|
2106
|
+
x.d = null;
|
|
2107
|
+
} else if (e < Decimal2.minE) {
|
|
2108
|
+
x.e = 0;
|
|
2109
|
+
x.d = [0];
|
|
2110
|
+
} else {
|
|
2111
|
+
x.e = e;
|
|
2112
|
+
x.d = [v];
|
|
2113
|
+
}
|
|
2114
|
+
} else {
|
|
2115
|
+
x.e = e;
|
|
2116
|
+
x.d = [v];
|
|
2117
|
+
}
|
|
2118
|
+
return;
|
|
2119
|
+
} else if (v * 0 !== 0) {
|
|
2120
|
+
if (!v)
|
|
2121
|
+
x.s = NaN;
|
|
2122
|
+
x.e = NaN;
|
|
2123
|
+
x.d = null;
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
return parseDecimal(x, v.toString());
|
|
2127
|
+
} else if (t !== "string") {
|
|
2128
|
+
throw Error(invalidArgument + v);
|
|
2129
|
+
}
|
|
2130
|
+
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
2131
|
+
v = v.slice(1);
|
|
2132
|
+
x.s = -1;
|
|
2133
|
+
} else {
|
|
2134
|
+
if (i2 === 43)
|
|
2135
|
+
v = v.slice(1);
|
|
2136
|
+
x.s = 1;
|
|
2137
|
+
}
|
|
2138
|
+
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
|
2139
|
+
}
|
|
2140
|
+
Decimal2.prototype = P;
|
|
2141
|
+
Decimal2.ROUND_UP = 0;
|
|
2142
|
+
Decimal2.ROUND_DOWN = 1;
|
|
2143
|
+
Decimal2.ROUND_CEIL = 2;
|
|
2144
|
+
Decimal2.ROUND_FLOOR = 3;
|
|
2145
|
+
Decimal2.ROUND_HALF_UP = 4;
|
|
2146
|
+
Decimal2.ROUND_HALF_DOWN = 5;
|
|
2147
|
+
Decimal2.ROUND_HALF_EVEN = 6;
|
|
2148
|
+
Decimal2.ROUND_HALF_CEIL = 7;
|
|
2149
|
+
Decimal2.ROUND_HALF_FLOOR = 8;
|
|
2150
|
+
Decimal2.EUCLID = 9;
|
|
2151
|
+
Decimal2.config = Decimal2.set = config;
|
|
2152
|
+
Decimal2.clone = clone;
|
|
2153
|
+
Decimal2.isDecimal = isDecimalInstance;
|
|
2154
|
+
Decimal2.abs = abs;
|
|
2155
|
+
Decimal2.acos = acos;
|
|
2156
|
+
Decimal2.acosh = acosh;
|
|
2157
|
+
Decimal2.add = add;
|
|
2158
|
+
Decimal2.asin = asin;
|
|
2159
|
+
Decimal2.asinh = asinh;
|
|
2160
|
+
Decimal2.atan = atan;
|
|
2161
|
+
Decimal2.atanh = atanh;
|
|
2162
|
+
Decimal2.atan2 = atan2;
|
|
2163
|
+
Decimal2.cbrt = cbrt;
|
|
2164
|
+
Decimal2.ceil = ceil;
|
|
2165
|
+
Decimal2.clamp = clamp;
|
|
2166
|
+
Decimal2.cos = cos;
|
|
2167
|
+
Decimal2.cosh = cosh;
|
|
2168
|
+
Decimal2.div = div;
|
|
2169
|
+
Decimal2.exp = exp;
|
|
2170
|
+
Decimal2.floor = floor;
|
|
2171
|
+
Decimal2.hypot = hypot;
|
|
2172
|
+
Decimal2.ln = ln;
|
|
2173
|
+
Decimal2.log = log;
|
|
2174
|
+
Decimal2.log10 = log10;
|
|
2175
|
+
Decimal2.log2 = log2;
|
|
2176
|
+
Decimal2.max = max;
|
|
2177
|
+
Decimal2.min = min;
|
|
2178
|
+
Decimal2.mod = mod;
|
|
2179
|
+
Decimal2.mul = mul;
|
|
2180
|
+
Decimal2.pow = pow;
|
|
2181
|
+
Decimal2.random = random;
|
|
2182
|
+
Decimal2.round = round;
|
|
2183
|
+
Decimal2.sign = sign;
|
|
2184
|
+
Decimal2.sin = sin;
|
|
2185
|
+
Decimal2.sinh = sinh;
|
|
2186
|
+
Decimal2.sqrt = sqrt;
|
|
2187
|
+
Decimal2.sub = sub;
|
|
2188
|
+
Decimal2.sum = sum;
|
|
2189
|
+
Decimal2.tan = tan;
|
|
2190
|
+
Decimal2.tanh = tanh;
|
|
2191
|
+
Decimal2.trunc = trunc;
|
|
2192
|
+
if (obj === void 0)
|
|
2193
|
+
obj = {};
|
|
2194
|
+
if (obj) {
|
|
2195
|
+
if (obj.defaults !== true) {
|
|
2196
|
+
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
2197
|
+
for (i = 0; i < ps.length; )
|
|
2198
|
+
if (!obj.hasOwnProperty(p = ps[i++]))
|
|
2199
|
+
obj[p] = this[p];
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
Decimal2.config(obj);
|
|
2203
|
+
return Decimal2;
|
|
2204
|
+
}
|
|
2205
|
+
function div(x, y) {
|
|
2206
|
+
return new this(x).div(y);
|
|
2207
|
+
}
|
|
2208
|
+
function exp(x) {
|
|
2209
|
+
return new this(x).exp();
|
|
2210
|
+
}
|
|
2211
|
+
function floor(x) {
|
|
2212
|
+
return finalise(x = new this(x), x.e + 1, 3);
|
|
2213
|
+
}
|
|
2214
|
+
function hypot() {
|
|
2215
|
+
var i, n, t = new this(0);
|
|
2216
|
+
external = false;
|
|
2217
|
+
for (i = 0; i < arguments.length; ) {
|
|
2218
|
+
n = new this(arguments[i++]);
|
|
2219
|
+
if (!n.d) {
|
|
2220
|
+
if (n.s) {
|
|
2221
|
+
external = true;
|
|
2222
|
+
return new this(1 / 0);
|
|
2223
|
+
}
|
|
2224
|
+
t = n;
|
|
2225
|
+
} else if (t.d) {
|
|
2226
|
+
t = t.plus(n.times(n));
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
external = true;
|
|
2230
|
+
return t.sqrt();
|
|
2231
|
+
}
|
|
2232
|
+
function isDecimalInstance(obj) {
|
|
2233
|
+
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
2234
|
+
}
|
|
2235
|
+
function ln(x) {
|
|
2236
|
+
return new this(x).ln();
|
|
2237
|
+
}
|
|
2238
|
+
function log(x, y) {
|
|
2239
|
+
return new this(x).log(y);
|
|
2240
|
+
}
|
|
2241
|
+
function log2(x) {
|
|
2242
|
+
return new this(x).log(2);
|
|
2243
|
+
}
|
|
2244
|
+
function log10(x) {
|
|
2245
|
+
return new this(x).log(10);
|
|
2246
|
+
}
|
|
2247
|
+
function max() {
|
|
2248
|
+
return maxOrMin(this, arguments, "lt");
|
|
2249
|
+
}
|
|
2250
|
+
function min() {
|
|
2251
|
+
return maxOrMin(this, arguments, "gt");
|
|
2252
|
+
}
|
|
2253
|
+
function mod(x, y) {
|
|
2254
|
+
return new this(x).mod(y);
|
|
2255
|
+
}
|
|
2256
|
+
function mul(x, y) {
|
|
2257
|
+
return new this(x).mul(y);
|
|
2258
|
+
}
|
|
2259
|
+
function pow(x, y) {
|
|
2260
|
+
return new this(x).pow(y);
|
|
2261
|
+
}
|
|
2262
|
+
function random(sd) {
|
|
2263
|
+
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
2264
|
+
if (sd === void 0)
|
|
2265
|
+
sd = this.precision;
|
|
2266
|
+
else
|
|
2267
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
2268
|
+
k = Math.ceil(sd / LOG_BASE);
|
|
2269
|
+
if (!this.crypto) {
|
|
2270
|
+
for (; i < k; )
|
|
2271
|
+
rd[i++] = Math.random() * 1e7 | 0;
|
|
2272
|
+
} else if (crypto.getRandomValues) {
|
|
2273
|
+
d = crypto.getRandomValues(new Uint32Array(k));
|
|
2274
|
+
for (; i < k; ) {
|
|
2275
|
+
n = d[i];
|
|
2276
|
+
if (n >= 429e7) {
|
|
2277
|
+
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
2278
|
+
} else {
|
|
2279
|
+
rd[i++] = n % 1e7;
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
} else if (crypto.randomBytes) {
|
|
2283
|
+
d = crypto.randomBytes(k *= 4);
|
|
2284
|
+
for (; i < k; ) {
|
|
2285
|
+
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
2286
|
+
if (n >= 214e7) {
|
|
2287
|
+
crypto.randomBytes(4).copy(d, i);
|
|
2288
|
+
} else {
|
|
2289
|
+
rd.push(n % 1e7);
|
|
2290
|
+
i += 4;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
i = k / 4;
|
|
2294
|
+
} else {
|
|
2295
|
+
throw Error(cryptoUnavailable);
|
|
2296
|
+
}
|
|
2297
|
+
k = rd[--i];
|
|
2298
|
+
sd %= LOG_BASE;
|
|
2299
|
+
if (k && sd) {
|
|
2300
|
+
n = mathpow(10, LOG_BASE - sd);
|
|
2301
|
+
rd[i] = (k / n | 0) * n;
|
|
2302
|
+
}
|
|
2303
|
+
for (; rd[i] === 0; i--)
|
|
2304
|
+
rd.pop();
|
|
2305
|
+
if (i < 0) {
|
|
2306
|
+
e = 0;
|
|
2307
|
+
rd = [0];
|
|
2308
|
+
} else {
|
|
2309
|
+
e = -1;
|
|
2310
|
+
for (; rd[0] === 0; e -= LOG_BASE)
|
|
2311
|
+
rd.shift();
|
|
2312
|
+
for (k = 1, n = rd[0]; n >= 10; n /= 10)
|
|
2313
|
+
k++;
|
|
2314
|
+
if (k < LOG_BASE)
|
|
2315
|
+
e -= LOG_BASE - k;
|
|
2316
|
+
}
|
|
2317
|
+
r.e = e;
|
|
2318
|
+
r.d = rd;
|
|
2319
|
+
return r;
|
|
2320
|
+
}
|
|
2321
|
+
function round(x) {
|
|
2322
|
+
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
2323
|
+
}
|
|
2324
|
+
function sign(x) {
|
|
2325
|
+
x = new this(x);
|
|
2326
|
+
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
2327
|
+
}
|
|
2328
|
+
function sin(x) {
|
|
2329
|
+
return new this(x).sin();
|
|
2330
|
+
}
|
|
2331
|
+
function sinh(x) {
|
|
2332
|
+
return new this(x).sinh();
|
|
2333
|
+
}
|
|
2334
|
+
function sqrt(x) {
|
|
2335
|
+
return new this(x).sqrt();
|
|
2336
|
+
}
|
|
2337
|
+
function sub(x, y) {
|
|
2338
|
+
return new this(x).sub(y);
|
|
2339
|
+
}
|
|
2340
|
+
function sum() {
|
|
2341
|
+
var i = 0, args = arguments, x = new this(args[i]);
|
|
2342
|
+
external = false;
|
|
2343
|
+
for (; x.s && ++i < args.length; )
|
|
2344
|
+
x = x.plus(args[i]);
|
|
2345
|
+
external = true;
|
|
2346
|
+
return finalise(x, this.precision, this.rounding);
|
|
2347
|
+
}
|
|
2348
|
+
function tan(x) {
|
|
2349
|
+
return new this(x).tan();
|
|
2350
|
+
}
|
|
2351
|
+
function tanh(x) {
|
|
2352
|
+
return new this(x).tanh();
|
|
2353
|
+
}
|
|
2354
|
+
function trunc(x) {
|
|
2355
|
+
return finalise(x = new this(x), x.e + 1, 1);
|
|
2356
|
+
}
|
|
2357
|
+
P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
2358
|
+
P[Symbol.toStringTag] = "Decimal";
|
|
2359
|
+
var Decimal = P.constructor = clone(DEFAULTS);
|
|
2360
|
+
LN10 = new Decimal(LN10);
|
|
2361
|
+
PI = new Decimal(PI);
|
|
2362
|
+
var decimal_default = Decimal;
|
|
2363
|
+
|
|
2364
|
+
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/constants.js
|
|
2365
|
+
var TEN = new decimal_default(10);
|
|
2366
|
+
var ZERO = new decimal_default(0);
|
|
2367
|
+
var NEGATIVE_ZERO = new decimal_default(-0);
|
|
2368
|
+
|
|
14
2369
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/262.js
|
|
15
2370
|
function ToString(o) {
|
|
16
2371
|
if (typeof o === "symbol") {
|
|
@@ -20,21 +2375,18 @@
|
|
|
20
2375
|
}
|
|
21
2376
|
function ToNumber(val) {
|
|
22
2377
|
if (val === void 0) {
|
|
23
|
-
return NaN;
|
|
2378
|
+
return new Decimal(NaN);
|
|
24
2379
|
}
|
|
25
2380
|
if (val === null) {
|
|
26
|
-
return
|
|
2381
|
+
return ZERO;
|
|
27
2382
|
}
|
|
28
2383
|
if (typeof val === "boolean") {
|
|
29
|
-
return val ? 1 : 0;
|
|
30
|
-
}
|
|
31
|
-
if (typeof val === "number") {
|
|
32
|
-
return val;
|
|
2384
|
+
return new Decimal(val ? 1 : 0);
|
|
33
2385
|
}
|
|
34
2386
|
if (typeof val === "symbol" || typeof val === "bigint") {
|
|
35
2387
|
throw new TypeError("Cannot convert symbol/bigint to number");
|
|
36
2388
|
}
|
|
37
|
-
return Number(val);
|
|
2389
|
+
return new Decimal(Number(val));
|
|
38
2390
|
}
|
|
39
2391
|
function ToObject(arg) {
|
|
40
2392
|
if (arg == null) {
|
|
@@ -42,15 +2394,6 @@
|
|
|
42
2394
|
}
|
|
43
2395
|
return Object(arg);
|
|
44
2396
|
}
|
|
45
|
-
function SameValue(x, y) {
|
|
46
|
-
if (Object.is) {
|
|
47
|
-
return Object.is(x, y);
|
|
48
|
-
}
|
|
49
|
-
if (x === y) {
|
|
50
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
51
|
-
}
|
|
52
|
-
return x !== x && y !== y;
|
|
53
|
-
}
|
|
54
2397
|
function Type(x) {
|
|
55
2398
|
if (x === null) {
|
|
56
2399
|
return "Null";
|
|
@@ -92,13 +2435,13 @@
|
|
|
92
2435
|
}
|
|
93
2436
|
|
|
94
2437
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/DefaultNumberOption.js
|
|
95
|
-
function DefaultNumberOption(inputVal,
|
|
2438
|
+
function DefaultNumberOption(inputVal, min2, max2, fallback) {
|
|
96
2439
|
if (inputVal === void 0) {
|
|
97
2440
|
return fallback;
|
|
98
2441
|
}
|
|
99
2442
|
var val = Number(inputVal);
|
|
100
|
-
if (isNaN(val) || val <
|
|
101
|
-
throw new RangeError("".concat(val, " is outside of range [").concat(
|
|
2443
|
+
if (isNaN(val) || val < min2 || val > max2) {
|
|
2444
|
+
throw new RangeError("".concat(val, " is outside of range [").concat(min2, ", ").concat(max2, "]"));
|
|
102
2445
|
}
|
|
103
2446
|
return Math.floor(val);
|
|
104
2447
|
}
|
|
@@ -266,15 +2609,21 @@
|
|
|
266
2609
|
var serializerDefault = function() {
|
|
267
2610
|
return JSON.stringify(arguments);
|
|
268
2611
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
2612
|
+
var ObjectWithoutPrototypeCache = (
|
|
2613
|
+
/** @class */
|
|
2614
|
+
function() {
|
|
2615
|
+
function ObjectWithoutPrototypeCache2() {
|
|
2616
|
+
this.cache = /* @__PURE__ */ Object.create(null);
|
|
2617
|
+
}
|
|
2618
|
+
ObjectWithoutPrototypeCache2.prototype.get = function(key) {
|
|
2619
|
+
return this.cache[key];
|
|
2620
|
+
};
|
|
2621
|
+
ObjectWithoutPrototypeCache2.prototype.set = function(key, value) {
|
|
2622
|
+
this.cache[key] = value;
|
|
2623
|
+
};
|
|
2624
|
+
return ObjectWithoutPrototypeCache2;
|
|
2625
|
+
}()
|
|
2626
|
+
);
|
|
278
2627
|
var cacheDefault = {
|
|
279
2628
|
create: function create() {
|
|
280
2629
|
return new ObjectWithoutPrototypeCache();
|
|
@@ -286,9 +2635,6 @@
|
|
|
286
2635
|
};
|
|
287
2636
|
|
|
288
2637
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/utils.js
|
|
289
|
-
function getMagnitude(x) {
|
|
290
|
-
return Math.floor(Math.log(x) * Math.LOG10E);
|
|
291
|
-
}
|
|
292
2638
|
function repeat(s, times) {
|
|
293
2639
|
if (typeof s.repeat === "function") {
|
|
294
2640
|
return s.repeat(times);
|
|
@@ -358,136 +2704,315 @@
|
|
|
358
2704
|
strategy: strategies.variadic
|
|
359
2705
|
});
|
|
360
2706
|
|
|
361
|
-
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/
|
|
362
|
-
function
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
m = repeat("0", p);
|
|
369
|
-
e = 0;
|
|
370
|
-
xFinal = 0;
|
|
371
|
-
} else {
|
|
372
|
-
var xToString = x.toString();
|
|
373
|
-
var xToStringExponentIndex = xToString.indexOf("e");
|
|
374
|
-
var _a = xToString.split("e"), xToStringMantissa = _a[0], xToStringExponent = _a[1];
|
|
375
|
-
var xToStringMantissaWithoutDecimalPoint = xToStringMantissa.replace(".", "");
|
|
376
|
-
if (xToStringExponentIndex >= 0 && xToStringMantissaWithoutDecimalPoint.length <= p) {
|
|
377
|
-
e = +xToStringExponent;
|
|
378
|
-
m = xToStringMantissaWithoutDecimalPoint + repeat("0", p - xToStringMantissaWithoutDecimalPoint.length);
|
|
379
|
-
xFinal = x;
|
|
380
|
-
} else {
|
|
381
|
-
e = getMagnitude(x);
|
|
382
|
-
var decimalPlaceOffset = e - p + 1;
|
|
383
|
-
var n = Math.round(adjustDecimalPlace(x, decimalPlaceOffset));
|
|
384
|
-
if (adjustDecimalPlace(n, p - 1) >= 10) {
|
|
385
|
-
e = e + 1;
|
|
386
|
-
n = Math.floor(n / 10);
|
|
387
|
-
}
|
|
388
|
-
m = n.toString();
|
|
389
|
-
xFinal = adjustDecimalPlace(n, p - 1 - e);
|
|
390
|
-
}
|
|
2707
|
+
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ApplyUnsignedRoundingMode.js
|
|
2708
|
+
function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
|
|
2709
|
+
if (x.eq(r1))
|
|
2710
|
+
return r1;
|
|
2711
|
+
invariant(r1.lessThan(x) && x.lessThan(r2), "x should be between r1 and r2 but x=".concat(x, ", r1=").concat(r1, ", r2=").concat(r2));
|
|
2712
|
+
if (unsignedRoundingMode === "zero") {
|
|
2713
|
+
return r1;
|
|
391
2714
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
m = m + repeat("0", e - p + 1);
|
|
395
|
-
int = e + 1;
|
|
396
|
-
} else if (e >= 0) {
|
|
397
|
-
m = "".concat(m.slice(0, e + 1), ".").concat(m.slice(e + 1));
|
|
398
|
-
int = e + 1;
|
|
399
|
-
} else {
|
|
400
|
-
m = "0.".concat(repeat("0", -e - 1)).concat(m);
|
|
401
|
-
int = 1;
|
|
2715
|
+
if (unsignedRoundingMode === "infinity") {
|
|
2716
|
+
return r2;
|
|
402
2717
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
2718
|
+
var d1 = x.minus(r1);
|
|
2719
|
+
var d2 = r2.minus(x);
|
|
2720
|
+
if (d1.lessThan(d2)) {
|
|
2721
|
+
return r1;
|
|
2722
|
+
}
|
|
2723
|
+
if (d2.lessThan(d1)) {
|
|
2724
|
+
return r2;
|
|
2725
|
+
}
|
|
2726
|
+
invariant(d1.eq(d2), "d1 should be equal to d2");
|
|
2727
|
+
if (unsignedRoundingMode === "half-zero") {
|
|
2728
|
+
return r1;
|
|
2729
|
+
}
|
|
2730
|
+
if (unsignedRoundingMode === "half-infinity") {
|
|
2731
|
+
return r2;
|
|
412
2732
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
2733
|
+
invariant(unsignedRoundingMode === "half-even", "unsignedRoundingMode should be half-even");
|
|
2734
|
+
var cardinality = r1.div(r2.minus(r1)).mod(2);
|
|
2735
|
+
if (cardinality.isZero()) {
|
|
2736
|
+
return r1;
|
|
2737
|
+
}
|
|
2738
|
+
return r2;
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ComputeExponentForMagnitude.js
|
|
2742
|
+
decimal_default.set({
|
|
2743
|
+
toExpPos: 100
|
|
2744
|
+
});
|
|
2745
|
+
|
|
2746
|
+
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/GetUnsignedRoundingMode.js
|
|
2747
|
+
var negativeMapping = {
|
|
2748
|
+
ceil: "zero",
|
|
2749
|
+
floor: "infinity",
|
|
2750
|
+
expand: "infinity",
|
|
2751
|
+
trunc: "zero",
|
|
2752
|
+
halfCeil: "half-zero",
|
|
2753
|
+
halfFloor: "half-infinity",
|
|
2754
|
+
halfExpand: "half-infinity",
|
|
2755
|
+
halfTrunc: "half-zero",
|
|
2756
|
+
halfEven: "half-even"
|
|
2757
|
+
};
|
|
2758
|
+
var positiveMapping = {
|
|
2759
|
+
ceil: "infinity",
|
|
2760
|
+
floor: "zero",
|
|
2761
|
+
expand: "infinity",
|
|
2762
|
+
trunc: "zero",
|
|
2763
|
+
halfCeil: "half-infinity",
|
|
2764
|
+
halfFloor: "half-zero",
|
|
2765
|
+
halfExpand: "half-infinity",
|
|
2766
|
+
halfTrunc: "half-zero",
|
|
2767
|
+
halfEven: "half-even"
|
|
2768
|
+
};
|
|
2769
|
+
function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
2770
|
+
if (isNegative) {
|
|
2771
|
+
return negativeMapping[roundingMode];
|
|
416
2772
|
}
|
|
2773
|
+
return positiveMapping[roundingMode];
|
|
417
2774
|
}
|
|
418
2775
|
|
|
419
2776
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ToRawFixed.js
|
|
420
|
-
|
|
2777
|
+
decimal_default.set({
|
|
2778
|
+
toExpPos: 100
|
|
2779
|
+
});
|
|
2780
|
+
function ToRawFixedFn(n, f) {
|
|
2781
|
+
return n.times(TEN.pow(-f));
|
|
2782
|
+
}
|
|
2783
|
+
function findN1R1(x, f, roundingIncrement) {
|
|
2784
|
+
var nx = x.times(TEN.pow(f)).floor();
|
|
2785
|
+
var n1 = nx.div(roundingIncrement).floor().times(roundingIncrement);
|
|
2786
|
+
var r1 = ToRawFixedFn(n1, f);
|
|
2787
|
+
return {
|
|
2788
|
+
n1,
|
|
2789
|
+
r1
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
function findN2R2(x, f, roundingIncrement) {
|
|
2793
|
+
var nx = x.times(TEN.pow(f)).ceil();
|
|
2794
|
+
var n2 = nx.div(roundingIncrement).ceil().times(roundingIncrement);
|
|
2795
|
+
var r2 = ToRawFixedFn(n2, f);
|
|
2796
|
+
return {
|
|
2797
|
+
n2,
|
|
2798
|
+
r2
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
|
|
421
2802
|
var f = maxFraction;
|
|
422
|
-
var
|
|
423
|
-
var
|
|
2803
|
+
var _a = findN1R1(x, f, roundingIncrement), n1 = _a.n1, r1 = _a.r1;
|
|
2804
|
+
var _b = findN2R2(x, f, roundingIncrement), n2 = _b.n2, r2 = _b.r2;
|
|
2805
|
+
var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
|
|
2806
|
+
var n, xFinal;
|
|
424
2807
|
var m;
|
|
425
|
-
if (
|
|
426
|
-
|
|
2808
|
+
if (r.eq(r1)) {
|
|
2809
|
+
n = n1;
|
|
2810
|
+
xFinal = r1;
|
|
2811
|
+
} else {
|
|
2812
|
+
n = n2;
|
|
2813
|
+
xFinal = r2;
|
|
2814
|
+
}
|
|
2815
|
+
if (n.isZero()) {
|
|
2816
|
+
m = "0";
|
|
427
2817
|
} else {
|
|
428
2818
|
m = n.toString();
|
|
429
|
-
var _a = m.split("e"), mantissa = _a[0], exponent = _a[1];
|
|
430
|
-
m = mantissa.replace(".", "");
|
|
431
|
-
m = m + repeat("0", Math.max(+exponent - m.length + 1, 0));
|
|
432
2819
|
}
|
|
433
2820
|
var int;
|
|
434
2821
|
if (f !== 0) {
|
|
435
2822
|
var k = m.length;
|
|
436
2823
|
if (k <= f) {
|
|
437
|
-
var z = repeat("0", f + 1
|
|
2824
|
+
var z = repeat("0", f - k + 1);
|
|
438
2825
|
m = z + m;
|
|
439
2826
|
k = f + 1;
|
|
440
2827
|
}
|
|
441
2828
|
var a = m.slice(0, k - f);
|
|
442
|
-
var b = m.slice(
|
|
443
|
-
m =
|
|
2829
|
+
var b = m.slice(m.length - f);
|
|
2830
|
+
m = a + "." + b;
|
|
444
2831
|
int = a.length;
|
|
445
2832
|
} else {
|
|
446
2833
|
int = m.length;
|
|
447
2834
|
}
|
|
448
2835
|
var cut = maxFraction - minFraction;
|
|
449
2836
|
while (cut > 0 && m[m.length - 1] === "0") {
|
|
450
|
-
m = m.slice(0, -1);
|
|
2837
|
+
m = m.slice(0, m.length - 1);
|
|
451
2838
|
cut--;
|
|
452
2839
|
}
|
|
453
2840
|
if (m[m.length - 1] === ".") {
|
|
454
|
-
m = m.slice(0, -1);
|
|
2841
|
+
m = m.slice(0, m.length - 1);
|
|
2842
|
+
}
|
|
2843
|
+
return {
|
|
2844
|
+
formattedString: m,
|
|
2845
|
+
roundedNumber: xFinal,
|
|
2846
|
+
integerDigitsCount: int,
|
|
2847
|
+
roundingMagnitude: -f
|
|
2848
|
+
};
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/ToRawPrecision.js
|
|
2852
|
+
decimal_default.set({
|
|
2853
|
+
toExpPos: 100
|
|
2854
|
+
});
|
|
2855
|
+
function ToRawPrecisionFn(n, e, p) {
|
|
2856
|
+
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));
|
|
2857
|
+
return n.times(TEN.pow(e.minus(p).plus(1)));
|
|
2858
|
+
}
|
|
2859
|
+
function findN1E1R1(x, p) {
|
|
2860
|
+
var maxN1 = TEN.pow(p);
|
|
2861
|
+
var minN1 = TEN.pow(p - 1);
|
|
2862
|
+
var maxE1 = x.div(minN1).log(10).plus(p).minus(1).ceil();
|
|
2863
|
+
for (var currentE1 = maxE1; ; currentE1 = currentE1.minus(1)) {
|
|
2864
|
+
var currentN1 = x.div(TEN.pow(currentE1.minus(p).plus(1))).floor();
|
|
2865
|
+
if (currentN1.lessThan(maxN1) && currentN1.greaterThanOrEqualTo(minN1)) {
|
|
2866
|
+
var currentR1 = ToRawPrecisionFn(currentN1, currentE1, p);
|
|
2867
|
+
if (currentR1.lessThanOrEqualTo(x)) {
|
|
2868
|
+
return {
|
|
2869
|
+
n1: currentN1,
|
|
2870
|
+
e1: currentE1,
|
|
2871
|
+
r1: currentR1
|
|
2872
|
+
};
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
function findN2E2R2(x, p) {
|
|
2878
|
+
var maxN2 = TEN.pow(p);
|
|
2879
|
+
var minN2 = TEN.pow(p - 1);
|
|
2880
|
+
var minE2 = x.div(maxN2).log(10).plus(p).minus(1).floor();
|
|
2881
|
+
for (var currentE2 = minE2; ; currentE2 = currentE2.plus(1)) {
|
|
2882
|
+
var currentN2 = x.div(TEN.pow(currentE2.minus(p).plus(1))).ceil();
|
|
2883
|
+
if (currentN2.lessThan(maxN2) && currentN2.greaterThanOrEqualTo(minN2)) {
|
|
2884
|
+
var currentR2 = ToRawPrecisionFn(currentN2, currentE2, p);
|
|
2885
|
+
if (currentR2.greaterThanOrEqualTo(x)) {
|
|
2886
|
+
return {
|
|
2887
|
+
n2: currentN2,
|
|
2888
|
+
e2: currentE2,
|
|
2889
|
+
r2: currentR2
|
|
2890
|
+
};
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
2896
|
+
var p = maxPrecision;
|
|
2897
|
+
var m;
|
|
2898
|
+
var e;
|
|
2899
|
+
var xFinal;
|
|
2900
|
+
if (x.isZero()) {
|
|
2901
|
+
m = repeat("0", p);
|
|
2902
|
+
e = 0;
|
|
2903
|
+
xFinal = ZERO;
|
|
2904
|
+
} else {
|
|
2905
|
+
var _a = findN1E1R1(x, p), n1 = _a.n1, e1 = _a.e1, r1 = _a.r1;
|
|
2906
|
+
var _b = findN2E2R2(x, p), n2 = _b.n2, e2 = _b.e2, r2 = _b.r2;
|
|
2907
|
+
var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
|
|
2908
|
+
var n = void 0;
|
|
2909
|
+
if (r.eq(r1)) {
|
|
2910
|
+
n = n1;
|
|
2911
|
+
e = e1.toNumber();
|
|
2912
|
+
xFinal = r1;
|
|
2913
|
+
} else {
|
|
2914
|
+
n = n2;
|
|
2915
|
+
e = e2.toNumber();
|
|
2916
|
+
xFinal = r2;
|
|
2917
|
+
}
|
|
2918
|
+
m = n.toString();
|
|
2919
|
+
}
|
|
2920
|
+
var int;
|
|
2921
|
+
if (e >= p - 1) {
|
|
2922
|
+
m = m + repeat("0", e - p + 1);
|
|
2923
|
+
int = e + 1;
|
|
2924
|
+
} else if (e >= 0) {
|
|
2925
|
+
m = m.slice(0, e + 1) + "." + m.slice(m.length - (p - (e + 1)));
|
|
2926
|
+
int = e + 1;
|
|
2927
|
+
} else {
|
|
2928
|
+
invariant(e < 0, "e should be less than 0");
|
|
2929
|
+
m = "0." + repeat("0", -e - 1) + m;
|
|
2930
|
+
int = 1;
|
|
455
2931
|
}
|
|
456
|
-
|
|
2932
|
+
if (m.includes(".") && maxPrecision > minPrecision) {
|
|
2933
|
+
var cut = maxPrecision - minPrecision;
|
|
2934
|
+
while (cut > 0 && m[m.length - 1] === "0") {
|
|
2935
|
+
m = m.slice(0, m.length - 1);
|
|
2936
|
+
cut--;
|
|
2937
|
+
}
|
|
2938
|
+
if (m[m.length - 1] === ".") {
|
|
2939
|
+
m = m.slice(0, m.length - 1);
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
return {
|
|
2943
|
+
formattedString: m,
|
|
2944
|
+
roundedNumber: xFinal,
|
|
2945
|
+
integerDigitsCount: int,
|
|
2946
|
+
roundingMagnitude: e
|
|
2947
|
+
};
|
|
457
2948
|
}
|
|
458
2949
|
|
|
459
2950
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/FormatNumericToString.js
|
|
460
2951
|
function FormatNumericToString(intlObject, x) {
|
|
461
|
-
var
|
|
462
|
-
if (isNegative) {
|
|
463
|
-
|
|
2952
|
+
var sign2;
|
|
2953
|
+
if (x.isZero() && x.isNegative()) {
|
|
2954
|
+
sign2 = "negative";
|
|
2955
|
+
x = ZERO;
|
|
2956
|
+
} else {
|
|
2957
|
+
invariant(x.isFinite(), "NumberFormatDigitInternalSlots value is not finite");
|
|
2958
|
+
if (x.lessThan(0)) {
|
|
2959
|
+
sign2 = "negative";
|
|
2960
|
+
} else {
|
|
2961
|
+
sign2 = "positive";
|
|
2962
|
+
}
|
|
2963
|
+
if (sign2 === "negative") {
|
|
2964
|
+
x = x.negated();
|
|
2965
|
+
}
|
|
464
2966
|
}
|
|
465
2967
|
var result;
|
|
466
|
-
var
|
|
467
|
-
|
|
2968
|
+
var roundingType = intlObject.roundingType;
|
|
2969
|
+
var unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign2 === "negative");
|
|
2970
|
+
switch (roundingType) {
|
|
468
2971
|
case "significantDigits":
|
|
469
|
-
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
|
|
2972
|
+
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
470
2973
|
break;
|
|
471
2974
|
case "fractionDigits":
|
|
472
|
-
result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
|
|
2975
|
+
result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
|
|
473
2976
|
break;
|
|
474
2977
|
default:
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
2978
|
+
var sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
2979
|
+
var fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
|
|
2980
|
+
if (intlObject.roundingType === "morePrecision") {
|
|
2981
|
+
if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
|
|
2982
|
+
result = sResult;
|
|
2983
|
+
} else {
|
|
2984
|
+
result = fResult;
|
|
2985
|
+
}
|
|
2986
|
+
} else {
|
|
2987
|
+
invariant(intlObject.roundingType === "lessPrecision", "Invalid roundingType");
|
|
2988
|
+
if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
|
|
2989
|
+
result = fResult;
|
|
2990
|
+
} else {
|
|
2991
|
+
result = sResult;
|
|
2992
|
+
}
|
|
478
2993
|
}
|
|
479
2994
|
break;
|
|
480
2995
|
}
|
|
481
2996
|
x = result.roundedNumber;
|
|
482
2997
|
var string = result.formattedString;
|
|
2998
|
+
if (intlObject.trailingZeroDisplay === "stripIfInteger" && x.isInteger()) {
|
|
2999
|
+
var i = string.indexOf(".");
|
|
3000
|
+
if (i > -1) {
|
|
3001
|
+
string = string.slice(0, i);
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
483
3004
|
var int = result.integerDigitsCount;
|
|
484
3005
|
var minInteger = intlObject.minimumIntegerDigits;
|
|
485
3006
|
if (int < minInteger) {
|
|
486
3007
|
var forwardZeros = repeat("0", minInteger - int);
|
|
487
3008
|
string = forwardZeros + string;
|
|
488
3009
|
}
|
|
489
|
-
if (
|
|
490
|
-
x
|
|
3010
|
+
if (sign2 === "negative") {
|
|
3011
|
+
if (x.isZero()) {
|
|
3012
|
+
x = NEGATIVE_ZERO;
|
|
3013
|
+
} else {
|
|
3014
|
+
x = x.negated();
|
|
3015
|
+
}
|
|
491
3016
|
}
|
|
492
3017
|
return { roundedNumber: x, formattedString: string };
|
|
493
3018
|
}
|
|
@@ -4872,6 +7397,23 @@
|
|
|
4872
7397
|
}
|
|
4873
7398
|
|
|
4874
7399
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/SetNumberFormatDigitOptions.js
|
|
7400
|
+
var VALID_ROUNDING_INCREMENTS = /* @__PURE__ */ new Set([
|
|
7401
|
+
1,
|
|
7402
|
+
2,
|
|
7403
|
+
5,
|
|
7404
|
+
10,
|
|
7405
|
+
20,
|
|
7406
|
+
25,
|
|
7407
|
+
50,
|
|
7408
|
+
100,
|
|
7409
|
+
200,
|
|
7410
|
+
250,
|
|
7411
|
+
500,
|
|
7412
|
+
1e3,
|
|
7413
|
+
2e3,
|
|
7414
|
+
2500,
|
|
7415
|
+
5e3
|
|
7416
|
+
]);
|
|
4875
7417
|
function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
4876
7418
|
var mnid = GetNumberOption(opts, "minimumIntegerDigits", 1, 21, 1);
|
|
4877
7419
|
var mnfd = opts.minimumFractionDigits;
|
|
@@ -4879,7 +7421,27 @@
|
|
|
4879
7421
|
var mnsd = opts.minimumSignificantDigits;
|
|
4880
7422
|
var mxsd = opts.maximumSignificantDigits;
|
|
4881
7423
|
internalSlots.minimumIntegerDigits = mnid;
|
|
7424
|
+
var roundingIncrement = GetNumberOption(opts, "roundingIncrement", 1, 5e3, 1);
|
|
7425
|
+
invariant(VALID_ROUNDING_INCREMENTS.has(roundingIncrement), "Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(Array.from(VALID_ROUNDING_INCREMENTS).join(", "), "."));
|
|
7426
|
+
var roundingMode = GetOption(opts, "roundingMode", "string", [
|
|
7427
|
+
"ceil",
|
|
7428
|
+
"floor",
|
|
7429
|
+
"expand",
|
|
7430
|
+
"trunc",
|
|
7431
|
+
"halfCeil",
|
|
7432
|
+
"halfFloor",
|
|
7433
|
+
"halfExpand",
|
|
7434
|
+
"halfTrunc",
|
|
7435
|
+
"halfEven"
|
|
7436
|
+
], "halfExpand");
|
|
4882
7437
|
var roundingPriority = GetOption(opts, "roundingPriority", "string", ["auto", "morePrecision", "lessPrecision"], "auto");
|
|
7438
|
+
var trailingZeroDisplay = GetOption(opts, "trailingZeroDisplay", "string", ["auto", "stripIfInteger"], "auto");
|
|
7439
|
+
if (roundingIncrement !== 1) {
|
|
7440
|
+
mxfdDefault = mnfdDefault;
|
|
7441
|
+
}
|
|
7442
|
+
internalSlots.roundingIncrement = roundingIncrement;
|
|
7443
|
+
internalSlots.roundingMode = roundingMode;
|
|
7444
|
+
internalSlots.trailingZeroDisplay = trailingZeroDisplay;
|
|
4883
7445
|
var hasSd = mnsd !== void 0 || mxsd !== void 0;
|
|
4884
7446
|
var hasFd = mnfd !== void 0 || mxfd !== void 0;
|
|
4885
7447
|
var needSd = true;
|
|
@@ -4892,10 +7454,8 @@
|
|
|
4892
7454
|
}
|
|
4893
7455
|
if (needSd) {
|
|
4894
7456
|
if (hasSd) {
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
internalSlots.minimumSignificantDigits = mnsd;
|
|
4898
|
-
internalSlots.maximumSignificantDigits = mxsd;
|
|
7457
|
+
internalSlots.minimumSignificantDigits = DefaultNumberOption(mnsd, 1, 21, 1);
|
|
7458
|
+
internalSlots.maximumSignificantDigits = DefaultNumberOption(mxsd, internalSlots.minimumSignificantDigits, 21, 21);
|
|
4899
7459
|
} else {
|
|
4900
7460
|
internalSlots.minimumSignificantDigits = 1;
|
|
4901
7461
|
internalSlots.maximumSignificantDigits = 21;
|
|
@@ -4903,10 +7463,10 @@
|
|
|
4903
7463
|
}
|
|
4904
7464
|
if (needFd) {
|
|
4905
7465
|
if (hasFd) {
|
|
4906
|
-
mnfd = DefaultNumberOption(mnfd, 0,
|
|
4907
|
-
mxfd = DefaultNumberOption(mxfd, 0,
|
|
7466
|
+
mnfd = DefaultNumberOption(mnfd, 0, 100, void 0);
|
|
7467
|
+
mxfd = DefaultNumberOption(mxfd, 0, 100, void 0);
|
|
4908
7468
|
if (mnfd === void 0) {
|
|
4909
|
-
mnfd = Math.min(mnfdDefault, mxfd);
|
|
7469
|
+
mnfd = Math.min(mnfdDefault, mxfd !== null && mxfd !== void 0 ? mxfd : 0);
|
|
4910
7470
|
} else if (mxfd === void 0) {
|
|
4911
7471
|
mxfd = Math.max(mxfdDefault, mnfd);
|
|
4912
7472
|
} else if (mnfd > mxfd) {
|
|
@@ -4919,22 +7479,29 @@
|
|
|
4919
7479
|
internalSlots.maximumFractionDigits = mxfdDefault;
|
|
4920
7480
|
}
|
|
4921
7481
|
}
|
|
4922
|
-
if (needSd
|
|
4923
|
-
if (roundingPriority === "morePrecision") {
|
|
4924
|
-
internalSlots.roundingType = "morePrecision";
|
|
4925
|
-
} else if (roundingPriority === "lessPrecision") {
|
|
4926
|
-
internalSlots.roundingType = "lessPrecision";
|
|
4927
|
-
} else if (hasSd) {
|
|
4928
|
-
internalSlots.roundingType = "significantDigits";
|
|
4929
|
-
} else {
|
|
4930
|
-
internalSlots.roundingType = "fractionDigits";
|
|
4931
|
-
}
|
|
4932
|
-
} else {
|
|
4933
|
-
internalSlots.roundingType = "morePrecision";
|
|
7482
|
+
if (!needSd && !needFd) {
|
|
4934
7483
|
internalSlots.minimumFractionDigits = 0;
|
|
4935
7484
|
internalSlots.maximumFractionDigits = 0;
|
|
4936
7485
|
internalSlots.minimumSignificantDigits = 1;
|
|
4937
7486
|
internalSlots.maximumSignificantDigits = 2;
|
|
7487
|
+
internalSlots.roundingType = "morePrecision";
|
|
7488
|
+
internalSlots.roundingPriority = "morePrecision";
|
|
7489
|
+
} else if (roundingPriority === "morePrecision") {
|
|
7490
|
+
internalSlots.roundingType = "morePrecision";
|
|
7491
|
+
internalSlots.roundingPriority = "morePrecision";
|
|
7492
|
+
} else if (roundingPriority === "lessPrecision") {
|
|
7493
|
+
internalSlots.roundingType = "lessPrecision";
|
|
7494
|
+
internalSlots.roundingPriority = "lessPrecision";
|
|
7495
|
+
} else if (hasSd) {
|
|
7496
|
+
internalSlots.roundingType = "significantDigits";
|
|
7497
|
+
internalSlots.roundingPriority = "auto";
|
|
7498
|
+
} else {
|
|
7499
|
+
internalSlots.roundingType = "fractionDigits";
|
|
7500
|
+
internalSlots.roundingPriority = "auto";
|
|
7501
|
+
}
|
|
7502
|
+
if (roundingIncrement !== 1) {
|
|
7503
|
+
invariant(internalSlots.roundingType === "fractionDigits", "Invalid roundingType");
|
|
7504
|
+
invariant(internalSlots.maximumFractionDigits === internalSlots.minimumFractionDigits, "With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.");
|
|
4938
7505
|
}
|
|
4939
7506
|
}
|
|
4940
7507
|
|
|
@@ -4994,14 +7561,6 @@
|
|
|
4994
7561
|
"best fit"
|
|
4995
7562
|
);
|
|
4996
7563
|
opt.localeMatcher = matcher;
|
|
4997
|
-
internalSlots.type = GetOption(
|
|
4998
|
-
opts,
|
|
4999
|
-
"type",
|
|
5000
|
-
"string",
|
|
5001
|
-
["cardinal", "ordinal"],
|
|
5002
|
-
"cardinal"
|
|
5003
|
-
);
|
|
5004
|
-
SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, "standard");
|
|
5005
7564
|
const r = ResolveLocale(
|
|
5006
7565
|
availableLocales,
|
|
5007
7566
|
requestedLocales,
|
|
@@ -5011,6 +7570,14 @@
|
|
|
5011
7570
|
getDefaultLocale
|
|
5012
7571
|
);
|
|
5013
7572
|
internalSlots.locale = r.locale;
|
|
7573
|
+
internalSlots.type = GetOption(
|
|
7574
|
+
opts,
|
|
7575
|
+
"type",
|
|
7576
|
+
"string",
|
|
7577
|
+
["cardinal", "ordinal"],
|
|
7578
|
+
"cardinal"
|
|
7579
|
+
);
|
|
7580
|
+
SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, "standard");
|
|
5014
7581
|
return pl;
|
|
5015
7582
|
}
|
|
5016
7583
|
|
|
@@ -5021,7 +7588,7 @@
|
|
|
5021
7588
|
`GetOperands should have been called with a string`
|
|
5022
7589
|
);
|
|
5023
7590
|
const n = ToNumber(s);
|
|
5024
|
-
invariant(isFinite(
|
|
7591
|
+
invariant(n.isFinite(), "n should be finite");
|
|
5025
7592
|
let dp = s.indexOf(".");
|
|
5026
7593
|
let iv;
|
|
5027
7594
|
let f;
|
|
@@ -5029,7 +7596,7 @@
|
|
|
5029
7596
|
let fv = "";
|
|
5030
7597
|
if (dp === -1) {
|
|
5031
7598
|
iv = n;
|
|
5032
|
-
f =
|
|
7599
|
+
f = ZERO;
|
|
5033
7600
|
v = 0;
|
|
5034
7601
|
} else {
|
|
5035
7602
|
iv = s.slice(0, dp);
|
|
@@ -5037,24 +7604,24 @@
|
|
|
5037
7604
|
f = ToNumber(fv);
|
|
5038
7605
|
v = fv.length;
|
|
5039
7606
|
}
|
|
5040
|
-
const i =
|
|
7607
|
+
const i = ToNumber(iv).abs();
|
|
5041
7608
|
let w;
|
|
5042
7609
|
let t;
|
|
5043
|
-
if (f
|
|
7610
|
+
if (!f.isZero()) {
|
|
5044
7611
|
const ft = fv.replace(/0+$/, "");
|
|
5045
7612
|
w = ft.length;
|
|
5046
7613
|
t = ToNumber(ft);
|
|
5047
7614
|
} else {
|
|
5048
7615
|
w = 0;
|
|
5049
|
-
t =
|
|
7616
|
+
t = ZERO;
|
|
5050
7617
|
}
|
|
5051
7618
|
return {
|
|
5052
7619
|
Number: n,
|
|
5053
|
-
IntegerDigits: i,
|
|
7620
|
+
IntegerDigits: i.toNumber(),
|
|
5054
7621
|
NumberOfFractionDigits: v,
|
|
5055
7622
|
NumberOfFractionDigitsWithoutTrailing: w,
|
|
5056
|
-
FractionDigits: f,
|
|
5057
|
-
FractionDigitsWithoutTrailing: t
|
|
7623
|
+
FractionDigits: f.toNumber(),
|
|
7624
|
+
FractionDigitsWithoutTrailing: t.toNumber()
|
|
5058
7625
|
};
|
|
5059
7626
|
}
|
|
5060
7627
|
|
|
@@ -5069,8 +7636,7 @@
|
|
|
5069
7636
|
"initializedPluralRules" in internalSlots,
|
|
5070
7637
|
"pluralrules must be initialized"
|
|
5071
7638
|
);
|
|
5072
|
-
|
|
5073
|
-
if (!isFinite(n)) {
|
|
7639
|
+
if (!n.isFinite()) {
|
|
5074
7640
|
return "other";
|
|
5075
7641
|
}
|
|
5076
7642
|
const { locale, type } = internalSlots;
|
|
@@ -5245,4 +7811,15 @@
|
|
|
5245
7811
|
});
|
|
5246
7812
|
}
|
|
5247
7813
|
})();
|
|
7814
|
+
/*! Bundled license information:
|
|
7815
|
+
|
|
7816
|
+
decimal.js/decimal.mjs:
|
|
7817
|
+
(*!
|
|
7818
|
+
* decimal.js v10.4.3
|
|
7819
|
+
* An arbitrary-precision Decimal type for JavaScript.
|
|
7820
|
+
* https://github.com/MikeMcl/decimal.js
|
|
7821
|
+
* Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
7822
|
+
* MIT Licence
|
|
7823
|
+
*)
|
|
7824
|
+
*/
|
|
5248
7825
|
//# sourceMappingURL=polyfill.iife.js.map
|