@prisma/client-runtime-utils 6.17.0-integration-feat-tml-1074-extract-utilities-entrypoint.1

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