teleton 0.7.5 → 0.8.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.
Files changed (43) hide show
  1. package/README.md +35 -15
  2. package/dist/chunk-3RG5ZIWI.js +10 -0
  3. package/dist/{chunk-LCCVZ4D2.js → chunk-3S4GGLLR.js} +28 -26
  4. package/dist/{chunk-NUGDTPE4.js → chunk-4L66JHQE.js} +2 -1
  5. package/dist/{chunk-OGMVWDVU.js → chunk-5FNWBZ5K.js} +1826 -4992
  6. package/dist/{chunk-U7FQYCBQ.js → chunk-7TECSLJ4.js} +2 -2
  7. package/dist/{chunk-2GLHOJ5C.js → chunk-7U7BOHCL.js} +103 -36
  8. package/dist/{chunk-DMXTIRUW.js → chunk-AYWEJCDB.js} +20 -39
  9. package/dist/chunk-CGOXE4WP.js +11315 -0
  10. package/dist/{chunk-5UVXJMOX.js → chunk-KVXV7EF7.js} +4 -4
  11. package/dist/{chunk-QOQWUUA4.js → chunk-OJCLKU5Z.js} +68 -2
  12. package/dist/{chunk-CB2Y45HA.js → chunk-PHSAHTK4.js} +51 -3
  13. package/dist/{chunk-WIKM24GZ.js → chunk-QBHRXLZS.js} +5 -0
  14. package/dist/{chunk-OCLG5GKI.js → chunk-QV2GLOTK.js} +14 -3
  15. package/dist/{chunk-AVDWXYQ7.js → chunk-S6PHGKOC.js} +12 -1
  16. package/dist/{chunk-YP25WTQK.js → chunk-UP55PXFH.js} +6 -0
  17. package/dist/cli/index.js +21 -21
  18. package/dist/{client-O37XDCJB.js → client-MPHPIZB6.js} +4 -4
  19. package/dist/{get-my-gifts-TPVUGUWT.js → get-my-gifts-CC6HAVWB.js} +2 -2
  20. package/dist/index.js +14 -15
  21. package/dist/{memory-KQALFUV3.js → memory-UBHM7ILG.js} +5 -5
  22. package/dist/{migrate-UV3WEL5D.js → migrate-UBBEJ5BL.js} +5 -5
  23. package/dist/{multipart-parser-S3YC6NRJ.js → multipart-parser-UFQLJOV2.js} +2 -2
  24. package/dist/{paths-TMNTEDDD.js → paths-XA2RJH4S.js} +1 -1
  25. package/dist/{server-BHHJGUDF.js → server-3FHI2SEB.js} +398 -56
  26. package/dist/{setup-server-G7UG2DI3.js → setup-server-32XGDPE6.js} +161 -11
  27. package/dist/{store-H4XPNGC2.js → store-M5IMUQCL.js} +6 -6
  28. package/dist/{task-dependency-resolver-VMEVJRPO.js → task-dependency-resolver-RR2O5S7B.js} +3 -3
  29. package/dist/{task-executor-WWSPBJ4V.js → task-executor-6W5HRX5C.js} +3 -3
  30. package/dist/{tasks-QSCWSMPS.js → tasks-WQIKXDX5.js} +2 -2
  31. package/dist/{tool-adapter-Y3TCEQOC.js → tool-adapter-IH5VGBOO.js} +1 -1
  32. package/dist/{tool-index-2KH3OB6X.js → tool-index-PMAOXWUA.js} +9 -6
  33. package/dist/{transcript-UDJZP6NK.js → transcript-NGDPSNIH.js} +2 -2
  34. package/dist/web/assets/index-BfYCdwLI.js +80 -0
  35. package/dist/web/assets/{index-BrVqauzj.css → index-DmlyQVhR.css} +1 -1
  36. package/dist/web/assets/{index.es-Pet5-M13.js → index.es-DitvF-9H.js} +1 -1
  37. package/dist/web/index.html +2 -2
  38. package/package.json +12 -5
  39. package/dist/BigInteger-DQ33LTTE.js +0 -5
  40. package/dist/chunk-G2LLMJXJ.js +0 -5048
  41. package/dist/chunk-QGM4M3NI.js +0 -37
  42. package/dist/chunk-TSKJCWQQ.js +0 -1263
  43. package/dist/web/assets/index-Bx8JW3gV.js +0 -72
@@ -1,1263 +0,0 @@
1
- import {
2
- __commonJS
3
- } from "./chunk-QGM4M3NI.js";
4
-
5
- // node_modules/big-integer/BigInteger.js
6
- var require_BigInteger = __commonJS({
7
- "node_modules/big-integer/BigInteger.js"(exports, module) {
8
- var bigInt = (function(undefined) {
9
- "use strict";
10
- var BASE = 1e7, LOG_BASE = 7, MAX_INT = 9007199254740992, MAX_INT_ARR = smallToArray(MAX_INT), DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
11
- var supportsNativeBigInt = typeof BigInt === "function";
12
- function Integer(v, radix, alphabet, caseSensitive) {
13
- if (typeof v === "undefined") return Integer[0];
14
- if (typeof radix !== "undefined") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive);
15
- return parseValue(v);
16
- }
17
- function BigInteger(value, sign) {
18
- this.value = value;
19
- this.sign = sign;
20
- this.isSmall = false;
21
- }
22
- BigInteger.prototype = Object.create(Integer.prototype);
23
- function SmallInteger(value) {
24
- this.value = value;
25
- this.sign = value < 0;
26
- this.isSmall = true;
27
- }
28
- SmallInteger.prototype = Object.create(Integer.prototype);
29
- function NativeBigInt(value) {
30
- this.value = value;
31
- }
32
- NativeBigInt.prototype = Object.create(Integer.prototype);
33
- function isPrecise(n) {
34
- return -MAX_INT < n && n < MAX_INT;
35
- }
36
- function smallToArray(n) {
37
- if (n < 1e7)
38
- return [n];
39
- if (n < 1e14)
40
- return [n % 1e7, Math.floor(n / 1e7)];
41
- return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];
42
- }
43
- function arrayToSmall(arr) {
44
- trim(arr);
45
- var length = arr.length;
46
- if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
47
- switch (length) {
48
- case 0:
49
- return 0;
50
- case 1:
51
- return arr[0];
52
- case 2:
53
- return arr[0] + arr[1] * BASE;
54
- default:
55
- return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
56
- }
57
- }
58
- return arr;
59
- }
60
- function trim(v) {
61
- var i2 = v.length;
62
- while (v[--i2] === 0) ;
63
- v.length = i2 + 1;
64
- }
65
- function createArray(length) {
66
- var x = new Array(length);
67
- var i2 = -1;
68
- while (++i2 < length) {
69
- x[i2] = 0;
70
- }
71
- return x;
72
- }
73
- function truncate(n) {
74
- if (n > 0) return Math.floor(n);
75
- return Math.ceil(n);
76
- }
77
- function add(a, b) {
78
- var l_a = a.length, l_b = b.length, r = new Array(l_a), carry = 0, base = BASE, sum, i2;
79
- for (i2 = 0; i2 < l_b; i2++) {
80
- sum = a[i2] + b[i2] + carry;
81
- carry = sum >= base ? 1 : 0;
82
- r[i2] = sum - carry * base;
83
- }
84
- while (i2 < l_a) {
85
- sum = a[i2] + carry;
86
- carry = sum === base ? 1 : 0;
87
- r[i2++] = sum - carry * base;
88
- }
89
- if (carry > 0) r.push(carry);
90
- return r;
91
- }
92
- function addAny(a, b) {
93
- if (a.length >= b.length) return add(a, b);
94
- return add(b, a);
95
- }
96
- function addSmall(a, carry) {
97
- var l = a.length, r = new Array(l), base = BASE, sum, i2;
98
- for (i2 = 0; i2 < l; i2++) {
99
- sum = a[i2] - base + carry;
100
- carry = Math.floor(sum / base);
101
- r[i2] = sum - carry * base;
102
- carry += 1;
103
- }
104
- while (carry > 0) {
105
- r[i2++] = carry % base;
106
- carry = Math.floor(carry / base);
107
- }
108
- return r;
109
- }
110
- BigInteger.prototype.add = function(v) {
111
- var n = parseValue(v);
112
- if (this.sign !== n.sign) {
113
- return this.subtract(n.negate());
114
- }
115
- var a = this.value, b = n.value;
116
- if (n.isSmall) {
117
- return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
118
- }
119
- return new BigInteger(addAny(a, b), this.sign);
120
- };
121
- BigInteger.prototype.plus = BigInteger.prototype.add;
122
- SmallInteger.prototype.add = function(v) {
123
- var n = parseValue(v);
124
- var a = this.value;
125
- if (a < 0 !== n.sign) {
126
- return this.subtract(n.negate());
127
- }
128
- var b = n.value;
129
- if (n.isSmall) {
130
- if (isPrecise(a + b)) return new SmallInteger(a + b);
131
- b = smallToArray(Math.abs(b));
132
- }
133
- return new BigInteger(addSmall(b, Math.abs(a)), a < 0);
134
- };
135
- SmallInteger.prototype.plus = SmallInteger.prototype.add;
136
- NativeBigInt.prototype.add = function(v) {
137
- return new NativeBigInt(this.value + parseValue(v).value);
138
- };
139
- NativeBigInt.prototype.plus = NativeBigInt.prototype.add;
140
- function subtract(a, b) {
141
- var a_l = a.length, b_l = b.length, r = new Array(a_l), borrow = 0, base = BASE, i2, difference;
142
- for (i2 = 0; i2 < b_l; i2++) {
143
- difference = a[i2] - borrow - b[i2];
144
- if (difference < 0) {
145
- difference += base;
146
- borrow = 1;
147
- } else borrow = 0;
148
- r[i2] = difference;
149
- }
150
- for (i2 = b_l; i2 < a_l; i2++) {
151
- difference = a[i2] - borrow;
152
- if (difference < 0) difference += base;
153
- else {
154
- r[i2++] = difference;
155
- break;
156
- }
157
- r[i2] = difference;
158
- }
159
- for (; i2 < a_l; i2++) {
160
- r[i2] = a[i2];
161
- }
162
- trim(r);
163
- return r;
164
- }
165
- function subtractAny(a, b, sign) {
166
- var value;
167
- if (compareAbs(a, b) >= 0) {
168
- value = subtract(a, b);
169
- } else {
170
- value = subtract(b, a);
171
- sign = !sign;
172
- }
173
- value = arrayToSmall(value);
174
- if (typeof value === "number") {
175
- if (sign) value = -value;
176
- return new SmallInteger(value);
177
- }
178
- return new BigInteger(value, sign);
179
- }
180
- function subtractSmall(a, b, sign) {
181
- var l = a.length, r = new Array(l), carry = -b, base = BASE, i2, difference;
182
- for (i2 = 0; i2 < l; i2++) {
183
- difference = a[i2] + carry;
184
- carry = Math.floor(difference / base);
185
- difference %= base;
186
- r[i2] = difference < 0 ? difference + base : difference;
187
- }
188
- r = arrayToSmall(r);
189
- if (typeof r === "number") {
190
- if (sign) r = -r;
191
- return new SmallInteger(r);
192
- }
193
- return new BigInteger(r, sign);
194
- }
195
- BigInteger.prototype.subtract = function(v) {
196
- var n = parseValue(v);
197
- if (this.sign !== n.sign) {
198
- return this.add(n.negate());
199
- }
200
- var a = this.value, b = n.value;
201
- if (n.isSmall)
202
- return subtractSmall(a, Math.abs(b), this.sign);
203
- return subtractAny(a, b, this.sign);
204
- };
205
- BigInteger.prototype.minus = BigInteger.prototype.subtract;
206
- SmallInteger.prototype.subtract = function(v) {
207
- var n = parseValue(v);
208
- var a = this.value;
209
- if (a < 0 !== n.sign) {
210
- return this.add(n.negate());
211
- }
212
- var b = n.value;
213
- if (n.isSmall) {
214
- return new SmallInteger(a - b);
215
- }
216
- return subtractSmall(b, Math.abs(a), a >= 0);
217
- };
218
- SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
219
- NativeBigInt.prototype.subtract = function(v) {
220
- return new NativeBigInt(this.value - parseValue(v).value);
221
- };
222
- NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;
223
- BigInteger.prototype.negate = function() {
224
- return new BigInteger(this.value, !this.sign);
225
- };
226
- SmallInteger.prototype.negate = function() {
227
- var sign = this.sign;
228
- var small = new SmallInteger(-this.value);
229
- small.sign = !sign;
230
- return small;
231
- };
232
- NativeBigInt.prototype.negate = function() {
233
- return new NativeBigInt(-this.value);
234
- };
235
- BigInteger.prototype.abs = function() {
236
- return new BigInteger(this.value, false);
237
- };
238
- SmallInteger.prototype.abs = function() {
239
- return new SmallInteger(Math.abs(this.value));
240
- };
241
- NativeBigInt.prototype.abs = function() {
242
- return new NativeBigInt(this.value >= 0 ? this.value : -this.value);
243
- };
244
- function multiplyLong(a, b) {
245
- var a_l = a.length, b_l = b.length, l = a_l + b_l, r = createArray(l), base = BASE, product, carry, i2, a_i, b_j;
246
- for (i2 = 0; i2 < a_l; ++i2) {
247
- a_i = a[i2];
248
- for (var j = 0; j < b_l; ++j) {
249
- b_j = b[j];
250
- product = a_i * b_j + r[i2 + j];
251
- carry = Math.floor(product / base);
252
- r[i2 + j] = product - carry * base;
253
- r[i2 + j + 1] += carry;
254
- }
255
- }
256
- trim(r);
257
- return r;
258
- }
259
- function multiplySmall(a, b) {
260
- var l = a.length, r = new Array(l), base = BASE, carry = 0, product, i2;
261
- for (i2 = 0; i2 < l; i2++) {
262
- product = a[i2] * b + carry;
263
- carry = Math.floor(product / base);
264
- r[i2] = product - carry * base;
265
- }
266
- while (carry > 0) {
267
- r[i2++] = carry % base;
268
- carry = Math.floor(carry / base);
269
- }
270
- return r;
271
- }
272
- function shiftLeft(x, n) {
273
- var r = [];
274
- while (n-- > 0) r.push(0);
275
- return r.concat(x);
276
- }
277
- function multiplyKaratsuba(x, y) {
278
- var n = Math.max(x.length, y.length);
279
- if (n <= 30) return multiplyLong(x, y);
280
- n = Math.ceil(n / 2);
281
- var b = x.slice(n), a = x.slice(0, n), d = y.slice(n), c = y.slice(0, n);
282
- var ac = multiplyKaratsuba(a, c), bd = multiplyKaratsuba(b, d), abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));
283
- var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));
284
- trim(product);
285
- return product;
286
- }
287
- function useKaratsuba(l1, l2) {
288
- return -0.012 * l1 - 0.012 * l2 + 15e-6 * l1 * l2 > 0;
289
- }
290
- BigInteger.prototype.multiply = function(v) {
291
- var n = parseValue(v), a = this.value, b = n.value, sign = this.sign !== n.sign, abs;
292
- if (n.isSmall) {
293
- if (b === 0) return Integer[0];
294
- if (b === 1) return this;
295
- if (b === -1) return this.negate();
296
- abs = Math.abs(b);
297
- if (abs < BASE) {
298
- return new BigInteger(multiplySmall(a, abs), sign);
299
- }
300
- b = smallToArray(abs);
301
- }
302
- if (useKaratsuba(a.length, b.length))
303
- return new BigInteger(multiplyKaratsuba(a, b), sign);
304
- return new BigInteger(multiplyLong(a, b), sign);
305
- };
306
- BigInteger.prototype.times = BigInteger.prototype.multiply;
307
- function multiplySmallAndArray(a, b, sign) {
308
- if (a < BASE) {
309
- return new BigInteger(multiplySmall(b, a), sign);
310
- }
311
- return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
312
- }
313
- SmallInteger.prototype._multiplyBySmall = function(a) {
314
- if (isPrecise(a.value * this.value)) {
315
- return new SmallInteger(a.value * this.value);
316
- }
317
- return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
318
- };
319
- BigInteger.prototype._multiplyBySmall = function(a) {
320
- if (a.value === 0) return Integer[0];
321
- if (a.value === 1) return this;
322
- if (a.value === -1) return this.negate();
323
- return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
324
- };
325
- SmallInteger.prototype.multiply = function(v) {
326
- return parseValue(v)._multiplyBySmall(this);
327
- };
328
- SmallInteger.prototype.times = SmallInteger.prototype.multiply;
329
- NativeBigInt.prototype.multiply = function(v) {
330
- return new NativeBigInt(this.value * parseValue(v).value);
331
- };
332
- NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;
333
- function square(a) {
334
- var l = a.length, r = createArray(l + l), base = BASE, product, carry, i2, a_i, a_j;
335
- for (i2 = 0; i2 < l; i2++) {
336
- a_i = a[i2];
337
- carry = 0 - a_i * a_i;
338
- for (var j = i2; j < l; j++) {
339
- a_j = a[j];
340
- product = 2 * (a_i * a_j) + r[i2 + j] + carry;
341
- carry = Math.floor(product / base);
342
- r[i2 + j] = product - carry * base;
343
- }
344
- r[i2 + l] = carry;
345
- }
346
- trim(r);
347
- return r;
348
- }
349
- BigInteger.prototype.square = function() {
350
- return new BigInteger(square(this.value), false);
351
- };
352
- SmallInteger.prototype.square = function() {
353
- var value = this.value * this.value;
354
- if (isPrecise(value)) return new SmallInteger(value);
355
- return new BigInteger(square(smallToArray(Math.abs(this.value))), false);
356
- };
357
- NativeBigInt.prototype.square = function(v) {
358
- return new NativeBigInt(this.value * this.value);
359
- };
360
- function divMod1(a, b) {
361
- var a_l = a.length, b_l = b.length, base = BASE, result = createArray(b.length), divisorMostSignificantDigit = b[b_l - 1], lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), remainder = multiplySmall(a, lambda), divisor = multiplySmall(b, lambda), quotientDigit, shift, carry, borrow, i2, l, q;
362
- if (remainder.length <= a_l) remainder.push(0);
363
- divisor.push(0);
364
- divisorMostSignificantDigit = divisor[b_l - 1];
365
- for (shift = a_l - b_l; shift >= 0; shift--) {
366
- quotientDigit = base - 1;
367
- if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
368
- quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
369
- }
370
- carry = 0;
371
- borrow = 0;
372
- l = divisor.length;
373
- for (i2 = 0; i2 < l; i2++) {
374
- carry += quotientDigit * divisor[i2];
375
- q = Math.floor(carry / base);
376
- borrow += remainder[shift + i2] - (carry - q * base);
377
- carry = q;
378
- if (borrow < 0) {
379
- remainder[shift + i2] = borrow + base;
380
- borrow = -1;
381
- } else {
382
- remainder[shift + i2] = borrow;
383
- borrow = 0;
384
- }
385
- }
386
- while (borrow !== 0) {
387
- quotientDigit -= 1;
388
- carry = 0;
389
- for (i2 = 0; i2 < l; i2++) {
390
- carry += remainder[shift + i2] - base + divisor[i2];
391
- if (carry < 0) {
392
- remainder[shift + i2] = carry + base;
393
- carry = 0;
394
- } else {
395
- remainder[shift + i2] = carry;
396
- carry = 1;
397
- }
398
- }
399
- borrow += carry;
400
- }
401
- result[shift] = quotientDigit;
402
- }
403
- remainder = divModSmall(remainder, lambda)[0];
404
- return [arrayToSmall(result), arrayToSmall(remainder)];
405
- }
406
- function divMod2(a, b) {
407
- var a_l = a.length, b_l = b.length, result = [], part = [], base = BASE, guess, xlen, highx, highy, check;
408
- while (a_l) {
409
- part.unshift(a[--a_l]);
410
- trim(part);
411
- if (compareAbs(part, b) < 0) {
412
- result.push(0);
413
- continue;
414
- }
415
- xlen = part.length;
416
- highx = part[xlen - 1] * base + part[xlen - 2];
417
- highy = b[b_l - 1] * base + b[b_l - 2];
418
- if (xlen > b_l) {
419
- highx = (highx + 1) * base;
420
- }
421
- guess = Math.ceil(highx / highy);
422
- do {
423
- check = multiplySmall(b, guess);
424
- if (compareAbs(check, part) <= 0) break;
425
- guess--;
426
- } while (guess);
427
- result.push(guess);
428
- part = subtract(part, check);
429
- }
430
- result.reverse();
431
- return [arrayToSmall(result), arrayToSmall(part)];
432
- }
433
- function divModSmall(value, lambda) {
434
- var length = value.length, quotient = createArray(length), base = BASE, i2, q, remainder, divisor;
435
- remainder = 0;
436
- for (i2 = length - 1; i2 >= 0; --i2) {
437
- divisor = remainder * base + value[i2];
438
- q = truncate(divisor / lambda);
439
- remainder = divisor - q * lambda;
440
- quotient[i2] = q | 0;
441
- }
442
- return [quotient, remainder | 0];
443
- }
444
- function divModAny(self, v) {
445
- var value, n = parseValue(v);
446
- if (supportsNativeBigInt) {
447
- return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)];
448
- }
449
- var a = self.value, b = n.value;
450
- var quotient;
451
- if (b === 0) throw new Error("Cannot divide by zero");
452
- if (self.isSmall) {
453
- if (n.isSmall) {
454
- return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
455
- }
456
- return [Integer[0], self];
457
- }
458
- if (n.isSmall) {
459
- if (b === 1) return [self, Integer[0]];
460
- if (b == -1) return [self.negate(), Integer[0]];
461
- var abs = Math.abs(b);
462
- if (abs < BASE) {
463
- value = divModSmall(a, abs);
464
- quotient = arrayToSmall(value[0]);
465
- var remainder = value[1];
466
- if (self.sign) remainder = -remainder;
467
- if (typeof quotient === "number") {
468
- if (self.sign !== n.sign) quotient = -quotient;
469
- return [new SmallInteger(quotient), new SmallInteger(remainder)];
470
- }
471
- return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
472
- }
473
- b = smallToArray(abs);
474
- }
475
- var comparison = compareAbs(a, b);
476
- if (comparison === -1) return [Integer[0], self];
477
- if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
478
- if (a.length + b.length <= 200)
479
- value = divMod1(a, b);
480
- else value = divMod2(a, b);
481
- quotient = value[0];
482
- var qSign = self.sign !== n.sign, mod = value[1], mSign = self.sign;
483
- if (typeof quotient === "number") {
484
- if (qSign) quotient = -quotient;
485
- quotient = new SmallInteger(quotient);
486
- } else quotient = new BigInteger(quotient, qSign);
487
- if (typeof mod === "number") {
488
- if (mSign) mod = -mod;
489
- mod = new SmallInteger(mod);
490
- } else mod = new BigInteger(mod, mSign);
491
- return [quotient, mod];
492
- }
493
- BigInteger.prototype.divmod = function(v) {
494
- var result = divModAny(this, v);
495
- return {
496
- quotient: result[0],
497
- remainder: result[1]
498
- };
499
- };
500
- NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
501
- BigInteger.prototype.divide = function(v) {
502
- return divModAny(this, v)[0];
503
- };
504
- NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function(v) {
505
- return new NativeBigInt(this.value / parseValue(v).value);
506
- };
507
- SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
508
- BigInteger.prototype.mod = function(v) {
509
- return divModAny(this, v)[1];
510
- };
511
- NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function(v) {
512
- return new NativeBigInt(this.value % parseValue(v).value);
513
- };
514
- SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
515
- BigInteger.prototype.pow = function(v) {
516
- var n = parseValue(v), a = this.value, b = n.value, value, x, y;
517
- if (b === 0) return Integer[1];
518
- if (a === 0) return Integer[0];
519
- if (a === 1) return Integer[1];
520
- if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
521
- if (n.sign) {
522
- return Integer[0];
523
- }
524
- if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
525
- if (this.isSmall) {
526
- if (isPrecise(value = Math.pow(a, b)))
527
- return new SmallInteger(truncate(value));
528
- }
529
- x = this;
530
- y = Integer[1];
531
- while (true) {
532
- if (b & true) {
533
- y = y.times(x);
534
- --b;
535
- }
536
- if (b === 0) break;
537
- b /= 2;
538
- x = x.square();
539
- }
540
- return y;
541
- };
542
- SmallInteger.prototype.pow = BigInteger.prototype.pow;
543
- NativeBigInt.prototype.pow = function(v) {
544
- var n = parseValue(v);
545
- var a = this.value, b = n.value;
546
- var _0 = BigInt(0), _1 = BigInt(1), _2 = BigInt(2);
547
- if (b === _0) return Integer[1];
548
- if (a === _0) return Integer[0];
549
- if (a === _1) return Integer[1];
550
- if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1];
551
- if (n.isNegative()) return new NativeBigInt(_0);
552
- var x = this;
553
- var y = Integer[1];
554
- while (true) {
555
- if ((b & _1) === _1) {
556
- y = y.times(x);
557
- --b;
558
- }
559
- if (b === _0) break;
560
- b /= _2;
561
- x = x.square();
562
- }
563
- return y;
564
- };
565
- BigInteger.prototype.modPow = function(exp, mod) {
566
- exp = parseValue(exp);
567
- mod = parseValue(mod);
568
- if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
569
- var r = Integer[1], base = this.mod(mod);
570
- if (exp.isNegative()) {
571
- exp = exp.multiply(Integer[-1]);
572
- base = base.modInv(mod);
573
- }
574
- while (exp.isPositive()) {
575
- if (base.isZero()) return Integer[0];
576
- if (exp.isOdd()) r = r.multiply(base).mod(mod);
577
- exp = exp.divide(2);
578
- base = base.square().mod(mod);
579
- }
580
- return r;
581
- };
582
- NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
583
- function compareAbs(a, b) {
584
- if (a.length !== b.length) {
585
- return a.length > b.length ? 1 : -1;
586
- }
587
- for (var i2 = a.length - 1; i2 >= 0; i2--) {
588
- if (a[i2] !== b[i2]) return a[i2] > b[i2] ? 1 : -1;
589
- }
590
- return 0;
591
- }
592
- BigInteger.prototype.compareAbs = function(v) {
593
- var n = parseValue(v), a = this.value, b = n.value;
594
- if (n.isSmall) return 1;
595
- return compareAbs(a, b);
596
- };
597
- SmallInteger.prototype.compareAbs = function(v) {
598
- var n = parseValue(v), a = Math.abs(this.value), b = n.value;
599
- if (n.isSmall) {
600
- b = Math.abs(b);
601
- return a === b ? 0 : a > b ? 1 : -1;
602
- }
603
- return -1;
604
- };
605
- NativeBigInt.prototype.compareAbs = function(v) {
606
- var a = this.value;
607
- var b = parseValue(v).value;
608
- a = a >= 0 ? a : -a;
609
- b = b >= 0 ? b : -b;
610
- return a === b ? 0 : a > b ? 1 : -1;
611
- };
612
- BigInteger.prototype.compare = function(v) {
613
- if (v === Infinity) {
614
- return -1;
615
- }
616
- if (v === -Infinity) {
617
- return 1;
618
- }
619
- var n = parseValue(v), a = this.value, b = n.value;
620
- if (this.sign !== n.sign) {
621
- return n.sign ? 1 : -1;
622
- }
623
- if (n.isSmall) {
624
- return this.sign ? -1 : 1;
625
- }
626
- return compareAbs(a, b) * (this.sign ? -1 : 1);
627
- };
628
- BigInteger.prototype.compareTo = BigInteger.prototype.compare;
629
- SmallInteger.prototype.compare = function(v) {
630
- if (v === Infinity) {
631
- return -1;
632
- }
633
- if (v === -Infinity) {
634
- return 1;
635
- }
636
- var n = parseValue(v), a = this.value, b = n.value;
637
- if (n.isSmall) {
638
- return a == b ? 0 : a > b ? 1 : -1;
639
- }
640
- if (a < 0 !== n.sign) {
641
- return a < 0 ? -1 : 1;
642
- }
643
- return a < 0 ? 1 : -1;
644
- };
645
- SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
646
- NativeBigInt.prototype.compare = function(v) {
647
- if (v === Infinity) {
648
- return -1;
649
- }
650
- if (v === -Infinity) {
651
- return 1;
652
- }
653
- var a = this.value;
654
- var b = parseValue(v).value;
655
- return a === b ? 0 : a > b ? 1 : -1;
656
- };
657
- NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;
658
- BigInteger.prototype.equals = function(v) {
659
- return this.compare(v) === 0;
660
- };
661
- NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
662
- BigInteger.prototype.notEquals = function(v) {
663
- return this.compare(v) !== 0;
664
- };
665
- NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
666
- BigInteger.prototype.greater = function(v) {
667
- return this.compare(v) > 0;
668
- };
669
- NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
670
- BigInteger.prototype.lesser = function(v) {
671
- return this.compare(v) < 0;
672
- };
673
- NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
674
- BigInteger.prototype.greaterOrEquals = function(v) {
675
- return this.compare(v) >= 0;
676
- };
677
- NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
678
- BigInteger.prototype.lesserOrEquals = function(v) {
679
- return this.compare(v) <= 0;
680
- };
681
- NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
682
- BigInteger.prototype.isEven = function() {
683
- return (this.value[0] & 1) === 0;
684
- };
685
- SmallInteger.prototype.isEven = function() {
686
- return (this.value & 1) === 0;
687
- };
688
- NativeBigInt.prototype.isEven = function() {
689
- return (this.value & BigInt(1)) === BigInt(0);
690
- };
691
- BigInteger.prototype.isOdd = function() {
692
- return (this.value[0] & 1) === 1;
693
- };
694
- SmallInteger.prototype.isOdd = function() {
695
- return (this.value & 1) === 1;
696
- };
697
- NativeBigInt.prototype.isOdd = function() {
698
- return (this.value & BigInt(1)) === BigInt(1);
699
- };
700
- BigInteger.prototype.isPositive = function() {
701
- return !this.sign;
702
- };
703
- SmallInteger.prototype.isPositive = function() {
704
- return this.value > 0;
705
- };
706
- NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;
707
- BigInteger.prototype.isNegative = function() {
708
- return this.sign;
709
- };
710
- SmallInteger.prototype.isNegative = function() {
711
- return this.value < 0;
712
- };
713
- NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;
714
- BigInteger.prototype.isUnit = function() {
715
- return false;
716
- };
717
- SmallInteger.prototype.isUnit = function() {
718
- return Math.abs(this.value) === 1;
719
- };
720
- NativeBigInt.prototype.isUnit = function() {
721
- return this.abs().value === BigInt(1);
722
- };
723
- BigInteger.prototype.isZero = function() {
724
- return false;
725
- };
726
- SmallInteger.prototype.isZero = function() {
727
- return this.value === 0;
728
- };
729
- NativeBigInt.prototype.isZero = function() {
730
- return this.value === BigInt(0);
731
- };
732
- BigInteger.prototype.isDivisibleBy = function(v) {
733
- var n = parseValue(v);
734
- if (n.isZero()) return false;
735
- if (n.isUnit()) return true;
736
- if (n.compareAbs(2) === 0) return this.isEven();
737
- return this.mod(n).isZero();
738
- };
739
- NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
740
- function isBasicPrime(v) {
741
- var n = v.abs();
742
- if (n.isUnit()) return false;
743
- if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
744
- if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
745
- if (n.lesser(49)) return true;
746
- }
747
- function millerRabinTest(n, a) {
748
- var nPrev = n.prev(), b = nPrev, r = 0, d, t, i2, x;
749
- while (b.isEven()) b = b.divide(2), r++;
750
- next: for (i2 = 0; i2 < a.length; i2++) {
751
- if (n.lesser(a[i2])) continue;
752
- x = bigInt(a[i2]).modPow(b, n);
753
- if (x.isUnit() || x.equals(nPrev)) continue;
754
- for (d = r - 1; d != 0; d--) {
755
- x = x.square().mod(n);
756
- if (x.isUnit()) return false;
757
- if (x.equals(nPrev)) continue next;
758
- }
759
- return false;
760
- }
761
- return true;
762
- }
763
- BigInteger.prototype.isPrime = function(strict) {
764
- var isPrime = isBasicPrime(this);
765
- if (isPrime !== undefined) return isPrime;
766
- var n = this.abs();
767
- var bits = n.bitLength();
768
- if (bits <= 64)
769
- return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]);
770
- var logN = Math.log(2) * bits.toJSNumber();
771
- var t = Math.ceil(strict === true ? 2 * Math.pow(logN, 2) : logN);
772
- for (var a = [], i2 = 0; i2 < t; i2++) {
773
- a.push(bigInt(i2 + 2));
774
- }
775
- return millerRabinTest(n, a);
776
- };
777
- NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
778
- BigInteger.prototype.isProbablePrime = function(iterations, rng) {
779
- var isPrime = isBasicPrime(this);
780
- if (isPrime !== undefined) return isPrime;
781
- var n = this.abs();
782
- var t = iterations === undefined ? 5 : iterations;
783
- for (var a = [], i2 = 0; i2 < t; i2++) {
784
- a.push(bigInt.randBetween(2, n.minus(2), rng));
785
- }
786
- return millerRabinTest(n, a);
787
- };
788
- NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
789
- BigInteger.prototype.modInv = function(n) {
790
- var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;
791
- while (!newR.isZero()) {
792
- q = r.divide(newR);
793
- lastT = t;
794
- lastR = r;
795
- t = newT;
796
- r = newR;
797
- newT = lastT.subtract(q.multiply(newT));
798
- newR = lastR.subtract(q.multiply(newR));
799
- }
800
- if (!r.isUnit()) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime");
801
- if (t.compare(0) === -1) {
802
- t = t.add(n);
803
- }
804
- if (this.isNegative()) {
805
- return t.negate();
806
- }
807
- return t;
808
- };
809
- NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
810
- BigInteger.prototype.next = function() {
811
- var value = this.value;
812
- if (this.sign) {
813
- return subtractSmall(value, 1, this.sign);
814
- }
815
- return new BigInteger(addSmall(value, 1), this.sign);
816
- };
817
- SmallInteger.prototype.next = function() {
818
- var value = this.value;
819
- if (value + 1 < MAX_INT) return new SmallInteger(value + 1);
820
- return new BigInteger(MAX_INT_ARR, false);
821
- };
822
- NativeBigInt.prototype.next = function() {
823
- return new NativeBigInt(this.value + BigInt(1));
824
- };
825
- BigInteger.prototype.prev = function() {
826
- var value = this.value;
827
- if (this.sign) {
828
- return new BigInteger(addSmall(value, 1), true);
829
- }
830
- return subtractSmall(value, 1, this.sign);
831
- };
832
- SmallInteger.prototype.prev = function() {
833
- var value = this.value;
834
- if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
835
- return new BigInteger(MAX_INT_ARR, true);
836
- };
837
- NativeBigInt.prototype.prev = function() {
838
- return new NativeBigInt(this.value - BigInt(1));
839
- };
840
- var powersOfTwo = [1];
841
- while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
842
- var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
843
- function shift_isSmall(n) {
844
- return Math.abs(n) <= BASE;
845
- }
846
- BigInteger.prototype.shiftLeft = function(v) {
847
- var n = parseValue(v).toJSNumber();
848
- if (!shift_isSmall(n)) {
849
- throw new Error(String(n) + " is too large for shifting.");
850
- }
851
- if (n < 0) return this.shiftRight(-n);
852
- var result = this;
853
- if (result.isZero()) return result;
854
- while (n >= powers2Length) {
855
- result = result.multiply(highestPower2);
856
- n -= powers2Length - 1;
857
- }
858
- return result.multiply(powersOfTwo[n]);
859
- };
860
- NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
861
- BigInteger.prototype.shiftRight = function(v) {
862
- var remQuo;
863
- var n = parseValue(v).toJSNumber();
864
- if (!shift_isSmall(n)) {
865
- throw new Error(String(n) + " is too large for shifting.");
866
- }
867
- if (n < 0) return this.shiftLeft(-n);
868
- var result = this;
869
- while (n >= powers2Length) {
870
- if (result.isZero() || result.isNegative() && result.isUnit()) return result;
871
- remQuo = divModAny(result, highestPower2);
872
- result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
873
- n -= powers2Length - 1;
874
- }
875
- remQuo = divModAny(result, powersOfTwo[n]);
876
- return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
877
- };
878
- NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
879
- function bitwise(x, y, fn) {
880
- y = parseValue(y);
881
- var xSign = x.isNegative(), ySign = y.isNegative();
882
- var xRem = xSign ? x.not() : x, yRem = ySign ? y.not() : y;
883
- var xDigit = 0, yDigit = 0;
884
- var xDivMod = null, yDivMod = null;
885
- var result = [];
886
- while (!xRem.isZero() || !yRem.isZero()) {
887
- xDivMod = divModAny(xRem, highestPower2);
888
- xDigit = xDivMod[1].toJSNumber();
889
- if (xSign) {
890
- xDigit = highestPower2 - 1 - xDigit;
891
- }
892
- yDivMod = divModAny(yRem, highestPower2);
893
- yDigit = yDivMod[1].toJSNumber();
894
- if (ySign) {
895
- yDigit = highestPower2 - 1 - yDigit;
896
- }
897
- xRem = xDivMod[0];
898
- yRem = yDivMod[0];
899
- result.push(fn(xDigit, yDigit));
900
- }
901
- var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);
902
- for (var i2 = result.length - 1; i2 >= 0; i2 -= 1) {
903
- sum = sum.multiply(highestPower2).add(bigInt(result[i2]));
904
- }
905
- return sum;
906
- }
907
- BigInteger.prototype.not = function() {
908
- return this.negate().prev();
909
- };
910
- NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not;
911
- BigInteger.prototype.and = function(n) {
912
- return bitwise(this, n, function(a, b) {
913
- return a & b;
914
- });
915
- };
916
- NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and;
917
- BigInteger.prototype.or = function(n) {
918
- return bitwise(this, n, function(a, b) {
919
- return a | b;
920
- });
921
- };
922
- NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or;
923
- BigInteger.prototype.xor = function(n) {
924
- return bitwise(this, n, function(a, b) {
925
- return a ^ b;
926
- });
927
- };
928
- NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;
929
- var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
930
- function roughLOB(n) {
931
- var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : typeof v === "bigint" ? v | BigInt(LOBMASK_I) : v[0] + v[1] * BASE | LOBMASK_BI;
932
- return x & -x;
933
- }
934
- function integerLogarithm(value, base) {
935
- if (base.compareTo(value) <= 0) {
936
- var tmp = integerLogarithm(value, base.square(base));
937
- var p = tmp.p;
938
- var e = tmp.e;
939
- var t = p.multiply(base);
940
- return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p, e: e * 2 };
941
- }
942
- return { p: bigInt(1), e: 0 };
943
- }
944
- BigInteger.prototype.bitLength = function() {
945
- var n = this;
946
- if (n.compareTo(bigInt(0)) < 0) {
947
- n = n.negate().subtract(bigInt(1));
948
- }
949
- if (n.compareTo(bigInt(0)) === 0) {
950
- return bigInt(0);
951
- }
952
- return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));
953
- };
954
- NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;
955
- function max(a, b) {
956
- a = parseValue(a);
957
- b = parseValue(b);
958
- return a.greater(b) ? a : b;
959
- }
960
- function min(a, b) {
961
- a = parseValue(a);
962
- b = parseValue(b);
963
- return a.lesser(b) ? a : b;
964
- }
965
- function gcd(a, b) {
966
- a = parseValue(a).abs();
967
- b = parseValue(b).abs();
968
- if (a.equals(b)) return a;
969
- if (a.isZero()) return b;
970
- if (b.isZero()) return a;
971
- var c = Integer[1], d, t;
972
- while (a.isEven() && b.isEven()) {
973
- d = min(roughLOB(a), roughLOB(b));
974
- a = a.divide(d);
975
- b = b.divide(d);
976
- c = c.multiply(d);
977
- }
978
- while (a.isEven()) {
979
- a = a.divide(roughLOB(a));
980
- }
981
- do {
982
- while (b.isEven()) {
983
- b = b.divide(roughLOB(b));
984
- }
985
- if (a.greater(b)) {
986
- t = b;
987
- b = a;
988
- a = t;
989
- }
990
- b = b.subtract(a);
991
- } while (!b.isZero());
992
- return c.isUnit() ? a : a.multiply(c);
993
- }
994
- function lcm(a, b) {
995
- a = parseValue(a).abs();
996
- b = parseValue(b).abs();
997
- return a.divide(gcd(a, b)).multiply(b);
998
- }
999
- function randBetween(a, b, rng) {
1000
- a = parseValue(a);
1001
- b = parseValue(b);
1002
- var usedRNG = rng || Math.random;
1003
- var low = min(a, b), high = max(a, b);
1004
- var range = high.subtract(low).add(1);
1005
- if (range.isSmall) return low.add(Math.floor(usedRNG() * range));
1006
- var digits = toBase(range, BASE).value;
1007
- var result = [], restricted = true;
1008
- for (var i2 = 0; i2 < digits.length; i2++) {
1009
- var top = restricted ? digits[i2] + (i2 + 1 < digits.length ? digits[i2 + 1] / BASE : 0) : BASE;
1010
- var digit = truncate(usedRNG() * top);
1011
- result.push(digit);
1012
- if (digit < digits[i2]) restricted = false;
1013
- }
1014
- return low.add(Integer.fromArray(result, BASE, false));
1015
- }
1016
- var parseBase = function(text, base, alphabet, caseSensitive) {
1017
- alphabet = alphabet || DEFAULT_ALPHABET;
1018
- text = String(text);
1019
- if (!caseSensitive) {
1020
- text = text.toLowerCase();
1021
- alphabet = alphabet.toLowerCase();
1022
- }
1023
- var length = text.length;
1024
- var i2;
1025
- var absBase = Math.abs(base);
1026
- var alphabetValues = {};
1027
- for (i2 = 0; i2 < alphabet.length; i2++) {
1028
- alphabetValues[alphabet[i2]] = i2;
1029
- }
1030
- for (i2 = 0; i2 < length; i2++) {
1031
- var c = text[i2];
1032
- if (c === "-") continue;
1033
- if (c in alphabetValues) {
1034
- if (alphabetValues[c] >= absBase) {
1035
- if (c === "1" && absBase === 1) continue;
1036
- throw new Error(c + " is not a valid digit in base " + base + ".");
1037
- }
1038
- }
1039
- }
1040
- base = parseValue(base);
1041
- var digits = [];
1042
- var isNegative = text[0] === "-";
1043
- for (i2 = isNegative ? 1 : 0; i2 < text.length; i2++) {
1044
- var c = text[i2];
1045
- if (c in alphabetValues) digits.push(parseValue(alphabetValues[c]));
1046
- else if (c === "<") {
1047
- var start = i2;
1048
- do {
1049
- i2++;
1050
- } while (text[i2] !== ">" && i2 < text.length);
1051
- digits.push(parseValue(text.slice(start + 1, i2)));
1052
- } else throw new Error(c + " is not a valid character");
1053
- }
1054
- return parseBaseFromArray(digits, base, isNegative);
1055
- };
1056
- function parseBaseFromArray(digits, base, isNegative) {
1057
- var val = Integer[0], pow = Integer[1], i2;
1058
- for (i2 = digits.length - 1; i2 >= 0; i2--) {
1059
- val = val.add(digits[i2].times(pow));
1060
- pow = pow.times(base);
1061
- }
1062
- return isNegative ? val.negate() : val;
1063
- }
1064
- function stringify(digit, alphabet) {
1065
- alphabet = alphabet || DEFAULT_ALPHABET;
1066
- if (digit < alphabet.length) {
1067
- return alphabet[digit];
1068
- }
1069
- return "<" + digit + ">";
1070
- }
1071
- function toBase(n, base) {
1072
- base = bigInt(base);
1073
- if (base.isZero()) {
1074
- if (n.isZero()) return { value: [0], isNegative: false };
1075
- throw new Error("Cannot convert nonzero numbers to base 0.");
1076
- }
1077
- if (base.equals(-1)) {
1078
- if (n.isZero()) return { value: [0], isNegative: false };
1079
- if (n.isNegative())
1080
- return {
1081
- value: [].concat.apply(
1082
- [],
1083
- Array.apply(null, Array(-n.toJSNumber())).map(Array.prototype.valueOf, [1, 0])
1084
- ),
1085
- isNegative: false
1086
- };
1087
- var arr = Array.apply(null, Array(n.toJSNumber() - 1)).map(Array.prototype.valueOf, [0, 1]);
1088
- arr.unshift([1]);
1089
- return {
1090
- value: [].concat.apply([], arr),
1091
- isNegative: false
1092
- };
1093
- }
1094
- var neg = false;
1095
- if (n.isNegative() && base.isPositive()) {
1096
- neg = true;
1097
- n = n.abs();
1098
- }
1099
- if (base.isUnit()) {
1100
- if (n.isZero()) return { value: [0], isNegative: false };
1101
- return {
1102
- value: Array.apply(null, Array(n.toJSNumber())).map(Number.prototype.valueOf, 1),
1103
- isNegative: neg
1104
- };
1105
- }
1106
- var out = [];
1107
- var left = n, divmod;
1108
- while (left.isNegative() || left.compareAbs(base) >= 0) {
1109
- divmod = left.divmod(base);
1110
- left = divmod.quotient;
1111
- var digit = divmod.remainder;
1112
- if (digit.isNegative()) {
1113
- digit = base.minus(digit).abs();
1114
- left = left.next();
1115
- }
1116
- out.push(digit.toJSNumber());
1117
- }
1118
- out.push(left.toJSNumber());
1119
- return { value: out.reverse(), isNegative: neg };
1120
- }
1121
- function toBaseString(n, base, alphabet) {
1122
- var arr = toBase(n, base);
1123
- return (arr.isNegative ? "-" : "") + arr.value.map(function(x) {
1124
- return stringify(x, alphabet);
1125
- }).join("");
1126
- }
1127
- BigInteger.prototype.toArray = function(radix) {
1128
- return toBase(this, radix);
1129
- };
1130
- SmallInteger.prototype.toArray = function(radix) {
1131
- return toBase(this, radix);
1132
- };
1133
- NativeBigInt.prototype.toArray = function(radix) {
1134
- return toBase(this, radix);
1135
- };
1136
- BigInteger.prototype.toString = function(radix, alphabet) {
1137
- if (radix === undefined) radix = 10;
1138
- if (radix !== 10 || alphabet) return toBaseString(this, radix, alphabet);
1139
- var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit;
1140
- while (--l >= 0) {
1141
- digit = String(v[l]);
1142
- str += zeros.slice(digit.length) + digit;
1143
- }
1144
- var sign = this.sign ? "-" : "";
1145
- return sign + str;
1146
- };
1147
- SmallInteger.prototype.toString = function(radix, alphabet) {
1148
- if (radix === undefined) radix = 10;
1149
- if (radix != 10 || alphabet) return toBaseString(this, radix, alphabet);
1150
- return String(this.value);
1151
- };
1152
- NativeBigInt.prototype.toString = SmallInteger.prototype.toString;
1153
- NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function() {
1154
- return this.toString();
1155
- };
1156
- BigInteger.prototype.valueOf = function() {
1157
- return parseInt(this.toString(), 10);
1158
- };
1159
- BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
1160
- SmallInteger.prototype.valueOf = function() {
1161
- return this.value;
1162
- };
1163
- SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
1164
- NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function() {
1165
- return parseInt(this.toString(), 10);
1166
- };
1167
- function parseStringValue(v) {
1168
- if (isPrecise(+v)) {
1169
- var x = +v;
1170
- if (x === truncate(x))
1171
- return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x);
1172
- throw new Error("Invalid integer: " + v);
1173
- }
1174
- var sign = v[0] === "-";
1175
- if (sign) v = v.slice(1);
1176
- var split = v.split(/e/i);
1177
- if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
1178
- if (split.length === 2) {
1179
- var exp = split[1];
1180
- if (exp[0] === "+") exp = exp.slice(1);
1181
- exp = +exp;
1182
- if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
1183
- var text = split[0];
1184
- var decimalPlace = text.indexOf(".");
1185
- if (decimalPlace >= 0) {
1186
- exp -= text.length - decimalPlace - 1;
1187
- text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
1188
- }
1189
- if (exp < 0) throw new Error("Cannot include negative exponent part for integers");
1190
- text += new Array(exp + 1).join("0");
1191
- v = text;
1192
- }
1193
- var isValid = /^([0-9][0-9]*)$/.test(v);
1194
- if (!isValid) throw new Error("Invalid integer: " + v);
1195
- if (supportsNativeBigInt) {
1196
- return new NativeBigInt(BigInt(sign ? "-" + v : v));
1197
- }
1198
- var r = [], max2 = v.length, l = LOG_BASE, min2 = max2 - l;
1199
- while (max2 > 0) {
1200
- r.push(+v.slice(min2, max2));
1201
- min2 -= l;
1202
- if (min2 < 0) min2 = 0;
1203
- max2 -= l;
1204
- }
1205
- trim(r);
1206
- return new BigInteger(r, sign);
1207
- }
1208
- function parseNumberValue(v) {
1209
- if (supportsNativeBigInt) {
1210
- return new NativeBigInt(BigInt(v));
1211
- }
1212
- if (isPrecise(v)) {
1213
- if (v !== truncate(v)) throw new Error(v + " is not an integer.");
1214
- return new SmallInteger(v);
1215
- }
1216
- return parseStringValue(v.toString());
1217
- }
1218
- function parseValue(v) {
1219
- if (typeof v === "number") {
1220
- return parseNumberValue(v);
1221
- }
1222
- if (typeof v === "string") {
1223
- return parseStringValue(v);
1224
- }
1225
- if (typeof v === "bigint") {
1226
- return new NativeBigInt(v);
1227
- }
1228
- return v;
1229
- }
1230
- for (var i = 0; i < 1e3; i++) {
1231
- Integer[i] = parseValue(i);
1232
- if (i > 0) Integer[-i] = parseValue(-i);
1233
- }
1234
- Integer.one = Integer[1];
1235
- Integer.zero = Integer[0];
1236
- Integer.minusOne = Integer[-1];
1237
- Integer.max = max;
1238
- Integer.min = min;
1239
- Integer.gcd = gcd;
1240
- Integer.lcm = lcm;
1241
- Integer.isInstance = function(x) {
1242
- return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt;
1243
- };
1244
- Integer.randBetween = randBetween;
1245
- Integer.fromArray = function(digits, base, isNegative) {
1246
- return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative);
1247
- };
1248
- return Integer;
1249
- })();
1250
- if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
1251
- module.exports = bigInt;
1252
- }
1253
- if (typeof define === "function" && define.amd) {
1254
- define(function() {
1255
- return bigInt;
1256
- });
1257
- }
1258
- }
1259
- });
1260
-
1261
- export {
1262
- require_BigInteger
1263
- };