@naturalcycles/abba 1.6.0 → 1.9.0

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