vome-core 0.3.27 → 0.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/admin/components/ui/avatar/index.js +1 -1
  2. package/dist/admin/components/ui/checkbox/index.js +1 -1
  3. package/dist/admin/components/ui/dialog/index.js +1 -1
  4. package/dist/admin/components/ui/dropdown-menu/index.js +1 -1
  5. package/dist/admin/components/ui/input/index.js +1 -1
  6. package/dist/admin/components/ui/label/index.js +1 -1
  7. package/dist/admin/components/ui/scroll-area/index.js +1 -1
  8. package/dist/admin/components/ui/select/index.js +1 -1
  9. package/dist/admin/components/ui/separator/index.js +1 -1
  10. package/dist/admin/components/ui/sheet/index.js +1 -1
  11. package/dist/admin/components/ui/sonner/index.js +1 -1
  12. package/dist/admin/components/ui/table/index.js +1 -1
  13. package/dist/admin/components/ui/tabs/index.js +1 -1
  14. package/dist/admin/components/ui/tooltip/index.js +1 -1
  15. package/dist/admin/crud/auto-fields.js +1 -1
  16. package/dist/admin/crud/components/vm-color-picker.vue +1 -1
  17. package/dist/admin/crud/components/vm-number-range.vue +8 -3
  18. package/dist/admin/crud/components/vm-preview-viewer.vue +2 -2
  19. package/dist/admin/crud/components/vm-richtext-extensions.js +1 -1
  20. package/dist/admin/crud/config.js +1 -1
  21. package/dist/admin/crud/confirm.js +1 -1
  22. package/dist/admin/crud/crud-page-request.js +1 -1
  23. package/dist/admin/crud/data-i18n.js +1 -1
  24. package/dist/admin/crud/dict.js +1 -1
  25. package/dist/admin/crud/export-fetch.js +1 -1
  26. package/dist/admin/crud/key.js +1 -1
  27. package/dist/admin/crud/plugins.js +1 -1
  28. package/dist/admin/crud/span.js +1 -1
  29. package/dist/admin/crud/style.js +1 -1
  30. package/dist/admin/crud/validate.js +1 -1
  31. package/dist/admin/directives/perm.js +1 -1
  32. package/dist/admin/hooks/useUpload.js +1 -1
  33. package/dist/admin/lib/browser.js +1 -1
  34. package/dist/admin/lib/cn.js +1 -1
  35. package/dist/admin/lib/compress-image.d.ts +1 -2
  36. package/dist/admin/lib/compress-image.js +2 -2
  37. package/dist/admin/lib/dialog-float.js +1 -1
  38. package/dist/admin/lib/export-excel.js +1 -1
  39. package/dist/admin/lib/import-excel.js +1 -1
  40. package/dist/admin/lib/json.js +1 -1
  41. package/dist/admin/lib/menu.js +1 -1
  42. package/dist/admin/lib/micro-locale.js +1 -1
  43. package/dist/admin/lib/micro-theme.js +1 -1
  44. package/dist/admin/lib/shell.js +1 -1
  45. package/dist/admin/lib/theme-color-options.js +1 -1
  46. package/dist/admin/lib/tree.js +1 -1
  47. package/dist/admin/lib/upload.js +1 -1
  48. package/dist/admin/lib/video-frame.js +1 -1
  49. package/dist/admin/router/create.js +1 -1
  50. package/dist/admin/router/guards.js +1 -1
  51. package/dist/admin/vendor/browser-image-compression.js +2033 -0
  52. package/dist/admin/vendor/decimal-js.js +2316 -0
  53. package/dist/admin/vendor/manifest.json +5 -0
  54. package/dist/admin/vendor/xlsx.js +27956 -0
  55. package/dist/ai/index.js +1 -1
  56. package/dist/client/admin-vendor.d.ts +13 -0
  57. package/dist/client/admin-vendor.js +20 -0
  58. package/dist/client/ai-model-registry.js +1 -1
  59. package/dist/client/base.js +1 -1
  60. package/dist/client/configure.js +1 -1
  61. package/dist/client/dict.js +1 -1
  62. package/dist/client/eps-payload.js +1 -1
  63. package/dist/client/eps.js +1 -1
  64. package/dist/client/index.js +1 -1
  65. package/dist/client/locale-change.js +1 -1
  66. package/dist/client/locale-store.js +1 -1
  67. package/dist/client/service.js +1 -1
  68. package/dist/client/vite-admin.d.ts +2 -1
  69. package/dist/client/vite-admin.js +1 -1
  70. package/dist/client/vite-auto-import.js +1 -1
  71. package/dist/client/vite-micro-proxy.js +1 -1
  72. package/dist/client/vite-plugin-eps.js +1 -1
  73. package/dist/client/vite-resolve.d.ts +1 -1
  74. package/dist/client/vite-resolve.js +1 -1
  75. package/dist/config/index.js +1 -1
  76. package/dist/index.js +1 -1
  77. package/dist/server/index.js +1 -1
  78. package/dist/shared/datetime-picker.js +1 -1
  79. package/dist/shared/decimal.d.ts +6 -0
  80. package/dist/shared/decimal.js +1 -0
  81. package/dist/shared/excel.js +1 -1
  82. package/dist/shared/index.d.ts +1 -0
  83. package/dist/shared/index.js +1 -1
  84. package/dist/shared/locale-json.js +1 -1
  85. package/dist/shared/tree.js +1 -1
  86. package/package.json +2 -1
@@ -0,0 +1,2316 @@
1
+ // node_modules/decimal.js/decimal.mjs
2
+ /*!
3
+ * decimal.js v10.6.0
4
+ * An arbitrary-precision Decimal type for JavaScript.
5
+ * https://github.com/MikeMcl/decimal.js
6
+ * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
7
+ * MIT Licence
8
+ */
9
+ var EXP_LIMIT = 9000000000000000;
10
+ var MAX_DIGITS = 1e9;
11
+ var NUMERALS = "0123456789abcdef";
12
+ var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
13
+ var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
14
+ var DEFAULTS = {
15
+ precision: 20,
16
+ rounding: 4,
17
+ modulo: 1,
18
+ toExpNeg: -7,
19
+ toExpPos: 21,
20
+ minE: -EXP_LIMIT,
21
+ maxE: EXP_LIMIT,
22
+ crypto: false
23
+ };
24
+ var inexact;
25
+ var quadrant;
26
+ var external = true;
27
+ var decimalError = "[DecimalError] ";
28
+ var invalidArgument = decimalError + "Invalid argument: ";
29
+ var precisionLimitExceeded = decimalError + "Precision limit exceeded";
30
+ var cryptoUnavailable = decimalError + "crypto unavailable";
31
+ var tag = "[object Decimal]";
32
+ var mathfloor = Math.floor;
33
+ var mathpow = Math.pow;
34
+ var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
35
+ var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
36
+ var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
37
+ var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
38
+ var BASE = 1e7;
39
+ var LOG_BASE = 7;
40
+ var MAX_SAFE_INTEGER = 9007199254740991;
41
+ var LN10_PRECISION = LN10.length - 1;
42
+ var PI_PRECISION = PI.length - 1;
43
+ var P = { toStringTag: tag };
44
+ P.absoluteValue = P.abs = function() {
45
+ var x = new this.constructor(this);
46
+ if (x.s < 0)
47
+ x.s = 1;
48
+ return finalise(x);
49
+ };
50
+ P.ceil = function() {
51
+ return finalise(new this.constructor(this), this.e + 1, 2);
52
+ };
53
+ P.clampedTo = P.clamp = function(min, max) {
54
+ var k, x = this, Ctor = x.constructor;
55
+ min = new Ctor(min);
56
+ max = new Ctor(max);
57
+ if (!min.s || !max.s)
58
+ return new Ctor(NaN);
59
+ if (min.gt(max))
60
+ throw Error(invalidArgument + max);
61
+ k = x.cmp(min);
62
+ return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
63
+ };
64
+ P.comparedTo = P.cmp = function(y) {
65
+ var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
66
+ if (!xd || !yd) {
67
+ return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
68
+ }
69
+ if (!xd[0] || !yd[0])
70
+ return xd[0] ? xs : yd[0] ? -ys : 0;
71
+ if (xs !== ys)
72
+ return xs;
73
+ if (x.e !== y.e)
74
+ return x.e > y.e ^ xs < 0 ? 1 : -1;
75
+ xdL = xd.length;
76
+ ydL = yd.length;
77
+ for (i = 0, j = xdL < ydL ? xdL : ydL;i < j; ++i) {
78
+ if (xd[i] !== yd[i])
79
+ return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
80
+ }
81
+ return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
82
+ };
83
+ P.cosine = P.cos = function() {
84
+ var pr, rm, x = this, Ctor = x.constructor;
85
+ if (!x.d)
86
+ return new Ctor(NaN);
87
+ if (!x.d[0])
88
+ return new Ctor(1);
89
+ pr = Ctor.precision;
90
+ rm = Ctor.rounding;
91
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
92
+ Ctor.rounding = 1;
93
+ x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
94
+ Ctor.precision = pr;
95
+ Ctor.rounding = rm;
96
+ return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
97
+ };
98
+ P.cubeRoot = P.cbrt = function() {
99
+ var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
100
+ if (!x.isFinite() || x.isZero())
101
+ return new Ctor(x);
102
+ external = false;
103
+ s = x.s * mathpow(x.s * x, 1 / 3);
104
+ if (!s || Math.abs(s) == 1 / 0) {
105
+ n = digitsToString(x.d);
106
+ e = x.e;
107
+ if (s = (e - n.length + 1) % 3)
108
+ n += s == 1 || s == -2 ? "0" : "00";
109
+ s = mathpow(n, 1 / 3);
110
+ e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
111
+ if (s == 1 / 0) {
112
+ n = "5e" + e;
113
+ } else {
114
+ n = s.toExponential();
115
+ n = n.slice(0, n.indexOf("e") + 1) + e;
116
+ }
117
+ r = new Ctor(n);
118
+ r.s = x.s;
119
+ } else {
120
+ r = new Ctor(s.toString());
121
+ }
122
+ sd = (e = Ctor.precision) + 3;
123
+ for (;; ) {
124
+ t = r;
125
+ t3 = t.times(t).times(t);
126
+ t3plusx = t3.plus(x);
127
+ r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
128
+ if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
129
+ n = n.slice(sd - 3, sd + 1);
130
+ if (n == "9999" || !rep && n == "4999") {
131
+ if (!rep) {
132
+ finalise(t, e + 1, 0);
133
+ if (t.times(t).times(t).eq(x)) {
134
+ r = t;
135
+ break;
136
+ }
137
+ }
138
+ sd += 4;
139
+ rep = 1;
140
+ } else {
141
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
142
+ finalise(r, e + 1, 1);
143
+ m = !r.times(r).times(r).eq(x);
144
+ }
145
+ break;
146
+ }
147
+ }
148
+ }
149
+ external = true;
150
+ return finalise(r, e, Ctor.rounding, m);
151
+ };
152
+ P.decimalPlaces = P.dp = function() {
153
+ var w, d = this.d, n = NaN;
154
+ if (d) {
155
+ w = d.length - 1;
156
+ n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
157
+ w = d[w];
158
+ if (w)
159
+ for (;w % 10 == 0; w /= 10)
160
+ n--;
161
+ if (n < 0)
162
+ n = 0;
163
+ }
164
+ return n;
165
+ };
166
+ P.dividedBy = P.div = function(y) {
167
+ return divide(this, new this.constructor(y));
168
+ };
169
+ P.dividedToIntegerBy = P.divToInt = function(y) {
170
+ var x = this, Ctor = x.constructor;
171
+ return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
172
+ };
173
+ P.equals = P.eq = function(y) {
174
+ return this.cmp(y) === 0;
175
+ };
176
+ P.floor = function() {
177
+ return finalise(new this.constructor(this), this.e + 1, 3);
178
+ };
179
+ P.greaterThan = P.gt = function(y) {
180
+ return this.cmp(y) > 0;
181
+ };
182
+ P.greaterThanOrEqualTo = P.gte = function(y) {
183
+ var k = this.cmp(y);
184
+ return k == 1 || k === 0;
185
+ };
186
+ P.hyperbolicCosine = P.cosh = function() {
187
+ var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
188
+ if (!x.isFinite())
189
+ return new Ctor(x.s ? 1 / 0 : NaN);
190
+ if (x.isZero())
191
+ return one;
192
+ pr = Ctor.precision;
193
+ rm = Ctor.rounding;
194
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
195
+ Ctor.rounding = 1;
196
+ len = x.d.length;
197
+ if (len < 32) {
198
+ k = Math.ceil(len / 3);
199
+ n = (1 / tinyPow(4, k)).toString();
200
+ } else {
201
+ k = 16;
202
+ n = "2.3283064365386962890625e-10";
203
+ }
204
+ x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
205
+ var cosh2_x, i = k, d8 = new Ctor(8);
206
+ for (;i--; ) {
207
+ cosh2_x = x.times(x);
208
+ x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
209
+ }
210
+ return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
211
+ };
212
+ P.hyperbolicSine = P.sinh = function() {
213
+ var k, pr, rm, len, x = this, Ctor = x.constructor;
214
+ if (!x.isFinite() || x.isZero())
215
+ return new Ctor(x);
216
+ pr = Ctor.precision;
217
+ rm = Ctor.rounding;
218
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
219
+ Ctor.rounding = 1;
220
+ len = x.d.length;
221
+ if (len < 3) {
222
+ x = taylorSeries(Ctor, 2, x, x, true);
223
+ } else {
224
+ k = 1.4 * Math.sqrt(len);
225
+ k = k > 16 ? 16 : k | 0;
226
+ x = x.times(1 / tinyPow(5, k));
227
+ x = taylorSeries(Ctor, 2, x, x, true);
228
+ var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
229
+ for (;k--; ) {
230
+ sinh2_x = x.times(x);
231
+ x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
232
+ }
233
+ }
234
+ Ctor.precision = pr;
235
+ Ctor.rounding = rm;
236
+ return finalise(x, pr, rm, true);
237
+ };
238
+ P.hyperbolicTangent = P.tanh = function() {
239
+ var pr, rm, x = this, Ctor = x.constructor;
240
+ if (!x.isFinite())
241
+ return new Ctor(x.s);
242
+ if (x.isZero())
243
+ return new Ctor(x);
244
+ pr = Ctor.precision;
245
+ rm = Ctor.rounding;
246
+ Ctor.precision = pr + 7;
247
+ Ctor.rounding = 1;
248
+ return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
249
+ };
250
+ P.inverseCosine = P.acos = function() {
251
+ var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
252
+ if (k !== -1) {
253
+ return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
254
+ }
255
+ if (x.isZero())
256
+ return getPi(Ctor, pr + 4, rm).times(0.5);
257
+ Ctor.precision = pr + 6;
258
+ Ctor.rounding = 1;
259
+ x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
260
+ Ctor.precision = pr;
261
+ Ctor.rounding = rm;
262
+ return x.times(2);
263
+ };
264
+ P.inverseHyperbolicCosine = P.acosh = function() {
265
+ var pr, rm, x = this, Ctor = x.constructor;
266
+ if (x.lte(1))
267
+ return new Ctor(x.eq(1) ? 0 : NaN);
268
+ if (!x.isFinite())
269
+ return new Ctor(x);
270
+ pr = Ctor.precision;
271
+ rm = Ctor.rounding;
272
+ Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
273
+ Ctor.rounding = 1;
274
+ external = false;
275
+ x = x.times(x).minus(1).sqrt().plus(x);
276
+ external = true;
277
+ Ctor.precision = pr;
278
+ Ctor.rounding = rm;
279
+ return x.ln();
280
+ };
281
+ P.inverseHyperbolicSine = P.asinh = function() {
282
+ var pr, rm, x = this, Ctor = x.constructor;
283
+ if (!x.isFinite() || x.isZero())
284
+ return new Ctor(x);
285
+ pr = Ctor.precision;
286
+ rm = Ctor.rounding;
287
+ Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
288
+ Ctor.rounding = 1;
289
+ external = false;
290
+ x = x.times(x).plus(1).sqrt().plus(x);
291
+ external = true;
292
+ Ctor.precision = pr;
293
+ Ctor.rounding = rm;
294
+ return x.ln();
295
+ };
296
+ P.inverseHyperbolicTangent = P.atanh = function() {
297
+ var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
298
+ if (!x.isFinite())
299
+ return new Ctor(NaN);
300
+ if (x.e >= 0)
301
+ return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
302
+ pr = Ctor.precision;
303
+ rm = Ctor.rounding;
304
+ xsd = x.sd();
305
+ if (Math.max(xsd, pr) < 2 * -x.e - 1)
306
+ return finalise(new Ctor(x), pr, rm, true);
307
+ Ctor.precision = wpr = xsd - x.e;
308
+ x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
309
+ Ctor.precision = pr + 4;
310
+ Ctor.rounding = 1;
311
+ x = x.ln();
312
+ Ctor.precision = pr;
313
+ Ctor.rounding = rm;
314
+ return x.times(0.5);
315
+ };
316
+ P.inverseSine = P.asin = function() {
317
+ var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
318
+ if (x.isZero())
319
+ return new Ctor(x);
320
+ k = x.abs().cmp(1);
321
+ pr = Ctor.precision;
322
+ rm = Ctor.rounding;
323
+ if (k !== -1) {
324
+ if (k === 0) {
325
+ halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
326
+ halfPi.s = x.s;
327
+ return halfPi;
328
+ }
329
+ return new Ctor(NaN);
330
+ }
331
+ Ctor.precision = pr + 6;
332
+ Ctor.rounding = 1;
333
+ x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
334
+ Ctor.precision = pr;
335
+ Ctor.rounding = rm;
336
+ return x.times(2);
337
+ };
338
+ P.inverseTangent = P.atan = function() {
339
+ var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
340
+ if (!x.isFinite()) {
341
+ if (!x.s)
342
+ return new Ctor(NaN);
343
+ if (pr + 4 <= PI_PRECISION) {
344
+ r = getPi(Ctor, pr + 4, rm).times(0.5);
345
+ r.s = x.s;
346
+ return r;
347
+ }
348
+ } else if (x.isZero()) {
349
+ return new Ctor(x);
350
+ } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
351
+ r = getPi(Ctor, pr + 4, rm).times(0.25);
352
+ r.s = x.s;
353
+ return r;
354
+ }
355
+ Ctor.precision = wpr = pr + 10;
356
+ Ctor.rounding = 1;
357
+ k = Math.min(28, wpr / LOG_BASE + 2 | 0);
358
+ for (i = k;i; --i)
359
+ x = x.div(x.times(x).plus(1).sqrt().plus(1));
360
+ external = false;
361
+ j = Math.ceil(wpr / LOG_BASE);
362
+ n = 1;
363
+ x2 = x.times(x);
364
+ r = new Ctor(x);
365
+ px = x;
366
+ for (;i !== -1; ) {
367
+ px = px.times(x2);
368
+ t = r.minus(px.div(n += 2));
369
+ px = px.times(x2);
370
+ r = t.plus(px.div(n += 2));
371
+ if (r.d[j] !== undefined)
372
+ for (i = j;r.d[i] === t.d[i] && i--; )
373
+ ;
374
+ }
375
+ if (k)
376
+ r = r.times(2 << k - 1);
377
+ external = true;
378
+ return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
379
+ };
380
+ P.isFinite = function() {
381
+ return !!this.d;
382
+ };
383
+ P.isInteger = P.isInt = function() {
384
+ return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
385
+ };
386
+ P.isNaN = function() {
387
+ return !this.s;
388
+ };
389
+ P.isNegative = P.isNeg = function() {
390
+ return this.s < 0;
391
+ };
392
+ P.isPositive = P.isPos = function() {
393
+ return this.s > 0;
394
+ };
395
+ P.isZero = function() {
396
+ return !!this.d && this.d[0] === 0;
397
+ };
398
+ P.lessThan = P.lt = function(y) {
399
+ return this.cmp(y) < 0;
400
+ };
401
+ P.lessThanOrEqualTo = P.lte = function(y) {
402
+ return this.cmp(y) < 1;
403
+ };
404
+ P.logarithm = P.log = function(base) {
405
+ var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
406
+ if (base == null) {
407
+ base = new Ctor(10);
408
+ isBase10 = true;
409
+ } else {
410
+ base = new Ctor(base);
411
+ d = base.d;
412
+ if (base.s < 0 || !d || !d[0] || base.eq(1))
413
+ return new Ctor(NaN);
414
+ isBase10 = base.eq(10);
415
+ }
416
+ d = arg.d;
417
+ if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
418
+ return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
419
+ }
420
+ if (isBase10) {
421
+ if (d.length > 1) {
422
+ inf = true;
423
+ } else {
424
+ for (k = d[0];k % 10 === 0; )
425
+ k /= 10;
426
+ inf = k !== 1;
427
+ }
428
+ }
429
+ external = false;
430
+ sd = pr + guard;
431
+ num = naturalLogarithm(arg, sd);
432
+ denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
433
+ r = divide(num, denominator, sd, 1);
434
+ if (checkRoundingDigits(r.d, k = pr, rm)) {
435
+ do {
436
+ sd += 10;
437
+ num = naturalLogarithm(arg, sd);
438
+ denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
439
+ r = divide(num, denominator, sd, 1);
440
+ if (!inf) {
441
+ if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 100000000000000) {
442
+ r = finalise(r, pr + 1, 0);
443
+ }
444
+ break;
445
+ }
446
+ } while (checkRoundingDigits(r.d, k += 10, rm));
447
+ }
448
+ external = true;
449
+ return finalise(r, pr, rm);
450
+ };
451
+ P.minus = P.sub = function(y) {
452
+ var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
453
+ y = new Ctor(y);
454
+ if (!x.d || !y.d) {
455
+ if (!x.s || !y.s)
456
+ y = new Ctor(NaN);
457
+ else if (x.d)
458
+ y.s = -y.s;
459
+ else
460
+ y = new Ctor(y.d || x.s !== y.s ? x : NaN);
461
+ return y;
462
+ }
463
+ if (x.s != y.s) {
464
+ y.s = -y.s;
465
+ return x.plus(y);
466
+ }
467
+ xd = x.d;
468
+ yd = y.d;
469
+ pr = Ctor.precision;
470
+ rm = Ctor.rounding;
471
+ if (!xd[0] || !yd[0]) {
472
+ if (yd[0])
473
+ y.s = -y.s;
474
+ else if (xd[0])
475
+ y = new Ctor(x);
476
+ else
477
+ return new Ctor(rm === 3 ? -0 : 0);
478
+ return external ? finalise(y, pr, rm) : y;
479
+ }
480
+ e = mathfloor(y.e / LOG_BASE);
481
+ xe = mathfloor(x.e / LOG_BASE);
482
+ xd = xd.slice();
483
+ k = xe - e;
484
+ if (k) {
485
+ xLTy = k < 0;
486
+ if (xLTy) {
487
+ d = xd;
488
+ k = -k;
489
+ len = yd.length;
490
+ } else {
491
+ d = yd;
492
+ e = xe;
493
+ len = xd.length;
494
+ }
495
+ i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
496
+ if (k > i) {
497
+ k = i;
498
+ d.length = 1;
499
+ }
500
+ d.reverse();
501
+ for (i = k;i--; )
502
+ d.push(0);
503
+ d.reverse();
504
+ } else {
505
+ i = xd.length;
506
+ len = yd.length;
507
+ xLTy = i < len;
508
+ if (xLTy)
509
+ len = i;
510
+ for (i = 0;i < len; i++) {
511
+ if (xd[i] != yd[i]) {
512
+ xLTy = xd[i] < yd[i];
513
+ break;
514
+ }
515
+ }
516
+ k = 0;
517
+ }
518
+ if (xLTy) {
519
+ d = xd;
520
+ xd = yd;
521
+ yd = d;
522
+ y.s = -y.s;
523
+ }
524
+ len = xd.length;
525
+ for (i = yd.length - len;i > 0; --i)
526
+ xd[len++] = 0;
527
+ for (i = yd.length;i > k; ) {
528
+ if (xd[--i] < yd[i]) {
529
+ for (j = i;j && xd[--j] === 0; )
530
+ xd[j] = BASE - 1;
531
+ --xd[j];
532
+ xd[i] += BASE;
533
+ }
534
+ xd[i] -= yd[i];
535
+ }
536
+ for (;xd[--len] === 0; )
537
+ xd.pop();
538
+ for (;xd[0] === 0; xd.shift())
539
+ --e;
540
+ if (!xd[0])
541
+ return new Ctor(rm === 3 ? -0 : 0);
542
+ y.d = xd;
543
+ y.e = getBase10Exponent(xd, e);
544
+ return external ? finalise(y, pr, rm) : y;
545
+ };
546
+ P.modulo = P.mod = function(y) {
547
+ var q, x = this, Ctor = x.constructor;
548
+ y = new Ctor(y);
549
+ if (!x.d || !y.s || y.d && !y.d[0])
550
+ return new Ctor(NaN);
551
+ if (!y.d || x.d && !x.d[0]) {
552
+ return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
553
+ }
554
+ external = false;
555
+ if (Ctor.modulo == 9) {
556
+ q = divide(x, y.abs(), 0, 3, 1);
557
+ q.s *= y.s;
558
+ } else {
559
+ q = divide(x, y, 0, Ctor.modulo, 1);
560
+ }
561
+ q = q.times(y);
562
+ external = true;
563
+ return x.minus(q);
564
+ };
565
+ P.naturalExponential = P.exp = function() {
566
+ return naturalExponential(this);
567
+ };
568
+ P.naturalLogarithm = P.ln = function() {
569
+ return naturalLogarithm(this);
570
+ };
571
+ P.negated = P.neg = function() {
572
+ var x = new this.constructor(this);
573
+ x.s = -x.s;
574
+ return finalise(x);
575
+ };
576
+ P.plus = P.add = function(y) {
577
+ var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
578
+ y = new Ctor(y);
579
+ if (!x.d || !y.d) {
580
+ if (!x.s || !y.s)
581
+ y = new Ctor(NaN);
582
+ else if (!x.d)
583
+ y = new Ctor(y.d || x.s === y.s ? x : NaN);
584
+ return y;
585
+ }
586
+ if (x.s != y.s) {
587
+ y.s = -y.s;
588
+ return x.minus(y);
589
+ }
590
+ xd = x.d;
591
+ yd = y.d;
592
+ pr = Ctor.precision;
593
+ rm = Ctor.rounding;
594
+ if (!xd[0] || !yd[0]) {
595
+ if (!yd[0])
596
+ y = new Ctor(x);
597
+ return external ? finalise(y, pr, rm) : y;
598
+ }
599
+ k = mathfloor(x.e / LOG_BASE);
600
+ e = mathfloor(y.e / LOG_BASE);
601
+ xd = xd.slice();
602
+ i = k - e;
603
+ if (i) {
604
+ if (i < 0) {
605
+ d = xd;
606
+ i = -i;
607
+ len = yd.length;
608
+ } else {
609
+ d = yd;
610
+ e = k;
611
+ len = xd.length;
612
+ }
613
+ k = Math.ceil(pr / LOG_BASE);
614
+ len = k > len ? k + 1 : len + 1;
615
+ if (i > len) {
616
+ i = len;
617
+ d.length = 1;
618
+ }
619
+ d.reverse();
620
+ for (;i--; )
621
+ d.push(0);
622
+ d.reverse();
623
+ }
624
+ len = xd.length;
625
+ i = yd.length;
626
+ if (len - i < 0) {
627
+ i = len;
628
+ d = yd;
629
+ yd = xd;
630
+ xd = d;
631
+ }
632
+ for (carry = 0;i; ) {
633
+ carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
634
+ xd[i] %= BASE;
635
+ }
636
+ if (carry) {
637
+ xd.unshift(carry);
638
+ ++e;
639
+ }
640
+ for (len = xd.length;xd[--len] == 0; )
641
+ xd.pop();
642
+ y.d = xd;
643
+ y.e = getBase10Exponent(xd, e);
644
+ return external ? finalise(y, pr, rm) : y;
645
+ };
646
+ P.precision = P.sd = function(z) {
647
+ var k, x = this;
648
+ if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
649
+ throw Error(invalidArgument + z);
650
+ if (x.d) {
651
+ k = getPrecision(x.d);
652
+ if (z && x.e + 1 > k)
653
+ k = x.e + 1;
654
+ } else {
655
+ k = NaN;
656
+ }
657
+ return k;
658
+ };
659
+ P.round = function() {
660
+ var x = this, Ctor = x.constructor;
661
+ return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
662
+ };
663
+ P.sine = P.sin = function() {
664
+ var pr, rm, x = this, Ctor = x.constructor;
665
+ if (!x.isFinite())
666
+ return new Ctor(NaN);
667
+ if (x.isZero())
668
+ return new Ctor(x);
669
+ pr = Ctor.precision;
670
+ rm = Ctor.rounding;
671
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
672
+ Ctor.rounding = 1;
673
+ x = sine(Ctor, toLessThanHalfPi(Ctor, x));
674
+ Ctor.precision = pr;
675
+ Ctor.rounding = rm;
676
+ return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
677
+ };
678
+ P.squareRoot = P.sqrt = function() {
679
+ var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
680
+ if (s !== 1 || !d || !d[0]) {
681
+ return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
682
+ }
683
+ external = false;
684
+ s = Math.sqrt(+x);
685
+ if (s == 0 || s == 1 / 0) {
686
+ n = digitsToString(d);
687
+ if ((n.length + e) % 2 == 0)
688
+ n += "0";
689
+ s = Math.sqrt(n);
690
+ e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
691
+ if (s == 1 / 0) {
692
+ n = "5e" + e;
693
+ } else {
694
+ n = s.toExponential();
695
+ n = n.slice(0, n.indexOf("e") + 1) + e;
696
+ }
697
+ r = new Ctor(n);
698
+ } else {
699
+ r = new Ctor(s.toString());
700
+ }
701
+ sd = (e = Ctor.precision) + 3;
702
+ for (;; ) {
703
+ t = r;
704
+ r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
705
+ if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
706
+ n = n.slice(sd - 3, sd + 1);
707
+ if (n == "9999" || !rep && n == "4999") {
708
+ if (!rep) {
709
+ finalise(t, e + 1, 0);
710
+ if (t.times(t).eq(x)) {
711
+ r = t;
712
+ break;
713
+ }
714
+ }
715
+ sd += 4;
716
+ rep = 1;
717
+ } else {
718
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
719
+ finalise(r, e + 1, 1);
720
+ m = !r.times(r).eq(x);
721
+ }
722
+ break;
723
+ }
724
+ }
725
+ }
726
+ external = true;
727
+ return finalise(r, e, Ctor.rounding, m);
728
+ };
729
+ P.tangent = P.tan = function() {
730
+ var pr, rm, x = this, Ctor = x.constructor;
731
+ if (!x.isFinite())
732
+ return new Ctor(NaN);
733
+ if (x.isZero())
734
+ return new Ctor(x);
735
+ pr = Ctor.precision;
736
+ rm = Ctor.rounding;
737
+ Ctor.precision = pr + 10;
738
+ Ctor.rounding = 1;
739
+ x = x.sin();
740
+ x.s = 1;
741
+ x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
742
+ Ctor.precision = pr;
743
+ Ctor.rounding = rm;
744
+ return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
745
+ };
746
+ P.times = P.mul = function(y) {
747
+ var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
748
+ y.s *= x.s;
749
+ if (!xd || !xd[0] || !yd || !yd[0]) {
750
+ return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
751
+ }
752
+ e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
753
+ xdL = xd.length;
754
+ ydL = yd.length;
755
+ if (xdL < ydL) {
756
+ r = xd;
757
+ xd = yd;
758
+ yd = r;
759
+ rL = xdL;
760
+ xdL = ydL;
761
+ ydL = rL;
762
+ }
763
+ r = [];
764
+ rL = xdL + ydL;
765
+ for (i = rL;i--; )
766
+ r.push(0);
767
+ for (i = ydL;--i >= 0; ) {
768
+ carry = 0;
769
+ for (k = xdL + i;k > i; ) {
770
+ t = r[k] + yd[i] * xd[k - i - 1] + carry;
771
+ r[k--] = t % BASE | 0;
772
+ carry = t / BASE | 0;
773
+ }
774
+ r[k] = (r[k] + carry) % BASE | 0;
775
+ }
776
+ for (;!r[--rL]; )
777
+ r.pop();
778
+ if (carry)
779
+ ++e;
780
+ else
781
+ r.shift();
782
+ y.d = r;
783
+ y.e = getBase10Exponent(r, e);
784
+ return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
785
+ };
786
+ P.toBinary = function(sd, rm) {
787
+ return toStringBinary(this, 2, sd, rm);
788
+ };
789
+ P.toDecimalPlaces = P.toDP = function(dp, rm) {
790
+ var x = this, Ctor = x.constructor;
791
+ x = new Ctor(x);
792
+ if (dp === undefined)
793
+ return x;
794
+ checkInt32(dp, 0, MAX_DIGITS);
795
+ if (rm === undefined)
796
+ rm = Ctor.rounding;
797
+ else
798
+ checkInt32(rm, 0, 8);
799
+ return finalise(x, dp + x.e + 1, rm);
800
+ };
801
+ P.toExponential = function(dp, rm) {
802
+ var str, x = this, Ctor = x.constructor;
803
+ if (dp === undefined) {
804
+ str = finiteToString(x, true);
805
+ } else {
806
+ checkInt32(dp, 0, MAX_DIGITS);
807
+ if (rm === undefined)
808
+ rm = Ctor.rounding;
809
+ else
810
+ checkInt32(rm, 0, 8);
811
+ x = finalise(new Ctor(x), dp + 1, rm);
812
+ str = finiteToString(x, true, dp + 1);
813
+ }
814
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
815
+ };
816
+ P.toFixed = function(dp, rm) {
817
+ var str, y, x = this, Ctor = x.constructor;
818
+ if (dp === undefined) {
819
+ str = finiteToString(x);
820
+ } else {
821
+ checkInt32(dp, 0, MAX_DIGITS);
822
+ if (rm === undefined)
823
+ rm = Ctor.rounding;
824
+ else
825
+ checkInt32(rm, 0, 8);
826
+ y = finalise(new Ctor(x), dp + x.e + 1, rm);
827
+ str = finiteToString(y, false, dp + y.e + 1);
828
+ }
829
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
830
+ };
831
+ P.toFraction = function(maxD) {
832
+ var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
833
+ if (!xd)
834
+ return new Ctor(x);
835
+ n1 = d0 = new Ctor(1);
836
+ d1 = n0 = new Ctor(0);
837
+ d = new Ctor(d1);
838
+ e = d.e = getPrecision(xd) - x.e - 1;
839
+ k = e % LOG_BASE;
840
+ d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
841
+ if (maxD == null) {
842
+ maxD = e > 0 ? d : n1;
843
+ } else {
844
+ n = new Ctor(maxD);
845
+ if (!n.isInt() || n.lt(n1))
846
+ throw Error(invalidArgument + n);
847
+ maxD = n.gt(d) ? e > 0 ? d : n1 : n;
848
+ }
849
+ external = false;
850
+ n = new Ctor(digitsToString(xd));
851
+ pr = Ctor.precision;
852
+ Ctor.precision = e = xd.length * LOG_BASE * 2;
853
+ for (;; ) {
854
+ q = divide(n, d, 0, 1, 1);
855
+ d2 = d0.plus(q.times(d1));
856
+ if (d2.cmp(maxD) == 1)
857
+ break;
858
+ d0 = d1;
859
+ d1 = d2;
860
+ d2 = n1;
861
+ n1 = n0.plus(q.times(d2));
862
+ n0 = d2;
863
+ d2 = d;
864
+ d = n.minus(q.times(d2));
865
+ n = d2;
866
+ }
867
+ d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
868
+ n0 = n0.plus(d2.times(n1));
869
+ d0 = d0.plus(d2.times(d1));
870
+ n0.s = n1.s = x.s;
871
+ r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
872
+ Ctor.precision = pr;
873
+ external = true;
874
+ return r;
875
+ };
876
+ P.toHexadecimal = P.toHex = function(sd, rm) {
877
+ return toStringBinary(this, 16, sd, rm);
878
+ };
879
+ P.toNearest = function(y, rm) {
880
+ var x = this, Ctor = x.constructor;
881
+ x = new Ctor(x);
882
+ if (y == null) {
883
+ if (!x.d)
884
+ return x;
885
+ y = new Ctor(1);
886
+ rm = Ctor.rounding;
887
+ } else {
888
+ y = new Ctor(y);
889
+ if (rm === undefined) {
890
+ rm = Ctor.rounding;
891
+ } else {
892
+ checkInt32(rm, 0, 8);
893
+ }
894
+ if (!x.d)
895
+ return y.s ? x : y;
896
+ if (!y.d) {
897
+ if (y.s)
898
+ y.s = x.s;
899
+ return y;
900
+ }
901
+ }
902
+ if (y.d[0]) {
903
+ external = false;
904
+ x = divide(x, y, 0, rm, 1).times(y);
905
+ external = true;
906
+ finalise(x);
907
+ } else {
908
+ y.s = x.s;
909
+ x = y;
910
+ }
911
+ return x;
912
+ };
913
+ P.toNumber = function() {
914
+ return +this;
915
+ };
916
+ P.toOctal = function(sd, rm) {
917
+ return toStringBinary(this, 8, sd, rm);
918
+ };
919
+ P.toPower = P.pow = function(y) {
920
+ var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
921
+ if (!x.d || !y.d || !x.d[0] || !y.d[0])
922
+ return new Ctor(mathpow(+x, yn));
923
+ x = new Ctor(x);
924
+ if (x.eq(1))
925
+ return x;
926
+ pr = Ctor.precision;
927
+ rm = Ctor.rounding;
928
+ if (y.eq(1))
929
+ return finalise(x, pr, rm);
930
+ e = mathfloor(y.e / LOG_BASE);
931
+ if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
932
+ r = intPow(Ctor, x, k, pr);
933
+ return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
934
+ }
935
+ s = x.s;
936
+ if (s < 0) {
937
+ if (e < y.d.length - 1)
938
+ return new Ctor(NaN);
939
+ if ((y.d[e] & 1) == 0)
940
+ s = 1;
941
+ if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
942
+ x.s = s;
943
+ return x;
944
+ }
945
+ }
946
+ k = mathpow(+x, yn);
947
+ e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
948
+ if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
949
+ return new Ctor(e > 0 ? s / 0 : 0);
950
+ external = false;
951
+ Ctor.rounding = x.s = 1;
952
+ k = Math.min(12, (e + "").length);
953
+ r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
954
+ if (r.d) {
955
+ r = finalise(r, pr + 5, 1);
956
+ if (checkRoundingDigits(r.d, pr, rm)) {
957
+ e = pr + 10;
958
+ r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
959
+ if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
960
+ r = finalise(r, pr + 1, 0);
961
+ }
962
+ }
963
+ }
964
+ r.s = s;
965
+ external = true;
966
+ Ctor.rounding = rm;
967
+ return finalise(r, pr, rm);
968
+ };
969
+ P.toPrecision = function(sd, rm) {
970
+ var str, x = this, Ctor = x.constructor;
971
+ if (sd === undefined) {
972
+ str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
973
+ } else {
974
+ checkInt32(sd, 1, MAX_DIGITS);
975
+ if (rm === undefined)
976
+ rm = Ctor.rounding;
977
+ else
978
+ checkInt32(rm, 0, 8);
979
+ x = finalise(new Ctor(x), sd, rm);
980
+ str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
981
+ }
982
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
983
+ };
984
+ P.toSignificantDigits = P.toSD = function(sd, rm) {
985
+ var x = this, Ctor = x.constructor;
986
+ if (sd === undefined) {
987
+ sd = Ctor.precision;
988
+ rm = Ctor.rounding;
989
+ } else {
990
+ checkInt32(sd, 1, MAX_DIGITS);
991
+ if (rm === undefined)
992
+ rm = Ctor.rounding;
993
+ else
994
+ checkInt32(rm, 0, 8);
995
+ }
996
+ return finalise(new Ctor(x), sd, rm);
997
+ };
998
+ P.toString = function() {
999
+ var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1000
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
1001
+ };
1002
+ P.truncated = P.trunc = function() {
1003
+ return finalise(new this.constructor(this), this.e + 1, 1);
1004
+ };
1005
+ P.valueOf = P.toJSON = function() {
1006
+ var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1007
+ return x.isNeg() ? "-" + str : str;
1008
+ };
1009
+ function digitsToString(d) {
1010
+ var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
1011
+ if (indexOfLastWord > 0) {
1012
+ str += w;
1013
+ for (i = 1;i < indexOfLastWord; i++) {
1014
+ ws = d[i] + "";
1015
+ k = LOG_BASE - ws.length;
1016
+ if (k)
1017
+ str += getZeroString(k);
1018
+ str += ws;
1019
+ }
1020
+ w = d[i];
1021
+ ws = w + "";
1022
+ k = LOG_BASE - ws.length;
1023
+ if (k)
1024
+ str += getZeroString(k);
1025
+ } else if (w === 0) {
1026
+ return "0";
1027
+ }
1028
+ for (;w % 10 === 0; )
1029
+ w /= 10;
1030
+ return str + w;
1031
+ }
1032
+ function checkInt32(i, min, max) {
1033
+ if (i !== ~~i || i < min || i > max) {
1034
+ throw Error(invalidArgument + i);
1035
+ }
1036
+ }
1037
+ function checkRoundingDigits(d, i, rm, repeating) {
1038
+ var di, k, r, rd;
1039
+ for (k = d[0];k >= 10; k /= 10)
1040
+ --i;
1041
+ if (--i < 0) {
1042
+ i += LOG_BASE;
1043
+ di = 0;
1044
+ } else {
1045
+ di = Math.ceil((i + 1) / LOG_BASE);
1046
+ i %= LOG_BASE;
1047
+ }
1048
+ k = mathpow(10, LOG_BASE - i);
1049
+ rd = d[di] % k | 0;
1050
+ if (repeating == null) {
1051
+ if (i < 3) {
1052
+ if (i == 0)
1053
+ rd = rd / 100 | 0;
1054
+ else if (i == 1)
1055
+ rd = rd / 10 | 0;
1056
+ r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
1057
+ } else {
1058
+ 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;
1059
+ }
1060
+ } else {
1061
+ if (i < 4) {
1062
+ if (i == 0)
1063
+ rd = rd / 1000 | 0;
1064
+ else if (i == 1)
1065
+ rd = rd / 100 | 0;
1066
+ else if (i == 2)
1067
+ rd = rd / 10 | 0;
1068
+ r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
1069
+ } else {
1070
+ r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
1071
+ }
1072
+ }
1073
+ return r;
1074
+ }
1075
+ function convertBase(str, baseIn, baseOut) {
1076
+ var j, arr = [0], arrL, i = 0, strL = str.length;
1077
+ for (;i < strL; ) {
1078
+ for (arrL = arr.length;arrL--; )
1079
+ arr[arrL] *= baseIn;
1080
+ arr[0] += NUMERALS.indexOf(str.charAt(i++));
1081
+ for (j = 0;j < arr.length; j++) {
1082
+ if (arr[j] > baseOut - 1) {
1083
+ if (arr[j + 1] === undefined)
1084
+ arr[j + 1] = 0;
1085
+ arr[j + 1] += arr[j] / baseOut | 0;
1086
+ arr[j] %= baseOut;
1087
+ }
1088
+ }
1089
+ }
1090
+ return arr.reverse();
1091
+ }
1092
+ function cosine(Ctor, x) {
1093
+ var k, len, y;
1094
+ if (x.isZero())
1095
+ return x;
1096
+ len = x.d.length;
1097
+ if (len < 32) {
1098
+ k = Math.ceil(len / 3);
1099
+ y = (1 / tinyPow(4, k)).toString();
1100
+ } else {
1101
+ k = 16;
1102
+ y = "2.3283064365386962890625e-10";
1103
+ }
1104
+ Ctor.precision += k;
1105
+ x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
1106
+ for (var i = k;i--; ) {
1107
+ var cos2x = x.times(x);
1108
+ x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
1109
+ }
1110
+ Ctor.precision -= k;
1111
+ return x;
1112
+ }
1113
+ var divide = function() {
1114
+ function multiplyInteger(x, k, base) {
1115
+ var temp, carry = 0, i = x.length;
1116
+ for (x = x.slice();i--; ) {
1117
+ temp = x[i] * k + carry;
1118
+ x[i] = temp % base | 0;
1119
+ carry = temp / base | 0;
1120
+ }
1121
+ if (carry)
1122
+ x.unshift(carry);
1123
+ return x;
1124
+ }
1125
+ function compare(a, b, aL, bL) {
1126
+ var i, r;
1127
+ if (aL != bL) {
1128
+ r = aL > bL ? 1 : -1;
1129
+ } else {
1130
+ for (i = r = 0;i < aL; i++) {
1131
+ if (a[i] != b[i]) {
1132
+ r = a[i] > b[i] ? 1 : -1;
1133
+ break;
1134
+ }
1135
+ }
1136
+ }
1137
+ return r;
1138
+ }
1139
+ function subtract(a, b, aL, base) {
1140
+ var i = 0;
1141
+ for (;aL--; ) {
1142
+ a[aL] -= i;
1143
+ i = a[aL] < b[aL] ? 1 : 0;
1144
+ a[aL] = i * base + a[aL] - b[aL];
1145
+ }
1146
+ for (;!a[0] && a.length > 1; )
1147
+ a.shift();
1148
+ }
1149
+ return function(x, y, pr, rm, dp, base) {
1150
+ var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
1151
+ if (!xd || !xd[0] || !yd || !yd[0]) {
1152
+ return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
1153
+ }
1154
+ if (base) {
1155
+ logBase = 1;
1156
+ e = x.e - y.e;
1157
+ } else {
1158
+ base = BASE;
1159
+ logBase = LOG_BASE;
1160
+ e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
1161
+ }
1162
+ yL = yd.length;
1163
+ xL = xd.length;
1164
+ q = new Ctor(sign);
1165
+ qd = q.d = [];
1166
+ for (i = 0;yd[i] == (xd[i] || 0); i++)
1167
+ ;
1168
+ if (yd[i] > (xd[i] || 0))
1169
+ e--;
1170
+ if (pr == null) {
1171
+ sd = pr = Ctor.precision;
1172
+ rm = Ctor.rounding;
1173
+ } else if (dp) {
1174
+ sd = pr + (x.e - y.e) + 1;
1175
+ } else {
1176
+ sd = pr;
1177
+ }
1178
+ if (sd < 0) {
1179
+ qd.push(1);
1180
+ more = true;
1181
+ } else {
1182
+ sd = sd / logBase + 2 | 0;
1183
+ i = 0;
1184
+ if (yL == 1) {
1185
+ k = 0;
1186
+ yd = yd[0];
1187
+ sd++;
1188
+ for (;(i < xL || k) && sd--; i++) {
1189
+ t = k * base + (xd[i] || 0);
1190
+ qd[i] = t / yd | 0;
1191
+ k = t % yd | 0;
1192
+ }
1193
+ more = k || i < xL;
1194
+ } else {
1195
+ k = base / (yd[0] + 1) | 0;
1196
+ if (k > 1) {
1197
+ yd = multiplyInteger(yd, k, base);
1198
+ xd = multiplyInteger(xd, k, base);
1199
+ yL = yd.length;
1200
+ xL = xd.length;
1201
+ }
1202
+ xi = yL;
1203
+ rem = xd.slice(0, yL);
1204
+ remL = rem.length;
1205
+ for (;remL < yL; )
1206
+ rem[remL++] = 0;
1207
+ yz = yd.slice();
1208
+ yz.unshift(0);
1209
+ yd0 = yd[0];
1210
+ if (yd[1] >= base / 2)
1211
+ ++yd0;
1212
+ do {
1213
+ k = 0;
1214
+ cmp = compare(yd, rem, yL, remL);
1215
+ if (cmp < 0) {
1216
+ rem0 = rem[0];
1217
+ if (yL != remL)
1218
+ rem0 = rem0 * base + (rem[1] || 0);
1219
+ k = rem0 / yd0 | 0;
1220
+ if (k > 1) {
1221
+ if (k >= base)
1222
+ k = base - 1;
1223
+ prod = multiplyInteger(yd, k, base);
1224
+ prodL = prod.length;
1225
+ remL = rem.length;
1226
+ cmp = compare(prod, rem, prodL, remL);
1227
+ if (cmp == 1) {
1228
+ k--;
1229
+ subtract(prod, yL < prodL ? yz : yd, prodL, base);
1230
+ }
1231
+ } else {
1232
+ if (k == 0)
1233
+ cmp = k = 1;
1234
+ prod = yd.slice();
1235
+ }
1236
+ prodL = prod.length;
1237
+ if (prodL < remL)
1238
+ prod.unshift(0);
1239
+ subtract(rem, prod, remL, base);
1240
+ if (cmp == -1) {
1241
+ remL = rem.length;
1242
+ cmp = compare(yd, rem, yL, remL);
1243
+ if (cmp < 1) {
1244
+ k++;
1245
+ subtract(rem, yL < remL ? yz : yd, remL, base);
1246
+ }
1247
+ }
1248
+ remL = rem.length;
1249
+ } else if (cmp === 0) {
1250
+ k++;
1251
+ rem = [0];
1252
+ }
1253
+ qd[i++] = k;
1254
+ if (cmp && rem[0]) {
1255
+ rem[remL++] = xd[xi] || 0;
1256
+ } else {
1257
+ rem = [xd[xi]];
1258
+ remL = 1;
1259
+ }
1260
+ } while ((xi++ < xL || rem[0] !== undefined) && sd--);
1261
+ more = rem[0] !== undefined;
1262
+ }
1263
+ if (!qd[0])
1264
+ qd.shift();
1265
+ }
1266
+ if (logBase == 1) {
1267
+ q.e = e;
1268
+ inexact = more;
1269
+ } else {
1270
+ for (i = 1, k = qd[0];k >= 10; k /= 10)
1271
+ i++;
1272
+ q.e = i + e * logBase - 1;
1273
+ finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
1274
+ }
1275
+ return q;
1276
+ };
1277
+ }();
1278
+ function finalise(x, sd, rm, isTruncated) {
1279
+ var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
1280
+ out:
1281
+ if (sd != null) {
1282
+ xd = x.d;
1283
+ if (!xd)
1284
+ return x;
1285
+ for (digits = 1, k = xd[0];k >= 10; k /= 10)
1286
+ digits++;
1287
+ i = sd - digits;
1288
+ if (i < 0) {
1289
+ i += LOG_BASE;
1290
+ j = sd;
1291
+ w = xd[xdi = 0];
1292
+ rd = w / mathpow(10, digits - j - 1) % 10 | 0;
1293
+ } else {
1294
+ xdi = Math.ceil((i + 1) / LOG_BASE);
1295
+ k = xd.length;
1296
+ if (xdi >= k) {
1297
+ if (isTruncated) {
1298
+ for (;k++ <= xdi; )
1299
+ xd.push(0);
1300
+ w = rd = 0;
1301
+ digits = 1;
1302
+ i %= LOG_BASE;
1303
+ j = i - LOG_BASE + 1;
1304
+ } else {
1305
+ break out;
1306
+ }
1307
+ } else {
1308
+ w = k = xd[xdi];
1309
+ for (digits = 1;k >= 10; k /= 10)
1310
+ digits++;
1311
+ i %= LOG_BASE;
1312
+ j = i - LOG_BASE + digits;
1313
+ rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
1314
+ }
1315
+ }
1316
+ isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j < 0 ? w : w % mathpow(10, digits - j - 1));
1317
+ roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
1318
+ if (sd < 1 || !xd[0]) {
1319
+ xd.length = 0;
1320
+ if (roundUp) {
1321
+ sd -= x.e + 1;
1322
+ xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
1323
+ x.e = -sd || 0;
1324
+ } else {
1325
+ xd[0] = x.e = 0;
1326
+ }
1327
+ return x;
1328
+ }
1329
+ if (i == 0) {
1330
+ xd.length = xdi;
1331
+ k = 1;
1332
+ xdi--;
1333
+ } else {
1334
+ xd.length = xdi + 1;
1335
+ k = mathpow(10, LOG_BASE - i);
1336
+ xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
1337
+ }
1338
+ if (roundUp) {
1339
+ for (;; ) {
1340
+ if (xdi == 0) {
1341
+ for (i = 1, j = xd[0];j >= 10; j /= 10)
1342
+ i++;
1343
+ j = xd[0] += k;
1344
+ for (k = 1;j >= 10; j /= 10)
1345
+ k++;
1346
+ if (i != k) {
1347
+ x.e++;
1348
+ if (xd[0] == BASE)
1349
+ xd[0] = 1;
1350
+ }
1351
+ break;
1352
+ } else {
1353
+ xd[xdi] += k;
1354
+ if (xd[xdi] != BASE)
1355
+ break;
1356
+ xd[xdi--] = 0;
1357
+ k = 1;
1358
+ }
1359
+ }
1360
+ }
1361
+ for (i = xd.length;xd[--i] === 0; )
1362
+ xd.pop();
1363
+ }
1364
+ if (external) {
1365
+ if (x.e > Ctor.maxE) {
1366
+ x.d = null;
1367
+ x.e = NaN;
1368
+ } else if (x.e < Ctor.minE) {
1369
+ x.e = 0;
1370
+ x.d = [0];
1371
+ }
1372
+ }
1373
+ return x;
1374
+ }
1375
+ function finiteToString(x, isExp, sd) {
1376
+ if (!x.isFinite())
1377
+ return nonFiniteToString(x);
1378
+ var k, e = x.e, str = digitsToString(x.d), len = str.length;
1379
+ if (isExp) {
1380
+ if (sd && (k = sd - len) > 0) {
1381
+ str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
1382
+ } else if (len > 1) {
1383
+ str = str.charAt(0) + "." + str.slice(1);
1384
+ }
1385
+ str = str + (x.e < 0 ? "e" : "e+") + x.e;
1386
+ } else if (e < 0) {
1387
+ str = "0." + getZeroString(-e - 1) + str;
1388
+ if (sd && (k = sd - len) > 0)
1389
+ str += getZeroString(k);
1390
+ } else if (e >= len) {
1391
+ str += getZeroString(e + 1 - len);
1392
+ if (sd && (k = sd - e - 1) > 0)
1393
+ str = str + "." + getZeroString(k);
1394
+ } else {
1395
+ if ((k = e + 1) < len)
1396
+ str = str.slice(0, k) + "." + str.slice(k);
1397
+ if (sd && (k = sd - len) > 0) {
1398
+ if (e + 1 === len)
1399
+ str += ".";
1400
+ str += getZeroString(k);
1401
+ }
1402
+ }
1403
+ return str;
1404
+ }
1405
+ function getBase10Exponent(digits, e) {
1406
+ var w = digits[0];
1407
+ for (e *= LOG_BASE;w >= 10; w /= 10)
1408
+ e++;
1409
+ return e;
1410
+ }
1411
+ function getLn10(Ctor, sd, pr) {
1412
+ if (sd > LN10_PRECISION) {
1413
+ external = true;
1414
+ if (pr)
1415
+ Ctor.precision = pr;
1416
+ throw Error(precisionLimitExceeded);
1417
+ }
1418
+ return finalise(new Ctor(LN10), sd, 1, true);
1419
+ }
1420
+ function getPi(Ctor, sd, rm) {
1421
+ if (sd > PI_PRECISION)
1422
+ throw Error(precisionLimitExceeded);
1423
+ return finalise(new Ctor(PI), sd, rm, true);
1424
+ }
1425
+ function getPrecision(digits) {
1426
+ var w = digits.length - 1, len = w * LOG_BASE + 1;
1427
+ w = digits[w];
1428
+ if (w) {
1429
+ for (;w % 10 == 0; w /= 10)
1430
+ len--;
1431
+ for (w = digits[0];w >= 10; w /= 10)
1432
+ len++;
1433
+ }
1434
+ return len;
1435
+ }
1436
+ function getZeroString(k) {
1437
+ var zs = "";
1438
+ for (;k--; )
1439
+ zs += "0";
1440
+ return zs;
1441
+ }
1442
+ function intPow(Ctor, x, n, pr) {
1443
+ var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
1444
+ external = false;
1445
+ for (;; ) {
1446
+ if (n % 2) {
1447
+ r = r.times(x);
1448
+ if (truncate(r.d, k))
1449
+ isTruncated = true;
1450
+ }
1451
+ n = mathfloor(n / 2);
1452
+ if (n === 0) {
1453
+ n = r.d.length - 1;
1454
+ if (isTruncated && r.d[n] === 0)
1455
+ ++r.d[n];
1456
+ break;
1457
+ }
1458
+ x = x.times(x);
1459
+ truncate(x.d, k);
1460
+ }
1461
+ external = true;
1462
+ return r;
1463
+ }
1464
+ function isOdd(n) {
1465
+ return n.d[n.d.length - 1] & 1;
1466
+ }
1467
+ function maxOrMin(Ctor, args, n) {
1468
+ var k, y, x = new Ctor(args[0]), i = 0;
1469
+ for (;++i < args.length; ) {
1470
+ y = new Ctor(args[i]);
1471
+ if (!y.s) {
1472
+ x = y;
1473
+ break;
1474
+ }
1475
+ k = x.cmp(y);
1476
+ if (k === n || k === 0 && x.s === n) {
1477
+ x = y;
1478
+ }
1479
+ }
1480
+ return x;
1481
+ }
1482
+ function naturalExponential(x, sd) {
1483
+ var denominator, guard, j, pow, sum, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1484
+ if (!x.d || !x.d[0] || x.e > 17) {
1485
+ return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
1486
+ }
1487
+ if (sd == null) {
1488
+ external = false;
1489
+ wpr = pr;
1490
+ } else {
1491
+ wpr = sd;
1492
+ }
1493
+ t = new Ctor(0.03125);
1494
+ while (x.e > -2) {
1495
+ x = x.times(t);
1496
+ k += 5;
1497
+ }
1498
+ guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1499
+ wpr += guard;
1500
+ denominator = pow = sum = new Ctor(1);
1501
+ Ctor.precision = wpr;
1502
+ for (;; ) {
1503
+ pow = finalise(pow.times(x), wpr, 1);
1504
+ denominator = denominator.times(++i);
1505
+ t = sum.plus(divide(pow, denominator, wpr, 1));
1506
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
1507
+ j = k;
1508
+ while (j--)
1509
+ sum = finalise(sum.times(sum), wpr, 1);
1510
+ if (sd == null) {
1511
+ if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
1512
+ Ctor.precision = wpr += 10;
1513
+ denominator = pow = t = new Ctor(1);
1514
+ i = 0;
1515
+ rep++;
1516
+ } else {
1517
+ return finalise(sum, Ctor.precision = pr, rm, external = true);
1518
+ }
1519
+ } else {
1520
+ Ctor.precision = pr;
1521
+ return sum;
1522
+ }
1523
+ }
1524
+ sum = t;
1525
+ }
1526
+ }
1527
+ function naturalLogarithm(y, sd) {
1528
+ var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1529
+ if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
1530
+ return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
1531
+ }
1532
+ if (sd == null) {
1533
+ external = false;
1534
+ wpr = pr;
1535
+ } else {
1536
+ wpr = sd;
1537
+ }
1538
+ Ctor.precision = wpr += guard;
1539
+ c = digitsToString(xd);
1540
+ c0 = c.charAt(0);
1541
+ if (Math.abs(e = x.e) < 1500000000000000) {
1542
+ while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
1543
+ x = x.times(y);
1544
+ c = digitsToString(x.d);
1545
+ c0 = c.charAt(0);
1546
+ n++;
1547
+ }
1548
+ e = x.e;
1549
+ if (c0 > 1) {
1550
+ x = new Ctor("0." + c);
1551
+ e++;
1552
+ } else {
1553
+ x = new Ctor(c0 + "." + c.slice(1));
1554
+ }
1555
+ } else {
1556
+ t = getLn10(Ctor, wpr + 2, pr).times(e + "");
1557
+ x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
1558
+ Ctor.precision = pr;
1559
+ return sd == null ? finalise(x, pr, rm, external = true) : x;
1560
+ }
1561
+ x1 = x;
1562
+ sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
1563
+ x2 = finalise(x.times(x), wpr, 1);
1564
+ denominator = 3;
1565
+ for (;; ) {
1566
+ numerator = finalise(numerator.times(x2), wpr, 1);
1567
+ t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
1568
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
1569
+ sum = sum.times(2);
1570
+ if (e !== 0)
1571
+ sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
1572
+ sum = divide(sum, new Ctor(n), wpr, 1);
1573
+ if (sd == null) {
1574
+ if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
1575
+ Ctor.precision = wpr += guard;
1576
+ t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
1577
+ x2 = finalise(x.times(x), wpr, 1);
1578
+ denominator = rep = 1;
1579
+ } else {
1580
+ return finalise(sum, Ctor.precision = pr, rm, external = true);
1581
+ }
1582
+ } else {
1583
+ Ctor.precision = pr;
1584
+ return sum;
1585
+ }
1586
+ }
1587
+ sum = t;
1588
+ denominator += 2;
1589
+ }
1590
+ }
1591
+ function nonFiniteToString(x) {
1592
+ return String(x.s * x.s / 0);
1593
+ }
1594
+ function parseDecimal(x, str) {
1595
+ var e, i, len;
1596
+ if ((e = str.indexOf(".")) > -1)
1597
+ str = str.replace(".", "");
1598
+ if ((i = str.search(/e/i)) > 0) {
1599
+ if (e < 0)
1600
+ e = i;
1601
+ e += +str.slice(i + 1);
1602
+ str = str.substring(0, i);
1603
+ } else if (e < 0) {
1604
+ e = str.length;
1605
+ }
1606
+ for (i = 0;str.charCodeAt(i) === 48; i++)
1607
+ ;
1608
+ for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
1609
+ ;
1610
+ str = str.slice(i, len);
1611
+ if (str) {
1612
+ len -= i;
1613
+ x.e = e = e - i - 1;
1614
+ x.d = [];
1615
+ i = (e + 1) % LOG_BASE;
1616
+ if (e < 0)
1617
+ i += LOG_BASE;
1618
+ if (i < len) {
1619
+ if (i)
1620
+ x.d.push(+str.slice(0, i));
1621
+ for (len -= LOG_BASE;i < len; )
1622
+ x.d.push(+str.slice(i, i += LOG_BASE));
1623
+ str = str.slice(i);
1624
+ i = LOG_BASE - str.length;
1625
+ } else {
1626
+ i -= len;
1627
+ }
1628
+ for (;i--; )
1629
+ str += "0";
1630
+ x.d.push(+str);
1631
+ if (external) {
1632
+ if (x.e > x.constructor.maxE) {
1633
+ x.d = null;
1634
+ x.e = NaN;
1635
+ } else if (x.e < x.constructor.minE) {
1636
+ x.e = 0;
1637
+ x.d = [0];
1638
+ }
1639
+ }
1640
+ } else {
1641
+ x.e = 0;
1642
+ x.d = [0];
1643
+ }
1644
+ return x;
1645
+ }
1646
+ function parseOther(x, str) {
1647
+ var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
1648
+ if (str.indexOf("_") > -1) {
1649
+ str = str.replace(/(\d)_(?=\d)/g, "$1");
1650
+ if (isDecimal.test(str))
1651
+ return parseDecimal(x, str);
1652
+ } else if (str === "Infinity" || str === "NaN") {
1653
+ if (!+str)
1654
+ x.s = NaN;
1655
+ x.e = NaN;
1656
+ x.d = null;
1657
+ return x;
1658
+ }
1659
+ if (isHex.test(str)) {
1660
+ base = 16;
1661
+ str = str.toLowerCase();
1662
+ } else if (isBinary.test(str)) {
1663
+ base = 2;
1664
+ } else if (isOctal.test(str)) {
1665
+ base = 8;
1666
+ } else {
1667
+ throw Error(invalidArgument + str);
1668
+ }
1669
+ i = str.search(/p/i);
1670
+ if (i > 0) {
1671
+ p = +str.slice(i + 1);
1672
+ str = str.substring(2, i);
1673
+ } else {
1674
+ str = str.slice(2);
1675
+ }
1676
+ i = str.indexOf(".");
1677
+ isFloat = i >= 0;
1678
+ Ctor = x.constructor;
1679
+ if (isFloat) {
1680
+ str = str.replace(".", "");
1681
+ len = str.length;
1682
+ i = len - i;
1683
+ divisor = intPow(Ctor, new Ctor(base), i, i * 2);
1684
+ }
1685
+ xd = convertBase(str, base, BASE);
1686
+ xe = xd.length - 1;
1687
+ for (i = xe;xd[i] === 0; --i)
1688
+ xd.pop();
1689
+ if (i < 0)
1690
+ return new Ctor(x.s * 0);
1691
+ x.e = getBase10Exponent(xd, xe);
1692
+ x.d = xd;
1693
+ external = false;
1694
+ if (isFloat)
1695
+ x = divide(x, divisor, len * 4);
1696
+ if (p)
1697
+ x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
1698
+ external = true;
1699
+ return x;
1700
+ }
1701
+ function sine(Ctor, x) {
1702
+ var k, len = x.d.length;
1703
+ if (len < 3) {
1704
+ return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
1705
+ }
1706
+ k = 1.4 * Math.sqrt(len);
1707
+ k = k > 16 ? 16 : k | 0;
1708
+ x = x.times(1 / tinyPow(5, k));
1709
+ x = taylorSeries(Ctor, 2, x, x);
1710
+ var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
1711
+ for (;k--; ) {
1712
+ sin2_x = x.times(x);
1713
+ x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
1714
+ }
1715
+ return x;
1716
+ }
1717
+ function taylorSeries(Ctor, n, x, y, isHyperbolic) {
1718
+ var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
1719
+ external = false;
1720
+ x2 = x.times(x);
1721
+ u = new Ctor(y);
1722
+ for (;; ) {
1723
+ t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
1724
+ u = isHyperbolic ? y.plus(t) : y.minus(t);
1725
+ y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
1726
+ t = u.plus(y);
1727
+ if (t.d[k] !== undefined) {
1728
+ for (j = k;t.d[j] === u.d[j] && j--; )
1729
+ ;
1730
+ if (j == -1)
1731
+ break;
1732
+ }
1733
+ j = u;
1734
+ u = y;
1735
+ y = t;
1736
+ t = j;
1737
+ i++;
1738
+ }
1739
+ external = true;
1740
+ t.d.length = k + 1;
1741
+ return t;
1742
+ }
1743
+ function tinyPow(b, e) {
1744
+ var n = b;
1745
+ while (--e)
1746
+ n *= b;
1747
+ return n;
1748
+ }
1749
+ function toLessThanHalfPi(Ctor, x) {
1750
+ var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
1751
+ x = x.abs();
1752
+ if (x.lte(halfPi)) {
1753
+ quadrant = isNeg ? 4 : 1;
1754
+ return x;
1755
+ }
1756
+ t = x.divToInt(pi);
1757
+ if (t.isZero()) {
1758
+ quadrant = isNeg ? 3 : 2;
1759
+ } else {
1760
+ x = x.minus(t.times(pi));
1761
+ if (x.lte(halfPi)) {
1762
+ quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
1763
+ return x;
1764
+ }
1765
+ quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
1766
+ }
1767
+ return x.minus(pi).abs();
1768
+ }
1769
+ function toStringBinary(x, baseOut, sd, rm) {
1770
+ var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== undefined;
1771
+ if (isExp) {
1772
+ checkInt32(sd, 1, MAX_DIGITS);
1773
+ if (rm === undefined)
1774
+ rm = Ctor.rounding;
1775
+ else
1776
+ checkInt32(rm, 0, 8);
1777
+ } else {
1778
+ sd = Ctor.precision;
1779
+ rm = Ctor.rounding;
1780
+ }
1781
+ if (!x.isFinite()) {
1782
+ str = nonFiniteToString(x);
1783
+ } else {
1784
+ str = finiteToString(x);
1785
+ i = str.indexOf(".");
1786
+ if (isExp) {
1787
+ base = 2;
1788
+ if (baseOut == 16) {
1789
+ sd = sd * 4 - 3;
1790
+ } else if (baseOut == 8) {
1791
+ sd = sd * 3 - 2;
1792
+ }
1793
+ } else {
1794
+ base = baseOut;
1795
+ }
1796
+ if (i >= 0) {
1797
+ str = str.replace(".", "");
1798
+ y = new Ctor(1);
1799
+ y.e = str.length - i;
1800
+ y.d = convertBase(finiteToString(y), 10, base);
1801
+ y.e = y.d.length;
1802
+ }
1803
+ xd = convertBase(str, 10, base);
1804
+ e = len = xd.length;
1805
+ for (;xd[--len] == 0; )
1806
+ xd.pop();
1807
+ if (!xd[0]) {
1808
+ str = isExp ? "0p+0" : "0";
1809
+ } else {
1810
+ if (i < 0) {
1811
+ e--;
1812
+ } else {
1813
+ x = new Ctor(x);
1814
+ x.d = xd;
1815
+ x.e = e;
1816
+ x = divide(x, y, sd, rm, 0, base);
1817
+ xd = x.d;
1818
+ e = x.e;
1819
+ roundUp = inexact;
1820
+ }
1821
+ i = xd[sd];
1822
+ k = base / 2;
1823
+ roundUp = roundUp || xd[sd + 1] !== undefined;
1824
+ roundUp = rm < 4 ? (i !== undefined || 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));
1825
+ xd.length = sd;
1826
+ if (roundUp) {
1827
+ for (;++xd[--sd] > base - 1; ) {
1828
+ xd[sd] = 0;
1829
+ if (!sd) {
1830
+ ++e;
1831
+ xd.unshift(1);
1832
+ }
1833
+ }
1834
+ }
1835
+ for (len = xd.length;!xd[len - 1]; --len)
1836
+ ;
1837
+ for (i = 0, str = "";i < len; i++)
1838
+ str += NUMERALS.charAt(xd[i]);
1839
+ if (isExp) {
1840
+ if (len > 1) {
1841
+ if (baseOut == 16 || baseOut == 8) {
1842
+ i = baseOut == 16 ? 4 : 3;
1843
+ for (--len;len % i; len++)
1844
+ str += "0";
1845
+ xd = convertBase(str, base, baseOut);
1846
+ for (len = xd.length;!xd[len - 1]; --len)
1847
+ ;
1848
+ for (i = 1, str = "1.";i < len; i++)
1849
+ str += NUMERALS.charAt(xd[i]);
1850
+ } else {
1851
+ str = str.charAt(0) + "." + str.slice(1);
1852
+ }
1853
+ }
1854
+ str = str + (e < 0 ? "p" : "p+") + e;
1855
+ } else if (e < 0) {
1856
+ for (;++e; )
1857
+ str = "0" + str;
1858
+ str = "0." + str;
1859
+ } else {
1860
+ if (++e > len)
1861
+ for (e -= len;e--; )
1862
+ str += "0";
1863
+ else if (e < len)
1864
+ str = str.slice(0, e) + "." + str.slice(e);
1865
+ }
1866
+ }
1867
+ str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
1868
+ }
1869
+ return x.s < 0 ? "-" + str : str;
1870
+ }
1871
+ function truncate(arr, len) {
1872
+ if (arr.length > len) {
1873
+ arr.length = len;
1874
+ return true;
1875
+ }
1876
+ }
1877
+ function abs(x) {
1878
+ return new this(x).abs();
1879
+ }
1880
+ function acos(x) {
1881
+ return new this(x).acos();
1882
+ }
1883
+ function acosh(x) {
1884
+ return new this(x).acosh();
1885
+ }
1886
+ function add(x, y) {
1887
+ return new this(x).plus(y);
1888
+ }
1889
+ function asin(x) {
1890
+ return new this(x).asin();
1891
+ }
1892
+ function asinh(x) {
1893
+ return new this(x).asinh();
1894
+ }
1895
+ function atan(x) {
1896
+ return new this(x).atan();
1897
+ }
1898
+ function atanh(x) {
1899
+ return new this(x).atanh();
1900
+ }
1901
+ function atan2(y, x) {
1902
+ y = new this(y);
1903
+ x = new this(x);
1904
+ var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
1905
+ if (!y.s || !x.s) {
1906
+ r = new this(NaN);
1907
+ } else if (!y.d && !x.d) {
1908
+ r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
1909
+ r.s = y.s;
1910
+ } else if (!x.d || y.isZero()) {
1911
+ r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
1912
+ r.s = y.s;
1913
+ } else if (!y.d || x.isZero()) {
1914
+ r = getPi(this, wpr, 1).times(0.5);
1915
+ r.s = y.s;
1916
+ } else if (x.s < 0) {
1917
+ this.precision = wpr;
1918
+ this.rounding = 1;
1919
+ r = this.atan(divide(y, x, wpr, 1));
1920
+ x = getPi(this, wpr, 1);
1921
+ this.precision = pr;
1922
+ this.rounding = rm;
1923
+ r = y.s < 0 ? r.minus(x) : r.plus(x);
1924
+ } else {
1925
+ r = this.atan(divide(y, x, wpr, 1));
1926
+ }
1927
+ return r;
1928
+ }
1929
+ function cbrt(x) {
1930
+ return new this(x).cbrt();
1931
+ }
1932
+ function ceil(x) {
1933
+ return finalise(x = new this(x), x.e + 1, 2);
1934
+ }
1935
+ function clamp(x, min, max) {
1936
+ return new this(x).clamp(min, max);
1937
+ }
1938
+ function config(obj) {
1939
+ if (!obj || typeof obj !== "object")
1940
+ throw Error(decimalError + "Object expected");
1941
+ var i, p, v, useDefaults = obj.defaults === true, ps = [
1942
+ "precision",
1943
+ 1,
1944
+ MAX_DIGITS,
1945
+ "rounding",
1946
+ 0,
1947
+ 8,
1948
+ "toExpNeg",
1949
+ -EXP_LIMIT,
1950
+ 0,
1951
+ "toExpPos",
1952
+ 0,
1953
+ EXP_LIMIT,
1954
+ "maxE",
1955
+ 0,
1956
+ EXP_LIMIT,
1957
+ "minE",
1958
+ -EXP_LIMIT,
1959
+ 0,
1960
+ "modulo",
1961
+ 0,
1962
+ 9
1963
+ ];
1964
+ for (i = 0;i < ps.length; i += 3) {
1965
+ if (p = ps[i], useDefaults)
1966
+ this[p] = DEFAULTS[p];
1967
+ if ((v = obj[p]) !== undefined) {
1968
+ if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
1969
+ this[p] = v;
1970
+ else
1971
+ throw Error(invalidArgument + p + ": " + v);
1972
+ }
1973
+ }
1974
+ if (p = "crypto", useDefaults)
1975
+ this[p] = DEFAULTS[p];
1976
+ if ((v = obj[p]) !== undefined) {
1977
+ if (v === true || v === false || v === 0 || v === 1) {
1978
+ if (v) {
1979
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
1980
+ this[p] = true;
1981
+ } else {
1982
+ throw Error(cryptoUnavailable);
1983
+ }
1984
+ } else {
1985
+ this[p] = false;
1986
+ }
1987
+ } else {
1988
+ throw Error(invalidArgument + p + ": " + v);
1989
+ }
1990
+ }
1991
+ return this;
1992
+ }
1993
+ function cos(x) {
1994
+ return new this(x).cos();
1995
+ }
1996
+ function cosh(x) {
1997
+ return new this(x).cosh();
1998
+ }
1999
+ function clone(obj) {
2000
+ var i, p, ps;
2001
+ function Decimal(v) {
2002
+ var e, i2, t, x = this;
2003
+ if (!(x instanceof Decimal))
2004
+ return new Decimal(v);
2005
+ x.constructor = Decimal;
2006
+ if (isDecimalInstance(v)) {
2007
+ x.s = v.s;
2008
+ if (external) {
2009
+ if (!v.d || v.e > Decimal.maxE) {
2010
+ x.e = NaN;
2011
+ x.d = null;
2012
+ } else if (v.e < Decimal.minE) {
2013
+ x.e = 0;
2014
+ x.d = [0];
2015
+ } else {
2016
+ x.e = v.e;
2017
+ x.d = v.d.slice();
2018
+ }
2019
+ } else {
2020
+ x.e = v.e;
2021
+ x.d = v.d ? v.d.slice() : v.d;
2022
+ }
2023
+ return;
2024
+ }
2025
+ t = typeof v;
2026
+ if (t === "number") {
2027
+ if (v === 0) {
2028
+ x.s = 1 / v < 0 ? -1 : 1;
2029
+ x.e = 0;
2030
+ x.d = [0];
2031
+ return;
2032
+ }
2033
+ if (v < 0) {
2034
+ v = -v;
2035
+ x.s = -1;
2036
+ } else {
2037
+ x.s = 1;
2038
+ }
2039
+ if (v === ~~v && v < 1e7) {
2040
+ for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
2041
+ e++;
2042
+ if (external) {
2043
+ if (e > Decimal.maxE) {
2044
+ x.e = NaN;
2045
+ x.d = null;
2046
+ } else if (e < Decimal.minE) {
2047
+ x.e = 0;
2048
+ x.d = [0];
2049
+ } else {
2050
+ x.e = e;
2051
+ x.d = [v];
2052
+ }
2053
+ } else {
2054
+ x.e = e;
2055
+ x.d = [v];
2056
+ }
2057
+ return;
2058
+ }
2059
+ if (v * 0 !== 0) {
2060
+ if (!v)
2061
+ x.s = NaN;
2062
+ x.e = NaN;
2063
+ x.d = null;
2064
+ return;
2065
+ }
2066
+ return parseDecimal(x, v.toString());
2067
+ }
2068
+ if (t === "string") {
2069
+ if ((i2 = v.charCodeAt(0)) === 45) {
2070
+ v = v.slice(1);
2071
+ x.s = -1;
2072
+ } else {
2073
+ if (i2 === 43)
2074
+ v = v.slice(1);
2075
+ x.s = 1;
2076
+ }
2077
+ return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
2078
+ }
2079
+ if (t === "bigint") {
2080
+ if (v < 0) {
2081
+ v = -v;
2082
+ x.s = -1;
2083
+ } else {
2084
+ x.s = 1;
2085
+ }
2086
+ return parseDecimal(x, v.toString());
2087
+ }
2088
+ throw Error(invalidArgument + v);
2089
+ }
2090
+ Decimal.prototype = P;
2091
+ Decimal.ROUND_UP = 0;
2092
+ Decimal.ROUND_DOWN = 1;
2093
+ Decimal.ROUND_CEIL = 2;
2094
+ Decimal.ROUND_FLOOR = 3;
2095
+ Decimal.ROUND_HALF_UP = 4;
2096
+ Decimal.ROUND_HALF_DOWN = 5;
2097
+ Decimal.ROUND_HALF_EVEN = 6;
2098
+ Decimal.ROUND_HALF_CEIL = 7;
2099
+ Decimal.ROUND_HALF_FLOOR = 8;
2100
+ Decimal.EUCLID = 9;
2101
+ Decimal.config = Decimal.set = config;
2102
+ Decimal.clone = clone;
2103
+ Decimal.isDecimal = isDecimalInstance;
2104
+ Decimal.abs = abs;
2105
+ Decimal.acos = acos;
2106
+ Decimal.acosh = acosh;
2107
+ Decimal.add = add;
2108
+ Decimal.asin = asin;
2109
+ Decimal.asinh = asinh;
2110
+ Decimal.atan = atan;
2111
+ Decimal.atanh = atanh;
2112
+ Decimal.atan2 = atan2;
2113
+ Decimal.cbrt = cbrt;
2114
+ Decimal.ceil = ceil;
2115
+ Decimal.clamp = clamp;
2116
+ Decimal.cos = cos;
2117
+ Decimal.cosh = cosh;
2118
+ Decimal.div = div;
2119
+ Decimal.exp = exp;
2120
+ Decimal.floor = floor;
2121
+ Decimal.hypot = hypot;
2122
+ Decimal.ln = ln;
2123
+ Decimal.log = log;
2124
+ Decimal.log10 = log10;
2125
+ Decimal.log2 = log2;
2126
+ Decimal.max = max;
2127
+ Decimal.min = min;
2128
+ Decimal.mod = mod;
2129
+ Decimal.mul = mul;
2130
+ Decimal.pow = pow;
2131
+ Decimal.random = random;
2132
+ Decimal.round = round;
2133
+ Decimal.sign = sign;
2134
+ Decimal.sin = sin;
2135
+ Decimal.sinh = sinh;
2136
+ Decimal.sqrt = sqrt;
2137
+ Decimal.sub = sub;
2138
+ Decimal.sum = sum;
2139
+ Decimal.tan = tan;
2140
+ Decimal.tanh = tanh;
2141
+ Decimal.trunc = trunc;
2142
+ if (obj === undefined)
2143
+ obj = {};
2144
+ if (obj) {
2145
+ if (obj.defaults !== true) {
2146
+ ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
2147
+ for (i = 0;i < ps.length; )
2148
+ if (!obj.hasOwnProperty(p = ps[i++]))
2149
+ obj[p] = this[p];
2150
+ }
2151
+ }
2152
+ Decimal.config(obj);
2153
+ return Decimal;
2154
+ }
2155
+ function div(x, y) {
2156
+ return new this(x).div(y);
2157
+ }
2158
+ function exp(x) {
2159
+ return new this(x).exp();
2160
+ }
2161
+ function floor(x) {
2162
+ return finalise(x = new this(x), x.e + 1, 3);
2163
+ }
2164
+ function hypot() {
2165
+ var i, n, t = new this(0);
2166
+ external = false;
2167
+ for (i = 0;i < arguments.length; ) {
2168
+ n = new this(arguments[i++]);
2169
+ if (!n.d) {
2170
+ if (n.s) {
2171
+ external = true;
2172
+ return new this(1 / 0);
2173
+ }
2174
+ t = n;
2175
+ } else if (t.d) {
2176
+ t = t.plus(n.times(n));
2177
+ }
2178
+ }
2179
+ external = true;
2180
+ return t.sqrt();
2181
+ }
2182
+ function isDecimalInstance(obj) {
2183
+ return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
2184
+ }
2185
+ function ln(x) {
2186
+ return new this(x).ln();
2187
+ }
2188
+ function log(x, y) {
2189
+ return new this(x).log(y);
2190
+ }
2191
+ function log2(x) {
2192
+ return new this(x).log(2);
2193
+ }
2194
+ function log10(x) {
2195
+ return new this(x).log(10);
2196
+ }
2197
+ function max() {
2198
+ return maxOrMin(this, arguments, -1);
2199
+ }
2200
+ function min() {
2201
+ return maxOrMin(this, arguments, 1);
2202
+ }
2203
+ function mod(x, y) {
2204
+ return new this(x).mod(y);
2205
+ }
2206
+ function mul(x, y) {
2207
+ return new this(x).mul(y);
2208
+ }
2209
+ function pow(x, y) {
2210
+ return new this(x).pow(y);
2211
+ }
2212
+ function random(sd) {
2213
+ var d, e, k, n, i = 0, r = new this(1), rd = [];
2214
+ if (sd === undefined)
2215
+ sd = this.precision;
2216
+ else
2217
+ checkInt32(sd, 1, MAX_DIGITS);
2218
+ k = Math.ceil(sd / LOG_BASE);
2219
+ if (!this.crypto) {
2220
+ for (;i < k; )
2221
+ rd[i++] = Math.random() * 1e7 | 0;
2222
+ } else if (crypto.getRandomValues) {
2223
+ d = crypto.getRandomValues(new Uint32Array(k));
2224
+ for (;i < k; ) {
2225
+ n = d[i];
2226
+ if (n >= 4290000000) {
2227
+ d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
2228
+ } else {
2229
+ rd[i++] = n % 1e7;
2230
+ }
2231
+ }
2232
+ } else if (crypto.randomBytes) {
2233
+ d = crypto.randomBytes(k *= 4);
2234
+ for (;i < k; ) {
2235
+ n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
2236
+ if (n >= 2140000000) {
2237
+ crypto.randomBytes(4).copy(d, i);
2238
+ } else {
2239
+ rd.push(n % 1e7);
2240
+ i += 4;
2241
+ }
2242
+ }
2243
+ i = k / 4;
2244
+ } else {
2245
+ throw Error(cryptoUnavailable);
2246
+ }
2247
+ k = rd[--i];
2248
+ sd %= LOG_BASE;
2249
+ if (k && sd) {
2250
+ n = mathpow(10, LOG_BASE - sd);
2251
+ rd[i] = (k / n | 0) * n;
2252
+ }
2253
+ for (;rd[i] === 0; i--)
2254
+ rd.pop();
2255
+ if (i < 0) {
2256
+ e = 0;
2257
+ rd = [0];
2258
+ } else {
2259
+ e = -1;
2260
+ for (;rd[0] === 0; e -= LOG_BASE)
2261
+ rd.shift();
2262
+ for (k = 1, n = rd[0];n >= 10; n /= 10)
2263
+ k++;
2264
+ if (k < LOG_BASE)
2265
+ e -= LOG_BASE - k;
2266
+ }
2267
+ r.e = e;
2268
+ r.d = rd;
2269
+ return r;
2270
+ }
2271
+ function round(x) {
2272
+ return finalise(x = new this(x), x.e + 1, this.rounding);
2273
+ }
2274
+ function sign(x) {
2275
+ x = new this(x);
2276
+ return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
2277
+ }
2278
+ function sin(x) {
2279
+ return new this(x).sin();
2280
+ }
2281
+ function sinh(x) {
2282
+ return new this(x).sinh();
2283
+ }
2284
+ function sqrt(x) {
2285
+ return new this(x).sqrt();
2286
+ }
2287
+ function sub(x, y) {
2288
+ return new this(x).sub(y);
2289
+ }
2290
+ function sum() {
2291
+ var i = 0, args = arguments, x = new this(args[i]);
2292
+ external = false;
2293
+ for (;x.s && ++i < args.length; )
2294
+ x = x.plus(args[i]);
2295
+ external = true;
2296
+ return finalise(x, this.precision, this.rounding);
2297
+ }
2298
+ function tan(x) {
2299
+ return new this(x).tan();
2300
+ }
2301
+ function tanh(x) {
2302
+ return new this(x).tanh();
2303
+ }
2304
+ function trunc(x) {
2305
+ return finalise(x = new this(x), x.e + 1, 1);
2306
+ }
2307
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
2308
+ P[Symbol.toStringTag] = "Decimal";
2309
+ var Decimal = P.constructor = clone(DEFAULTS);
2310
+ LN10 = new Decimal(LN10);
2311
+ PI = new Decimal(PI);
2312
+ var decimal_default = Decimal;
2313
+ export {
2314
+ Decimal,
2315
+ decimal_default as default
2316
+ };