@formatjs/intl-pluralrules 6.2.4 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstract/GetOperands.d.ts +1 -1
- package/abstract/ResolvePlural.d.ts +1 -1
- package/abstract/ResolvePlural.js +1 -1
- package/abstract/ResolvePluralRange.d.ts +1 -1
- package/locale-data/af.js +15 -0
- package/locale-data/ak.js +15 -0
- package/locale-data/am.js +16 -0
- package/locale-data/an.js +15 -0
- package/locale-data/ar.js +23 -0
- package/locale-data/ars.js +23 -0
- package/locale-data/as.js +24 -0
- package/locale-data/asa.js +15 -0
- package/locale-data/ast.js +16 -0
- package/locale-data/az.js +22 -0
- package/locale-data/bal.js +17 -0
- package/locale-data/be.js +21 -0
- package/locale-data/bem.js +15 -0
- package/locale-data/bez.js +15 -0
- package/locale-data/bg.js +15 -0
- package/locale-data/bho.js +15 -0
- package/locale-data/bm.js +4 -0
- package/locale-data/bn.js +24 -0
- package/locale-data/bo.js +4 -0
- package/locale-data/br.js +21 -0
- package/locale-data/brx.js +15 -0
- package/locale-data/bs.js +19 -0
- package/locale-data/ca.js +26 -0
- package/locale-data/ce.js +15 -0
- package/locale-data/ceb.js +17 -0
- package/locale-data/cgg.js +15 -0
- package/locale-data/chr.js +15 -0
- package/locale-data/ckb.js +15 -0
- package/locale-data/cs.js +20 -0
- package/locale-data/cy.js +33 -0
- package/locale-data/da.js +18 -0
- package/locale-data/de.js +16 -0
- package/locale-data/doi.js +16 -0
- package/locale-data/dsb.js +21 -0
- package/locale-data/dv.js +15 -0
- package/locale-data/dz.js +4 -0
- package/locale-data/ee.js +15 -0
- package/locale-data/el.js +15 -0
- package/locale-data/en.js +23 -0
- package/locale-data/eo.js +15 -0
- package/locale-data/es.js +20 -0
- package/locale-data/et.js +16 -0
- package/locale-data/eu.js +15 -0
- package/locale-data/fa.js +16 -0
- package/locale-data/ff.js +15 -0
- package/locale-data/fi.js +16 -0
- package/locale-data/fil.js +20 -0
- package/locale-data/fo.js +15 -0
- package/locale-data/fr.js +22 -0
- package/locale-data/fur.js +15 -0
- package/locale-data/fy.js +16 -0
- package/locale-data/ga.js +23 -0
- package/locale-data/gd.js +25 -0
- package/locale-data/gl.js +16 -0
- package/locale-data/gsw.js +15 -0
- package/locale-data/gu.js +24 -0
- package/locale-data/guw.js +15 -0
- package/locale-data/gv.js +22 -0
- package/locale-data/ha.js +15 -0
- package/locale-data/haw.js +15 -0
- package/locale-data/he.js +18 -0
- package/locale-data/hi.js +24 -0
- package/locale-data/hnj.js +4 -0
- package/locale-data/hr.js +19 -0
- package/locale-data/hsb.js +21 -0
- package/locale-data/hu.js +17 -0
- package/locale-data/hy.js +18 -0
- package/locale-data/ia.js +16 -0
- package/locale-data/id.js +4 -0
- package/locale-data/ig.js +4 -0
- package/locale-data/ii.js +4 -0
- package/locale-data/io.js +16 -0
- package/locale-data/is.js +17 -0
- package/locale-data/it.js +22 -0
- package/locale-data/iu.js +17 -0
- package/locale-data/ja.js +4 -0
- package/locale-data/jbo.js +4 -0
- package/locale-data/jgo.js +15 -0
- package/locale-data/jmc.js +15 -0
- package/locale-data/jv.js +4 -0
- package/locale-data/jw.js +4 -0
- package/locale-data/ka.js +20 -0
- package/locale-data/kab.js +15 -0
- package/locale-data/kaj.js +15 -0
- package/locale-data/kcg.js +15 -0
- package/locale-data/kde.js +4 -0
- package/locale-data/kea.js +4 -0
- package/locale-data/kk.js +17 -0
- package/locale-data/kkj.js +15 -0
- package/locale-data/kl.js +15 -0
- package/locale-data/km.js +4 -0
- package/locale-data/kn.js +16 -0
- package/locale-data/ko.js +4 -0
- package/locale-data/ks.js +15 -0
- package/locale-data/ksb.js +15 -0
- package/locale-data/ksh.js +17 -0
- package/locale-data/ku.js +15 -0
- package/locale-data/kw.js +27 -0
- package/locale-data/ky.js +15 -0
- package/locale-data/lag.js +18 -0
- package/locale-data/lb.js +15 -0
- package/locale-data/lg.js +15 -0
- package/locale-data/lij.js +19 -0
- package/locale-data/lkt.js +4 -0
- package/locale-data/ln.js +15 -0
- package/locale-data/lo.js +15 -0
- package/locale-data/lt.js +21 -0
- package/locale-data/lv.js +19 -0
- package/locale-data/mas.js +15 -0
- package/locale-data/mg.js +15 -0
- package/locale-data/mgo.js +15 -0
- package/locale-data/mk.js +23 -0
- package/locale-data/ml.js +15 -0
- package/locale-data/mn.js +15 -0
- package/locale-data/mo.js +21 -0
- package/locale-data/mr.js +21 -0
- package/locale-data/ms.js +15 -0
- package/locale-data/mt.js +21 -0
- package/locale-data/my.js +4 -0
- package/locale-data/nah.js +15 -0
- package/locale-data/naq.js +17 -0
- package/locale-data/nb.js +15 -0
- package/locale-data/nd.js +15 -0
- package/locale-data/ne.js +17 -0
- package/locale-data/nl.js +16 -0
- package/locale-data/nn.js +15 -0
- package/locale-data/nnh.js +15 -0
- package/locale-data/no.js +15 -0
- package/locale-data/nqo.js +4 -0
- package/locale-data/nr.js +15 -0
- package/locale-data/nso.js +15 -0
- package/locale-data/ny.js +15 -0
- package/locale-data/nyn.js +15 -0
- package/locale-data/om.js +15 -0
- package/locale-data/or.js +23 -0
- package/locale-data/os.js +15 -0
- package/locale-data/osa.js +4 -0
- package/locale-data/pa.js +15 -0
- package/locale-data/pap.js +15 -0
- package/locale-data/pcm.js +16 -0
- package/locale-data/pl.js +20 -0
- package/locale-data/prg.js +19 -0
- package/locale-data/ps.js +15 -0
- package/locale-data/pt-PT.js +19 -0
- package/locale-data/pt.js +19 -0
- package/locale-data/rm.js +15 -0
- package/locale-data/ro.js +21 -0
- package/locale-data/rof.js +15 -0
- package/locale-data/ru.js +20 -0
- package/locale-data/rwk.js +15 -0
- package/locale-data/sah.js +4 -0
- package/locale-data/saq.js +15 -0
- package/locale-data/sat.js +17 -0
- package/locale-data/sc.js +19 -0
- package/locale-data/scn.js +22 -0
- package/locale-data/sd.js +15 -0
- package/locale-data/sdh.js +15 -0
- package/locale-data/se.js +17 -0
- package/locale-data/seh.js +15 -0
- package/locale-data/ses.js +4 -0
- package/locale-data/sg.js +4 -0
- package/locale-data/sh.js +19 -0
- package/locale-data/shi.js +18 -0
- package/locale-data/si.js +18 -0
- package/locale-data/sk.js +20 -0
- package/locale-data/sl.js +20 -0
- package/locale-data/sma.js +17 -0
- package/locale-data/smi.js +17 -0
- package/locale-data/smj.js +17 -0
- package/locale-data/smn.js +17 -0
- package/locale-data/sms.js +17 -0
- package/locale-data/sn.js +15 -0
- package/locale-data/so.js +15 -0
- package/locale-data/sq.js +19 -0
- package/locale-data/sr.js +19 -0
- package/locale-data/ss.js +15 -0
- package/locale-data/ssy.js +15 -0
- package/locale-data/st.js +15 -0
- package/locale-data/su.js +4 -0
- package/locale-data/sv.js +19 -0
- package/locale-data/sw.js +16 -0
- package/locale-data/syr.js +15 -0
- package/locale-data/ta.js +15 -0
- package/locale-data/te.js +15 -0
- package/locale-data/teo.js +15 -0
- package/locale-data/th.js +4 -0
- package/locale-data/ti.js +15 -0
- package/locale-data/tig.js +15 -0
- package/locale-data/tk.js +17 -0
- package/locale-data/tl.js +20 -0
- package/locale-data/tn.js +15 -0
- package/locale-data/to.js +4 -0
- package/locale-data/tpi.js +4 -0
- package/locale-data/tr.js +15 -0
- package/locale-data/ts.js +15 -0
- package/locale-data/tzm.js +15 -0
- package/locale-data/ug.js +15 -0
- package/locale-data/uk.js +23 -0
- package/locale-data/und.js +4 -0
- package/locale-data/ur.js +16 -0
- package/locale-data/uz.js +15 -0
- package/locale-data/ve.js +15 -0
- package/locale-data/vi.js +15 -0
- package/locale-data/vo.js +15 -0
- package/locale-data/vun.js +15 -0
- package/locale-data/wa.js +15 -0
- package/locale-data/wae.js +15 -0
- package/locale-data/wo.js +4 -0
- package/locale-data/xh.js +15 -0
- package/locale-data/xog.js +15 -0
- package/locale-data/yi.js +16 -0
- package/locale-data/yo.js +4 -0
- package/locale-data/yue.js +4 -0
- package/locale-data/zh.js +4 -0
- package/locale-data/zu.js +16 -0
- package/package.json +6 -6
- package/polyfill-force.js +6 -0
- package/polyfill.iife.js +620 -2356
- package/polyfill.js +6 -0
package/polyfill.iife.js
CHANGED
|
@@ -11,2372 +11,647 @@
|
|
|
11
11
|
return Intl.getCanonicalLocales(locales);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// node_modules/.aspect_rules_js
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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))));
|
|
14
|
+
// node_modules/.aspect_rules_js/@formatjs+bigdecimal@0.0.0/node_modules/@formatjs/bigdecimal/index.js
|
|
15
|
+
var DIV_PRECISION = 40;
|
|
16
|
+
var SpecialValue = function(SpecialValue2) {
|
|
17
|
+
SpecialValue2[SpecialValue2["NONE"] = 0] = "NONE";
|
|
18
|
+
SpecialValue2[SpecialValue2["NAN"] = 1] = "NAN";
|
|
19
|
+
SpecialValue2[SpecialValue2["POSITIVE_INFINITY"] = 2] = "POSITIVE_INFINITY";
|
|
20
|
+
SpecialValue2[SpecialValue2["NEGATIVE_INFINITY"] = 3] = "NEGATIVE_INFINITY";
|
|
21
|
+
return SpecialValue2;
|
|
22
|
+
}(SpecialValue || {});
|
|
23
|
+
function removeTrailingZeros(mantissa, exponent) {
|
|
24
|
+
if (mantissa === 0n)
|
|
25
|
+
return [0n, 0];
|
|
26
|
+
while (mantissa % 10n === 0n) {
|
|
27
|
+
mantissa /= 10n;
|
|
28
|
+
exponent++;
|
|
29
|
+
}
|
|
30
|
+
return [mantissa, exponent];
|
|
31
|
+
}
|
|
32
|
+
function bigintAbs(n) {
|
|
33
|
+
return n < 0n ? -n : n;
|
|
34
|
+
}
|
|
35
|
+
function digitCount(n) {
|
|
36
|
+
if (n === 0n)
|
|
37
|
+
return 1;
|
|
38
|
+
if (n < 0n)
|
|
39
|
+
n = -n;
|
|
40
|
+
let count = 0;
|
|
41
|
+
const big15 = 1000000000000000n;
|
|
42
|
+
while (n >= big15) {
|
|
43
|
+
n /= big15;
|
|
44
|
+
count += 15;
|
|
45
|
+
}
|
|
46
|
+
let r = Number(n);
|
|
47
|
+
while (r >= 1) {
|
|
48
|
+
r /= 10;
|
|
49
|
+
count++;
|
|
50
|
+
}
|
|
51
|
+
return count;
|
|
52
|
+
}
|
|
53
|
+
var TEN_BIGINT = 10n;
|
|
54
|
+
function bigintPow10(n) {
|
|
55
|
+
if (n <= 0)
|
|
56
|
+
return 1n;
|
|
57
|
+
let result = 1n;
|
|
58
|
+
let base = TEN_BIGINT;
|
|
59
|
+
let exp = n;
|
|
60
|
+
while (exp > 0) {
|
|
61
|
+
if (exp & 1)
|
|
62
|
+
result *= base;
|
|
63
|
+
base *= base;
|
|
64
|
+
exp >>= 1;
|
|
264
65
|
}
|
|
265
|
-
return
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function parseDecimalString(s) {
|
|
69
|
+
s = s.trim();
|
|
70
|
+
if (s === "NaN") {
|
|
71
|
+
return {
|
|
72
|
+
mantissa: 0n,
|
|
73
|
+
exponent: 0,
|
|
74
|
+
special: SpecialValue.NAN,
|
|
75
|
+
negativeZero: false
|
|
76
|
+
};
|
|
288
77
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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 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 = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
|
|
315
|
-
Ctor.precision = pr;
|
|
316
|
-
Ctor.rounding = rm;
|
|
317
|
-
return x.times(2);
|
|
318
|
-
};
|
|
319
|
-
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
320
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
321
|
-
if (x.lte(1))
|
|
322
|
-
return new Ctor(x.eq(1) ? 0 : NaN);
|
|
323
|
-
if (!x.isFinite())
|
|
324
|
-
return new Ctor(x);
|
|
325
|
-
pr = Ctor.precision;
|
|
326
|
-
rm = Ctor.rounding;
|
|
327
|
-
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
328
|
-
Ctor.rounding = 1;
|
|
329
|
-
external = false;
|
|
330
|
-
x = x.times(x).minus(1).sqrt().plus(x);
|
|
331
|
-
external = true;
|
|
332
|
-
Ctor.precision = pr;
|
|
333
|
-
Ctor.rounding = rm;
|
|
334
|
-
return x.ln();
|
|
335
|
-
};
|
|
336
|
-
P.inverseHyperbolicSine = P.asinh = function() {
|
|
337
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
338
|
-
if (!x.isFinite() || x.isZero())
|
|
339
|
-
return new Ctor(x);
|
|
340
|
-
pr = Ctor.precision;
|
|
341
|
-
rm = Ctor.rounding;
|
|
342
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
343
|
-
Ctor.rounding = 1;
|
|
344
|
-
external = false;
|
|
345
|
-
x = x.times(x).plus(1).sqrt().plus(x);
|
|
346
|
-
external = true;
|
|
347
|
-
Ctor.precision = pr;
|
|
348
|
-
Ctor.rounding = rm;
|
|
349
|
-
return x.ln();
|
|
350
|
-
};
|
|
351
|
-
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
352
|
-
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
353
|
-
if (!x.isFinite())
|
|
354
|
-
return new Ctor(NaN);
|
|
355
|
-
if (x.e >= 0)
|
|
356
|
-
return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
357
|
-
pr = Ctor.precision;
|
|
358
|
-
rm = Ctor.rounding;
|
|
359
|
-
xsd = x.sd();
|
|
360
|
-
if (Math.max(xsd, pr) < 2 * -x.e - 1)
|
|
361
|
-
return finalise(new Ctor(x), pr, rm, true);
|
|
362
|
-
Ctor.precision = wpr = xsd - x.e;
|
|
363
|
-
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
364
|
-
Ctor.precision = pr + 4;
|
|
365
|
-
Ctor.rounding = 1;
|
|
366
|
-
x = x.ln();
|
|
367
|
-
Ctor.precision = pr;
|
|
368
|
-
Ctor.rounding = rm;
|
|
369
|
-
return x.times(0.5);
|
|
370
|
-
};
|
|
371
|
-
P.inverseSine = P.asin = function() {
|
|
372
|
-
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
373
|
-
if (x.isZero())
|
|
374
|
-
return new Ctor(x);
|
|
375
|
-
k = x.abs().cmp(1);
|
|
376
|
-
pr = Ctor.precision;
|
|
377
|
-
rm = Ctor.rounding;
|
|
378
|
-
if (k !== -1) {
|
|
379
|
-
if (k === 0) {
|
|
380
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
381
|
-
halfPi.s = x.s;
|
|
382
|
-
return halfPi;
|
|
383
|
-
}
|
|
384
|
-
return new Ctor(NaN);
|
|
385
|
-
}
|
|
386
|
-
Ctor.precision = pr + 6;
|
|
387
|
-
Ctor.rounding = 1;
|
|
388
|
-
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
|
389
|
-
Ctor.precision = pr;
|
|
390
|
-
Ctor.rounding = rm;
|
|
391
|
-
return x.times(2);
|
|
392
|
-
};
|
|
393
|
-
P.inverseTangent = P.atan = function() {
|
|
394
|
-
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
395
|
-
if (!x.isFinite()) {
|
|
396
|
-
if (!x.s)
|
|
397
|
-
return new Ctor(NaN);
|
|
398
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
399
|
-
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
400
|
-
r.s = x.s;
|
|
401
|
-
return r;
|
|
402
|
-
}
|
|
403
|
-
} else if (x.isZero()) {
|
|
404
|
-
return new Ctor(x);
|
|
405
|
-
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
406
|
-
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
407
|
-
r.s = x.s;
|
|
408
|
-
return r;
|
|
409
|
-
}
|
|
410
|
-
Ctor.precision = wpr = pr + 10;
|
|
411
|
-
Ctor.rounding = 1;
|
|
412
|
-
k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
|
413
|
-
for (i = k; i; --i)
|
|
414
|
-
x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
|
415
|
-
external = false;
|
|
416
|
-
j = Math.ceil(wpr / LOG_BASE);
|
|
417
|
-
n = 1;
|
|
418
|
-
x2 = x.times(x);
|
|
419
|
-
r = new Ctor(x);
|
|
420
|
-
px = x;
|
|
421
|
-
for (; i !== -1; ) {
|
|
422
|
-
px = px.times(x2);
|
|
423
|
-
t = r.minus(px.div(n += 2));
|
|
424
|
-
px = px.times(x2);
|
|
425
|
-
r = t.plus(px.div(n += 2));
|
|
426
|
-
if (r.d[j] !== void 0)
|
|
427
|
-
for (i = j; r.d[i] === t.d[i] && i--; )
|
|
428
|
-
;
|
|
429
|
-
}
|
|
430
|
-
if (k)
|
|
431
|
-
r = r.times(2 << k - 1);
|
|
432
|
-
external = true;
|
|
433
|
-
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
434
|
-
};
|
|
435
|
-
P.isFinite = function() {
|
|
436
|
-
return !!this.d;
|
|
437
|
-
};
|
|
438
|
-
P.isInteger = P.isInt = function() {
|
|
439
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
440
|
-
};
|
|
441
|
-
P.isNaN = function() {
|
|
442
|
-
return !this.s;
|
|
443
|
-
};
|
|
444
|
-
P.isNegative = P.isNeg = function() {
|
|
445
|
-
return this.s < 0;
|
|
446
|
-
};
|
|
447
|
-
P.isPositive = P.isPos = function() {
|
|
448
|
-
return this.s > 0;
|
|
449
|
-
};
|
|
450
|
-
P.isZero = function() {
|
|
451
|
-
return !!this.d && this.d[0] === 0;
|
|
452
|
-
};
|
|
453
|
-
P.lessThan = P.lt = function(y) {
|
|
454
|
-
return this.cmp(y) < 0;
|
|
455
|
-
};
|
|
456
|
-
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
457
|
-
return this.cmp(y) < 1;
|
|
458
|
-
};
|
|
459
|
-
P.logarithm = P.log = function(base) {
|
|
460
|
-
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
461
|
-
if (base == null) {
|
|
462
|
-
base = new Ctor(10);
|
|
463
|
-
isBase10 = true;
|
|
464
|
-
} else {
|
|
465
|
-
base = new Ctor(base);
|
|
466
|
-
d = base.d;
|
|
467
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1))
|
|
468
|
-
return new Ctor(NaN);
|
|
469
|
-
isBase10 = base.eq(10);
|
|
470
|
-
}
|
|
471
|
-
d = arg.d;
|
|
472
|
-
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
473
|
-
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
474
|
-
}
|
|
475
|
-
if (isBase10) {
|
|
476
|
-
if (d.length > 1) {
|
|
477
|
-
inf = true;
|
|
478
|
-
} else {
|
|
479
|
-
for (k = d[0]; k % 10 === 0; )
|
|
480
|
-
k /= 10;
|
|
481
|
-
inf = k !== 1;
|
|
482
|
-
}
|
|
78
|
+
if (s === "Infinity" || s === "+Infinity") {
|
|
79
|
+
return {
|
|
80
|
+
mantissa: 0n,
|
|
81
|
+
exponent: 0,
|
|
82
|
+
special: SpecialValue.POSITIVE_INFINITY,
|
|
83
|
+
negativeZero: false
|
|
84
|
+
};
|
|
483
85
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
sd += 10;
|
|
492
|
-
num = naturalLogarithm(arg, sd);
|
|
493
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
494
|
-
r = divide(num, denominator, sd, 1);
|
|
495
|
-
if (!inf) {
|
|
496
|
-
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
|
497
|
-
r = finalise(r, pr + 1, 0);
|
|
498
|
-
}
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
} while (checkRoundingDigits(r.d, k += 10, rm));
|
|
86
|
+
if (s === "-Infinity") {
|
|
87
|
+
return {
|
|
88
|
+
mantissa: 0n,
|
|
89
|
+
exponent: 0,
|
|
90
|
+
special: SpecialValue.NEGATIVE_INFINITY,
|
|
91
|
+
negativeZero: false
|
|
92
|
+
};
|
|
502
93
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
y.s = -y.s;
|
|
520
|
-
return x.plus(y);
|
|
521
|
-
}
|
|
522
|
-
xd = x.d;
|
|
523
|
-
yd = y.d;
|
|
524
|
-
pr = Ctor.precision;
|
|
525
|
-
rm = Ctor.rounding;
|
|
526
|
-
if (!xd[0] || !yd[0]) {
|
|
527
|
-
if (yd[0])
|
|
528
|
-
y.s = -y.s;
|
|
529
|
-
else if (xd[0])
|
|
530
|
-
y = new Ctor(x);
|
|
531
|
-
else
|
|
532
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
533
|
-
return external ? finalise(y, pr, rm) : y;
|
|
534
|
-
}
|
|
535
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
536
|
-
xe = mathfloor(x.e / LOG_BASE);
|
|
537
|
-
xd = xd.slice();
|
|
538
|
-
k = xe - e;
|
|
539
|
-
if (k) {
|
|
540
|
-
xLTy = k < 0;
|
|
541
|
-
if (xLTy) {
|
|
542
|
-
d = xd;
|
|
543
|
-
k = -k;
|
|
544
|
-
len = yd.length;
|
|
545
|
-
} else {
|
|
546
|
-
d = yd;
|
|
547
|
-
e = xe;
|
|
548
|
-
len = xd.length;
|
|
549
|
-
}
|
|
550
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
551
|
-
if (k > i) {
|
|
552
|
-
k = i;
|
|
553
|
-
d.length = 1;
|
|
554
|
-
}
|
|
555
|
-
d.reverse();
|
|
556
|
-
for (i = k; i--; )
|
|
557
|
-
d.push(0);
|
|
558
|
-
d.reverse();
|
|
94
|
+
let negative = false;
|
|
95
|
+
let idx = 0;
|
|
96
|
+
if (s[idx] === "-") {
|
|
97
|
+
negative = true;
|
|
98
|
+
idx++;
|
|
99
|
+
} else if (s[idx] === "+") {
|
|
100
|
+
idx++;
|
|
101
|
+
}
|
|
102
|
+
let eIdx = s.indexOf("e", idx);
|
|
103
|
+
if (eIdx === -1)
|
|
104
|
+
eIdx = s.indexOf("E", idx);
|
|
105
|
+
let sciExp = 0;
|
|
106
|
+
let numPart;
|
|
107
|
+
if (eIdx !== -1) {
|
|
108
|
+
sciExp = parseInt(s.substring(eIdx + 1), 10);
|
|
109
|
+
numPart = s.substring(idx, eIdx);
|
|
559
110
|
} else {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
k = 0;
|
|
572
|
-
}
|
|
573
|
-
if (xLTy) {
|
|
574
|
-
d = xd;
|
|
575
|
-
xd = yd;
|
|
576
|
-
yd = d;
|
|
577
|
-
y.s = -y.s;
|
|
578
|
-
}
|
|
579
|
-
len = xd.length;
|
|
580
|
-
for (i = yd.length - len; i > 0; --i)
|
|
581
|
-
xd[len++] = 0;
|
|
582
|
-
for (i = yd.length; i > k; ) {
|
|
583
|
-
if (xd[--i] < yd[i]) {
|
|
584
|
-
for (j = i; j && xd[--j] === 0; )
|
|
585
|
-
xd[j] = BASE - 1;
|
|
586
|
-
--xd[j];
|
|
587
|
-
xd[i] += BASE;
|
|
588
|
-
}
|
|
589
|
-
xd[i] -= yd[i];
|
|
590
|
-
}
|
|
591
|
-
for (; xd[--len] === 0; )
|
|
592
|
-
xd.pop();
|
|
593
|
-
for (; xd[0] === 0; xd.shift())
|
|
594
|
-
--e;
|
|
595
|
-
if (!xd[0])
|
|
596
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
597
|
-
y.d = xd;
|
|
598
|
-
y.e = getBase10Exponent(xd, e);
|
|
599
|
-
return external ? finalise(y, pr, rm) : y;
|
|
600
|
-
};
|
|
601
|
-
P.modulo = P.mod = function(y) {
|
|
602
|
-
var q, x = this, Ctor = x.constructor;
|
|
603
|
-
y = new Ctor(y);
|
|
604
|
-
if (!x.d || !y.s || y.d && !y.d[0])
|
|
605
|
-
return new Ctor(NaN);
|
|
606
|
-
if (!y.d || x.d && !x.d[0]) {
|
|
607
|
-
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
608
|
-
}
|
|
609
|
-
external = false;
|
|
610
|
-
if (Ctor.modulo == 9) {
|
|
611
|
-
q = divide(x, y.abs(), 0, 3, 1);
|
|
612
|
-
q.s *= y.s;
|
|
111
|
+
numPart = s.substring(idx);
|
|
112
|
+
}
|
|
113
|
+
const dotIdx = numPart.indexOf(".");
|
|
114
|
+
let intPart;
|
|
115
|
+
let fracPart;
|
|
116
|
+
if (dotIdx !== -1) {
|
|
117
|
+
intPart = numPart.substring(0, dotIdx);
|
|
118
|
+
fracPart = numPart.substring(dotIdx + 1);
|
|
613
119
|
} else {
|
|
614
|
-
|
|
120
|
+
intPart = numPart;
|
|
121
|
+
fracPart = "";
|
|
615
122
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
};
|
|
626
|
-
P.negated = P.neg = function() {
|
|
627
|
-
var x = new this.constructor(this);
|
|
628
|
-
x.s = -x.s;
|
|
629
|
-
return finalise(x);
|
|
630
|
-
};
|
|
631
|
-
P.plus = P.add = function(y) {
|
|
632
|
-
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
633
|
-
y = new Ctor(y);
|
|
634
|
-
if (!x.d || !y.d) {
|
|
635
|
-
if (!x.s || !y.s)
|
|
636
|
-
y = new Ctor(NaN);
|
|
637
|
-
else if (!x.d)
|
|
638
|
-
y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
639
|
-
return y;
|
|
640
|
-
}
|
|
641
|
-
if (x.s != y.s) {
|
|
642
|
-
y.s = -y.s;
|
|
643
|
-
return x.minus(y);
|
|
644
|
-
}
|
|
645
|
-
xd = x.d;
|
|
646
|
-
yd = y.d;
|
|
647
|
-
pr = Ctor.precision;
|
|
648
|
-
rm = Ctor.rounding;
|
|
649
|
-
if (!xd[0] || !yd[0]) {
|
|
650
|
-
if (!yd[0])
|
|
651
|
-
y = new Ctor(x);
|
|
652
|
-
return external ? finalise(y, pr, rm) : y;
|
|
653
|
-
}
|
|
654
|
-
k = mathfloor(x.e / LOG_BASE);
|
|
655
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
656
|
-
xd = xd.slice();
|
|
657
|
-
i = k - e;
|
|
658
|
-
if (i) {
|
|
659
|
-
if (i < 0) {
|
|
660
|
-
d = xd;
|
|
661
|
-
i = -i;
|
|
662
|
-
len = yd.length;
|
|
663
|
-
} else {
|
|
664
|
-
d = yd;
|
|
665
|
-
e = k;
|
|
666
|
-
len = xd.length;
|
|
667
|
-
}
|
|
668
|
-
k = Math.ceil(pr / LOG_BASE);
|
|
669
|
-
len = k > len ? k + 1 : len + 1;
|
|
670
|
-
if (i > len) {
|
|
671
|
-
i = len;
|
|
672
|
-
d.length = 1;
|
|
673
|
-
}
|
|
674
|
-
d.reverse();
|
|
675
|
-
for (; i--; )
|
|
676
|
-
d.push(0);
|
|
677
|
-
d.reverse();
|
|
678
|
-
}
|
|
679
|
-
len = xd.length;
|
|
680
|
-
i = yd.length;
|
|
681
|
-
if (len - i < 0) {
|
|
682
|
-
i = len;
|
|
683
|
-
d = yd;
|
|
684
|
-
yd = xd;
|
|
685
|
-
xd = d;
|
|
686
|
-
}
|
|
687
|
-
for (carry = 0; i; ) {
|
|
688
|
-
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
689
|
-
xd[i] %= BASE;
|
|
690
|
-
}
|
|
691
|
-
if (carry) {
|
|
692
|
-
xd.unshift(carry);
|
|
693
|
-
++e;
|
|
694
|
-
}
|
|
695
|
-
for (len = xd.length; xd[--len] == 0; )
|
|
696
|
-
xd.pop();
|
|
697
|
-
y.d = xd;
|
|
698
|
-
y.e = getBase10Exponent(xd, e);
|
|
699
|
-
return external ? finalise(y, pr, rm) : y;
|
|
700
|
-
};
|
|
701
|
-
P.precision = P.sd = function(z) {
|
|
702
|
-
var k, x = this;
|
|
703
|
-
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
|
|
704
|
-
throw Error(invalidArgument + z);
|
|
705
|
-
if (x.d) {
|
|
706
|
-
k = getPrecision(x.d);
|
|
707
|
-
if (z && x.e + 1 > k)
|
|
708
|
-
k = x.e + 1;
|
|
709
|
-
} else {
|
|
710
|
-
k = NaN;
|
|
123
|
+
const combined = intPart + fracPart;
|
|
124
|
+
const exponent = sciExp - fracPart.length;
|
|
125
|
+
if (combined === "" || combined === "0" || /^0+$/.test(combined)) {
|
|
126
|
+
return {
|
|
127
|
+
mantissa: 0n,
|
|
128
|
+
exponent: 0,
|
|
129
|
+
special: SpecialValue.NONE,
|
|
130
|
+
negativeZero: negative
|
|
131
|
+
};
|
|
711
132
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
return
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
737
|
-
}
|
|
738
|
-
external = false;
|
|
739
|
-
s = Math.sqrt(+x);
|
|
740
|
-
if (s == 0 || s == 1 / 0) {
|
|
741
|
-
n = digitsToString(d);
|
|
742
|
-
if ((n.length + e) % 2 == 0)
|
|
743
|
-
n += "0";
|
|
744
|
-
s = Math.sqrt(n);
|
|
745
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
746
|
-
if (s == 1 / 0) {
|
|
747
|
-
n = "5e" + e;
|
|
748
|
-
} else {
|
|
749
|
-
n = s.toExponential();
|
|
750
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
133
|
+
let mantissa = BigInt(combined);
|
|
134
|
+
if (negative)
|
|
135
|
+
mantissa = -mantissa;
|
|
136
|
+
const [normMantissa, normExponent] = removeTrailingZeros(mantissa, exponent);
|
|
137
|
+
return {
|
|
138
|
+
mantissa: normMantissa,
|
|
139
|
+
exponent: normExponent,
|
|
140
|
+
special: SpecialValue.NONE,
|
|
141
|
+
negativeZero: false
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
var BigDecimal = class _BigDecimal {
|
|
145
|
+
constructor(value) {
|
|
146
|
+
__publicField(this, "_mantissa");
|
|
147
|
+
__publicField(this, "_exponent");
|
|
148
|
+
__publicField(this, "_special");
|
|
149
|
+
__publicField(this, "_negativeZero");
|
|
150
|
+
if (typeof value === "bigint") {
|
|
151
|
+
const [m, e] = removeTrailingZeros(value, 0);
|
|
152
|
+
this._mantissa = m;
|
|
153
|
+
this._exponent = e;
|
|
154
|
+
this._special = SpecialValue.NONE;
|
|
155
|
+
this._negativeZero = false;
|
|
156
|
+
return;
|
|
751
157
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
|
760
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
761
|
-
n = n.slice(sd - 3, sd + 1);
|
|
762
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
763
|
-
if (!rep) {
|
|
764
|
-
finalise(t, e + 1, 0);
|
|
765
|
-
if (t.times(t).eq(x)) {
|
|
766
|
-
r = t;
|
|
767
|
-
break;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
sd += 4;
|
|
771
|
-
rep = 1;
|
|
772
|
-
} else {
|
|
773
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
774
|
-
finalise(r, e + 1, 1);
|
|
775
|
-
m = !r.times(r).eq(x);
|
|
776
|
-
}
|
|
777
|
-
break;
|
|
158
|
+
if (typeof value === "number") {
|
|
159
|
+
if (Number.isNaN(value)) {
|
|
160
|
+
this._mantissa = 0n;
|
|
161
|
+
this._exponent = 0;
|
|
162
|
+
this._special = SpecialValue.NAN;
|
|
163
|
+
this._negativeZero = false;
|
|
164
|
+
return;
|
|
778
165
|
}
|
|
166
|
+
if (value === Infinity) {
|
|
167
|
+
this._mantissa = 0n;
|
|
168
|
+
this._exponent = 0;
|
|
169
|
+
this._special = SpecialValue.POSITIVE_INFINITY;
|
|
170
|
+
this._negativeZero = false;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (value === -Infinity) {
|
|
174
|
+
this._mantissa = 0n;
|
|
175
|
+
this._exponent = 0;
|
|
176
|
+
this._special = SpecialValue.NEGATIVE_INFINITY;
|
|
177
|
+
this._negativeZero = false;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (value === 0) {
|
|
181
|
+
this._mantissa = 0n;
|
|
182
|
+
this._exponent = 0;
|
|
183
|
+
this._special = SpecialValue.NONE;
|
|
184
|
+
this._negativeZero = Object.is(value, -0);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
value = String(value);
|
|
779
188
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
805
|
-
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
806
|
-
}
|
|
807
|
-
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
808
|
-
xdL = xd.length;
|
|
809
|
-
ydL = yd.length;
|
|
810
|
-
if (xdL < ydL) {
|
|
811
|
-
r = xd;
|
|
812
|
-
xd = yd;
|
|
813
|
-
yd = r;
|
|
814
|
-
rL = xdL;
|
|
815
|
-
xdL = ydL;
|
|
816
|
-
ydL = rL;
|
|
817
|
-
}
|
|
818
|
-
r = [];
|
|
819
|
-
rL = xdL + ydL;
|
|
820
|
-
for (i = rL; i--; )
|
|
821
|
-
r.push(0);
|
|
822
|
-
for (i = ydL; --i >= 0; ) {
|
|
823
|
-
carry = 0;
|
|
824
|
-
for (k = xdL + i; k > i; ) {
|
|
825
|
-
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
826
|
-
r[k--] = t % BASE | 0;
|
|
827
|
-
carry = t / BASE | 0;
|
|
828
|
-
}
|
|
829
|
-
r[k] = (r[k] + carry) % BASE | 0;
|
|
830
|
-
}
|
|
831
|
-
for (; !r[--rL]; )
|
|
832
|
-
r.pop();
|
|
833
|
-
if (carry)
|
|
834
|
-
++e;
|
|
835
|
-
else
|
|
836
|
-
r.shift();
|
|
837
|
-
y.d = r;
|
|
838
|
-
y.e = getBase10Exponent(r, e);
|
|
839
|
-
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
840
|
-
};
|
|
841
|
-
P.toBinary = function(sd, rm) {
|
|
842
|
-
return toStringBinary(this, 2, sd, rm);
|
|
843
|
-
};
|
|
844
|
-
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
845
|
-
var x = this, Ctor = x.constructor;
|
|
846
|
-
x = new Ctor(x);
|
|
847
|
-
if (dp === void 0)
|
|
848
|
-
return x;
|
|
849
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
850
|
-
if (rm === void 0)
|
|
851
|
-
rm = Ctor.rounding;
|
|
852
|
-
else
|
|
853
|
-
checkInt32(rm, 0, 8);
|
|
854
|
-
return finalise(x, dp + x.e + 1, rm);
|
|
855
|
-
};
|
|
856
|
-
P.toExponential = function(dp, rm) {
|
|
857
|
-
var str, x = this, Ctor = x.constructor;
|
|
858
|
-
if (dp === void 0) {
|
|
859
|
-
str = finiteToString(x, true);
|
|
860
|
-
} else {
|
|
861
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
862
|
-
if (rm === void 0)
|
|
863
|
-
rm = Ctor.rounding;
|
|
864
|
-
else
|
|
865
|
-
checkInt32(rm, 0, 8);
|
|
866
|
-
x = finalise(new Ctor(x), dp + 1, rm);
|
|
867
|
-
str = finiteToString(x, true, dp + 1);
|
|
868
|
-
}
|
|
869
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
870
|
-
};
|
|
871
|
-
P.toFixed = function(dp, rm) {
|
|
872
|
-
var str, y, x = this, Ctor = x.constructor;
|
|
873
|
-
if (dp === void 0) {
|
|
874
|
-
str = finiteToString(x);
|
|
875
|
-
} else {
|
|
876
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
877
|
-
if (rm === void 0)
|
|
878
|
-
rm = Ctor.rounding;
|
|
879
|
-
else
|
|
880
|
-
checkInt32(rm, 0, 8);
|
|
881
|
-
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
882
|
-
str = finiteToString(y, false, dp + y.e + 1);
|
|
883
|
-
}
|
|
884
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
885
|
-
};
|
|
886
|
-
P.toFraction = function(maxD) {
|
|
887
|
-
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
888
|
-
if (!xd)
|
|
889
|
-
return new Ctor(x);
|
|
890
|
-
n1 = d0 = new Ctor(1);
|
|
891
|
-
d1 = n0 = new Ctor(0);
|
|
892
|
-
d = new Ctor(d1);
|
|
893
|
-
e = d.e = getPrecision(xd) - x.e - 1;
|
|
894
|
-
k = e % LOG_BASE;
|
|
895
|
-
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
896
|
-
if (maxD == null) {
|
|
897
|
-
maxD = e > 0 ? d : n1;
|
|
898
|
-
} else {
|
|
899
|
-
n = new Ctor(maxD);
|
|
900
|
-
if (!n.isInt() || n.lt(n1))
|
|
901
|
-
throw Error(invalidArgument + n);
|
|
902
|
-
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
903
|
-
}
|
|
904
|
-
external = false;
|
|
905
|
-
n = new Ctor(digitsToString(xd));
|
|
906
|
-
pr = Ctor.precision;
|
|
907
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
908
|
-
for (; ; ) {
|
|
909
|
-
q = divide(n, d, 0, 1, 1);
|
|
910
|
-
d2 = d0.plus(q.times(d1));
|
|
911
|
-
if (d2.cmp(maxD) == 1)
|
|
912
|
-
break;
|
|
913
|
-
d0 = d1;
|
|
914
|
-
d1 = d2;
|
|
915
|
-
d2 = n1;
|
|
916
|
-
n1 = n0.plus(q.times(d2));
|
|
917
|
-
n0 = d2;
|
|
918
|
-
d2 = d;
|
|
919
|
-
d = n.minus(q.times(d2));
|
|
920
|
-
n = d2;
|
|
921
|
-
}
|
|
922
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
923
|
-
n0 = n0.plus(d2.times(n1));
|
|
924
|
-
d0 = d0.plus(d2.times(d1));
|
|
925
|
-
n0.s = n1.s = x.s;
|
|
926
|
-
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
927
|
-
Ctor.precision = pr;
|
|
928
|
-
external = true;
|
|
929
|
-
return r;
|
|
930
|
-
};
|
|
931
|
-
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
932
|
-
return toStringBinary(this, 16, sd, rm);
|
|
933
|
-
};
|
|
934
|
-
P.toNearest = function(y, rm) {
|
|
935
|
-
var x = this, Ctor = x.constructor;
|
|
936
|
-
x = new Ctor(x);
|
|
937
|
-
if (y == null) {
|
|
938
|
-
if (!x.d)
|
|
939
|
-
return x;
|
|
940
|
-
y = new Ctor(1);
|
|
941
|
-
rm = Ctor.rounding;
|
|
942
|
-
} else {
|
|
943
|
-
y = new Ctor(y);
|
|
944
|
-
if (rm === void 0) {
|
|
945
|
-
rm = Ctor.rounding;
|
|
946
|
-
} else {
|
|
947
|
-
checkInt32(rm, 0, 8);
|
|
189
|
+
const parsed = parseDecimalString(value);
|
|
190
|
+
this._mantissa = parsed.mantissa;
|
|
191
|
+
this._exponent = parsed.exponent;
|
|
192
|
+
this._special = parsed.special;
|
|
193
|
+
this._negativeZero = parsed.negativeZero;
|
|
194
|
+
}
|
|
195
|
+
// Private constructor for internal use
|
|
196
|
+
static _create(mantissa, exponent, special, negativeZero) {
|
|
197
|
+
const bd = Object.create(_BigDecimal.prototype);
|
|
198
|
+
bd._mantissa = mantissa;
|
|
199
|
+
bd._exponent = exponent;
|
|
200
|
+
bd._special = special;
|
|
201
|
+
bd._negativeZero = negativeZero;
|
|
202
|
+
return bd;
|
|
203
|
+
}
|
|
204
|
+
// Auto-coerce to BigDecimal for decimal.js compat
|
|
205
|
+
static _coerce(v) {
|
|
206
|
+
return v instanceof _BigDecimal ? v : new _BigDecimal(v);
|
|
207
|
+
}
|
|
208
|
+
// --- Arithmetic ---
|
|
209
|
+
times(y) {
|
|
210
|
+
const other = _BigDecimal._coerce(y);
|
|
211
|
+
if (this._special || other._special) {
|
|
212
|
+
return this._specialArith(other, "times");
|
|
948
213
|
}
|
|
949
|
-
if (
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
if (y.s)
|
|
953
|
-
y.s = x.s;
|
|
954
|
-
return y;
|
|
214
|
+
if (this._mantissa === 0n || other._mantissa === 0n) {
|
|
215
|
+
const negZero = this._isSignNegative() ? !other._isSignNegative() : other._isSignNegative();
|
|
216
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
955
217
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
}
|
|
966
|
-
return x;
|
|
967
|
-
};
|
|
968
|
-
P.toNumber = function() {
|
|
969
|
-
return +this;
|
|
970
|
-
};
|
|
971
|
-
P.toOctal = function(sd, rm) {
|
|
972
|
-
return toStringBinary(this, 8, sd, rm);
|
|
973
|
-
};
|
|
974
|
-
P.toPower = P.pow = function(y) {
|
|
975
|
-
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
976
|
-
if (!x.d || !y.d || !x.d[0] || !y.d[0])
|
|
977
|
-
return new Ctor(mathpow(+x, yn));
|
|
978
|
-
x = new Ctor(x);
|
|
979
|
-
if (x.eq(1))
|
|
980
|
-
return x;
|
|
981
|
-
pr = Ctor.precision;
|
|
982
|
-
rm = Ctor.rounding;
|
|
983
|
-
if (y.eq(1))
|
|
984
|
-
return finalise(x, pr, rm);
|
|
985
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
986
|
-
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
987
|
-
r = intPow(Ctor, x, k, pr);
|
|
988
|
-
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
989
|
-
}
|
|
990
|
-
s = x.s;
|
|
991
|
-
if (s < 0) {
|
|
992
|
-
if (e < y.d.length - 1)
|
|
993
|
-
return new Ctor(NaN);
|
|
994
|
-
if ((y.d[e] & 1) == 0)
|
|
995
|
-
s = 1;
|
|
996
|
-
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
997
|
-
x.s = s;
|
|
998
|
-
return x;
|
|
218
|
+
const m = this._mantissa * other._mantissa;
|
|
219
|
+
const e = this._exponent + other._exponent;
|
|
220
|
+
const [nm, ne] = removeTrailingZeros(m, e);
|
|
221
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
222
|
+
}
|
|
223
|
+
div(y) {
|
|
224
|
+
const other = _BigDecimal._coerce(y);
|
|
225
|
+
if (this._special || other._special) {
|
|
226
|
+
return this._specialArith(other, "div");
|
|
999
227
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
|
|
1004
|
-
return new Ctor(e > 0 ? s / 0 : 0);
|
|
1005
|
-
external = false;
|
|
1006
|
-
Ctor.rounding = x.s = 1;
|
|
1007
|
-
k = Math.min(12, (e + "").length);
|
|
1008
|
-
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
|
1009
|
-
if (r.d) {
|
|
1010
|
-
r = finalise(r, pr + 5, 1);
|
|
1011
|
-
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
1012
|
-
e = pr + 10;
|
|
1013
|
-
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
1014
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
|
1015
|
-
r = finalise(r, pr + 1, 0);
|
|
228
|
+
if (other._mantissa === 0n) {
|
|
229
|
+
if (this._mantissa === 0n) {
|
|
230
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1016
231
|
}
|
|
232
|
+
const neg = this._isSignNegative() !== other._isSignNegative();
|
|
233
|
+
return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
|
|
1017
234
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
Ctor.rounding = rm;
|
|
1022
|
-
return finalise(r, pr, rm);
|
|
1023
|
-
};
|
|
1024
|
-
P.toPrecision = function(sd, rm) {
|
|
1025
|
-
var str, x = this, Ctor = x.constructor;
|
|
1026
|
-
if (sd === void 0) {
|
|
1027
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1028
|
-
} else {
|
|
1029
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
1030
|
-
if (rm === void 0)
|
|
1031
|
-
rm = Ctor.rounding;
|
|
1032
|
-
else
|
|
1033
|
-
checkInt32(rm, 0, 8);
|
|
1034
|
-
x = finalise(new Ctor(x), sd, rm);
|
|
1035
|
-
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
1036
|
-
}
|
|
1037
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
1038
|
-
};
|
|
1039
|
-
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
1040
|
-
var x = this, Ctor = x.constructor;
|
|
1041
|
-
if (sd === void 0) {
|
|
1042
|
-
sd = Ctor.precision;
|
|
1043
|
-
rm = Ctor.rounding;
|
|
1044
|
-
} else {
|
|
1045
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
1046
|
-
if (rm === void 0)
|
|
1047
|
-
rm = Ctor.rounding;
|
|
1048
|
-
else
|
|
1049
|
-
checkInt32(rm, 0, 8);
|
|
1050
|
-
}
|
|
1051
|
-
return finalise(new Ctor(x), sd, rm);
|
|
1052
|
-
};
|
|
1053
|
-
P.toString = function() {
|
|
1054
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1055
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
1056
|
-
};
|
|
1057
|
-
P.truncated = P.trunc = function() {
|
|
1058
|
-
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
1059
|
-
};
|
|
1060
|
-
P.valueOf = P.toJSON = function() {
|
|
1061
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
1062
|
-
return x.isNeg() ? "-" + str : str;
|
|
1063
|
-
};
|
|
1064
|
-
function digitsToString(d) {
|
|
1065
|
-
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
1066
|
-
if (indexOfLastWord > 0) {
|
|
1067
|
-
str += w;
|
|
1068
|
-
for (i = 1; i < indexOfLastWord; i++) {
|
|
1069
|
-
ws = d[i] + "";
|
|
1070
|
-
k = LOG_BASE - ws.length;
|
|
1071
|
-
if (k)
|
|
1072
|
-
str += getZeroString(k);
|
|
1073
|
-
str += ws;
|
|
235
|
+
if (this._mantissa === 0n) {
|
|
236
|
+
const negZero = this._isSignNegative() !== other._isSignNegative();
|
|
237
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
1074
238
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
return str + w;
|
|
1086
|
-
}
|
|
1087
|
-
function checkInt32(i, min2, max2) {
|
|
1088
|
-
if (i !== ~~i || i < min2 || i > max2) {
|
|
1089
|
-
throw Error(invalidArgument + i);
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
1093
|
-
var di, k, r, rd;
|
|
1094
|
-
for (k = d[0]; k >= 10; k /= 10)
|
|
1095
|
-
--i;
|
|
1096
|
-
if (--i < 0) {
|
|
1097
|
-
i += LOG_BASE;
|
|
1098
|
-
di = 0;
|
|
1099
|
-
} else {
|
|
1100
|
-
di = Math.ceil((i + 1) / LOG_BASE);
|
|
1101
|
-
i %= LOG_BASE;
|
|
1102
|
-
}
|
|
1103
|
-
k = mathpow(10, LOG_BASE - i);
|
|
1104
|
-
rd = d[di] % k | 0;
|
|
1105
|
-
if (repeating == null) {
|
|
1106
|
-
if (i < 3) {
|
|
1107
|
-
if (i == 0)
|
|
1108
|
-
rd = rd / 100 | 0;
|
|
1109
|
-
else if (i == 1)
|
|
1110
|
-
rd = rd / 10 | 0;
|
|
1111
|
-
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
|
1112
|
-
} else {
|
|
1113
|
-
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;
|
|
239
|
+
const scaledNumerator = this._mantissa * bigintPow10(DIV_PRECISION);
|
|
240
|
+
const quotient = scaledNumerator / other._mantissa;
|
|
241
|
+
const newExponent = this._exponent - other._exponent - DIV_PRECISION;
|
|
242
|
+
const [nm, ne] = removeTrailingZeros(quotient, newExponent);
|
|
243
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
244
|
+
}
|
|
245
|
+
plus(y) {
|
|
246
|
+
const other = _BigDecimal._coerce(y);
|
|
247
|
+
if (this._special || other._special) {
|
|
248
|
+
return this._specialArith(other, "plus");
|
|
1114
249
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
rd = rd / 1e3 | 0;
|
|
1119
|
-
else if (i == 1)
|
|
1120
|
-
rd = rd / 100 | 0;
|
|
1121
|
-
else if (i == 2)
|
|
1122
|
-
rd = rd / 10 | 0;
|
|
1123
|
-
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
1124
|
-
} else {
|
|
1125
|
-
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;
|
|
250
|
+
if (this._mantissa === 0n && other._mantissa === 0n) {
|
|
251
|
+
const negZero = this._negativeZero && other._negativeZero;
|
|
252
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
1126
253
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
254
|
+
if (this._mantissa === 0n)
|
|
255
|
+
return other;
|
|
256
|
+
if (other._mantissa === 0n)
|
|
257
|
+
return this;
|
|
258
|
+
let m1 = this._mantissa;
|
|
259
|
+
let m2 = other._mantissa;
|
|
260
|
+
const e1 = this._exponent;
|
|
261
|
+
const e2 = other._exponent;
|
|
262
|
+
const minE = Math.min(e1, e2);
|
|
263
|
+
if (e1 > minE)
|
|
264
|
+
m1 *= bigintPow10(e1 - minE);
|
|
265
|
+
if (e2 > minE)
|
|
266
|
+
m2 *= bigintPow10(e2 - minE);
|
|
267
|
+
const sum = m1 + m2;
|
|
268
|
+
if (sum === 0n) {
|
|
269
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
|
|
1143
270
|
}
|
|
271
|
+
const [nm, ne] = removeTrailingZeros(sum, minE);
|
|
272
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
1144
273
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
function cosine(Ctor, x) {
|
|
1148
|
-
var k, len, y;
|
|
1149
|
-
if (x.isZero())
|
|
1150
|
-
return x;
|
|
1151
|
-
len = x.d.length;
|
|
1152
|
-
if (len < 32) {
|
|
1153
|
-
k = Math.ceil(len / 3);
|
|
1154
|
-
y = (1 / tinyPow(4, k)).toString();
|
|
1155
|
-
} else {
|
|
1156
|
-
k = 16;
|
|
1157
|
-
y = "2.3283064365386962890625e-10";
|
|
274
|
+
minus(y) {
|
|
275
|
+
return this.plus(_BigDecimal._coerce(y).negated());
|
|
1158
276
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
var temp, carry = 0, i = x.length;
|
|
1171
|
-
for (x = x.slice(); i--; ) {
|
|
1172
|
-
temp = x[i] * k + carry;
|
|
1173
|
-
x[i] = temp % base | 0;
|
|
1174
|
-
carry = temp / base | 0;
|
|
1175
|
-
}
|
|
1176
|
-
if (carry)
|
|
1177
|
-
x.unshift(carry);
|
|
1178
|
-
return x;
|
|
1179
|
-
}
|
|
1180
|
-
function compare(a, b, aL, bL) {
|
|
1181
|
-
var i, r;
|
|
1182
|
-
if (aL != bL) {
|
|
1183
|
-
r = aL > bL ? 1 : -1;
|
|
1184
|
-
} else {
|
|
1185
|
-
for (i = r = 0; i < aL; i++) {
|
|
1186
|
-
if (a[i] != b[i]) {
|
|
1187
|
-
r = a[i] > b[i] ? 1 : -1;
|
|
1188
|
-
break;
|
|
1189
|
-
}
|
|
277
|
+
mod(y) {
|
|
278
|
+
const other = _BigDecimal._coerce(y);
|
|
279
|
+
if (this._special || other._special) {
|
|
280
|
+
if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN) {
|
|
281
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
282
|
+
}
|
|
283
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY || this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
284
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
285
|
+
}
|
|
286
|
+
if (other._special === SpecialValue.POSITIVE_INFINITY || other._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
287
|
+
return this;
|
|
1190
288
|
}
|
|
1191
289
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
function subtract(a, b, aL, base) {
|
|
1195
|
-
var i = 0;
|
|
1196
|
-
for (; aL--; ) {
|
|
1197
|
-
a[aL] -= i;
|
|
1198
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
1199
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
290
|
+
if (other._mantissa === 0n) {
|
|
291
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1200
292
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
return function(x, y, pr, rm, dp, base) {
|
|
1205
|
-
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;
|
|
1206
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
1207
|
-
return new Ctor(
|
|
1208
|
-
// Return NaN if either NaN, or both Infinity or 0.
|
|
1209
|
-
!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
|
|
1210
|
-
// Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
|
|
1211
|
-
xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
|
|
1212
|
-
)
|
|
1213
|
-
);
|
|
293
|
+
if (this._mantissa === 0n) {
|
|
294
|
+
return this;
|
|
1214
295
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
296
|
+
let m1 = this._mantissa;
|
|
297
|
+
let m2 = other._mantissa;
|
|
298
|
+
const e1 = this._exponent;
|
|
299
|
+
const e2 = other._exponent;
|
|
300
|
+
const minE = Math.min(e1, e2);
|
|
301
|
+
if (e1 > minE)
|
|
302
|
+
m1 *= bigintPow10(e1 - minE);
|
|
303
|
+
if (e2 > minE)
|
|
304
|
+
m2 *= bigintPow10(e2 - minE);
|
|
305
|
+
const remainder = m1 % m2;
|
|
306
|
+
if (remainder === 0n) {
|
|
307
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
|
|
1222
308
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
;
|
|
1229
|
-
if (
|
|
1230
|
-
|
|
1231
|
-
if (pr == null) {
|
|
1232
|
-
sd = pr = Ctor.precision;
|
|
1233
|
-
rm = Ctor.rounding;
|
|
1234
|
-
} else if (dp) {
|
|
1235
|
-
sd = pr + (x.e - y.e) + 1;
|
|
1236
|
-
} else {
|
|
1237
|
-
sd = pr;
|
|
309
|
+
const [nm, ne] = removeTrailingZeros(remainder, minE);
|
|
310
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
311
|
+
}
|
|
312
|
+
abs() {
|
|
313
|
+
if (this._special === SpecialValue.NAN)
|
|
314
|
+
return this;
|
|
315
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
316
|
+
return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
|
|
1238
317
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
k = 0;
|
|
1247
|
-
yd = yd[0];
|
|
1248
|
-
sd++;
|
|
1249
|
-
for (; (i < xL || k) && sd--; i++) {
|
|
1250
|
-
t = k * base + (xd[i] || 0);
|
|
1251
|
-
qd[i] = t / yd | 0;
|
|
1252
|
-
k = t % yd | 0;
|
|
1253
|
-
}
|
|
1254
|
-
more = k || i < xL;
|
|
1255
|
-
} else {
|
|
1256
|
-
k = base / (yd[0] + 1) | 0;
|
|
1257
|
-
if (k > 1) {
|
|
1258
|
-
yd = multiplyInteger(yd, k, base);
|
|
1259
|
-
xd = multiplyInteger(xd, k, base);
|
|
1260
|
-
yL = yd.length;
|
|
1261
|
-
xL = xd.length;
|
|
1262
|
-
}
|
|
1263
|
-
xi = yL;
|
|
1264
|
-
rem = xd.slice(0, yL);
|
|
1265
|
-
remL = rem.length;
|
|
1266
|
-
for (; remL < yL; )
|
|
1267
|
-
rem[remL++] = 0;
|
|
1268
|
-
yz = yd.slice();
|
|
1269
|
-
yz.unshift(0);
|
|
1270
|
-
yd0 = yd[0];
|
|
1271
|
-
if (yd[1] >= base / 2)
|
|
1272
|
-
++yd0;
|
|
1273
|
-
do {
|
|
1274
|
-
k = 0;
|
|
1275
|
-
cmp = compare(yd, rem, yL, remL);
|
|
1276
|
-
if (cmp < 0) {
|
|
1277
|
-
rem0 = rem[0];
|
|
1278
|
-
if (yL != remL)
|
|
1279
|
-
rem0 = rem0 * base + (rem[1] || 0);
|
|
1280
|
-
k = rem0 / yd0 | 0;
|
|
1281
|
-
if (k > 1) {
|
|
1282
|
-
if (k >= base)
|
|
1283
|
-
k = base - 1;
|
|
1284
|
-
prod = multiplyInteger(yd, k, base);
|
|
1285
|
-
prodL = prod.length;
|
|
1286
|
-
remL = rem.length;
|
|
1287
|
-
cmp = compare(prod, rem, prodL, remL);
|
|
1288
|
-
if (cmp == 1) {
|
|
1289
|
-
k--;
|
|
1290
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
1291
|
-
}
|
|
1292
|
-
} else {
|
|
1293
|
-
if (k == 0)
|
|
1294
|
-
cmp = k = 1;
|
|
1295
|
-
prod = yd.slice();
|
|
1296
|
-
}
|
|
1297
|
-
prodL = prod.length;
|
|
1298
|
-
if (prodL < remL)
|
|
1299
|
-
prod.unshift(0);
|
|
1300
|
-
subtract(rem, prod, remL, base);
|
|
1301
|
-
if (cmp == -1) {
|
|
1302
|
-
remL = rem.length;
|
|
1303
|
-
cmp = compare(yd, rem, yL, remL);
|
|
1304
|
-
if (cmp < 1) {
|
|
1305
|
-
k++;
|
|
1306
|
-
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
remL = rem.length;
|
|
1310
|
-
} else if (cmp === 0) {
|
|
1311
|
-
k++;
|
|
1312
|
-
rem = [0];
|
|
1313
|
-
}
|
|
1314
|
-
qd[i++] = k;
|
|
1315
|
-
if (cmp && rem[0]) {
|
|
1316
|
-
rem[remL++] = xd[xi] || 0;
|
|
1317
|
-
} else {
|
|
1318
|
-
rem = [xd[xi]];
|
|
1319
|
-
remL = 1;
|
|
1320
|
-
}
|
|
1321
|
-
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
1322
|
-
more = rem[0] !== void 0;
|
|
1323
|
-
}
|
|
1324
|
-
if (!qd[0])
|
|
1325
|
-
qd.shift();
|
|
318
|
+
return _BigDecimal._create(bigintAbs(this._mantissa), this._exponent, this._special, false);
|
|
319
|
+
}
|
|
320
|
+
negated() {
|
|
321
|
+
if (this._special === SpecialValue.NAN)
|
|
322
|
+
return this;
|
|
323
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY) {
|
|
324
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false);
|
|
1326
325
|
}
|
|
1327
|
-
if (
|
|
1328
|
-
|
|
1329
|
-
inexact = more;
|
|
1330
|
-
} else {
|
|
1331
|
-
for (i = 1, k = qd[0]; k >= 10; k /= 10)
|
|
1332
|
-
i++;
|
|
1333
|
-
q.e = i + e * logBase - 1;
|
|
1334
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
326
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
327
|
+
return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
|
|
1335
328
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
}();
|
|
1339
|
-
function finalise(x, sd, rm, isTruncated) {
|
|
1340
|
-
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
1341
|
-
out:
|
|
1342
|
-
if (sd != null) {
|
|
1343
|
-
xd = x.d;
|
|
1344
|
-
if (!xd)
|
|
1345
|
-
return x;
|
|
1346
|
-
for (digits = 1, k = xd[0]; k >= 10; k /= 10)
|
|
1347
|
-
digits++;
|
|
1348
|
-
i = sd - digits;
|
|
1349
|
-
if (i < 0) {
|
|
1350
|
-
i += LOG_BASE;
|
|
1351
|
-
j = sd;
|
|
1352
|
-
w = xd[xdi = 0];
|
|
1353
|
-
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
1354
|
-
} else {
|
|
1355
|
-
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
1356
|
-
k = xd.length;
|
|
1357
|
-
if (xdi >= k) {
|
|
1358
|
-
if (isTruncated) {
|
|
1359
|
-
for (; k++ <= xdi; )
|
|
1360
|
-
xd.push(0);
|
|
1361
|
-
w = rd = 0;
|
|
1362
|
-
digits = 1;
|
|
1363
|
-
i %= LOG_BASE;
|
|
1364
|
-
j = i - LOG_BASE + 1;
|
|
1365
|
-
} else {
|
|
1366
|
-
break out;
|
|
1367
|
-
}
|
|
1368
|
-
} else {
|
|
1369
|
-
w = k = xd[xdi];
|
|
1370
|
-
for (digits = 1; k >= 10; k /= 10)
|
|
1371
|
-
digits++;
|
|
1372
|
-
i %= LOG_BASE;
|
|
1373
|
-
j = i - LOG_BASE + digits;
|
|
1374
|
-
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
1378
|
-
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.
|
|
1379
|
-
(i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
1380
|
-
if (sd < 1 || !xd[0]) {
|
|
1381
|
-
xd.length = 0;
|
|
1382
|
-
if (roundUp) {
|
|
1383
|
-
sd -= x.e + 1;
|
|
1384
|
-
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
1385
|
-
x.e = -sd || 0;
|
|
1386
|
-
} else {
|
|
1387
|
-
xd[0] = x.e = 0;
|
|
1388
|
-
}
|
|
1389
|
-
return x;
|
|
1390
|
-
}
|
|
1391
|
-
if (i == 0) {
|
|
1392
|
-
xd.length = xdi;
|
|
1393
|
-
k = 1;
|
|
1394
|
-
xdi--;
|
|
1395
|
-
} else {
|
|
1396
|
-
xd.length = xdi + 1;
|
|
1397
|
-
k = mathpow(10, LOG_BASE - i);
|
|
1398
|
-
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
1399
|
-
}
|
|
1400
|
-
if (roundUp) {
|
|
1401
|
-
for (; ; ) {
|
|
1402
|
-
if (xdi == 0) {
|
|
1403
|
-
for (i = 1, j = xd[0]; j >= 10; j /= 10)
|
|
1404
|
-
i++;
|
|
1405
|
-
j = xd[0] += k;
|
|
1406
|
-
for (k = 1; j >= 10; j /= 10)
|
|
1407
|
-
k++;
|
|
1408
|
-
if (i != k) {
|
|
1409
|
-
x.e++;
|
|
1410
|
-
if (xd[0] == BASE)
|
|
1411
|
-
xd[0] = 1;
|
|
1412
|
-
}
|
|
1413
|
-
break;
|
|
1414
|
-
} else {
|
|
1415
|
-
xd[xdi] += k;
|
|
1416
|
-
if (xd[xdi] != BASE)
|
|
1417
|
-
break;
|
|
1418
|
-
xd[xdi--] = 0;
|
|
1419
|
-
k = 1;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
for (i = xd.length; xd[--i] === 0; )
|
|
1424
|
-
xd.pop();
|
|
329
|
+
if (this._mantissa === 0n) {
|
|
330
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, !this._negativeZero);
|
|
1425
331
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
332
|
+
return _BigDecimal._create(-this._mantissa, this._exponent, SpecialValue.NONE, false);
|
|
333
|
+
}
|
|
334
|
+
pow(n) {
|
|
335
|
+
if (this._special === SpecialValue.NAN)
|
|
336
|
+
return this;
|
|
337
|
+
if (n === 0)
|
|
338
|
+
return new _BigDecimal(1);
|
|
339
|
+
if (n < 0) {
|
|
340
|
+
return new _BigDecimal(1).div(this.pow(-n));
|
|
1433
341
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
if (!x.isFinite())
|
|
1439
|
-
return nonFiniteToString(x);
|
|
1440
|
-
var k, e = x.e, str = digitsToString(x.d), len = str.length;
|
|
1441
|
-
if (isExp) {
|
|
1442
|
-
if (sd && (k = sd - len) > 0) {
|
|
1443
|
-
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
1444
|
-
} else if (len > 1) {
|
|
1445
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
342
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
343
|
+
return this;
|
|
344
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
345
|
+
return n % 2 === 0 ? _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false) : this;
|
|
1446
346
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
if (
|
|
1458
|
-
|
|
1459
|
-
if (
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
347
|
+
if (this._mantissa === 0n)
|
|
348
|
+
return new _BigDecimal(0);
|
|
349
|
+
const m = this._mantissa ** BigInt(n);
|
|
350
|
+
const e = this._exponent * n;
|
|
351
|
+
const [nm, ne] = removeTrailingZeros(m, e);
|
|
352
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
353
|
+
}
|
|
354
|
+
floor() {
|
|
355
|
+
if (this._special !== SpecialValue.NONE)
|
|
356
|
+
return this;
|
|
357
|
+
if (this._mantissa === 0n)
|
|
358
|
+
return this;
|
|
359
|
+
if (this._exponent >= 0)
|
|
360
|
+
return this;
|
|
361
|
+
const divisor = bigintPow10(-this._exponent);
|
|
362
|
+
const m = this._mantissa;
|
|
363
|
+
let q = m / divisor;
|
|
364
|
+
if (m < 0n && m % divisor !== 0n) {
|
|
365
|
+
q -= 1n;
|
|
1463
366
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
function getBase10Exponent(digits, e) {
|
|
1468
|
-
var w = digits[0];
|
|
1469
|
-
for (e *= LOG_BASE; w >= 10; w /= 10)
|
|
1470
|
-
e++;
|
|
1471
|
-
return e;
|
|
1472
|
-
}
|
|
1473
|
-
function getLn10(Ctor, sd, pr) {
|
|
1474
|
-
if (sd > LN10_PRECISION) {
|
|
1475
|
-
external = true;
|
|
1476
|
-
if (pr)
|
|
1477
|
-
Ctor.precision = pr;
|
|
1478
|
-
throw Error(precisionLimitExceeded);
|
|
1479
|
-
}
|
|
1480
|
-
return finalise(new Ctor(LN10), sd, 1, true);
|
|
1481
|
-
}
|
|
1482
|
-
function getPi(Ctor, sd, rm) {
|
|
1483
|
-
if (sd > PI_PRECISION)
|
|
1484
|
-
throw Error(precisionLimitExceeded);
|
|
1485
|
-
return finalise(new Ctor(PI), sd, rm, true);
|
|
1486
|
-
}
|
|
1487
|
-
function getPrecision(digits) {
|
|
1488
|
-
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
1489
|
-
w = digits[w];
|
|
1490
|
-
if (w) {
|
|
1491
|
-
for (; w % 10 == 0; w /= 10)
|
|
1492
|
-
len--;
|
|
1493
|
-
for (w = digits[0]; w >= 10; w /= 10)
|
|
1494
|
-
len++;
|
|
1495
|
-
}
|
|
1496
|
-
return len;
|
|
1497
|
-
}
|
|
1498
|
-
function getZeroString(k) {
|
|
1499
|
-
var zs = "";
|
|
1500
|
-
for (; k--; )
|
|
1501
|
-
zs += "0";
|
|
1502
|
-
return zs;
|
|
1503
|
-
}
|
|
1504
|
-
function intPow(Ctor, x, n, pr) {
|
|
1505
|
-
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
1506
|
-
external = false;
|
|
1507
|
-
for (; ; ) {
|
|
1508
|
-
if (n % 2) {
|
|
1509
|
-
r = r.times(x);
|
|
1510
|
-
if (truncate(r.d, k))
|
|
1511
|
-
isTruncated = true;
|
|
367
|
+
if (q === 0n) {
|
|
368
|
+
const negZero = this._mantissa < 0n;
|
|
369
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
1512
370
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
371
|
+
const [nm, ne] = removeTrailingZeros(q, 0);
|
|
372
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
373
|
+
}
|
|
374
|
+
ceil() {
|
|
375
|
+
if (this._special !== SpecialValue.NONE)
|
|
376
|
+
return this;
|
|
377
|
+
if (this._mantissa === 0n)
|
|
378
|
+
return this;
|
|
379
|
+
if (this._exponent >= 0)
|
|
380
|
+
return this;
|
|
381
|
+
const divisor = bigintPow10(-this._exponent);
|
|
382
|
+
const m = this._mantissa;
|
|
383
|
+
let q = m / divisor;
|
|
384
|
+
if (m > 0n && m % divisor !== 0n) {
|
|
385
|
+
q += 1n;
|
|
1519
386
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
external = true;
|
|
1524
|
-
return r;
|
|
1525
|
-
}
|
|
1526
|
-
function isOdd(n) {
|
|
1527
|
-
return n.d[n.d.length - 1] & 1;
|
|
1528
|
-
}
|
|
1529
|
-
function maxOrMin(Ctor, args, n) {
|
|
1530
|
-
var k, y, x = new Ctor(args[0]), i = 0;
|
|
1531
|
-
for (; ++i < args.length; ) {
|
|
1532
|
-
y = new Ctor(args[i]);
|
|
1533
|
-
if (!y.s) {
|
|
1534
|
-
x = y;
|
|
1535
|
-
break;
|
|
387
|
+
if (q === 0n) {
|
|
388
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, false);
|
|
1536
389
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
390
|
+
const [nm, ne] = removeTrailingZeros(q, 0);
|
|
391
|
+
return _BigDecimal._create(nm, ne, SpecialValue.NONE, false);
|
|
392
|
+
}
|
|
393
|
+
log(base) {
|
|
394
|
+
if (this._special === SpecialValue.NAN)
|
|
395
|
+
return this;
|
|
396
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
397
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1540
398
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
}
|
|
1544
|
-
function naturalExponential(x, sd) {
|
|
1545
|
-
var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
1546
|
-
if (!x.d || !x.d[0] || x.e > 17) {
|
|
1547
|
-
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
|
1548
|
-
}
|
|
1549
|
-
if (sd == null) {
|
|
1550
|
-
external = false;
|
|
1551
|
-
wpr = pr;
|
|
1552
|
-
} else {
|
|
1553
|
-
wpr = sd;
|
|
1554
|
-
}
|
|
1555
|
-
t = new Ctor(0.03125);
|
|
1556
|
-
while (x.e > -2) {
|
|
1557
|
-
x = x.times(t);
|
|
1558
|
-
k += 5;
|
|
1559
|
-
}
|
|
1560
|
-
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
1561
|
-
wpr += guard;
|
|
1562
|
-
denominator = pow2 = sum2 = new Ctor(1);
|
|
1563
|
-
Ctor.precision = wpr;
|
|
1564
|
-
for (; ; ) {
|
|
1565
|
-
pow2 = finalise(pow2.times(x), wpr, 1);
|
|
1566
|
-
denominator = denominator.times(++i);
|
|
1567
|
-
t = sum2.plus(divide(pow2, denominator, wpr, 1));
|
|
1568
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1569
|
-
j = k;
|
|
1570
|
-
while (j--)
|
|
1571
|
-
sum2 = finalise(sum2.times(sum2), wpr, 1);
|
|
1572
|
-
if (sd == null) {
|
|
1573
|
-
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1574
|
-
Ctor.precision = wpr += 10;
|
|
1575
|
-
denominator = pow2 = t = new Ctor(1);
|
|
1576
|
-
i = 0;
|
|
1577
|
-
rep++;
|
|
1578
|
-
} else {
|
|
1579
|
-
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
1580
|
-
}
|
|
1581
|
-
} else {
|
|
1582
|
-
Ctor.precision = pr;
|
|
1583
|
-
return sum2;
|
|
1584
|
-
}
|
|
399
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY) {
|
|
400
|
+
return _BigDecimal._create(0n, 0, SpecialValue.POSITIVE_INFINITY, false);
|
|
1585
401
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
}
|
|
1589
|
-
function naturalLogarithm(y, sd) {
|
|
1590
|
-
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;
|
|
1591
|
-
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
|
1592
|
-
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
|
1593
|
-
}
|
|
1594
|
-
if (sd == null) {
|
|
1595
|
-
external = false;
|
|
1596
|
-
wpr = pr;
|
|
1597
|
-
} else {
|
|
1598
|
-
wpr = sd;
|
|
1599
|
-
}
|
|
1600
|
-
Ctor.precision = wpr += guard;
|
|
1601
|
-
c = digitsToString(xd);
|
|
1602
|
-
c0 = c.charAt(0);
|
|
1603
|
-
if (Math.abs(e = x.e) < 15e14) {
|
|
1604
|
-
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
1605
|
-
x = x.times(y);
|
|
1606
|
-
c = digitsToString(x.d);
|
|
1607
|
-
c0 = c.charAt(0);
|
|
1608
|
-
n++;
|
|
402
|
+
if (this._mantissa < 0n) {
|
|
403
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
1609
404
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
x = new Ctor("0." + c);
|
|
1613
|
-
e++;
|
|
1614
|
-
} else {
|
|
1615
|
-
x = new Ctor(c0 + "." + c.slice(1));
|
|
405
|
+
if (this._mantissa === 0n) {
|
|
406
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NEGATIVE_INFINITY, false);
|
|
1616
407
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
1620
|
-
Ctor.precision = pr;
|
|
1621
|
-
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
|
1622
|
-
}
|
|
1623
|
-
x1 = x;
|
|
1624
|
-
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
1625
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
1626
|
-
denominator = 3;
|
|
1627
|
-
for (; ; ) {
|
|
1628
|
-
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
1629
|
-
t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
1630
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1631
|
-
sum2 = sum2.times(2);
|
|
1632
|
-
if (e !== 0)
|
|
1633
|
-
sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
1634
|
-
sum2 = divide(sum2, new Ctor(n), wpr, 1);
|
|
1635
|
-
if (sd == null) {
|
|
1636
|
-
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1637
|
-
Ctor.precision = wpr += guard;
|
|
1638
|
-
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
1639
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
1640
|
-
denominator = rep = 1;
|
|
1641
|
-
} else {
|
|
1642
|
-
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
1643
|
-
}
|
|
1644
|
-
} else {
|
|
1645
|
-
Ctor.precision = pr;
|
|
1646
|
-
return sum2;
|
|
1647
|
-
}
|
|
408
|
+
if (base === 10) {
|
|
409
|
+
return this._log10();
|
|
1648
410
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
str = str.replace(".", "");
|
|
1660
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
1661
|
-
if (e < 0)
|
|
1662
|
-
e = i;
|
|
1663
|
-
e += +str.slice(i + 1);
|
|
1664
|
-
str = str.substring(0, i);
|
|
1665
|
-
} else if (e < 0) {
|
|
1666
|
-
e = str.length;
|
|
1667
|
-
}
|
|
1668
|
-
for (i = 0; str.charCodeAt(i) === 48; i++)
|
|
1669
|
-
;
|
|
1670
|
-
for (len = str.length; str.charCodeAt(len - 1) === 48; --len)
|
|
1671
|
-
;
|
|
1672
|
-
str = str.slice(i, len);
|
|
1673
|
-
if (str) {
|
|
1674
|
-
len -= i;
|
|
1675
|
-
x.e = e = e - i - 1;
|
|
1676
|
-
x.d = [];
|
|
1677
|
-
i = (e + 1) % LOG_BASE;
|
|
1678
|
-
if (e < 0)
|
|
1679
|
-
i += LOG_BASE;
|
|
1680
|
-
if (i < len) {
|
|
1681
|
-
if (i)
|
|
1682
|
-
x.d.push(+str.slice(0, i));
|
|
1683
|
-
for (len -= LOG_BASE; i < len; )
|
|
1684
|
-
x.d.push(+str.slice(i, i += LOG_BASE));
|
|
1685
|
-
str = str.slice(i);
|
|
1686
|
-
i = LOG_BASE - str.length;
|
|
411
|
+
const log10x = this._log10();
|
|
412
|
+
const log10b = new _BigDecimal(Math.log10(base));
|
|
413
|
+
return log10x.div(log10b);
|
|
414
|
+
}
|
|
415
|
+
_log10() {
|
|
416
|
+
const absMantissa = bigintAbs(this._mantissa);
|
|
417
|
+
const digits = digitCount(absMantissa);
|
|
418
|
+
let log10Mantissa;
|
|
419
|
+
if (digits <= 15) {
|
|
420
|
+
log10Mantissa = Math.log10(Number(absMantissa));
|
|
1687
421
|
} else {
|
|
1688
|
-
|
|
422
|
+
const shift = digits - 17;
|
|
423
|
+
const leading = absMantissa / bigintPow10(shift);
|
|
424
|
+
log10Mantissa = Math.log10(Number(leading)) + shift;
|
|
1689
425
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
426
|
+
const totalLog10 = log10Mantissa + this._exponent;
|
|
427
|
+
return new _BigDecimal(totalLog10);
|
|
428
|
+
}
|
|
429
|
+
// --- Comparison ---
|
|
430
|
+
eq(y) {
|
|
431
|
+
const other = _BigDecimal._coerce(y);
|
|
432
|
+
if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN)
|
|
433
|
+
return false;
|
|
434
|
+
if (this._special !== other._special)
|
|
435
|
+
return false;
|
|
436
|
+
if (this._special !== SpecialValue.NONE)
|
|
437
|
+
return true;
|
|
438
|
+
if (this._mantissa === 0n && other._mantissa === 0n)
|
|
439
|
+
return true;
|
|
440
|
+
return this._mantissa === other._mantissa && this._exponent === other._exponent;
|
|
441
|
+
}
|
|
442
|
+
_compareTo(other) {
|
|
443
|
+
if (this._special === SpecialValue.NAN || other._special === SpecialValue.NAN) {
|
|
444
|
+
return NaN;
|
|
1701
445
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
x.d = [0];
|
|
1705
|
-
}
|
|
1706
|
-
return x;
|
|
1707
|
-
}
|
|
1708
|
-
function parseOther(x, str) {
|
|
1709
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
1710
|
-
if (str.indexOf("_") > -1) {
|
|
1711
|
-
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
1712
|
-
if (isDecimal.test(str))
|
|
1713
|
-
return parseDecimal(x, str);
|
|
1714
|
-
} else if (str === "Infinity" || str === "NaN") {
|
|
1715
|
-
if (!+str)
|
|
1716
|
-
x.s = NaN;
|
|
1717
|
-
x.e = NaN;
|
|
1718
|
-
x.d = null;
|
|
1719
|
-
return x;
|
|
1720
|
-
}
|
|
1721
|
-
if (isHex.test(str)) {
|
|
1722
|
-
base = 16;
|
|
1723
|
-
str = str.toLowerCase();
|
|
1724
|
-
} else if (isBinary.test(str)) {
|
|
1725
|
-
base = 2;
|
|
1726
|
-
} else if (isOctal.test(str)) {
|
|
1727
|
-
base = 8;
|
|
1728
|
-
} else {
|
|
1729
|
-
throw Error(invalidArgument + str);
|
|
1730
|
-
}
|
|
1731
|
-
i = str.search(/p/i);
|
|
1732
|
-
if (i > 0) {
|
|
1733
|
-
p = +str.slice(i + 1);
|
|
1734
|
-
str = str.substring(2, i);
|
|
1735
|
-
} else {
|
|
1736
|
-
str = str.slice(2);
|
|
1737
|
-
}
|
|
1738
|
-
i = str.indexOf(".");
|
|
1739
|
-
isFloat = i >= 0;
|
|
1740
|
-
Ctor = x.constructor;
|
|
1741
|
-
if (isFloat) {
|
|
1742
|
-
str = str.replace(".", "");
|
|
1743
|
-
len = str.length;
|
|
1744
|
-
i = len - i;
|
|
1745
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
1746
|
-
}
|
|
1747
|
-
xd = convertBase(str, base, BASE);
|
|
1748
|
-
xe = xd.length - 1;
|
|
1749
|
-
for (i = xe; xd[i] === 0; --i)
|
|
1750
|
-
xd.pop();
|
|
1751
|
-
if (i < 0)
|
|
1752
|
-
return new Ctor(x.s * 0);
|
|
1753
|
-
x.e = getBase10Exponent(xd, xe);
|
|
1754
|
-
x.d = xd;
|
|
1755
|
-
external = false;
|
|
1756
|
-
if (isFloat)
|
|
1757
|
-
x = divide(x, divisor, len * 4);
|
|
1758
|
-
if (p)
|
|
1759
|
-
x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
1760
|
-
external = true;
|
|
1761
|
-
return x;
|
|
1762
|
-
}
|
|
1763
|
-
function sine(Ctor, x) {
|
|
1764
|
-
var k, len = x.d.length;
|
|
1765
|
-
if (len < 3) {
|
|
1766
|
-
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
1767
|
-
}
|
|
1768
|
-
k = 1.4 * Math.sqrt(len);
|
|
1769
|
-
k = k > 16 ? 16 : k | 0;
|
|
1770
|
-
x = x.times(1 / tinyPow(5, k));
|
|
1771
|
-
x = taylorSeries(Ctor, 2, x, x);
|
|
1772
|
-
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
1773
|
-
for (; k--; ) {
|
|
1774
|
-
sin2_x = x.times(x);
|
|
1775
|
-
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
1776
|
-
}
|
|
1777
|
-
return x;
|
|
1778
|
-
}
|
|
1779
|
-
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
1780
|
-
var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
|
1781
|
-
external = false;
|
|
1782
|
-
x2 = x.times(x);
|
|
1783
|
-
u = new Ctor(y);
|
|
1784
|
-
for (; ; ) {
|
|
1785
|
-
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
1786
|
-
u = isHyperbolic ? y.plus(t) : y.minus(t);
|
|
1787
|
-
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
1788
|
-
t = u.plus(y);
|
|
1789
|
-
if (t.d[k] !== void 0) {
|
|
1790
|
-
for (j = k; t.d[j] === u.d[j] && j--; )
|
|
1791
|
-
;
|
|
1792
|
-
if (j == -1)
|
|
1793
|
-
break;
|
|
446
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY) {
|
|
447
|
+
return other._special === SpecialValue.POSITIVE_INFINITY ? 0 : 1;
|
|
1794
448
|
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
y = t;
|
|
1798
|
-
t = j;
|
|
1799
|
-
i++;
|
|
1800
|
-
}
|
|
1801
|
-
external = true;
|
|
1802
|
-
t.d.length = k + 1;
|
|
1803
|
-
return t;
|
|
1804
|
-
}
|
|
1805
|
-
function tinyPow(b, e) {
|
|
1806
|
-
var n = b;
|
|
1807
|
-
while (--e)
|
|
1808
|
-
n *= b;
|
|
1809
|
-
return n;
|
|
1810
|
-
}
|
|
1811
|
-
function toLessThanHalfPi(Ctor, x) {
|
|
1812
|
-
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
1813
|
-
x = x.abs();
|
|
1814
|
-
if (x.lte(halfPi)) {
|
|
1815
|
-
quadrant = isNeg ? 4 : 1;
|
|
1816
|
-
return x;
|
|
1817
|
-
}
|
|
1818
|
-
t = x.divToInt(pi);
|
|
1819
|
-
if (t.isZero()) {
|
|
1820
|
-
quadrant = isNeg ? 3 : 2;
|
|
1821
|
-
} else {
|
|
1822
|
-
x = x.minus(t.times(pi));
|
|
1823
|
-
if (x.lte(halfPi)) {
|
|
1824
|
-
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
1825
|
-
return x;
|
|
449
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY) {
|
|
450
|
+
return other._special === SpecialValue.NEGATIVE_INFINITY ? 0 : -1;
|
|
1826
451
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
if (
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
452
|
+
if (other._special === SpecialValue.POSITIVE_INFINITY)
|
|
453
|
+
return -1;
|
|
454
|
+
if (other._special === SpecialValue.NEGATIVE_INFINITY)
|
|
455
|
+
return 1;
|
|
456
|
+
const thisZero = this._mantissa === 0n;
|
|
457
|
+
const otherZero = other._mantissa === 0n;
|
|
458
|
+
if (thisZero && otherZero)
|
|
459
|
+
return 0;
|
|
460
|
+
if (thisZero)
|
|
461
|
+
return other._mantissa > 0n ? -1 : 1;
|
|
462
|
+
if (otherZero)
|
|
463
|
+
return this._mantissa > 0n ? 1 : -1;
|
|
464
|
+
const thisNeg = this._mantissa < 0n;
|
|
465
|
+
const otherNeg = other._mantissa < 0n;
|
|
466
|
+
if (thisNeg !== otherNeg)
|
|
467
|
+
return thisNeg ? -1 : 1;
|
|
468
|
+
let m1 = this._mantissa;
|
|
469
|
+
let m2 = other._mantissa;
|
|
470
|
+
const e1 = this._exponent;
|
|
471
|
+
const e2 = other._exponent;
|
|
472
|
+
const minE = Math.min(e1, e2);
|
|
473
|
+
if (e1 > minE)
|
|
474
|
+
m1 *= bigintPow10(e1 - minE);
|
|
475
|
+
if (e2 > minE)
|
|
476
|
+
m2 *= bigintPow10(e2 - minE);
|
|
477
|
+
if (m1 < m2)
|
|
478
|
+
return -1;
|
|
479
|
+
if (m1 > m2)
|
|
480
|
+
return 1;
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
483
|
+
lessThan(y) {
|
|
484
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
485
|
+
return c === -1;
|
|
486
|
+
}
|
|
487
|
+
greaterThan(y) {
|
|
488
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
489
|
+
return c === 1;
|
|
490
|
+
}
|
|
491
|
+
lessThanOrEqualTo(y) {
|
|
492
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
493
|
+
return c === 0 || c === -1;
|
|
494
|
+
}
|
|
495
|
+
greaterThanOrEqualTo(y) {
|
|
496
|
+
const c = this._compareTo(_BigDecimal._coerce(y));
|
|
497
|
+
return c === 0 || c === 1;
|
|
498
|
+
}
|
|
499
|
+
// --- Queries ---
|
|
500
|
+
isZero() {
|
|
501
|
+
return this._special === SpecialValue.NONE && this._mantissa === 0n;
|
|
502
|
+
}
|
|
503
|
+
isNaN() {
|
|
504
|
+
return this._special === SpecialValue.NAN;
|
|
505
|
+
}
|
|
506
|
+
isFinite() {
|
|
507
|
+
return this._special === SpecialValue.NONE;
|
|
508
|
+
}
|
|
509
|
+
isNegative() {
|
|
510
|
+
if (this._special === SpecialValue.NAN)
|
|
511
|
+
return false;
|
|
512
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
513
|
+
return true;
|
|
514
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
515
|
+
return false;
|
|
516
|
+
if (this._mantissa === 0n)
|
|
517
|
+
return this._negativeZero;
|
|
518
|
+
return this._mantissa < 0n;
|
|
519
|
+
}
|
|
520
|
+
isPositive() {
|
|
521
|
+
if (this._special === SpecialValue.NAN)
|
|
522
|
+
return false;
|
|
523
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
524
|
+
return true;
|
|
525
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
526
|
+
return false;
|
|
527
|
+
if (this._mantissa === 0n)
|
|
528
|
+
return !this._negativeZero;
|
|
529
|
+
return this._mantissa > 0n;
|
|
530
|
+
}
|
|
531
|
+
isInteger() {
|
|
532
|
+
if (this._special !== SpecialValue.NONE)
|
|
533
|
+
return false;
|
|
534
|
+
if (this._mantissa === 0n)
|
|
535
|
+
return true;
|
|
536
|
+
return this._exponent >= 0;
|
|
537
|
+
}
|
|
538
|
+
// --- Conversion ---
|
|
539
|
+
toJSON() {
|
|
540
|
+
return this.toString();
|
|
541
|
+
}
|
|
542
|
+
toNumber() {
|
|
543
|
+
if (this._special === SpecialValue.NAN)
|
|
544
|
+
return NaN;
|
|
545
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
546
|
+
return Infinity;
|
|
547
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
548
|
+
return -Infinity;
|
|
549
|
+
if (this._mantissa === 0n)
|
|
550
|
+
return this._negativeZero ? -0 : 0;
|
|
551
|
+
return Number(this.toString());
|
|
1842
552
|
}
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
if (
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
553
|
+
toString() {
|
|
554
|
+
if (this._special === SpecialValue.NAN)
|
|
555
|
+
return "NaN";
|
|
556
|
+
if (this._special === SpecialValue.POSITIVE_INFINITY)
|
|
557
|
+
return "Infinity";
|
|
558
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
559
|
+
return "-Infinity";
|
|
560
|
+
if (this._mantissa === 0n)
|
|
561
|
+
return "0";
|
|
562
|
+
const negative = this._mantissa < 0n;
|
|
563
|
+
const absStr = bigintAbs(this._mantissa).toString();
|
|
564
|
+
const prefix = negative ? "-" : "";
|
|
565
|
+
if (this._exponent === 0) {
|
|
566
|
+
return prefix + absStr;
|
|
1857
567
|
}
|
|
1858
|
-
if (
|
|
1859
|
-
|
|
1860
|
-
y = new Ctor(1);
|
|
1861
|
-
y.e = str.length - i;
|
|
1862
|
-
y.d = convertBase(finiteToString(y), 10, base);
|
|
1863
|
-
y.e = y.d.length;
|
|
568
|
+
if (this._exponent > 0) {
|
|
569
|
+
return prefix + absStr + "0".repeat(this._exponent);
|
|
1864
570
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
str = isExp ? "0p+0" : "0";
|
|
571
|
+
const decimalPlaces = -this._exponent;
|
|
572
|
+
if (decimalPlaces < absStr.length) {
|
|
573
|
+
const intPart = absStr.slice(0, absStr.length - decimalPlaces);
|
|
574
|
+
const fracPart = absStr.slice(absStr.length - decimalPlaces);
|
|
575
|
+
return prefix + intPart + "." + fracPart;
|
|
1871
576
|
} else {
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
} else {
|
|
1875
|
-
x = new Ctor(x);
|
|
1876
|
-
x.d = xd;
|
|
1877
|
-
x.e = e;
|
|
1878
|
-
x = divide(x, y, sd, rm, 0, base);
|
|
1879
|
-
xd = x.d;
|
|
1880
|
-
e = x.e;
|
|
1881
|
-
roundUp = inexact;
|
|
1882
|
-
}
|
|
1883
|
-
i = xd[sd];
|
|
1884
|
-
k = base / 2;
|
|
1885
|
-
roundUp = roundUp || xd[sd + 1] !== void 0;
|
|
1886
|
-
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));
|
|
1887
|
-
xd.length = sd;
|
|
1888
|
-
if (roundUp) {
|
|
1889
|
-
for (; ++xd[--sd] > base - 1; ) {
|
|
1890
|
-
xd[sd] = 0;
|
|
1891
|
-
if (!sd) {
|
|
1892
|
-
++e;
|
|
1893
|
-
xd.unshift(1);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
for (len = xd.length; !xd[len - 1]; --len)
|
|
1898
|
-
;
|
|
1899
|
-
for (i = 0, str = ""; i < len; i++)
|
|
1900
|
-
str += NUMERALS.charAt(xd[i]);
|
|
1901
|
-
if (isExp) {
|
|
1902
|
-
if (len > 1) {
|
|
1903
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
1904
|
-
i = baseOut == 16 ? 4 : 3;
|
|
1905
|
-
for (--len; len % i; len++)
|
|
1906
|
-
str += "0";
|
|
1907
|
-
xd = convertBase(str, base, baseOut);
|
|
1908
|
-
for (len = xd.length; !xd[len - 1]; --len)
|
|
1909
|
-
;
|
|
1910
|
-
for (i = 1, str = "1."; i < len; i++)
|
|
1911
|
-
str += NUMERALS.charAt(xd[i]);
|
|
1912
|
-
} else {
|
|
1913
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
str = str + (e < 0 ? "p" : "p+") + e;
|
|
1917
|
-
} else if (e < 0) {
|
|
1918
|
-
for (; ++e; )
|
|
1919
|
-
str = "0" + str;
|
|
1920
|
-
str = "0." + str;
|
|
1921
|
-
} else {
|
|
1922
|
-
if (++e > len)
|
|
1923
|
-
for (e -= len; e--; )
|
|
1924
|
-
str += "0";
|
|
1925
|
-
else if (e < len)
|
|
1926
|
-
str = str.slice(0, e) + "." + str.slice(e);
|
|
1927
|
-
}
|
|
577
|
+
const leadingZeros = decimalPlaces - absStr.length;
|
|
578
|
+
return prefix + "0." + "0".repeat(leadingZeros) + absStr;
|
|
1928
579
|
}
|
|
1929
|
-
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
1930
580
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
return true;
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
function abs(x) {
|
|
1940
|
-
return new this(x).abs();
|
|
1941
|
-
}
|
|
1942
|
-
function acos(x) {
|
|
1943
|
-
return new this(x).acos();
|
|
1944
|
-
}
|
|
1945
|
-
function acosh(x) {
|
|
1946
|
-
return new this(x).acosh();
|
|
1947
|
-
}
|
|
1948
|
-
function add(x, y) {
|
|
1949
|
-
return new this(x).plus(y);
|
|
1950
|
-
}
|
|
1951
|
-
function asin(x) {
|
|
1952
|
-
return new this(x).asin();
|
|
1953
|
-
}
|
|
1954
|
-
function asinh(x) {
|
|
1955
|
-
return new this(x).asinh();
|
|
1956
|
-
}
|
|
1957
|
-
function atan(x) {
|
|
1958
|
-
return new this(x).atan();
|
|
1959
|
-
}
|
|
1960
|
-
function atanh(x) {
|
|
1961
|
-
return new this(x).atanh();
|
|
1962
|
-
}
|
|
1963
|
-
function atan2(y, x) {
|
|
1964
|
-
y = new this(y);
|
|
1965
|
-
x = new this(x);
|
|
1966
|
-
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
1967
|
-
if (!y.s || !x.s) {
|
|
1968
|
-
r = new this(NaN);
|
|
1969
|
-
} else if (!y.d && !x.d) {
|
|
1970
|
-
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
|
1971
|
-
r.s = y.s;
|
|
1972
|
-
} else if (!x.d || y.isZero()) {
|
|
1973
|
-
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
1974
|
-
r.s = y.s;
|
|
1975
|
-
} else if (!y.d || x.isZero()) {
|
|
1976
|
-
r = getPi(this, wpr, 1).times(0.5);
|
|
1977
|
-
r.s = y.s;
|
|
1978
|
-
} else if (x.s < 0) {
|
|
1979
|
-
this.precision = wpr;
|
|
1980
|
-
this.rounding = 1;
|
|
1981
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
1982
|
-
x = getPi(this, wpr, 1);
|
|
1983
|
-
this.precision = pr;
|
|
1984
|
-
this.rounding = rm;
|
|
1985
|
-
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
1986
|
-
} else {
|
|
1987
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
1988
|
-
}
|
|
1989
|
-
return r;
|
|
1990
|
-
}
|
|
1991
|
-
function cbrt(x) {
|
|
1992
|
-
return new this(x).cbrt();
|
|
1993
|
-
}
|
|
1994
|
-
function ceil(x) {
|
|
1995
|
-
return finalise(x = new this(x), x.e + 1, 2);
|
|
1996
|
-
}
|
|
1997
|
-
function clamp(x, min2, max2) {
|
|
1998
|
-
return new this(x).clamp(min2, max2);
|
|
1999
|
-
}
|
|
2000
|
-
function config(obj) {
|
|
2001
|
-
if (!obj || typeof obj !== "object")
|
|
2002
|
-
throw Error(decimalError + "Object expected");
|
|
2003
|
-
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
2004
|
-
"precision",
|
|
2005
|
-
1,
|
|
2006
|
-
MAX_DIGITS,
|
|
2007
|
-
"rounding",
|
|
2008
|
-
0,
|
|
2009
|
-
8,
|
|
2010
|
-
"toExpNeg",
|
|
2011
|
-
-EXP_LIMIT,
|
|
2012
|
-
0,
|
|
2013
|
-
"toExpPos",
|
|
2014
|
-
0,
|
|
2015
|
-
EXP_LIMIT,
|
|
2016
|
-
"maxE",
|
|
2017
|
-
0,
|
|
2018
|
-
EXP_LIMIT,
|
|
2019
|
-
"minE",
|
|
2020
|
-
-EXP_LIMIT,
|
|
2021
|
-
0,
|
|
2022
|
-
"modulo",
|
|
2023
|
-
0,
|
|
2024
|
-
9
|
|
2025
|
-
];
|
|
2026
|
-
for (i = 0; i < ps.length; i += 3) {
|
|
2027
|
-
if (p = ps[i], useDefaults)
|
|
2028
|
-
this[p] = DEFAULTS[p];
|
|
2029
|
-
if ((v = obj[p]) !== void 0) {
|
|
2030
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
|
|
2031
|
-
this[p] = v;
|
|
2032
|
-
else
|
|
2033
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
581
|
+
// --- Static ---
|
|
582
|
+
static pow(base, exp) {
|
|
583
|
+
const n = typeof exp === "number" ? exp : exp.toNumber();
|
|
584
|
+
if (typeof base === "number" && base === 10) {
|
|
585
|
+
return _BigDecimal._create(1n, n, SpecialValue.NONE, false);
|
|
2034
586
|
}
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
587
|
+
const bd = base instanceof _BigDecimal ? base : new _BigDecimal(base);
|
|
588
|
+
return bd.pow(n);
|
|
589
|
+
}
|
|
590
|
+
static set(_config) {
|
|
591
|
+
}
|
|
592
|
+
// --- Internal helpers ---
|
|
593
|
+
_isSignNegative() {
|
|
594
|
+
if (this._special === SpecialValue.NEGATIVE_INFINITY)
|
|
595
|
+
return true;
|
|
596
|
+
if (this._mantissa < 0n)
|
|
597
|
+
return true;
|
|
598
|
+
if (this._mantissa === 0n)
|
|
599
|
+
return this._negativeZero;
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
_specialArith(other, op) {
|
|
603
|
+
const a = this._special;
|
|
604
|
+
const b = other._special;
|
|
605
|
+
if (a === SpecialValue.NAN || b === SpecialValue.NAN) {
|
|
606
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2051
607
|
}
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
}
|
|
2061
|
-
function clone(obj) {
|
|
2062
|
-
var i, p, ps;
|
|
2063
|
-
function Decimal2(v) {
|
|
2064
|
-
var e, i2, t, x = this;
|
|
2065
|
-
if (!(x instanceof Decimal2))
|
|
2066
|
-
return new Decimal2(v);
|
|
2067
|
-
x.constructor = Decimal2;
|
|
2068
|
-
if (isDecimalInstance(v)) {
|
|
2069
|
-
x.s = v.s;
|
|
2070
|
-
if (external) {
|
|
2071
|
-
if (!v.d || v.e > Decimal2.maxE) {
|
|
2072
|
-
x.e = NaN;
|
|
2073
|
-
x.d = null;
|
|
2074
|
-
} else if (v.e < Decimal2.minE) {
|
|
2075
|
-
x.e = 0;
|
|
2076
|
-
x.d = [0];
|
|
2077
|
-
} else {
|
|
2078
|
-
x.e = v.e;
|
|
2079
|
-
x.d = v.d.slice();
|
|
608
|
+
const aNeg = this._isSignNegative();
|
|
609
|
+
const bNeg = other._isSignNegative();
|
|
610
|
+
const aInf = a === SpecialValue.POSITIVE_INFINITY || a === SpecialValue.NEGATIVE_INFINITY;
|
|
611
|
+
const bInf = b === SpecialValue.POSITIVE_INFINITY || b === SpecialValue.NEGATIVE_INFINITY;
|
|
612
|
+
if (op === "times") {
|
|
613
|
+
if (aInf || bInf) {
|
|
614
|
+
if (aInf && other._mantissa === 0n && !bInf || bInf && this._mantissa === 0n && !aInf) {
|
|
615
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2080
616
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
x.d = v.d ? v.d.slice() : v.d;
|
|
617
|
+
const neg = aNeg !== bNeg;
|
|
618
|
+
return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
|
|
2084
619
|
}
|
|
2085
|
-
return;
|
|
2086
620
|
}
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
x.s = 1 / v < 0 ? -1 : 1;
|
|
2091
|
-
x.e = 0;
|
|
2092
|
-
x.d = [0];
|
|
2093
|
-
return;
|
|
621
|
+
if (op === "div") {
|
|
622
|
+
if (aInf && bInf) {
|
|
623
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2094
624
|
}
|
|
2095
|
-
if (
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
} else {
|
|
2099
|
-
x.s = 1;
|
|
625
|
+
if (aInf) {
|
|
626
|
+
const neg = aNeg !== bNeg;
|
|
627
|
+
return _BigDecimal._create(0n, 0, neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, false);
|
|
2100
628
|
}
|
|
2101
|
-
if (
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
if (external) {
|
|
2105
|
-
if (e > Decimal2.maxE) {
|
|
2106
|
-
x.e = NaN;
|
|
2107
|
-
x.d = null;
|
|
2108
|
-
} else if (e < Decimal2.minE) {
|
|
2109
|
-
x.e = 0;
|
|
2110
|
-
x.d = [0];
|
|
2111
|
-
} else {
|
|
2112
|
-
x.e = e;
|
|
2113
|
-
x.d = [v];
|
|
2114
|
-
}
|
|
2115
|
-
} else {
|
|
2116
|
-
x.e = e;
|
|
2117
|
-
x.d = [v];
|
|
2118
|
-
}
|
|
2119
|
-
return;
|
|
629
|
+
if (bInf) {
|
|
630
|
+
const negZero = aNeg !== bNeg;
|
|
631
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NONE, negZero);
|
|
2120
632
|
}
|
|
2121
|
-
if (v * 0 !== 0) {
|
|
2122
|
-
if (!v)
|
|
2123
|
-
x.s = NaN;
|
|
2124
|
-
x.e = NaN;
|
|
2125
|
-
x.d = null;
|
|
2126
|
-
return;
|
|
2127
|
-
}
|
|
2128
|
-
return parseDecimal(x, v.toString());
|
|
2129
|
-
}
|
|
2130
|
-
if (t === "string") {
|
|
2131
|
-
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
2132
|
-
v = v.slice(1);
|
|
2133
|
-
x.s = -1;
|
|
2134
|
-
} else {
|
|
2135
|
-
if (i2 === 43)
|
|
2136
|
-
v = v.slice(1);
|
|
2137
|
-
x.s = 1;
|
|
2138
|
-
}
|
|
2139
|
-
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
|
2140
633
|
}
|
|
2141
|
-
if (
|
|
2142
|
-
if (
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
}
|
|
2148
|
-
return parseDecimal(x, v.toString());
|
|
2149
|
-
}
|
|
2150
|
-
throw Error(invalidArgument + v);
|
|
2151
|
-
}
|
|
2152
|
-
Decimal2.prototype = P;
|
|
2153
|
-
Decimal2.ROUND_UP = 0;
|
|
2154
|
-
Decimal2.ROUND_DOWN = 1;
|
|
2155
|
-
Decimal2.ROUND_CEIL = 2;
|
|
2156
|
-
Decimal2.ROUND_FLOOR = 3;
|
|
2157
|
-
Decimal2.ROUND_HALF_UP = 4;
|
|
2158
|
-
Decimal2.ROUND_HALF_DOWN = 5;
|
|
2159
|
-
Decimal2.ROUND_HALF_EVEN = 6;
|
|
2160
|
-
Decimal2.ROUND_HALF_CEIL = 7;
|
|
2161
|
-
Decimal2.ROUND_HALF_FLOOR = 8;
|
|
2162
|
-
Decimal2.EUCLID = 9;
|
|
2163
|
-
Decimal2.config = Decimal2.set = config;
|
|
2164
|
-
Decimal2.clone = clone;
|
|
2165
|
-
Decimal2.isDecimal = isDecimalInstance;
|
|
2166
|
-
Decimal2.abs = abs;
|
|
2167
|
-
Decimal2.acos = acos;
|
|
2168
|
-
Decimal2.acosh = acosh;
|
|
2169
|
-
Decimal2.add = add;
|
|
2170
|
-
Decimal2.asin = asin;
|
|
2171
|
-
Decimal2.asinh = asinh;
|
|
2172
|
-
Decimal2.atan = atan;
|
|
2173
|
-
Decimal2.atanh = atanh;
|
|
2174
|
-
Decimal2.atan2 = atan2;
|
|
2175
|
-
Decimal2.cbrt = cbrt;
|
|
2176
|
-
Decimal2.ceil = ceil;
|
|
2177
|
-
Decimal2.clamp = clamp;
|
|
2178
|
-
Decimal2.cos = cos;
|
|
2179
|
-
Decimal2.cosh = cosh;
|
|
2180
|
-
Decimal2.div = div;
|
|
2181
|
-
Decimal2.exp = exp;
|
|
2182
|
-
Decimal2.floor = floor;
|
|
2183
|
-
Decimal2.hypot = hypot;
|
|
2184
|
-
Decimal2.ln = ln;
|
|
2185
|
-
Decimal2.log = log;
|
|
2186
|
-
Decimal2.log10 = log10;
|
|
2187
|
-
Decimal2.log2 = log2;
|
|
2188
|
-
Decimal2.max = max;
|
|
2189
|
-
Decimal2.min = min;
|
|
2190
|
-
Decimal2.mod = mod;
|
|
2191
|
-
Decimal2.mul = mul;
|
|
2192
|
-
Decimal2.pow = pow;
|
|
2193
|
-
Decimal2.random = random;
|
|
2194
|
-
Decimal2.round = round;
|
|
2195
|
-
Decimal2.sign = sign;
|
|
2196
|
-
Decimal2.sin = sin;
|
|
2197
|
-
Decimal2.sinh = sinh;
|
|
2198
|
-
Decimal2.sqrt = sqrt;
|
|
2199
|
-
Decimal2.sub = sub;
|
|
2200
|
-
Decimal2.sum = sum;
|
|
2201
|
-
Decimal2.tan = tan;
|
|
2202
|
-
Decimal2.tanh = tanh;
|
|
2203
|
-
Decimal2.trunc = trunc;
|
|
2204
|
-
if (obj === void 0)
|
|
2205
|
-
obj = {};
|
|
2206
|
-
if (obj) {
|
|
2207
|
-
if (obj.defaults !== true) {
|
|
2208
|
-
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
2209
|
-
for (i = 0; i < ps.length; )
|
|
2210
|
-
if (!obj.hasOwnProperty(p = ps[i++]))
|
|
2211
|
-
obj[p] = this[p];
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
Decimal2.config(obj);
|
|
2215
|
-
return Decimal2;
|
|
2216
|
-
}
|
|
2217
|
-
function div(x, y) {
|
|
2218
|
-
return new this(x).div(y);
|
|
2219
|
-
}
|
|
2220
|
-
function exp(x) {
|
|
2221
|
-
return new this(x).exp();
|
|
2222
|
-
}
|
|
2223
|
-
function floor(x) {
|
|
2224
|
-
return finalise(x = new this(x), x.e + 1, 3);
|
|
2225
|
-
}
|
|
2226
|
-
function hypot() {
|
|
2227
|
-
var i, n, t = new this(0);
|
|
2228
|
-
external = false;
|
|
2229
|
-
for (i = 0; i < arguments.length; ) {
|
|
2230
|
-
n = new this(arguments[i++]);
|
|
2231
|
-
if (!n.d) {
|
|
2232
|
-
if (n.s) {
|
|
2233
|
-
external = true;
|
|
2234
|
-
return new this(1 / 0);
|
|
2235
|
-
}
|
|
2236
|
-
t = n;
|
|
2237
|
-
} else if (t.d) {
|
|
2238
|
-
t = t.plus(n.times(n));
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
external = true;
|
|
2242
|
-
return t.sqrt();
|
|
2243
|
-
}
|
|
2244
|
-
function isDecimalInstance(obj) {
|
|
2245
|
-
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
2246
|
-
}
|
|
2247
|
-
function ln(x) {
|
|
2248
|
-
return new this(x).ln();
|
|
2249
|
-
}
|
|
2250
|
-
function log(x, y) {
|
|
2251
|
-
return new this(x).log(y);
|
|
2252
|
-
}
|
|
2253
|
-
function log2(x) {
|
|
2254
|
-
return new this(x).log(2);
|
|
2255
|
-
}
|
|
2256
|
-
function log10(x) {
|
|
2257
|
-
return new this(x).log(10);
|
|
2258
|
-
}
|
|
2259
|
-
function max() {
|
|
2260
|
-
return maxOrMin(this, arguments, -1);
|
|
2261
|
-
}
|
|
2262
|
-
function min() {
|
|
2263
|
-
return maxOrMin(this, arguments, 1);
|
|
2264
|
-
}
|
|
2265
|
-
function mod(x, y) {
|
|
2266
|
-
return new this(x).mod(y);
|
|
2267
|
-
}
|
|
2268
|
-
function mul(x, y) {
|
|
2269
|
-
return new this(x).mul(y);
|
|
2270
|
-
}
|
|
2271
|
-
function pow(x, y) {
|
|
2272
|
-
return new this(x).pow(y);
|
|
2273
|
-
}
|
|
2274
|
-
function random(sd) {
|
|
2275
|
-
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
2276
|
-
if (sd === void 0)
|
|
2277
|
-
sd = this.precision;
|
|
2278
|
-
else
|
|
2279
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
2280
|
-
k = Math.ceil(sd / LOG_BASE);
|
|
2281
|
-
if (!this.crypto) {
|
|
2282
|
-
for (; i < k; )
|
|
2283
|
-
rd[i++] = Math.random() * 1e7 | 0;
|
|
2284
|
-
} else if (crypto.getRandomValues) {
|
|
2285
|
-
d = crypto.getRandomValues(new Uint32Array(k));
|
|
2286
|
-
for (; i < k; ) {
|
|
2287
|
-
n = d[i];
|
|
2288
|
-
if (n >= 429e7) {
|
|
2289
|
-
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
2290
|
-
} else {
|
|
2291
|
-
rd[i++] = n % 1e7;
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
} else if (crypto.randomBytes) {
|
|
2295
|
-
d = crypto.randomBytes(k *= 4);
|
|
2296
|
-
for (; i < k; ) {
|
|
2297
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
2298
|
-
if (n >= 214e7) {
|
|
2299
|
-
crypto.randomBytes(4).copy(d, i);
|
|
2300
|
-
} else {
|
|
2301
|
-
rd.push(n % 1e7);
|
|
2302
|
-
i += 4;
|
|
634
|
+
if (op === "plus") {
|
|
635
|
+
if (aInf && bInf) {
|
|
636
|
+
if (aNeg !== bNeg) {
|
|
637
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
638
|
+
}
|
|
639
|
+
return this;
|
|
2303
640
|
}
|
|
641
|
+
if (aInf)
|
|
642
|
+
return this;
|
|
643
|
+
if (bInf)
|
|
644
|
+
return other;
|
|
2304
645
|
}
|
|
2305
|
-
|
|
2306
|
-
} else {
|
|
2307
|
-
throw Error(cryptoUnavailable);
|
|
646
|
+
return _BigDecimal._create(0n, 0, SpecialValue.NAN, false);
|
|
2308
647
|
}
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
if (k && sd) {
|
|
2312
|
-
n = mathpow(10, LOG_BASE - sd);
|
|
2313
|
-
rd[i] = (k / n | 0) * n;
|
|
2314
|
-
}
|
|
2315
|
-
for (; rd[i] === 0; i--)
|
|
2316
|
-
rd.pop();
|
|
2317
|
-
if (i < 0) {
|
|
2318
|
-
e = 0;
|
|
2319
|
-
rd = [0];
|
|
2320
|
-
} else {
|
|
2321
|
-
e = -1;
|
|
2322
|
-
for (; rd[0] === 0; e -= LOG_BASE)
|
|
2323
|
-
rd.shift();
|
|
2324
|
-
for (k = 1, n = rd[0]; n >= 10; n /= 10)
|
|
2325
|
-
k++;
|
|
2326
|
-
if (k < LOG_BASE)
|
|
2327
|
-
e -= LOG_BASE - k;
|
|
2328
|
-
}
|
|
2329
|
-
r.e = e;
|
|
2330
|
-
r.d = rd;
|
|
2331
|
-
return r;
|
|
2332
|
-
}
|
|
2333
|
-
function round(x) {
|
|
2334
|
-
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
2335
|
-
}
|
|
2336
|
-
function sign(x) {
|
|
2337
|
-
x = new this(x);
|
|
2338
|
-
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
2339
|
-
}
|
|
2340
|
-
function sin(x) {
|
|
2341
|
-
return new this(x).sin();
|
|
2342
|
-
}
|
|
2343
|
-
function sinh(x) {
|
|
2344
|
-
return new this(x).sinh();
|
|
2345
|
-
}
|
|
2346
|
-
function sqrt(x) {
|
|
2347
|
-
return new this(x).sqrt();
|
|
2348
|
-
}
|
|
2349
|
-
function sub(x, y) {
|
|
2350
|
-
return new this(x).sub(y);
|
|
2351
|
-
}
|
|
2352
|
-
function sum() {
|
|
2353
|
-
var i = 0, args = arguments, x = new this(args[i]);
|
|
2354
|
-
external = false;
|
|
2355
|
-
for (; x.s && ++i < args.length; )
|
|
2356
|
-
x = x.plus(args[i]);
|
|
2357
|
-
external = true;
|
|
2358
|
-
return finalise(x, this.precision, this.rounding);
|
|
2359
|
-
}
|
|
2360
|
-
function tan(x) {
|
|
2361
|
-
return new this(x).tan();
|
|
2362
|
-
}
|
|
2363
|
-
function tanh(x) {
|
|
2364
|
-
return new this(x).tanh();
|
|
2365
|
-
}
|
|
2366
|
-
function trunc(x) {
|
|
2367
|
-
return finalise(x = new this(x), x.e + 1, 1);
|
|
2368
|
-
}
|
|
2369
|
-
P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
2370
|
-
P[Symbol.toStringTag] = "Decimal";
|
|
2371
|
-
var Decimal = P.constructor = clone(DEFAULTS);
|
|
2372
|
-
LN10 = new Decimal(LN10);
|
|
2373
|
-
PI = new Decimal(PI);
|
|
2374
|
-
var decimal_default = Decimal;
|
|
648
|
+
};
|
|
649
|
+
var bigdecimal_default = BigDecimal;
|
|
2375
650
|
|
|
2376
651
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/constants.js
|
|
2377
|
-
var TEN = new
|
|
2378
|
-
var ZERO = new
|
|
2379
|
-
var NEGATIVE_ZERO = new
|
|
652
|
+
var TEN = new BigDecimal(10);
|
|
653
|
+
var ZERO = new BigDecimal(0);
|
|
654
|
+
var NEGATIVE_ZERO = new BigDecimal(-0);
|
|
2380
655
|
|
|
2381
656
|
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
2382
657
|
function memoize(fn, options) {
|
|
@@ -2476,26 +751,26 @@
|
|
|
2476
751
|
}
|
|
2477
752
|
function ToNumber(arg) {
|
|
2478
753
|
if (typeof arg === "number") {
|
|
2479
|
-
return new
|
|
754
|
+
return new BigDecimal(arg);
|
|
2480
755
|
}
|
|
2481
756
|
if (typeof arg === "bigint") {
|
|
2482
|
-
return new
|
|
757
|
+
return new BigDecimal(arg.toString());
|
|
2483
758
|
}
|
|
2484
759
|
invariant(typeof arg !== "symbol", "Symbol is not supported", TypeError);
|
|
2485
760
|
if (arg === void 0) {
|
|
2486
|
-
return new
|
|
761
|
+
return new BigDecimal(NaN);
|
|
2487
762
|
}
|
|
2488
763
|
if (arg === null || arg === 0) {
|
|
2489
764
|
return ZERO;
|
|
2490
765
|
}
|
|
2491
766
|
if (arg === true) {
|
|
2492
|
-
return new
|
|
767
|
+
return new BigDecimal(1);
|
|
2493
768
|
}
|
|
2494
769
|
if (typeof arg === "string") {
|
|
2495
770
|
try {
|
|
2496
|
-
return new
|
|
2497
|
-
} catch
|
|
2498
|
-
return new
|
|
771
|
+
return new BigDecimal(arg);
|
|
772
|
+
} catch {
|
|
773
|
+
return new BigDecimal(NaN);
|
|
2499
774
|
}
|
|
2500
775
|
}
|
|
2501
776
|
invariant(typeof arg === "object", "object expected", TypeError);
|
|
@@ -2597,13 +872,13 @@
|
|
|
2597
872
|
}
|
|
2598
873
|
|
|
2599
874
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/DefaultNumberOption.js
|
|
2600
|
-
function DefaultNumberOption(inputVal,
|
|
875
|
+
function DefaultNumberOption(inputVal, min, max, fallback) {
|
|
2601
876
|
if (inputVal === void 0) {
|
|
2602
877
|
return fallback;
|
|
2603
878
|
}
|
|
2604
879
|
const val = Number(inputVal);
|
|
2605
|
-
if (isNaN(val) || val <
|
|
2606
|
-
throw new RangeError(`${val} is outside of range [${
|
|
880
|
+
if (isNaN(val) || val < min || val > max) {
|
|
881
|
+
throw new RangeError(`${val} is outside of range [${min}, ${max}]`);
|
|
2607
882
|
}
|
|
2608
883
|
return Math.floor(val);
|
|
2609
884
|
}
|
|
@@ -2727,11 +1002,10 @@
|
|
|
2727
1002
|
|
|
2728
1003
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/decimal-cache.js
|
|
2729
1004
|
var getPowerOf10 = memoize((exponent) => {
|
|
2730
|
-
return
|
|
1005
|
+
return BigDecimal.pow(10, exponent);
|
|
2731
1006
|
});
|
|
2732
1007
|
|
|
2733
1008
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
|
|
2734
|
-
Decimal.set({ toExpPos: 100 });
|
|
2735
1009
|
function ComputeExponentForMagnitude(internalSlots, magnitude) {
|
|
2736
1010
|
const { notation, dataLocaleData, numberingSystem } = internalSlots;
|
|
2737
1011
|
switch (notation) {
|
|
@@ -2814,7 +1088,6 @@
|
|
|
2814
1088
|
}
|
|
2815
1089
|
|
|
2816
1090
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ToRawFixed.js
|
|
2817
|
-
Decimal.set({ toExpPos: 100 });
|
|
2818
1091
|
function ToRawFixedFn(n, f) {
|
|
2819
1092
|
return n.times(getPowerOf10(-f));
|
|
2820
1093
|
}
|
|
@@ -3033,24 +1306,24 @@
|
|
|
3033
1306
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/FormatNumericToString.js
|
|
3034
1307
|
function FormatNumericToString(intlObject, _x) {
|
|
3035
1308
|
let x = _x;
|
|
3036
|
-
let
|
|
1309
|
+
let sign;
|
|
3037
1310
|
if (x.isZero() && x.isNegative()) {
|
|
3038
|
-
|
|
1311
|
+
sign = "negative";
|
|
3039
1312
|
x = ZERO;
|
|
3040
1313
|
} else {
|
|
3041
1314
|
invariant(x.isFinite(), "NumberFormatDigitInternalSlots value is not finite");
|
|
3042
1315
|
if (x.lessThan(0)) {
|
|
3043
|
-
|
|
1316
|
+
sign = "negative";
|
|
3044
1317
|
} else {
|
|
3045
|
-
|
|
1318
|
+
sign = "positive";
|
|
3046
1319
|
}
|
|
3047
|
-
if (
|
|
1320
|
+
if (sign === "negative") {
|
|
3048
1321
|
x = x.negated();
|
|
3049
1322
|
}
|
|
3050
1323
|
}
|
|
3051
1324
|
let result;
|
|
3052
1325
|
const roundingType = intlObject.roundingType;
|
|
3053
|
-
const unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode,
|
|
1326
|
+
const unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign === "negative");
|
|
3054
1327
|
switch (roundingType) {
|
|
3055
1328
|
case "significantDigits":
|
|
3056
1329
|
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
@@ -3091,7 +1364,7 @@
|
|
|
3091
1364
|
const forwardZeros = repeat("0", minInteger - int);
|
|
3092
1365
|
string = forwardZeros + string;
|
|
3093
1366
|
}
|
|
3094
|
-
if (
|
|
1367
|
+
if (sign === "negative") {
|
|
3095
1368
|
if (x.isZero()) {
|
|
3096
1369
|
x = NEGATIVE_ZERO;
|
|
3097
1370
|
} else {
|
|
@@ -6309,9 +4582,8 @@
|
|
|
6309
4582
|
var DEFAULT_MATCHING_THRESHOLD = 838;
|
|
6310
4583
|
var PROCESSED_DATA;
|
|
6311
4584
|
function processData() {
|
|
6312
|
-
var _a, _b;
|
|
6313
4585
|
if (!PROCESSED_DATA) {
|
|
6314
|
-
const paradigmLocales =
|
|
4586
|
+
const paradigmLocales = data.supplemental.languageMatching["written-new"][0]?.paradigmLocales?._locales.split(" ");
|
|
6315
4587
|
const matchVariables = data.supplemental.languageMatching["written-new"].slice(1, 5);
|
|
6316
4588
|
const data2 = data.supplemental.languageMatching["written-new"].slice(5);
|
|
6317
4589
|
const matches = data2.map((d) => {
|
|
@@ -6443,7 +4715,7 @@
|
|
|
6443
4715
|
try {
|
|
6444
4716
|
const canonical = Intl.getCanonicalLocales([locale]);
|
|
6445
4717
|
return canonical[0] || locale;
|
|
6446
|
-
} catch
|
|
4718
|
+
} catch {
|
|
6447
4719
|
return locale;
|
|
6448
4720
|
}
|
|
6449
4721
|
});
|
|
@@ -6480,7 +4752,7 @@
|
|
|
6480
4752
|
try {
|
|
6481
4753
|
const candidateMaximized = new Intl.Locale(candidate).maximize().toString();
|
|
6482
4754
|
distance = candidateMaximized === maximized ? 0 + i * 40 : j * 10 + i * 40;
|
|
6483
|
-
} catch
|
|
4755
|
+
} catch {
|
|
6484
4756
|
distance = j * 10 + i * 40;
|
|
6485
4757
|
}
|
|
6486
4758
|
if (!result.distances[desired]) {
|
|
@@ -6496,7 +4768,7 @@
|
|
|
6496
4768
|
}
|
|
6497
4769
|
}
|
|
6498
4770
|
}
|
|
6499
|
-
} catch
|
|
4771
|
+
} catch {
|
|
6500
4772
|
}
|
|
6501
4773
|
}
|
|
6502
4774
|
if (result.matchedSupportedLocale && lowestDistance === 0) {
|
|
@@ -6662,10 +4934,10 @@
|
|
|
6662
4934
|
key: subtag,
|
|
6663
4935
|
value: ""
|
|
6664
4936
|
};
|
|
6665
|
-
if (keywords.find((k2) => k2.key ===
|
|
4937
|
+
if (keywords.find((k2) => k2.key === keyword?.key) === void 0) {
|
|
6666
4938
|
keywords.push(keyword);
|
|
6667
4939
|
}
|
|
6668
|
-
} else if (
|
|
4940
|
+
} else if (keyword?.value === "") {
|
|
6669
4941
|
keyword.value = subtag;
|
|
6670
4942
|
} else {
|
|
6671
4943
|
invariant2(keyword !== void 0, "Expected keyword to be defined");
|
|
@@ -6681,7 +4953,6 @@
|
|
|
6681
4953
|
|
|
6682
4954
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/abstract/ResolveLocale.js
|
|
6683
4955
|
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
|
|
6684
|
-
var _a;
|
|
6685
4956
|
const matcher = options.localeMatcher;
|
|
6686
4957
|
let r;
|
|
6687
4958
|
if (matcher === "lookup") {
|
|
@@ -6711,7 +4982,7 @@
|
|
|
6711
4982
|
}
|
|
6712
4983
|
let supportedKeywords = [];
|
|
6713
4984
|
for (const key of relevantExtensionKeys) {
|
|
6714
|
-
let keyLocaleData =
|
|
4985
|
+
let keyLocaleData = foundLocaleData?.[key] ?? [];
|
|
6715
4986
|
invariant2(Array.isArray(keyLocaleData), `keyLocaleData for ${key} must be an array`);
|
|
6716
4987
|
let value = keyLocaleData[0];
|
|
6717
4988
|
invariant2(value === void 0 || typeof value === "string", `value must be a string or undefined`);
|
|
@@ -6777,7 +5048,7 @@
|
|
|
6777
5048
|
|
|
6778
5049
|
// node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/index.js
|
|
6779
5050
|
function match(requestedLocales, availableLocales, defaultLocale, opts) {
|
|
6780
|
-
return ResolveLocale(availableLocales, CanonicalizeLocaleList2(requestedLocales), { localeMatcher:
|
|
5051
|
+
return ResolveLocale(availableLocales, CanonicalizeLocaleList2(requestedLocales), { localeMatcher: opts?.algorithm || "best fit" }, [], {}, () => defaultLocale).locale;
|
|
6781
5052
|
}
|
|
6782
5053
|
|
|
6783
5054
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/SetNumberFormatDigitOptions.js
|
|
@@ -6919,25 +5190,25 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
6919
5190
|
// node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/ToIntlMathematicalValue.js
|
|
6920
5191
|
function ToIntlMathematicalValue(input) {
|
|
6921
5192
|
if (typeof input === "bigint") {
|
|
6922
|
-
return new
|
|
5193
|
+
return new BigDecimal(input.toString());
|
|
6923
5194
|
}
|
|
6924
5195
|
let primValue = ToPrimitive(input, "number");
|
|
6925
5196
|
if (primValue === void 0) {
|
|
6926
|
-
return new
|
|
5197
|
+
return new BigDecimal(NaN);
|
|
6927
5198
|
}
|
|
6928
5199
|
if (primValue === true) {
|
|
6929
|
-
return new
|
|
5200
|
+
return new BigDecimal(1);
|
|
6930
5201
|
}
|
|
6931
5202
|
if (primValue === false) {
|
|
6932
|
-
return new
|
|
5203
|
+
return new BigDecimal(0);
|
|
6933
5204
|
}
|
|
6934
5205
|
if (primValue === null) {
|
|
6935
|
-
return new
|
|
5206
|
+
return new BigDecimal(0);
|
|
6936
5207
|
}
|
|
6937
5208
|
try {
|
|
6938
|
-
return new
|
|
6939
|
-
} catch
|
|
6940
|
-
return new
|
|
5209
|
+
return new BigDecimal(primValue);
|
|
5210
|
+
} catch {
|
|
5211
|
+
return new BigDecimal(NaN);
|
|
6941
5212
|
}
|
|
6942
5213
|
}
|
|
6943
5214
|
|
|
@@ -7053,7 +5324,6 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
7053
5324
|
getInternalSlots: getInternalSlots2,
|
|
7054
5325
|
PluralRuleSelect: PluralRuleSelect2
|
|
7055
5326
|
}) {
|
|
7056
|
-
var _a;
|
|
7057
5327
|
const internalSlots = getInternalSlots2(pl);
|
|
7058
5328
|
invariant(Type(internalSlots) === "Object", "pl has to be an object");
|
|
7059
5329
|
invariant(
|
|
@@ -7068,12 +5338,12 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
7068
5338
|
const s = res.formattedString;
|
|
7069
5339
|
let exponent = 0;
|
|
7070
5340
|
if (notation === "compact" && !n.isZero()) {
|
|
7071
|
-
if (
|
|
5341
|
+
if (internalSlots.dataLocaleData?.numbers) {
|
|
7072
5342
|
try {
|
|
7073
5343
|
const magnitudeNum = Math.floor(Math.log10(Math.abs(n.toNumber())));
|
|
7074
|
-
const magnitude = new
|
|
5344
|
+
const magnitude = new bigdecimal_default(magnitudeNum);
|
|
7075
5345
|
exponent = ComputeExponentForMagnitude(internalSlots, magnitude);
|
|
7076
|
-
} catch
|
|
5346
|
+
} catch {
|
|
7077
5347
|
exponent = 0;
|
|
7078
5348
|
}
|
|
7079
5349
|
}
|
|
@@ -7160,14 +5430,13 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
7160
5430
|
);
|
|
7161
5431
|
}
|
|
7162
5432
|
function PluralRuleSelectRange(locale, type, xp, yp) {
|
|
7163
|
-
var _a;
|
|
7164
5433
|
const localeData = PluralRules.localeData[locale];
|
|
7165
5434
|
if (!localeData || !localeData.pluralRanges) {
|
|
7166
5435
|
return yp;
|
|
7167
5436
|
}
|
|
7168
5437
|
const key = `${xp}_${yp}`;
|
|
7169
5438
|
const rangeData = type === "ordinal" ? localeData.pluralRanges.ordinal : localeData.pluralRanges.cardinal;
|
|
7170
|
-
return
|
|
5439
|
+
return rangeData?.[key] ?? yp;
|
|
7171
5440
|
}
|
|
7172
5441
|
var _PluralRules = class _PluralRules {
|
|
7173
5442
|
constructor(locales, options) {
|
|
@@ -7303,7 +5572,7 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
7303
5572
|
enumerable: false,
|
|
7304
5573
|
configurable: true
|
|
7305
5574
|
});
|
|
7306
|
-
} catch
|
|
5575
|
+
} catch {
|
|
7307
5576
|
}
|
|
7308
5577
|
Object.defineProperty(PluralRules.prototype.constructor, "length", {
|
|
7309
5578
|
value: 0,
|
|
@@ -7323,7 +5592,7 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
7323
5592
|
enumerable: false,
|
|
7324
5593
|
configurable: true
|
|
7325
5594
|
});
|
|
7326
|
-
} catch
|
|
5595
|
+
} catch {
|
|
7327
5596
|
}
|
|
7328
5597
|
|
|
7329
5598
|
// packages/intl-pluralrules/supported-locales.generated.ts
|
|
@@ -7567,17 +5836,12 @@ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
|
7567
5836
|
enumerable: false,
|
|
7568
5837
|
configurable: true
|
|
7569
5838
|
});
|
|
5839
|
+
const buf = globalThis.__FORMATJS_PLURALRULES_DATA__;
|
|
5840
|
+
if (buf) {
|
|
5841
|
+
for (const d of buf)
|
|
5842
|
+
PluralRules.__addLocaleData(d);
|
|
5843
|
+
delete globalThis.__FORMATJS_PLURALRULES_DATA__;
|
|
5844
|
+
}
|
|
7570
5845
|
}
|
|
7571
5846
|
})();
|
|
7572
|
-
/*! Bundled license information:
|
|
7573
|
-
|
|
7574
|
-
decimal.js/decimal.mjs:
|
|
7575
|
-
(*!
|
|
7576
|
-
* decimal.js v10.6.0
|
|
7577
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
7578
|
-
* https://github.com/MikeMcl/decimal.js
|
|
7579
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
7580
|
-
* MIT Licence
|
|
7581
|
-
*)
|
|
7582
|
-
*/
|
|
7583
5847
|
//# sourceMappingURL=polyfill.iife.js.map
|