powiaina_num.js 0.2.0 → 0.2.2

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.
@@ -4,6 +4,51 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.PowiainaNum = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
11
+ }
12
+ function _arrayWithoutHoles(r) {
13
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
14
+ }
15
+ function _classCallCheck(a, n) {
16
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
17
+ }
18
+ function _defineProperties(e, r) {
19
+ for (var t = 0; t < r.length; t++) {
20
+ var o = r[t];
21
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
22
+ }
23
+ }
24
+ function _createClass(e, r, t) {
25
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
26
+ writable: !1
27
+ }), e;
28
+ }
29
+ function _iterableToArray(r) {
30
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
31
+ }
32
+ function _nonIterableSpread() {
33
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
34
+ }
35
+ function _toConsumableArray(r) {
36
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
37
+ }
38
+ function _toPrimitive(t, r) {
39
+ if ("object" != typeof t || !t) return t;
40
+ var e = t[Symbol.toPrimitive];
41
+ if (void 0 !== e) {
42
+ var i = e.call(t, r || "default");
43
+ if ("object" != typeof i) return i;
44
+ throw new TypeError("@@toPrimitive must return a primitive value.");
45
+ }
46
+ return ("string" === r ? String : Number)(t);
47
+ }
48
+ function _toPropertyKey(t) {
49
+ var i = _toPrimitive(t, "string");
50
+ return "symbol" == typeof i ? i : i + "";
51
+ }
7
52
  function _typeof(o) {
8
53
  "@babel/helpers - typeof";
9
54
 
@@ -13,37 +58,16 @@
13
58
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
14
59
  }, _typeof(o);
15
60
  }
61
+ function _unsupportedIterableToArray(r, a) {
62
+ if (r) {
63
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
64
+ var t = {}.toString.call(r).slice(8, -1);
65
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
66
+ }
67
+ }
16
68
 
17
- /******************************************************************************
18
- Copyright (c) Microsoft Corporation.
19
-
20
- Permission to use, copy, modify, and/or distribute this software for any
21
- purpose with or without fee is hereby granted.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
24
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
27
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
28
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
- PERFORMANCE OF THIS SOFTWARE.
30
- ***************************************************************************** */
31
-
32
- function __spreadArray(to, from, pack) {
33
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
34
- if (ar || !(i in from)) {
35
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
36
- ar[i] = from[i];
37
- }
38
- }
39
- return to.concat(ar || Array.prototype.slice.call(from));
40
- }
41
-
42
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
43
- var e = new Error(message);
44
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
- };
46
-
69
+ /* Author: VeryrrDefine 0.2.0-beta.1.1*/
70
+ var _a;
47
71
  var powiainaNumError = "[PowiainaNum 0.2 error]";
48
72
  var MSI = 9007199254740991;
49
73
  var MSI_LOG10 = 15.954589770191003;
@@ -52,16 +76,10 @@
52
76
  var EXP_E_REC = 1.444667861009766;
53
77
  var isPowiainaNum = /^(PN)?[\/\-\+]*(Infinity|NaN|(P+|P\^\d+ )?(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d*\x20*)*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;
54
78
  //#region some useful functions
55
- function newOperator(r, a, e, m) {
56
- if (a === void 0) {
57
- a = 0;
58
- }
59
- if (e === void 0) {
60
- e = 1;
61
- }
62
- if (m === void 0) {
63
- m = 1;
64
- }
79
+ function newOperator(r) {
80
+ var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
81
+ var e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
82
+ var m = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
65
83
  return {
66
84
  repeat: r,
67
85
  arrow: a,
@@ -70,10 +88,26 @@
70
88
  valuereplaced: a == Infinity ? 0 : e == Infinity ? 1 : -1
71
89
  };
72
90
  }
91
+ // parse 0.1.x PowiainaNum.js string
92
+ function parseLegacyPowiainaNumString(str) {
93
+ var pattern = /l(\d+)\s+s(\d+)\s+a(\[.*\])/;
94
+ var match = str.match(pattern);
95
+ try {
96
+ if (match) {
97
+ return {
98
+ lValue: parseInt(match[1]),
99
+ sValue: parseInt(match[2]),
100
+ array: JSON.parse(match[3])
101
+ };
102
+ }
103
+ } catch (_b) {
104
+ return null;
105
+ }
106
+ return null;
107
+ }
73
108
  function compareTuples() {
74
- var tuples = [];
75
- for (var _i = 0; _i < arguments.length; _i++) {
76
- tuples[_i] = arguments[_i];
109
+ for (var _len = arguments.length, tuples = new Array(_len), _key = 0; _key < _len; _key++) {
110
+ tuples[_key] = arguments[_key];
77
111
  }
78
112
  for (var i = 0; i < Math.min(tuples[0].length, tuples[1].length); i++) {
79
113
  var a = tuples[0][i];
@@ -139,13 +173,7 @@
139
173
  //from https://math.stackexchange.com/a/465183
140
174
  // The evaluation can become inaccurate very close to the branch point
141
175
  // Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
142
- function f_lambertw(z, t, pr) {
143
- if (t === void 0) {
144
- t = 1e-10;
145
- }
146
- if (pr === void 0) {
147
- pr = true;
148
- }
176
+ function f_lambertw(z) {
149
177
  var tol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
150
178
  var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
151
179
  var w;
@@ -199,6 +227,42 @@
199
227
  }
200
228
  return true;
201
229
  }
230
+ function replaceXToInfinity(x) {
231
+ if (x === "x") return Infinity;
232
+ return x;
233
+ }
234
+ function isFourLengthArray(x) {
235
+ return x.length == 4;
236
+ }
237
+ function isFourNumberArray(x) {
238
+ if (typeof x[0] == "number" && typeof x[1] == "number" && typeof x[2] == "number" && typeof x[3] == "number") {
239
+ return true;
240
+ }
241
+ return false;
242
+ }
243
+ function isFourArrayWithFirstTermX(x) {
244
+ if (x[0] === "x" && typeof x[1] == "number" && typeof x[2] == "number" && typeof x[3] == "number") {
245
+ return true;
246
+ }
247
+ return false;
248
+ }
249
+ function isFourArrayWithThirdTermX(x) {
250
+ if (typeof x[0] == "number" && typeof x[1] == "number" && x[2] == "x" && typeof x[3] == "number") {
251
+ return true;
252
+ }
253
+ return false;
254
+ }
255
+ function isPowiainaNum01XArray(x) {
256
+ if (!Array.isArray(x)) return false;
257
+ if (typeof x[0] != "number") return false;
258
+ for (var i = 1; i < x.length; i++) {
259
+ var b = x[i];
260
+ if (!Array.isArray(b)) return false;
261
+ if (!isFourLengthArray(b)) return false;
262
+ if (!isFourNumberArray(b) && !isFourArrayWithFirstTermX(b) && !isFourArrayWithThirdTermX(b)) return false;
263
+ }
264
+ return true;
265
+ }
202
266
  function countLeadingZerosAfterDecimal(numStr) {
203
267
  var match = numStr.match(/^0\.(0*)[1-9]/);
204
268
  return match ? match[1].length : 0;
@@ -214,13 +278,9 @@
214
278
  // at ``-1/e``. In some corner cases, `lambertw` might currently
215
279
  // fail to converge, or can end up on the wrong branch.
216
280
  // Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
217
- function d_lambertw(z, tol, principal) {
218
- if (tol === void 0) {
219
- tol = 1e10;
220
- }
221
- if (principal === void 0) {
222
- principal = true;
223
- }
281
+ function d_lambertw(z) {
282
+ var tol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e10;
283
+ var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
224
284
  z = new PowiainaNum(z);
225
285
  var w;
226
286
  if (!z.isFinite()) return z;
@@ -261,12 +321,13 @@
261
321
  }
262
322
  }
263
323
  //#endregion
264
- var PowiainaNum = /** @class */function () {
324
+ var PowiainaNum = /*#__PURE__*/function () {
265
325
  /**
266
326
  * Constructor of PowiainaNum class,
267
327
  * If no arguments, return `PowiainaNum.NaN`.
268
328
  */
269
329
  function PowiainaNum(arg1) {
330
+ _classCallCheck(this, PowiainaNum);
270
331
  this[_a] = "PowiainaNum";
271
332
  this.array = [{
272
333
  arrow: 0,
@@ -281,11 +342,11 @@
281
342
  var obj = PowiainaNum.fromNumber(arg1);
282
343
  this.resetFromObject(obj);
283
344
  } else if (_typeof(arg1) == "object") {
284
- var obj = PowiainaNum.fromObject(arg1);
285
- this.resetFromObject(obj);
345
+ var _obj = PowiainaNum.fromObject(arg1);
346
+ this.resetFromObject(_obj);
286
347
  } else if (typeof arg1 == "string") {
287
- var obj = PowiainaNum.fromString(arg1);
288
- this.resetFromObject(obj);
348
+ var _obj2 = PowiainaNum.fromString(arg1);
349
+ this.resetFromObject(_obj2);
289
350
  } else ;
290
351
  }
291
352
  //#region 4 Basic calculates.
@@ -293,1981 +354,1507 @@
293
354
  * Addition
294
355
  * @returns the sum of `this` and `other`
295
356
  */
296
- PowiainaNum.prototype.add = function (other) {
297
- var _b, _c, _d, _e;
298
- var x = this.clone();
299
- var y = new PowiainaNum(other);
300
- // inf + -inf = nan
301
- if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.POSITIVE_INFINITY)) return PowiainaNum.NaN.clone();
302
- // inf & nan check
303
- if (!x.isFinite()) return x.clone();
304
- if (!y.isFinite()) return y.clone();
305
- // if x or y = 0, return other.
306
- if (x.isZero()) return y.clone();
307
- if (y.isZero()) return x.clone();
308
- // x+ -x = 0
309
- if (x.sign == -y.sign && function () {
310
- var a = x.abs();
311
- var b = y.abs();
312
- return a.eq(b);
313
- }()) return PowiainaNum.ZERO.clone();
314
- // Run pure number calculates in there
315
- if (x.abs().lt(MSI) && y.abs().lt(MSI)) {
316
- return PowiainaNum.fromNumber(x.toNumber() + y.toNumber());
317
- }
318
- // calculate anything > e9e15 or <e-9e15, take absval bigger.
319
- if (x.abs().lt(PowiainaNum.E_MSI_REC) || x.abs().gt(PowiainaNum.E_MSI) || y.abs().lt(PowiainaNum.E_MSI_REC) || y.abs().gt(PowiainaNum.E_MSI)) {
320
- return x.maxabs(y);
321
- }
322
- if (x.sign == -1) {
323
- return x.neg().add(y.neg()).neg();
324
- }
325
- // if ((x.sign==1&&y.sign==-1&&x.lt(y.abs())) ) return y.neg().add(x.neg()).neg();
326
- var a, b; //a=bigger, b=smaller
327
- if (x.cmpabs(y) > 0) {
328
- a = x;
329
- b = y;
330
- } else {
331
- b = x;
332
- a = y;
333
- }
334
- var temp = a.toNumber() + b.toNumber();
335
- if (isFinite(temp) && temp !== 0) {
336
- return PowiainaNum.fromNumber(temp);
337
- }
338
- var mult = 1;
339
- if (!a.small && !b.small && !((_b = a.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) && !((_c = b.array[1]) === null || _c === void 0 ? void 0 : _c.repeat) && a.sign == b.sign) {
340
- return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
341
- }
342
- var alog10 = (a.small ? -1 : 1) * (((_d = a.array[1]) === null || _d === void 0 ? void 0 : _d.repeat) ? a.array[0].repeat : Math.log10(a.array[0].repeat));
343
- var blog10 = (b.small ? -1 : 1) * (((_e = b.array[1]) === null || _e === void 0 ? void 0 : _e.repeat) ? b.array[0].repeat : Math.log10(b.array[0].repeat));
344
- if (alog10 - blog10 > MSI_LOG10) return a;
345
- var offset = -Math.floor(alog10); //a number can make a+off in [0,1)
346
- var r,
347
- l = 0,
348
- t;
349
- t = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
350
- if (t > 0) l = Math.log10(t) - offset;
351
- if (t < 0) {
352
- l = Math.log10(-t) - offset;
353
- mult *= -1;
354
- }
355
- if (t == 0) throw Error("Encounter a calculate error");
356
- r = new PowiainaNum();
357
- r.sign = 1;
358
- if (l > MSI_LOG10 || l < -MSI_LOG10) {
359
- r.array = [newOperator(l, 0), newOperator(1, 1)];
360
- } else {
361
- r.array = [newOperator(Math.pow(10, Math.abs(l)), 0)];
362
- }
363
- r.small = l < 0 ? true : false;
364
- r.sign *= mult;
365
- return r;
366
- };
367
- PowiainaNum.add = function (t, other) {
368
- return new PowiainaNum(t).add(other);
369
- };
370
- PowiainaNum.prototype.sub = function (a) {
371
- return this.add(new PowiainaNum(a).neg());
372
- };
373
- PowiainaNum.sub = function (t, other) {
374
- return new PowiainaNum(t).sub(other);
375
- };
376
- PowiainaNum.prototype.mul = function (other) {
377
- var x = this.clone();
378
- var y = new PowiainaNum(other);
379
- // inf * -inf = -inf
380
- if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || y.eq(PowiainaNum.POSITIVE_INFINITY) && x.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.NEGATIVE_INFINITY.clone();
381
- if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
382
- if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
383
- // inf & nan check
384
- if (!x.isFinite()) return x.clone();
385
- if (!y.isFinite()) return y.clone();
386
- if (x.isZero() || y.isZero()) return PowiainaNum.ZERO.clone();
387
- // x* x^-1 = 0
388
- /* if (x.small==1-y.small&&(function(){
389
- let a = x.abs();
390
- let b = y.abs();
391
- return a.eq(b)
392
- })()) return (function () {
393
- let a = new PowiainaNum(1);
394
- a.sign = x.sign*y.sign as -1|0| 1;
395
- return a;
396
- })(); */
397
- // calculate use number directly using number
398
- var t = x.toNumber() * y.toNumber();
399
- if (isFinite(t) && t !== 0) {
400
- return PowiainaNum.fromNumber(t);
401
- }
402
- var r;
403
- r = x.abs().log10().add(y.abs().log10()).pow10();
404
- r.sign = x.sign * y.sign;
405
- return r;
406
- };
407
- PowiainaNum.mul = function (t, other) {
408
- return new PowiainaNum(t).mul(other);
409
- };
410
- PowiainaNum.prototype.div = function (other) {
411
- var x = new PowiainaNum(other).rec();
412
- return this.mul(x);
413
- };
414
- PowiainaNum.div = function (t, other) {
415
- return new PowiainaNum(t).div(other);
416
- };
417
- PowiainaNum.prototype.mod = function (x) {
418
- var other = new PowiainaNum(x);
419
- var division = this.div(other);
420
- return division.sub(division.floor()).mul(other);
421
- };
422
- //#endregion
423
- //#region power
424
- /**
425
- * @returns 10 to the power of `this`
426
- */
427
- PowiainaNum.prototype.pow10 = function () {
428
- var _b, _c;
429
- var r = this.clone();
430
- // inf & nan check
431
- if (!this.isFinite()) return this.clone();
432
- if (r.isneg()) {
433
- // 10^(-x) = 1/(10^x)
434
- r.sign *= -1;
435
- return r.pow10().rec();
436
- }
437
- if (r.lte(308.25471555991675)) {
438
- return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
439
- }
440
- if (r.small) {
441
- if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
442
- return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
443
- }
444
- if (r.gt(PowiainaNum.TETRATED_MSI)) return r;
445
- r.setOperator(((_c = (_b = r.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
446
- r.normalize();
447
- return r;
448
- };
449
- PowiainaNum.prototype.pow = function (x) {
450
- var other = new PowiainaNum(x);
451
- if (this.eq(1)) return PowiainaNum.ONE.clone();
452
- if (!other.isFinite()) return other.clone();
453
- if (!this.isFinite()) return this.clone();
454
- if (this.eq(10)) return other.pow10();
455
- if (this.isneg()) {
456
- if (!other.isInt()) return PowiainaNum.NaN.clone();
457
- var r = this.abs().pow(other);
458
- r.sign = function () {
459
- var a = other.mod(2).round();
460
- if (a.eq(0) || a.eq(2)) return 1;
461
- return -1;
462
- }();
357
+ return _createClass(PowiainaNum, [{
358
+ key: "add",
359
+ value: function add(other) {
360
+ var _b, _c, _d, _e;
361
+ var x = this.clone();
362
+ var y = new PowiainaNum(other);
363
+ // inf + -inf = nan
364
+ if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.POSITIVE_INFINITY)) return PowiainaNum.NaN.clone();
365
+ // inf & nan check
366
+ if (!x.isFinite()) return x.clone();
367
+ if (!y.isFinite()) return y.clone();
368
+ // if x or y = 0, return other.
369
+ if (x.isZero()) return y.clone();
370
+ if (y.isZero()) return x.clone();
371
+ // x+ -x = 0
372
+ if (x.sign == -y.sign && function () {
373
+ var a = x.abs();
374
+ var b = y.abs();
375
+ return a.eq(b);
376
+ }()) return PowiainaNum.ZERO.clone();
377
+ // Run pure number calculates in there
378
+ if (x.abs().lt(MSI) && y.abs().lt(MSI)) {
379
+ return PowiainaNum.fromNumber(x.toNumber() + y.toNumber());
380
+ }
381
+ // calculate anything > e9e15 or <e-9e15, take absval bigger.
382
+ if (x.abs().lt(PowiainaNum.E_MSI_REC) || x.abs().gt(PowiainaNum.E_MSI) || y.abs().lt(PowiainaNum.E_MSI_REC) || y.abs().gt(PowiainaNum.E_MSI)) {
383
+ return x.maxabs(y);
384
+ }
385
+ if (x.sign == -1) {
386
+ return x.neg().add(y.neg()).neg();
387
+ }
388
+ // if ((x.sign==1&&y.sign==-1&&x.lt(y.abs())) ) return y.neg().add(x.neg()).neg();
389
+ var a, b; //a=bigger, b=smaller
390
+ if (x.cmpabs(y) > 0) {
391
+ a = x;
392
+ b = y;
393
+ } else {
394
+ b = x;
395
+ a = y;
396
+ }
397
+ var temp = a.toNumber() + b.toNumber();
398
+ if (isFinite(temp) && temp !== 0) {
399
+ return PowiainaNum.fromNumber(temp);
400
+ }
401
+ var mult = 1;
402
+ if (!a.small && !b.small && !((_b = a.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) && !((_c = b.array[1]) === null || _c === void 0 ? void 0 : _c.repeat) && a.sign == b.sign) {
403
+ return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
404
+ }
405
+ var alog10 = (a.small ? -1 : 1) * (((_d = a.array[1]) === null || _d === void 0 ? void 0 : _d.repeat) ? a.array[0].repeat : Math.log10(a.array[0].repeat));
406
+ var blog10 = (b.small ? -1 : 1) * (((_e = b.array[1]) === null || _e === void 0 ? void 0 : _e.repeat) ? b.array[0].repeat : Math.log10(b.array[0].repeat));
407
+ if (alog10 - blog10 > MSI_LOG10) return a;
408
+ var offset = -Math.floor(alog10); //a number can make a+off in [0,1)
409
+ var r,
410
+ l = 0,
411
+ t;
412
+ t = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
413
+ if (t > 0) l = Math.log10(t) - offset;
414
+ if (t < 0) {
415
+ l = Math.log10(-t) - offset;
416
+ mult *= -1;
417
+ }
418
+ if (t == 0) throw Error("Encounter a calculate error");
419
+ r = new PowiainaNum();
420
+ r.sign = 1;
421
+ if (l > MSI_LOG10 || l < -MSI_LOG10) {
422
+ r.array = [newOperator(l, 0), newOperator(1, 1)];
423
+ } else {
424
+ r.array = [newOperator(Math.pow(10, Math.abs(l)), 0)];
425
+ }
426
+ r.small = l < 0 ? true : false;
427
+ r.sign *= mult;
463
428
  return r;
464
429
  }
465
- var a = this.toNumber();
466
- var b = other.toNumber();
467
- var t = Math.pow(a, b);
468
- if (isFinite(t) && t !== 0) {
469
- // optimize?
470
- return PowiainaNum.fromNumber(t);
471
- }
472
- if (this.isZero() && other.isZero()) {
473
- return PowiainaNum.ONE.clone();
474
- }
475
- if (this.isZero()) return PowiainaNum.ZERO.clone();
476
- if (other.isZero()) return PowiainaNum.ONE.clone();
477
- // if this<0, check other' rec is oddd
478
- if (this.gt(0)) {
479
- // log10(a^b) = b log10(a)
480
- return this.log10().mul(other).pow10();
481
- } else if (other.rec().mod(2).eq(1)) {
482
- return this.neg().log10().mul(other).pow10().neg();
483
- }
484
- return PowiainaNum.NaN.clone();
485
- };
486
- PowiainaNum.prototype.pow_base = function (x) {
487
- var a = new PowiainaNum(x);
488
- return a.pow(this);
489
- };
490
- PowiainaNum.pow = function (t, other) {
491
- return new PowiainaNum(t).pow(other);
492
- };
493
- PowiainaNum.prototype.root = function (x) {
494
- var other = new PowiainaNum(x);
495
- return this.pow(other.rec());
496
- };
497
- PowiainaNum.root = function (t, other) {
498
- return new PowiainaNum(t).root(other);
499
- };
500
- PowiainaNum.prototype.sqrt = function () {
501
- return this.pow(0.5);
502
- };
503
- PowiainaNum.sqrt = function (t) {
504
- return new PowiainaNum(t).sqrt();
505
- };
506
- PowiainaNum.prototype.cbrt = function () {
507
- return this.abs().root(3).mul(this.sign);
508
- };
509
- PowiainaNum.cbrt = function (t) {
510
- return new PowiainaNum(t).cbrt();
511
- };
512
- PowiainaNum.prototype.log10 = function () {
513
- if (this.isneg()) return PowiainaNum.NaN.clone();
514
- if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
515
- if (this.small) {
516
- var x_1 = this.clone();
517
- x_1.small = !x_1.small;
518
- return x_1.log10().neg();
519
- }
520
- if (this.array.length == 1) return new PowiainaNum(Math.log10(this.array[0].repeat));
521
- if (this.gte(PowiainaNum.TETRATED_MSI)) return this.clone();
522
- var x = this.clone();
523
- x.array[1].repeat = x.array[1].repeat - 1;
524
- x.normalize();
525
- return x;
526
- };
527
- PowiainaNum.log10 = function (t) {
528
- return new PowiainaNum(t).log10();
529
- };
530
- PowiainaNum.prototype.log = function (base) {
531
- if (base === void 0) {
532
- base = Math.E;
533
- }
534
- // log_a b = log_x b / log_x a;
535
- var other = new PowiainaNum(base);
536
- return this.log10().div(other.log10());
537
- };
538
- PowiainaNum.log = function (t, base) {
539
- if (base === void 0) {
540
- base = Math.E;
430
+ }, {
431
+ key: "sub",
432
+ value: function sub(a) {
433
+ return this.add(new PowiainaNum(a).neg());
434
+ }
435
+ }, {
436
+ key: "mul",
437
+ value: function mul(other) {
438
+ var x = this.clone();
439
+ var y = new PowiainaNum(other);
440
+ // inf * -inf = -inf
441
+ if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || y.eq(PowiainaNum.POSITIVE_INFINITY) && x.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.NEGATIVE_INFINITY.clone();
442
+ if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
443
+ if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
444
+ // inf & nan check
445
+ if (!x.isFinite()) return x.clone();
446
+ if (!y.isFinite()) return y.clone();
447
+ if (x.isZero() || y.isZero()) return PowiainaNum.ZERO.clone();
448
+ // x* x^-1 = 0
449
+ /* if (x.small==1-y.small&&(function(){
450
+ let a = x.abs();
451
+ let b = y.abs();
452
+ return a.eq(b)
453
+ })()) return (function () {
454
+ let a = new PowiainaNum(1);
455
+ a.sign = x.sign*y.sign as -1|0| 1;
456
+ return a;
457
+ })(); */
458
+ // calculate use number directly using number
459
+ var t = x.toNumber() * y.toNumber();
460
+ if (isFinite(t) && t !== 0) {
461
+ return PowiainaNum.fromNumber(t);
462
+ }
463
+ var r;
464
+ r = x.abs().log10().add(y.abs().log10()).pow10();
465
+ r.sign = x.sign * y.sign;
466
+ return r;
541
467
  }
542
- return new PowiainaNum(t).log(base);
543
- };
544
- PowiainaNum.prototype.ln = function () {
545
- return this.log();
546
- };
547
- /**
548
- * positive-Log10, Returns the base-10 logarithm of nonnegative Decimals, but returns 0 for negative Decimals.
549
- */
550
- PowiainaNum.prototype.pLog10 = function () {
551
- if (this.isneg()) return PowiainaNum.ZERO;
552
- return this.log10();
553
- };
554
- /**
555
- * positive-Log10
556
- */
557
- PowiainaNum.pLog10 = function (t) {
558
- return new PowiainaNum(t).pLog10();
559
- };
560
- PowiainaNum.exp = function (x) {
561
- var y = new PowiainaNum(x);
562
- return y.pow_base(Math.E);
563
- };
564
- PowiainaNum.prototype.exp = function () {
565
- return this.pow_base(Math.E);
566
- };
567
- //#endregion
568
- //#region some math functions
569
- /**
570
- * For positive integers, X factorial (written as X!) equals X * (X - 1) * (X - 2) *... * 3 * 2 * 1. 0! equals 1.
571
- * This can be extended to real numbers (except for negative integers) via the gamma function, which is what this function does.
572
- */
573
- //[Code from break_eternity.js]
574
- PowiainaNum.prototype.factorial = function () {
575
- if (this.abs().lt(MSI)) {
576
- return this.add(1).gamma();
577
- } else if (this.abs().lt(PowiainaNum.E_MSI)) {
578
- return PowiainaNum.exp(this.mul(this.log10().sub(1)));
579
- } else {
580
- return PowiainaNum.exp(this);
468
+ }, {
469
+ key: "div",
470
+ value: function div(other) {
471
+ var x = new PowiainaNum(other).rec();
472
+ return this.mul(x);
473
+ }
474
+ }, {
475
+ key: "mod",
476
+ value: function mod(x) {
477
+ var other = new PowiainaNum(x);
478
+ var division = this.div(other);
479
+ return division.sub(division.floor()).mul(other);
480
+ }
481
+ //#endregion
482
+ //#region power
483
+ /**
484
+ * @returns 10 to the power of `this`
485
+ */
486
+ }, {
487
+ key: "pow10",
488
+ value: function pow10() {
489
+ var _b, _c;
490
+ var r = this.clone();
491
+ // inf & nan check
492
+ if (!this.isFinite()) return this.clone();
493
+ if (r.isneg()) {
494
+ // 10^(-x) = 1/(10^x)
495
+ r.sign *= -1;
496
+ return r.pow10().rec();
497
+ }
498
+ if (r.lte(308.25471555991675)) {
499
+ return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
500
+ }
501
+ if (r.small) {
502
+ if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
503
+ return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
504
+ }
505
+ if (r.gt(PowiainaNum.TETRATED_MSI)) return r;
506
+ r.setOperator(((_c = (_b = r.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
507
+ r.normalize();
508
+ return r;
581
509
  }
582
- };
583
- PowiainaNum.factorial = function (x) {
584
- return new PowiainaNum(x).factorial();
585
- };
586
- /**
587
- * The gamma function extends the idea of factorials to non-whole numbers using some calculus.
588
- * Gamma(x) is defined as the integral of t^(x-1) * e^-t dt from t = 0 to t = infinity,
589
- * and gamma(x) = (x - 1)! for nonnegative integer x, so the factorial for non-whole numbers is defined using the gamma function.
590
- */
591
- //[Code from break_eternity.js]
592
- //from HyperCalc source code
593
- PowiainaNum.prototype.gamma = function () {
594
- if (this.small) {
595
- return this.rec();
596
- } else if (this.lte(MSI)) {
597
- if (this.lt(24)) {
598
- return PowiainaNum.fromNumber(f_gamma(this.sign * this.getOperator(0)));
599
- }
600
- var t = this.getOperator(0) - 1;
601
- var l = 0.9189385332046727; //0.5*Math.log(2*Math.PI)
602
- l = l + (t + 0.5) * Math.log(t);
603
- l = l - t;
604
- var n2 = t * t;
605
- var np = t;
606
- var lm = 12 * np;
607
- var adj = 1 / lm;
608
- var l2 = l + adj;
609
- if (l2 === l) {
610
- return PowiainaNum.exp(l);
510
+ }, {
511
+ key: "pow",
512
+ value: function pow(x) {
513
+ var other = new PowiainaNum(x);
514
+ if (this.eq(1)) return PowiainaNum.ONE.clone();
515
+ if (!other.isFinite()) return other.clone();
516
+ if (!this.isFinite()) return this.clone();
517
+ if (this.eq(10)) return other.pow10();
518
+ if (this.isneg()) {
519
+ if (!other.isInt()) return PowiainaNum.NaN.clone();
520
+ var r = this.abs().pow(other);
521
+ r.sign = function () {
522
+ var a = other.mod(2).round();
523
+ if (a.eq(0) || a.eq(2)) return 1;
524
+ return -1;
525
+ }();
526
+ return r;
611
527
  }
612
- l = l2;
613
- np = np * n2;
614
- lm = 360 * np;
615
- adj = 1 / lm;
616
- l2 = l - adj;
617
- if (l2 === l) {
618
- return PowiainaNum.exp(l);
528
+ var a = this.toNumber();
529
+ var b = other.toNumber();
530
+ var t = Math.pow(a, b);
531
+ if (isFinite(t) && t !== 0) {
532
+ // optimize?
533
+ return PowiainaNum.fromNumber(t);
534
+ }
535
+ if (this.isZero() && other.isZero()) {
536
+ return PowiainaNum.ONE.clone();
537
+ }
538
+ if (this.isZero()) return PowiainaNum.ZERO.clone();
539
+ if (other.isZero()) return PowiainaNum.ONE.clone();
540
+ // if this<0, check other' rec is oddd
541
+ if (this.gt(0)) {
542
+ // log10(a^b) = b log10(a)
543
+ return this.log10().mul(other).pow10();
544
+ } else if (other.rec().mod(2).eq(1)) {
545
+ return this.neg().log10().mul(other).pow10().neg();
619
546
  }
620
- l = l2;
621
- np = np * n2;
622
- lm = 1260 * np;
623
- var lt = 1 / lm;
624
- l = l + lt;
625
- np = np * n2;
626
- lm = 1680 * np;
627
- lt = 1 / lm;
628
- l = l - lt;
629
- return PowiainaNum.exp(l);
630
- } else if (this.gt(MSI)) {
631
- return PowiainaNum.exp(this.mul(this.log().sub(1)));
632
- } else {
633
- return PowiainaNum.exp(this);
547
+ return PowiainaNum.NaN.clone();
634
548
  }
635
- };
636
- PowiainaNum.gamma = function (x) {
637
- return new PowiainaNum(x).gamma();
638
- };
639
- /**
640
- * The Lambert W function, also called the omega function or product logarithm, is the solution W(x) === x*e^x.
641
- * https://en.wikipedia.org/wiki/Lambert_W_function
642
- *
643
- * This is a multi-valued function in the complex plane, but only two branches matter for real numbers: the "principal branch" W0, and the "non-principal branch" W_-1.
644
- * W_0 works for any number >= -1/e, but W_-1 only works for nonpositive numbers >= -1/e.
645
- * The "principal" parameter, which is true by default, decides which branch we're looking for: W_0 is used if principal is true, W_-1 is used if principal is false.
646
- */
647
- //Code from break_eternity.js
648
- //Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
649
- PowiainaNum.prototype.lambertw = function (princ) {
650
- if (princ === void 0) {
651
- princ = true;
652
- }
653
- var principal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
654
- if (this.lt(-0.3678794411710499)) {
655
- return PowiainaNum.NaN.clone(); //complex
656
- } else if (principal) {
657
- if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
658
- return PowiainaNum.fromNumber(f_lambertw(this.toNumber()));
659
- } else if (this.lt(MSI)) {
660
- return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0)));
661
- } else if (this.lt("eee15")) {
662
- return d_lambertw(this);
549
+ }, {
550
+ key: "pow_base",
551
+ value: function pow_base(x) {
552
+ var a = new PowiainaNum(x);
553
+ return a.pow(this);
554
+ }
555
+ }, {
556
+ key: "root",
557
+ value: function root(x) {
558
+ var other = new PowiainaNum(x);
559
+ return this.pow(other.rec());
560
+ }
561
+ }, {
562
+ key: "sqrt",
563
+ value: function sqrt() {
564
+ return this.pow(0.5);
565
+ }
566
+ }, {
567
+ key: "cbrt",
568
+ value: function cbrt() {
569
+ return this.abs().root(3).mul(this.sign);
570
+ }
571
+ }, {
572
+ key: "log10",
573
+ value: function log10() {
574
+ if (this.isneg()) return PowiainaNum.NaN.clone();
575
+ if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
576
+ if (this.small) {
577
+ var _x = this.clone();
578
+ _x.small = !_x.small;
579
+ return _x.log10().neg();
580
+ }
581
+ if (this.array.length == 1) return new PowiainaNum(Math.log10(this.array[0].repeat));
582
+ if (this.gte(PowiainaNum.TETRATED_MSI)) return this.clone();
583
+ var x = this.clone();
584
+ x.array[1].repeat = x.array[1].repeat - 1;
585
+ x.normalize();
586
+ return x;
587
+ }
588
+ }, {
589
+ key: "log",
590
+ value: function log() {
591
+ var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Math.E;
592
+ // log_a b = log_x b / log_x a;
593
+ var other = new PowiainaNum(base);
594
+ return this.log10().div(other.log10());
595
+ }
596
+ }, {
597
+ key: "ln",
598
+ value: function ln() {
599
+ return this.log();
600
+ }
601
+ /**
602
+ * positive-Log10, Returns the base-10 logarithm of nonnegative Decimals, but returns 0 for negative Decimals.
603
+ */
604
+ }, {
605
+ key: "pLog10",
606
+ value: function pLog10() {
607
+ if (this.isneg()) return PowiainaNum.ZERO;
608
+ return this.log10();
609
+ }
610
+ /**
611
+ * positive-Log10
612
+ */
613
+ }, {
614
+ key: "exp",
615
+ value: function exp() {
616
+ return this.pow_base(Math.E);
617
+ }
618
+ //#endregion
619
+ //#region some math functions
620
+ /**
621
+ * For positive integers, X factorial (written as X!) equals X * (X - 1) * (X - 2) *... * 3 * 2 * 1. 0! equals 1.
622
+ * This can be extended to real numbers (except for negative integers) via the gamma function, which is what this function does.
623
+ */
624
+ //[Code from break_eternity.js]
625
+ }, {
626
+ key: "factorial",
627
+ value: function factorial() {
628
+ if (this.abs().lt(MSI)) {
629
+ return this.add(1).gamma();
630
+ } else if (this.abs().lt(PowiainaNum.E_MSI)) {
631
+ return PowiainaNum.exp(this.mul(this.log10().sub(1)));
663
632
  } else {
664
- // Numbers this large would sometimes fail to converge using d_lambertw, and at this size this.ln() is close enough
665
- return this.log();
666
- }
667
- } else {
668
- if (this.sign === 1) {
669
- return PowiainaNum.NaN.clone(); //complex
633
+ return PowiainaNum.exp(this);
670
634
  }
671
- if (this.layer === 0) {
672
- return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
673
- } else if (this.layer == 1) {
674
- return d_lambertw(this, 1e-10, false);
635
+ }
636
+ }, {
637
+ key: "gamma",
638
+ value:
639
+ /**
640
+ * The gamma function extends the idea of factorials to non-whole numbers using some calculus.
641
+ * Gamma(x) is defined as the integral of t^(x-1) * e^-t dt from t = 0 to t = infinity,
642
+ * and gamma(x) = (x - 1)! for nonnegative integer x, so the factorial for non-whole numbers is defined using the gamma function.
643
+ */
644
+ //[Code from break_eternity.js]
645
+ //from HyperCalc source code
646
+ function gamma() {
647
+ if (this.small) {
648
+ return this.rec();
649
+ } else if (this.lte(MSI)) {
650
+ if (this.lt(24)) {
651
+ return PowiainaNum.fromNumber(f_gamma(this.sign * this.getOperator(0)));
652
+ }
653
+ var t = this.getOperator(0) - 1;
654
+ var l = 0.9189385332046727; //0.5*Math.log(2*Math.PI)
655
+ l = l + (t + 0.5) * Math.log(t);
656
+ l = l - t;
657
+ var n2 = t * t;
658
+ var np = t;
659
+ var lm = 12 * np;
660
+ var adj = 1 / lm;
661
+ var l2 = l + adj;
662
+ if (l2 === l) {
663
+ return PowiainaNum.exp(l);
664
+ }
665
+ l = l2;
666
+ np = np * n2;
667
+ lm = 360 * np;
668
+ adj = 1 / lm;
669
+ l2 = l - adj;
670
+ if (l2 === l) {
671
+ return PowiainaNum.exp(l);
672
+ }
673
+ l = l2;
674
+ np = np * n2;
675
+ lm = 1260 * np;
676
+ var lt = 1 / lm;
677
+ l = l + lt;
678
+ np = np * n2;
679
+ lm = 1680 * np;
680
+ lt = 1 / lm;
681
+ l = l - lt;
682
+ return PowiainaNum.exp(l);
683
+ } else if (this.gt(MSI)) {
684
+ return PowiainaNum.exp(this.mul(this.log().sub(1)));
675
685
  } else {
676
- return this.neg().rec().lambertw().neg();
686
+ return PowiainaNum.exp(this);
677
687
  }
678
688
  }
679
- };
680
- PowiainaNum.lambertw = function (x, principal) {
681
- if (principal === void 0) {
682
- principal = true;
683
- }
684
- return new PowiainaNum(x).lambertw(principal);
685
- };
686
- //#endregion
687
- //#region higher calculates
688
- //#region Tetration
689
- // Code from ExpantaNum.js
690
- PowiainaNum.prototype.tetrate = function (other2, payload) {
691
- if (payload === void 0) {
692
- payload = 1;
693
- }
694
- var t = this.clone();
695
- var other = new PowiainaNum(other2);
696
- var payl = new PowiainaNum(payload);
697
- if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
698
- if (t.eq(1)) return PowiainaNum.ONE.clone();
699
- if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
700
- var negln;
701
- if (other.isInfi() && other.sign > 0) {
702
- if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
703
- negln = this.log().neg();
704
- return negln.lambertw().div(negln);
705
- }
706
- if (other.lte(-2)) return PowiainaNum.NaN.clone();
707
- if (t.isZero()) {
708
- if (other.isZero()) return PowiainaNum.NaN.clone();
709
- if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
710
- return PowiainaNum.ONE.clone();
711
- }
712
- if (t.eq(PowiainaNum.ONE)) {
713
- if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
714
- return PowiainaNum.ONE.clone();
715
- }
716
- if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
717
- if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
718
- if (other.eq(PowiainaNum.ONE)) return t;
719
- if (other.eq(2)) return t.pow(t);
720
- if (t.eq(2)) {
721
- if (other.eq(3)) return PowiainaNum.fromNumber(16);
722
- if (other.eq(4)) return PowiainaNum.fromNumber(65536);
723
- }
724
- var m = t.max(other);
725
- if (m.gt(PowiainaNum.PENTATED_MSI)) return m;
726
- if (m.gt(PowiainaNum.TETRATED_MSI) || other.gt(MSI)) {
727
- if (this.lt(EXP_E_REC)) {
728
- negln = t.ln().neg();
729
- return negln.lambertw().div(negln);
730
- }
731
- var j = t.slog(10).add(other);
732
- j.setOperator(j.getOperator(2) + 1, 2);
733
- j.normalize();
734
- return j;
735
- }
736
- var y = other.toNumber();
737
- var f = Math.floor(y);
738
- var r = t.pow(y - f);
739
- var l = PowiainaNum.NaN;
740
- var i = 0;
741
- for (var w = PowiainaNum.E_MSI.clone(); f !== 0 && r.lt(w) && i < 100; ++i) {
742
- if (f > 0) {
743
- r = t.pow(r);
744
- if (l.eq(r)) {
745
- f = 0;
746
- break;
689
+ }, {
690
+ key: "lambertw",
691
+ value:
692
+ /**
693
+ * The Lambert W function, also called the omega function or product logarithm, is the solution W(x) === x*e^x.
694
+ * https://en.wikipedia.org/wiki/Lambert_W_function
695
+ *
696
+ * This is a multi-valued function in the complex plane, but only two branches matter for real numbers: the "principal branch" W0, and the "non-principal branch" W_-1.
697
+ * W_0 works for any number >= -1/e, but W_-1 only works for nonpositive numbers >= -1/e.
698
+ * The "principal" parameter, which is true by default, decides which branch we're looking for: W_0 is used if principal is true, W_-1 is used if principal is false.
699
+ */
700
+ //Code from break_eternity.js
701
+ //Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
702
+ function lambertw() {
703
+ var principal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
704
+ if (this.lt(-0.3678794411710499)) {
705
+ return PowiainaNum.NaN.clone(); //complex
706
+ } else if (principal) {
707
+ if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
708
+ return PowiainaNum.fromNumber(f_lambertw(this.toNumber()));
709
+ } else if (this.lt(MSI)) {
710
+ return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0)));
711
+ } else if (this.lt("eee15")) {
712
+ return d_lambertw(this);
713
+ } else {
714
+ // Numbers this large would sometimes fail to converge using d_lambertw, and at this size this.ln() is close enough
715
+ return this.log();
747
716
  }
748
- l = r;
749
- --f;
750
717
  } else {
751
- r = r.log(t);
752
- if (l.eq(r)) {
753
- f = 0;
754
- break;
718
+ if (this.sign === 1) {
719
+ return PowiainaNum.NaN.clone(); //complex
720
+ }
721
+ if (this.layer === 0) {
722
+ return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
723
+ } else if (this.layer == 1) {
724
+ return d_lambertw(this, 1e-10, false);
725
+ } else {
726
+ return this.neg().rec().lambertw().neg();
755
727
  }
756
- l = r;
757
- ++f;
758
728
  }
759
729
  }
760
- if (i == 100 || this.lt(EXP_E_REC)) f = 0;
761
- r.setOperator(r.getOperator(1) + f, 1);
762
- r.normalize();
763
- return r;
764
- };
765
- // Code from ExpantaNum.js
766
- PowiainaNum.prototype.slog = function (base) {
767
- if (base === void 0) {
768
- base = 10;
769
- }
770
- var x = this.clone();
771
- var b = new PowiainaNum(base);
772
- if (x.isInfiNaN()) return x;
773
- if (b.isNaN()) return b;
774
- if (b.isInfi()) return PowiainaNum.ZERO.clone();
775
- if (x.isZero()) return PowiainaNum.ONE.clone();
776
- if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
777
- if (x.eq(b)) return PowiainaNum.ONE.clone();
778
- if (b.lt(EXP_E_REC)) {
779
- var a = b.tetrate(Infinity);
780
- if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
781
- if (x.gt(a)) return PowiainaNum.NaN.clone();
782
- }
783
- if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
784
- if (x.gt(b)) return x;
785
- return PowiainaNum.ZERO.clone();
786
- }
787
- if (x.max(b).gt(PowiainaNum.TETRATED_MSI)) {
788
- if (x.gt(b)) {
789
- x.setOperator(x.getOperator(2) - 1, 2);
790
- x.normalize();
791
- return x.sub(x.getOperator(1));
792
- }
793
- }
794
- if (x.lt(PowiainaNum.ZERO.clone())) return b.pow(x).sub(2);
795
- // base^base^... = x? (? bases)
796
- var r = 0;
797
- // 计算x与base的差距
798
- var t = x.getOperator(1) - b.getOperator(1);
799
- if (t > 3) {
800
- var l = t - 3;
801
- r += l;
802
- x.setOperator(x.getOperator(1) - l, 1);
803
- }
804
- // 假设b=3, x=1e19
805
- for (var i = 0; i < 100; ++i) {
806
- if (x.lt(PowiainaNum.ZERO)) {
807
- x = PowiainaNum.pow(base, x);
808
- --r;
809
- } else if (x.lte(1)) {
810
- // 第五次,进入此处
811
- // 结果=4+0.08795395574340908-1=3.087953...
812
- // 验算3**3**3**(3**.08795395574340908)=10000000000000720000,符合预期
813
- return new PowiainaNum(r + x.toNumber() - 1);
814
- } else {
815
- // 第1-4次迭代,进入此处
816
- ++r;
817
- x = PowiainaNum.log(x, base);
818
- // 第一次:r = 1, x = log_3(1e19) ~ 39.822162211498316
819
- // 第二次:r = 2, x = log_3(39.822...) ~ 3.353706885314807
820
- // 第三次:r = 3, x = log_3(3.3537...) ~ 1.1014497830508163
821
- // 第四次:r = 4, x = log_3(1.1014...) ~ 0.08795395574340908
730
+ }, {
731
+ key: "tetrate",
732
+ value:
733
+ //#endregion
734
+ //#region higher calculates
735
+ //#region Tetration
736
+ // Code from ExpantaNum.js
737
+ function tetrate(other2) {
738
+ var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
739
+ var t = this.clone();
740
+ var other = new PowiainaNum(other2);
741
+ var payl = new PowiainaNum(payload);
742
+ if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
743
+ if (t.eq(1)) return PowiainaNum.ONE.clone();
744
+ if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
745
+ var negln;
746
+ if (other.isInfi() && other.sign > 0) {
747
+ if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
748
+ negln = this.log().neg();
749
+ return negln.lambertw().div(negln);
822
750
  }
823
- }
824
- if (x.gt(10)) return new PowiainaNum(r);
825
- return PowiainaNum.NaN.clone();
826
- };
827
- PowiainaNum.tetrate = function (t, other2, payload) {
828
- if (payload === void 0) {
829
- payload = 1;
830
- }
831
- return new PowiainaNum(t).tetrate(other2, payload);
832
- };
833
- PowiainaNum.prototype.ssqrt = function () {
834
- var x = this.clone();
835
- if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
836
- if (!x.isFinite()) return x;
837
- if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
838
- if (x.gt(PowiainaNum.EE_MSI)) {
839
- x.setOperator(x.getOperator(1) - 1, 1);
840
- return x;
841
- }
842
- // use lambertw
843
- var l = x.ln();
844
- return l.div(l.lambertw());
845
- };
846
- PowiainaNum.tetrate_10 = function (other2) {
847
- return PowiainaNum.fromNumber(10).tetrate(other2);
848
- };
849
- /**
850
- * iterated-log
851
- *
852
- * @example new P("10^10^3").iteratedlog(2,10) == 3
853
- */
854
- PowiainaNum.prototype.iteratedlog = function (other2, base2) {
855
- if (other2 === void 0) {
856
- other2 = 1;
857
- }
858
- if (base2 === void 0) {
859
- base2 = 10;
860
- }
861
- var t = this.clone();
862
- var base = new PowiainaNum(base2);
863
- var other = new PowiainaNum(other2);
864
- if (other.isZero()) return t;
865
- if (other.eq(PowiainaNum.ONE)) return t.log(base);
866
- return base.tetrate(t.slog(base).sub(other));
867
- };
868
- //#endregion
869
- /**
870
- * Arrow operation, return a function
871
- * The function has a parameter `other`
872
- * call this function returns a powiainanum `this`{`arrow2`}`other`
873
- * @param arrows2 arrow count
874
- * @returns A function
875
- */
876
- PowiainaNum.prototype.arrow = function (arrows2) {
877
- var t = this.clone();
878
- var arrows = new PowiainaNum(arrows2);
879
- if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
880
- console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
881
- return function () {
882
- return PowiainaNum.NaN.clone();
883
- };
884
- }
885
- if (arrows.eq(0)) return function (other) {
886
- return t.mul(other);
887
- };
888
- if (arrows.eq(1)) return function (other) {
889
- return t.pow(other);
890
- };
891
- if (arrows.eq(2)) return function (other) {
892
- return t.tetrate(other);
893
- };
894
- return function (other2, payload2, depth) {
895
- if (depth === void 0) {
896
- depth = 0;
751
+ if (other.lte(-2)) return PowiainaNum.NaN.clone();
752
+ if (t.isZero()) {
753
+ if (other.isZero()) return PowiainaNum.NaN.clone();
754
+ if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
755
+ return PowiainaNum.ONE.clone();
897
756
  }
898
- var other = new PowiainaNum(other2);
899
- var payload = new PowiainaNum(payload2);
900
- var ctt = PowiainaNum.arrowFuncMap.get("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth));
901
- if (ctt) return ctt.clone();
902
- var res = function () {
903
- var r;
904
- if (t.isNaN() || other.isNaN() || payload.isNaN()) return PowiainaNum.NaN.clone();
905
- if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
906
- if (t.eq(PowiainaNum.ZERO)) {
907
- if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
908
- return PowiainaNum.NaN.clone();
909
- }
910
- if (payload.neq(PowiainaNum.ONE)) other = other.add(payload.anyarrow_log(arrows)(t));
911
- if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
912
- if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
913
- if (other.eq(PowiainaNum.ONE)) return t.clone();
914
- // arrow > 9e15, that using 10{x}, x=arrow;
915
- if (arrows.gt(PowiainaNum.MSI)) {
916
- r = arrows.clone();
917
- r.setOperator(r.getOperator(Infinity) + 1, Infinity);
918
- return r;
757
+ if (t.eq(PowiainaNum.ONE)) {
758
+ if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
759
+ return PowiainaNum.ONE.clone();
760
+ }
761
+ if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
762
+ if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
763
+ if (other.eq(PowiainaNum.ONE)) return t;
764
+ if (other.eq(2)) return t.pow(t);
765
+ if (t.eq(2)) {
766
+ if (other.eq(3)) return PowiainaNum.fromNumber(16);
767
+ if (other.eq(4)) return PowiainaNum.fromNumber(65536);
768
+ }
769
+ var m = t.max(other);
770
+ if (m.gt(PowiainaNum.PENTATED_MSI)) return m;
771
+ if (m.gt(PowiainaNum.TETRATED_MSI) || other.gt(MSI)) {
772
+ if (this.lt(EXP_E_REC)) {
773
+ negln = t.ln().neg();
774
+ return negln.lambertw().div(negln);
919
775
  }
920
- var arrowsNum = arrows.toNumber();
921
- // arrow < 9e15
922
- // 10{x}2 = 10{x-1}10
923
- if (other.eq(2)) return t.arrow(arrowsNum - 1)(t, payload, depth + 1);
924
- if (t.max(other).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) return t.max(other);
925
- if (t.gt(PowiainaNum.arrowMSI(arrowsNum)) || other.gt(MSI)) {
926
- if (t.gt(PowiainaNum.arrowMSI(arrowsNum))) {
927
- r = t.clone();
928
- r.setOperator(r.getOperator(arrowsNum) - 1, arrowsNum);
929
- r.normalize();
930
- } else if (t.gt(PowiainaNum.arrowMSI(arrowsNum - 1))) {
931
- r = new PowiainaNum(t.getOperator(arrowsNum - 1));
932
- } else {
933
- r = PowiainaNum.ZERO;
776
+ var j = t.slog(10).add(other);
777
+ j.setOperator(j.getOperator(2) + 1, 2);
778
+ j.normalize();
779
+ return j;
780
+ }
781
+ var y = other.toNumber();
782
+ var f = Math.floor(y);
783
+ var r = t.pow(y - f);
784
+ var l = PowiainaNum.NaN;
785
+ var i = 0;
786
+ for (var w = PowiainaNum.E_MSI.clone(); f !== 0 && r.lt(w) && i < 100; ++i) {
787
+ if (f > 0) {
788
+ r = t.pow(r);
789
+ if (l.eq(r)) {
790
+ f = 0;
791
+ break;
934
792
  }
935
- var j = r.add(other);
936
- j.setOperator(j.getOperator(arrowsNum) + 1, arrowsNum);
937
- j.normalize();
938
- return j;
939
- }
940
- if (depth >= PowiainaNum.maxOps + 10) {
941
- return new PowiainaNum({
942
- small: false,
943
- sign: 1,
944
- layer: 0,
945
- array: [newOperator(10, 0), newOperator(1, arrowsNum)]
946
- });
947
- }
948
- var y = other.toNumber();
949
- var f = Math.floor(y);
950
- var arrows_m1 = arrows.sub(PowiainaNum.ONE);
951
- r = t.arrow(arrows_m1)(y - f, payload, depth + 1);
952
- var i = 0;
953
- for (var m = PowiainaNum.arrowMSI(arrowsNum - 1); f !== 0 && r.lt(m) && i < 100; i++) {
954
- if (f > 0) {
955
- r = t.arrow(arrows_m1)(r, payload, depth + 1);
956
- --f;
793
+ l = r;
794
+ --f;
795
+ } else {
796
+ r = r.log(t);
797
+ if (l.eq(r)) {
798
+ f = 0;
799
+ break;
957
800
  }
801
+ l = r;
802
+ ++f;
958
803
  }
959
- if (i == 100) f = 0;
960
- r.setOperator(r.getOperator(arrowsNum - 1) + f, arrowsNum - 1);
961
- r.normalize();
962
- return r;
963
- }();
964
- if (depth < PowiainaNum.maxOps + 10) {
965
- PowiainaNum.arrowFuncMap.set("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth), res.clone());
966
- }
967
- return res;
968
- };
969
- };
970
- /**
971
- * return `base`{`arrow2`}`x` = `this` which `x` is.
972
- *
973
- * @param arrow2
974
- * @returns
975
- */
976
- PowiainaNum.prototype.anyarrow_log = function (arrow2) {
977
- var x = this.clone();
978
- var arrow = new PowiainaNum(arrow2);
979
- var arrowsNum = arrow.toNumber();
980
- if (arrow.gt(MSI)) {
981
- throw new Error(powiainaNumError + "Not implemented");
982
- }
983
- if (!arrow.isInt() || arrow.lt(0)) return function () {
984
- return PowiainaNum.NaN.clone();
985
- };
986
- if (arrow.eq(0)) return function (base) {
987
- return x.div(base);
988
- };
989
- if (arrow.eq(1)) return function (base) {
990
- return x.log(base);
991
- };
992
- if (arrow.eq(2)) return function (base) {
993
- return x.slog(base);
994
- };
995
- if (x.isInfiNaN()) return function () {
996
- return x;
997
- };
998
- return function (base, depth) {
999
- if (depth === void 0) {
1000
- depth = 0;
1001
804
  }
805
+ if (i == 100 || this.lt(EXP_E_REC)) f = 0;
806
+ r.setOperator(r.getOperator(1) + f, 1);
807
+ r.normalize();
808
+ return r;
809
+ }
810
+ // Code from ExpantaNum.js
811
+ }, {
812
+ key: "slog",
813
+ value: function slog() {
814
+ var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
815
+ var x = this.clone();
1002
816
  var b = new PowiainaNum(base);
817
+ if (x.isInfiNaN()) return x;
1003
818
  if (b.isNaN()) return b;
1004
819
  if (b.isInfi()) return PowiainaNum.ZERO.clone();
1005
820
  if (x.isZero()) return PowiainaNum.ONE.clone();
1006
821
  if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1007
822
  if (x.eq(b)) return PowiainaNum.ONE.clone();
1008
- if (x.max(b).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) {
823
+ if (b.lt(EXP_E_REC)) {
824
+ var a = b.tetrate(Infinity);
825
+ if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
826
+ if (x.gt(a)) return PowiainaNum.NaN.clone();
827
+ }
828
+ if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
1009
829
  if (x.gt(b)) return x;
1010
830
  return PowiainaNum.ZERO.clone();
1011
831
  }
1012
- if (x.max(b).gt(PowiainaNum.arrowMSI(arrowsNum))) {
832
+ if (x.max(b).gt(PowiainaNum.TETRATED_MSI)) {
1013
833
  if (x.gt(b)) {
1014
- x.setOperator(x.getOperator(arrowsNum) - 1, arrowsNum);
834
+ x.setOperator(x.getOperator(2) - 1, 2);
1015
835
  x.normalize();
1016
- return x.sub(x.getOperator(arrowsNum - 1));
836
+ return x.sub(x.getOperator(1));
1017
837
  }
1018
838
  }
1019
- if (x.lt(PowiainaNum.ZERO.clone())) return PowiainaNum.NaN.clone();
839
+ if (x.lt(PowiainaNum.ZERO.clone())) return b.pow(x).sub(2);
1020
840
  // base^base^... = x? (? bases)
1021
841
  var r = 0;
1022
842
  // 计算x与base的差距
1023
- var t = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
843
+ var t = x.getOperator(1) - b.getOperator(1);
1024
844
  if (t > 3) {
1025
845
  var l = t - 3;
1026
846
  r += l;
1027
- x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
847
+ x.setOperator(x.getOperator(1) - l, 1);
1028
848
  }
1029
849
  // 假设b=3, x=1e19
1030
850
  for (var i = 0; i < 100; ++i) {
1031
851
  if (x.lt(PowiainaNum.ZERO)) {
1032
- x = x.arrow(arrowsNum - 1)(base);
852
+ x = PowiainaNum.pow(base, x);
1033
853
  --r;
1034
854
  } else if (x.lte(1)) {
855
+ // 第五次,进入此处
856
+ // 结果=4+0.08795395574340908-1=3.087953...
857
+ // 验算3**3**3**(3**.08795395574340908)=10000000000000720000,符合预期
1035
858
  return new PowiainaNum(r + x.toNumber() - 1);
1036
859
  } else {
1037
860
  // 第1-4次迭代,进入此处
1038
861
  ++r;
1039
- x = x.anyarrow_log(arrowsNum - 1)(base, depth + 1);
862
+ x = PowiainaNum.log(x, base);
863
+ // 第一次:r = 1, x = log_3(1e19) ~ 39.822162211498316
864
+ // 第二次:r = 2, x = log_3(39.822...) ~ 3.353706885314807
865
+ // 第三次:r = 3, x = log_3(3.3537...) ~ 1.1014497830508163
866
+ // 第四次:r = 4, x = log_3(1.1014...) ~ 0.08795395574340908
1040
867
  }
1041
868
  }
1042
869
  if (x.gt(10)) return new PowiainaNum(r);
1043
870
  return PowiainaNum.NaN.clone();
1044
- };
1045
- };
1046
- /**
1047
- * Arrow height inverse (ExpantaNum.js), an alias of `anyarrow_log`
1048
- * @param arrows
1049
- * @returns
1050
- */
1051
- PowiainaNum.prototype.arrow_height_inverse = function (arrows) {
1052
- return this.anyarrow_log(arrows);
1053
- };
1054
- PowiainaNum.arrowMSI = function (arrowsNum) {
1055
- return new PowiainaNum("10{".concat(arrowsNum, "}").concat(MSI));
1056
- };
1057
- PowiainaNum.prototype.chain = function (other, arrows) {
1058
- return this.arrow(arrows)(other);
1059
- };
1060
- PowiainaNum.hyper = function (arr) {
1061
- var z = new PowiainaNum(arr);
1062
- if (z.eq(0)) return function (x, y) {
1063
- return new PowiainaNum(y).eq(0) ? new PowiainaNum(x) : new PowiainaNum(x).add(1);
1064
- };
1065
- if (z.eq(1)) return PowiainaNum.add;else if (z.eq(2)) return PowiainaNum.mul;else if (z.eq(3)) return PowiainaNum.pow;else {
1066
- return function (x, y) {
1067
- return new PowiainaNum(x).arrow(z.sub(2))(y);
1068
- };
1069
- }
1070
- };
1071
- PowiainaNum.prototype.pentate = function (other) {
1072
- return this.arrow(3)(other);
1073
- };
1074
- PowiainaNum.prototype.hexate = function (other) {
1075
- return this.arrow(4)(other);
1076
- };
1077
- PowiainaNum.prototype.penta_log = function (base) {
1078
- if (base === void 0) {
1079
- base = 10;
1080
871
  }
1081
- return this.anyarrow_log(3)(base);
1082
- };
1083
- /**
1084
- * Expansion, which is `this`{{1}}`other2`.
1085
- *
1086
- * Expansion refers to the binary function a{{1}}b = a{a{...a{b}a...}a}a where there are b a's from the center out. It is {a,b,1,2} in BEAF and a{X+1}b in X-Sequence Hyper-Exponential Notation. The notation a{c}b means {a,b,c}, which is a "c + 2"-ated to b, using the bracket operator.
1087
- *
1088
- * @url https://googology.fandom.com/wiki/Expansion
1089
- */
1090
- PowiainaNum.prototype.expansion = function (other2) {
1091
- var other = new PowiainaNum(other2);
1092
- var t = this.clone();
1093
- if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
1094
- if (other.eq(PowiainaNum.ONE)) return this.clone();
1095
- if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1096
- if (!this.isInt()) return PowiainaNum.NaN.clone();
1097
- if (this.eq(2)) return new PowiainaNum(4);
1098
- if (other.eq(0)) return PowiainaNum.ONE.clone();
1099
- var r;
1100
- // I don't know is this added partrs work correctly...
1101
- if (t.gt("10{1,2}".concat(MSI)) || other.gt(MSI)) {
1102
- if (t.gt("10{1,2}".concat(MSI))) {
1103
- r = t.clone();
1104
- r.setOperator(r.getOperator(1, 2) - 1, 1, 2);
1105
- r.normalize();
1106
- } else if (t.gt("10{".concat(MSI, "}10"))) {
1107
- r = new PowiainaNum(t.getOperator(Infinity));
1108
- } else {
1109
- r = PowiainaNum.ZERO;
1110
- }
1111
- var j = r.add(other);
1112
- j.setOperator(j.getOperator(1, 2) + 1, 1, 2);
1113
- j.normalize();
1114
- return j;
1115
- }
1116
- var f = other.toNumber() - 1;
1117
- r = t.clone();
1118
- var i;
1119
- for (i = 0; f !== 0 && r.lt(MSI) && i < 100; ++i) {
1120
- if (f > 0) {
1121
- r = t.arrow(r)(t);
1122
- --f;
1123
- }
1124
- }
1125
- if (i == 100) f = 0;
1126
- r.setOperator(r.getOperator(Infinity) + f, Infinity);
1127
- r.normalize();
1128
- return r;
1129
- };
1130
- PowiainaNum.prototype.expansionArrow = function (arrow2) {
1131
- var arrow = new PowiainaNum(arrow2);
1132
- var t = this.clone();
1133
- if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
1134
- return PowiainaNum.NaN.clone();
1135
- };
1136
- if (arrow.eq(0)) return function (other) {
1137
- return t.arrow(other)(t);
1138
- };
1139
- if (arrow.eq(1)) return function (other) {
1140
- return t.expansion(other);
1141
- };
1142
- var arrows = arrow;
1143
- return function (other2, depth) {
1144
- if (depth === void 0) {
1145
- depth = 0;
872
+ }, {
873
+ key: "ssqrt",
874
+ value: function ssqrt() {
875
+ var x = this.clone();
876
+ if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
877
+ if (!x.isFinite()) return x;
878
+ if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
879
+ if (x.gt(PowiainaNum.EE_MSI)) {
880
+ x.setOperator(x.getOperator(1) - 1, 1);
881
+ return x;
1146
882
  }
883
+ // use lambertw
884
+ var l = x.ln();
885
+ return l.div(l.lambertw());
886
+ }
887
+ }, {
888
+ key: "iteratedlog",
889
+ value:
890
+ /**
891
+ * iterated-log
892
+ *
893
+ * @example new P("10^10^3").iteratedlog(2,10) == 3
894
+ */
895
+ function iteratedlog() {
896
+ var other2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
897
+ var base2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
898
+ var t = this.clone();
899
+ var base = new PowiainaNum(base2);
1147
900
  var other = new PowiainaNum(other2);
1148
- var r;
1149
- if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
1150
- if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1151
- if (t.eq(PowiainaNum.ZERO)) {
1152
- if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1153
- return PowiainaNum.NaN.clone();
1154
- }
1155
- if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1156
- if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
1157
- if (other.eq(PowiainaNum.ONE)) return t.clone();
1158
- // arrow > 9e15, that using 10{x,2}, x=arrow;
1159
- if (arrows.gt(PowiainaNum.MSI)) {
1160
- r = arrows.clone();
1161
- r.setOperator(r.getOperator(Infinity, 2) + 1, Infinity, 2);
1162
- return r;
901
+ if (other.isZero()) return t;
902
+ if (other.eq(PowiainaNum.ONE)) return t.log(base);
903
+ return base.tetrate(t.slog(base).sub(other));
904
+ }
905
+ //#endregion
906
+ /**
907
+ * Arrow operation, return a function
908
+ * The function has a parameter `other`
909
+ * call this function returns a powiainanum `this`{`arrow2`}`other`
910
+ * @param arrows2 arrow count
911
+ * @returns A function
912
+ */
913
+ }, {
914
+ key: "arrow",
915
+ value: function arrow(arrows2) {
916
+ var t = this.clone();
917
+ var arrows = new PowiainaNum(arrows2);
918
+ if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
919
+ console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
920
+ return function () {
921
+ return PowiainaNum.NaN.clone();
922
+ };
1163
923
  }
1164
- var arrowsNum = arrows.toNumber();
1165
- // arrow < 9e15
1166
- // 10{x}2 = 10{x-1}10
1167
- if (other.eq(2)) return t.expansionArrow(arrowsNum - 1)(t, depth + 1);
1168
- if (t.max(other).gt("10{".concat(arrowsNum + 1, ",2}").concat(MSI))) return t.max(other);
1169
- if (t.gt("10{".concat(arrowsNum, ",2}").concat(MSI)) || other.gt(MSI)) {
1170
- if (t.gt("10{".concat(arrowsNum, ",2}").concat(MSI))) {
1171
- r = t.clone();
1172
- r.setOperator(r.getOperator(arrowsNum, 2) - 1, arrowsNum, 2);
924
+ if (arrows.eq(0)) return function (other) {
925
+ return t.mul(other);
926
+ };
927
+ if (arrows.eq(1)) return function (other) {
928
+ return t.pow(other);
929
+ };
930
+ if (arrows.eq(2)) return function (other) {
931
+ return t.tetrate(other);
932
+ };
933
+ return function (other2, payload2) {
934
+ var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
935
+ var other = new PowiainaNum(other2);
936
+ var payload = new PowiainaNum(payload2);
937
+ var ctt = PowiainaNum.arrowFuncMap.get("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth));
938
+ if (ctt) return ctt.clone();
939
+ var res = function () {
940
+ var r;
941
+ if (t.isNaN() || other.isNaN() || payload.isNaN()) return PowiainaNum.NaN.clone();
942
+ if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
943
+ if (t.eq(PowiainaNum.ZERO)) {
944
+ if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
945
+ return PowiainaNum.NaN.clone();
946
+ }
947
+ if (payload.neq(PowiainaNum.ONE)) other = other.add(payload.anyarrow_log(arrows)(t));
948
+ if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
949
+ if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
950
+ if (other.eq(PowiainaNum.ONE)) return t.clone();
951
+ // arrow > 9e15, that using 10{x}, x=arrow;
952
+ if (arrows.gt(PowiainaNum.MSI)) {
953
+ r = arrows.clone();
954
+ r.setOperator(r.getOperator(Infinity) + 1, Infinity);
955
+ return r;
956
+ }
957
+ var arrowsNum = arrows.toNumber();
958
+ // arrow < 9e15
959
+ // 10{x}2 = 10{x-1}10
960
+ if (other.eq(2)) return t.arrow(arrowsNum - 1)(t, payload, depth + 1);
961
+ if (t.max(other).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) return t.max(other);
962
+ if (t.gt(PowiainaNum.arrowMSI(arrowsNum)) || other.gt(MSI)) {
963
+ if (t.gt(PowiainaNum.arrowMSI(arrowsNum))) {
964
+ r = t.clone();
965
+ r.setOperator(r.getOperator(arrowsNum) - 1, arrowsNum);
966
+ r.normalize();
967
+ } else if (t.gt(PowiainaNum.arrowMSI(arrowsNum - 1))) {
968
+ r = new PowiainaNum(t.getOperator(arrowsNum - 1));
969
+ } else {
970
+ r = PowiainaNum.ZERO;
971
+ }
972
+ var j = r.add(other);
973
+ j.setOperator(j.getOperator(arrowsNum) + 1, arrowsNum);
974
+ j.normalize();
975
+ return j;
976
+ }
977
+ if (depth >= PowiainaNum.maxOps + 10) {
978
+ return new PowiainaNum({
979
+ small: false,
980
+ sign: 1,
981
+ layer: 0,
982
+ array: [newOperator(10, 0), newOperator(1, arrowsNum)]
983
+ });
984
+ }
985
+ var y = other.toNumber();
986
+ var f = Math.floor(y);
987
+ var arrows_m1 = arrows.sub(PowiainaNum.ONE);
988
+ r = t.arrow(arrows_m1)(y - f, payload, depth + 1);
989
+ var i = 0;
990
+ for (var m = PowiainaNum.arrowMSI(arrowsNum - 1); f !== 0 && r.lt(m) && i < 100; i++) {
991
+ if (f > 0) {
992
+ r = t.arrow(arrows_m1)(r, payload, depth + 1);
993
+ --f;
994
+ }
995
+ }
996
+ if (i == 100) f = 0;
997
+ r.setOperator(r.getOperator(arrowsNum - 1) + f, arrowsNum - 1);
1173
998
  r.normalize();
1174
- } else if (t.gt("10{".concat(arrowsNum - 1, ",2}").concat(MSI))) {
1175
- r = new PowiainaNum(t.getOperator(arrowsNum - 1, 2));
1176
- } else {
1177
- r = PowiainaNum.ZERO;
1178
- }
1179
- var j = r.add(other);
1180
- j.setOperator(j.getOperator(arrowsNum, 2) + 1, arrowsNum, 2);
1181
- j.normalize();
1182
- return j;
1183
- }
1184
- if (depth >= PowiainaNum.maxOps + 10) {
1185
- return new PowiainaNum({
1186
- small: false,
1187
- sign: 1,
1188
- layer: 0,
1189
- array: [newOperator(10, 0), newOperator(1, arrowsNum, 2)]
1190
- });
1191
- }
1192
- var y = other.toNumber();
1193
- var f = Math.floor(y);
1194
- var arrows_m1 = arrows.sub(PowiainaNum.ONE);
1195
- r = t.expansionArrow(arrows_m1)(y - f, depth + 1);
1196
- var i = 0;
1197
- for (var m = new PowiainaNum("10{".concat(arrowsNum - 1, ",2}").concat(MSI)); f !== 0 && r.lt(m) && i < 100; i++) {
1198
- if (f > 0) {
1199
- r = t.expansionArrow(arrows_m1)(r, depth + 1);
1200
- --f;
999
+ return r;
1000
+ }();
1001
+ if (depth < PowiainaNum.maxOps + 10) {
1002
+ PowiainaNum.arrowFuncMap.set("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth), res.clone());
1201
1003
  }
1202
- }
1203
- if (i == 100) f = 0;
1204
- r.setOperator(r.getOperator(arrowsNum - 1, 2) + f, arrowsNum - 1, 2);
1205
- r.normalize();
1206
- return r;
1207
- };
1208
- };
1209
- PowiainaNum.expansion = function (t, other) {
1210
- return new PowiainaNum(t).expansion(other);
1211
- };
1212
- PowiainaNum.prototype.multiExpansion = function (other) {
1213
- return this.expansionArrow(2)(other);
1214
- };
1215
- PowiainaNum.multiExpansion = function (t, other) {
1216
- return new PowiainaNum(t).multiExpansion(other);
1217
- };
1218
- PowiainaNum.prototype.powerExpansion = function (other) {
1219
- return this.expansionArrow(3)(other);
1220
- };
1221
- PowiainaNum.powerExpansion = function (t, other) {
1222
- return new PowiainaNum(t).powerExpansion(other);
1223
- };
1224
- PowiainaNum.prototype.explosion = function (other) {
1225
- return PowiainaNum.BEAF(this, other, 1, 3);
1226
- };
1227
- PowiainaNum.prototype.megotion = function (other) {
1228
- return PowiainaNum.BEAF(this, other, 1, 1, 2);
1229
- };
1230
- PowiainaNum.prototype.powiaination = function (other) {
1231
- return PowiainaNum.BEAF(this, other, 1, 1, 1, 2);
1232
- };
1233
- PowiainaNum.BEAF = function (base2, power2, arrow2, expans2, megota2, powiaina2, depth) {
1234
- if (arrow2 === void 0) {
1235
- arrow2 = 1;
1236
- }
1237
- if (expans2 === void 0) {
1238
- expans2 = 1;
1239
- }
1240
- if (megota2 === void 0) {
1241
- megota2 = 1;
1242
- }
1243
- if (powiaina2 === void 0) {
1244
- powiaina2 = 1;
1245
- }
1246
- if (depth === void 0) {
1247
- depth = 0;
1248
- }
1249
- // console.warn(
1250
- // "This function is unstable when calculating numbers greater than *megotion*",
1251
- // );
1252
- var base = new PowiainaNum(base2);
1253
- var power = new PowiainaNum(power2);
1254
- function readArg(a) {
1255
- var _b;
1256
- return new PowiainaNum((_b = [arrow2, expans2, megota2, powiaina2][a]) !== null && _b !== void 0 ? _b : 1);
1257
- }
1258
- if (base.eq(1)) return new PowiainaNum(1);
1259
- if (power.eq(1)) return new PowiainaNum(base);
1260
- if (power.isZero()) return new PowiainaNum(1);
1261
- if (base.lt(0)) return PowiainaNum.NaN.clone();
1262
- // // check infinite
1263
- // let sufpowiaina = args.slice(4);
1264
- // if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
1265
- // return PowiainaNum.POSITIVE_INFINITY;
1266
- // }
1267
- if (new PowiainaNum(powiaina2).gte(3)) return PowiainaNum.POSITIVE_INFINITY.clone();
1268
- if (readArg(0).eq(1) && readArg(1).eq(1) && readArg(2).eq(1)) {
1269
- return base.pow(power);
1270
- }
1271
- if (readArg(0).eq(2) && readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
1272
- return base.tetrate(power);
1273
- }
1274
- if (readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
1275
- return base.arrow(readArg(0))(power);
1276
- }
1277
- if (readArg(1).eq(2) && readArg(2).eq(1) && readArg(3).eq(1)) {
1278
- return base.expansionArrow(readArg(0))(power);
1279
- }
1280
- var arrow = readArg(0).toNumber();
1281
- var expans = readArg(1);
1282
- var megota = readArg(2);
1283
- var powiaina = readArg(3);
1284
- if (powiaina.eq(2)) {
1285
- if (arrow != 1) return PowiainaNum.POSITIVE_INFINITY.clone();
1286
- if (expans.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
1287
- if (megota.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
1288
- if (power.gte(MSI)) return PowiainaNum.POSITIVE_INFINITY.clone();
1289
- var r = new PowiainaNum(10);
1290
- r.layer = power.toNumber();
1291
- r.normalize();
1292
- return r;
1293
- }
1294
- function convertOperator(arrows, expans, megota) {
1295
- var a = arrows;
1296
- var e = expans;
1297
- var m = megota;
1298
- if (a == 0 && e > 1) {
1299
- return [1 / 0, e - 1, m];
1300
- }
1301
- if (a == 0 && e == 1 && m > 1) {
1302
- return [1, 1 / 0, m - 1];
1303
- }
1304
- return [a, e, m];
1305
- }
1306
- if (megota.gt(MSI)) {
1307
- var temp = new PowiainaNum(megota);
1308
- temp.layer++;
1309
- temp.normalize();
1310
- return temp;
1004
+ return res;
1005
+ };
1311
1006
  }
1312
- function infToBang(x) {
1313
- if (!isFinite(x)) return "!";
1314
- return x.toString();
1007
+ /**
1008
+ * return `base`{`arrow2`}`x` = `this` which `x` is.
1009
+ *
1010
+ * @param arrow2
1011
+ * @returns
1012
+ */
1013
+ }, {
1014
+ key: "anyarrow_log",
1015
+ value: function anyarrow_log(arrow2) {
1016
+ var x = this.clone();
1017
+ var arrow = new PowiainaNum(arrow2);
1018
+ var arrowsNum = arrow.toNumber();
1019
+ if (arrow.gt(MSI)) {
1020
+ throw new Error(powiainaNumError + "Not implemented");
1021
+ }
1022
+ if (!arrow.isInt() || arrow.lt(0)) return function () {
1023
+ return PowiainaNum.NaN.clone();
1024
+ };
1025
+ if (arrow.eq(0)) return function (base) {
1026
+ return x.div(base);
1027
+ };
1028
+ if (arrow.eq(1)) return function (base) {
1029
+ return x.log(base);
1030
+ };
1031
+ if (arrow.eq(2)) return function (base) {
1032
+ return x.slog(base);
1033
+ };
1034
+ if (x.isInfiNaN()) return function () {
1035
+ return x;
1036
+ };
1037
+ return function (base) {
1038
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1039
+ var b = new PowiainaNum(base);
1040
+ if (b.isNaN()) return b;
1041
+ if (b.isInfi()) return PowiainaNum.ZERO.clone();
1042
+ if (x.isZero()) return PowiainaNum.ONE.clone();
1043
+ if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1044
+ if (x.eq(b)) return PowiainaNum.ONE.clone();
1045
+ if (x.max(b).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) {
1046
+ if (x.gt(b)) return x;
1047
+ return PowiainaNum.ZERO.clone();
1048
+ }
1049
+ if (x.max(b).gt(PowiainaNum.arrowMSI(arrowsNum))) {
1050
+ if (x.gt(b)) {
1051
+ x.setOperator(x.getOperator(arrowsNum) - 1, arrowsNum);
1052
+ x.normalize();
1053
+ return x.sub(x.getOperator(arrowsNum - 1));
1054
+ }
1055
+ }
1056
+ if (x.lt(PowiainaNum.ZERO.clone())) return PowiainaNum.NaN.clone();
1057
+ // base^base^... = x? (? bases)
1058
+ var r = 0;
1059
+ // 计算x与base的差距
1060
+ var t = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1061
+ if (t > 3) {
1062
+ var l = t - 3;
1063
+ r += l;
1064
+ x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
1065
+ }
1066
+ // 假设b=3, x=1e19
1067
+ for (var i = 0; i < 100; ++i) {
1068
+ if (x.lt(PowiainaNum.ZERO)) {
1069
+ x = x.arrow(arrowsNum - 1)(base);
1070
+ --r;
1071
+ } else if (x.lte(1)) {
1072
+ return new PowiainaNum(r + x.toNumber() - 1);
1073
+ } else {
1074
+ // 第1-4次迭代,进入此处
1075
+ ++r;
1076
+ x = x.anyarrow_log(arrowsNum - 1)(base, depth + 1);
1077
+ }
1078
+ }
1079
+ if (x.gt(10)) return new PowiainaNum(r);
1080
+ return PowiainaNum.NaN.clone();
1081
+ };
1315
1082
  }
1316
- function getMSIForm(arrow, expans, megota) {
1317
- return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
1083
+ /**
1084
+ * Arrow height inverse (ExpantaNum.js), an alias of `anyarrow_log`
1085
+ * @param arrows
1086
+ * @returns
1087
+ */
1088
+ }, {
1089
+ key: "arrow_height_inverse",
1090
+ value: function arrow_height_inverse(arrows) {
1091
+ return this.anyarrow_log(arrows);
1092
+ }
1093
+ }, {
1094
+ key: "chain",
1095
+ value: function chain(other, arrows) {
1096
+ return this.arrow(arrows)(other);
1097
+ }
1098
+ }, {
1099
+ key: "pentate",
1100
+ value: function pentate(other) {
1101
+ return this.arrow(3)(other);
1102
+ }
1103
+ }, {
1104
+ key: "hexate",
1105
+ value: function hexate(other) {
1106
+ return this.arrow(4)(other);
1107
+ }
1108
+ }, {
1109
+ key: "penta_log",
1110
+ value: function penta_log() {
1111
+ var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
1112
+ return this.anyarrow_log(3)(base);
1318
1113
  }
1319
- var t = base.clone();
1320
- var arrows = new PowiainaNum(readArg(0));
1321
- var result = function (other2, depth) {
1322
- if (depth === void 0) {
1323
- depth = 0;
1324
- }
1325
- console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
1114
+ /**
1115
+ * Expansion, which is `this`{{1}}`other2`.
1116
+ *
1117
+ * Expansion refers to the binary function a{{1}}b = a{a{...a{b}a...}a}a where there are b a's from the center out. It is {a,b,1,2} in BEAF and a{X+1}b in X-Sequence Hyper-Exponential Notation. The notation a{c}b means {a,b,c}, which is a "c + 2"-ated to b, using the bracket operator.
1118
+ *
1119
+ * @url https://googology.fandom.com/wiki/Expansion
1120
+ */
1121
+ }, {
1122
+ key: "expansion",
1123
+ value: function expansion(other2) {
1326
1124
  var other = new PowiainaNum(other2);
1125
+ var t = this.clone();
1126
+ if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
1127
+ if (other.eq(PowiainaNum.ONE)) return this.clone();
1128
+ if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1129
+ if (!this.isInt()) return PowiainaNum.NaN.clone();
1130
+ if (this.eq(2)) return new PowiainaNum(4);
1131
+ if (other.eq(0)) return PowiainaNum.ONE.clone();
1327
1132
  var r;
1328
- if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
1329
- if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1330
- if (t.eq(PowiainaNum.ZERO)) {
1331
- if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1332
- return PowiainaNum.NaN.clone();
1333
- }
1334
- if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1335
- if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
1336
- if (other.eq(PowiainaNum.ONE)) return t.clone();
1337
- if (arrows.eq(0)) {
1338
- return PowiainaNum.BEAF(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
1339
- // {this, this, power, expans-1, megota}
1340
- }
1341
- if (megota.eq(0)) {
1342
- return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
1343
- }
1344
- // expans > 9e15, that using 10{?, x}, x=expans;
1345
- if (expans.gt(MSI)) {
1346
- r = new PowiainaNum(expans);
1347
- r.setOperator(r.getOperator(1, Infinity, megota.toNumber()) + 1, 1, Infinity, megota.toNumber());
1348
- return r;
1349
- }
1350
- // arrow > 9e15, that using 10{x,2}, x=arrow;
1351
- if (arrows.gt(PowiainaNum.MSI)) {
1352
- r = arrows.clone();
1353
- r.setOperator(r.getOperator(Infinity, expans.toNumber(), megota.toNumber()) + 1, Infinity, expans.toNumber(), megota.toNumber());
1354
- return r;
1355
- }
1356
- var arrowsNum = arrows.toNumber();
1357
- // arrow < 9e15
1358
- // 10{x}2 = 10{x-1}10
1359
- if (other.eq(2)) return PowiainaNum.BEAF(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
1360
- if (t.max(other).gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber()))) return t.max(other);
1361
- if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
1362
- if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
1133
+ // I don't know is this added partrs work correctly...
1134
+ if (t.gt("10{1,2}".concat(MSI)) || other.gt(MSI)) {
1135
+ if (t.gt("10{1,2}".concat(MSI))) {
1363
1136
  r = t.clone();
1364
- r.setOperator(r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1, arrowsNum, expans.toNumber(), megota.toNumber());
1137
+ r.setOperator(r.getOperator(1, 2) - 1, 1, 2);
1365
1138
  r.normalize();
1366
- } else if (t.gt(getMSIForm.apply(void 0, convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())))) {
1367
- r = new PowiainaNum(t.getOperator.apply(t, convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())));
1139
+ } else if (t.gt("10{".concat(MSI, "}10"))) {
1140
+ r = new PowiainaNum(t.getOperator(Infinity));
1368
1141
  } else {
1369
1142
  r = PowiainaNum.ZERO;
1370
1143
  }
1371
1144
  var j = r.add(other);
1372
- j.setOperator(j.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) + 1, arrowsNum, expans.toNumber(), megota.toNumber());
1145
+ j.setOperator(j.getOperator(1, 2) + 1, 1, 2);
1373
1146
  j.normalize();
1374
1147
  return j;
1375
1148
  }
1376
- if (depth >= PowiainaNum.maxOps + 10) {
1377
- return new PowiainaNum({
1378
- small: false,
1379
- sign: 1,
1380
- layer: 0,
1381
- array: [newOperator(10, 0), newOperator(1, arrowsNum, expans.toNumber(), megota.toNumber())]
1382
- });
1383
- }
1384
- var y = other.toNumber();
1385
- var f = Math.floor(y);
1386
- var arrows_m1 = arrows.sub(PowiainaNum.ONE);
1387
- r = PowiainaNum.BEAF(t, y - f, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
1388
- var i = 0;
1389
- for (var m = new PowiainaNum(getMSIForm.apply(void 0, convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))); f !== 0 && r.lt(m) && i < 100; i++) {
1149
+ var f = other.toNumber() - 1;
1150
+ r = t.clone();
1151
+ var i;
1152
+ for (i = 0; f !== 0 && r.lt(MSI) && i < 100; ++i) {
1390
1153
  if (f > 0) {
1391
- r = PowiainaNum.BEAF(base, r, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
1154
+ r = t.arrow(r)(t);
1392
1155
  --f;
1393
1156
  }
1394
1157
  }
1395
1158
  if (i == 100) f = 0;
1396
- r.setOperator.apply(r, __spreadArray([r.getOperator.apply(r, convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())) + f], convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()), false));
1159
+ r.setOperator(r.getOperator(Infinity) + f, Infinity);
1397
1160
  r.normalize();
1398
1161
  return r;
1399
- }(power, depth);
1400
- console.log("".concat("-".repeat(depth), " = ").concat(result));
1401
- return result;
1402
- };
1403
- //#endregion
1404
- //#region comparsion
1405
- PowiainaNum.prototype.abs = function () {
1406
- var obj = this.clone();
1407
- if (obj.sign < 0) obj.sign *= -1;
1408
- return obj;
1409
- };
1410
- PowiainaNum.abs = function (x) {
1411
- return new PowiainaNum(x).abs();
1412
- };
1413
- /**
1414
- * Select the largest number of arguments.
1415
- */
1416
- PowiainaNum.max = function () {
1417
- var args = [];
1418
- for (var _i = 0; _i < arguments.length; _i++) {
1419
- args[_i] = arguments[_i];
1420
1162
  }
1421
- var max = PowiainaNum.NEGATIVE_INFINITY;
1422
- for (var i = 0; i < args.length; i++) {
1423
- if (max.lt(args[i])) {
1424
- max = new PowiainaNum(args[i]).clone();
1425
- }
1163
+ }, {
1164
+ key: "expansionArrow",
1165
+ value: function expansionArrow(arrow2) {
1166
+ var arrow = new PowiainaNum(arrow2);
1167
+ var t = this.clone();
1168
+ if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
1169
+ return PowiainaNum.NaN.clone();
1170
+ };
1171
+ if (arrow.eq(0)) return function (other) {
1172
+ return t.arrow(other)(t);
1173
+ };
1174
+ if (arrow.eq(1)) return function (other) {
1175
+ return t.expansion(other);
1176
+ };
1177
+ var arrows = arrow;
1178
+ return function (other2) {
1179
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1180
+ var other = new PowiainaNum(other2);
1181
+ var r;
1182
+ if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
1183
+ if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1184
+ if (t.eq(PowiainaNum.ZERO)) {
1185
+ if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1186
+ return PowiainaNum.NaN.clone();
1187
+ }
1188
+ if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1189
+ if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
1190
+ if (other.eq(PowiainaNum.ONE)) return t.clone();
1191
+ // arrow > 9e15, that using 10{x,2}, x=arrow;
1192
+ if (arrows.gt(PowiainaNum.MSI)) {
1193
+ r = arrows.clone();
1194
+ r.setOperator(r.getOperator(Infinity, 2) + 1, Infinity, 2);
1195
+ return r;
1196
+ }
1197
+ var arrowsNum = arrows.toNumber();
1198
+ // arrow < 9e15
1199
+ // 10{x}2 = 10{x-1}10
1200
+ if (other.eq(2)) return t.expansionArrow(arrowsNum - 1)(t, depth + 1);
1201
+ if (t.max(other).gt("10{".concat(arrowsNum + 1, ",2}").concat(MSI))) return t.max(other);
1202
+ if (t.gt("10{".concat(arrowsNum, ",2}").concat(MSI)) || other.gt(MSI)) {
1203
+ if (t.gt("10{".concat(arrowsNum, ",2}").concat(MSI))) {
1204
+ r = t.clone();
1205
+ r.setOperator(r.getOperator(arrowsNum, 2) - 1, arrowsNum, 2);
1206
+ r.normalize();
1207
+ } else if (t.gt("10{".concat(arrowsNum - 1, ",2}").concat(MSI))) {
1208
+ r = new PowiainaNum(t.getOperator(arrowsNum - 1, 2));
1209
+ } else {
1210
+ r = PowiainaNum.ZERO;
1211
+ }
1212
+ var j = r.add(other);
1213
+ j.setOperator(j.getOperator(arrowsNum, 2) + 1, arrowsNum, 2);
1214
+ j.normalize();
1215
+ return j;
1216
+ }
1217
+ if (depth >= PowiainaNum.maxOps + 10) {
1218
+ return new PowiainaNum({
1219
+ small: false,
1220
+ sign: 1,
1221
+ layer: 0,
1222
+ array: [newOperator(10, 0), newOperator(1, arrowsNum, 2)]
1223
+ });
1224
+ }
1225
+ var y = other.toNumber();
1226
+ var f = Math.floor(y);
1227
+ var arrows_m1 = arrows.sub(PowiainaNum.ONE);
1228
+ r = t.expansionArrow(arrows_m1)(y - f, depth + 1);
1229
+ var i = 0;
1230
+ for (var m = new PowiainaNum("10{".concat(arrowsNum - 1, ",2}").concat(MSI)); f !== 0 && r.lt(m) && i < 100; i++) {
1231
+ if (f > 0) {
1232
+ r = t.expansionArrow(arrows_m1)(r, depth + 1);
1233
+ --f;
1234
+ }
1235
+ }
1236
+ if (i == 100) f = 0;
1237
+ r.setOperator(r.getOperator(arrowsNum - 1, 2) + f, arrowsNum - 1, 2);
1238
+ r.normalize();
1239
+ return r;
1240
+ };
1426
1241
  }
1427
- return max;
1428
- };
1429
- /**
1430
- * Select the smallest number of arguments.
1431
- */
1432
- PowiainaNum.min = function () {
1433
- var args = [];
1434
- for (var _i = 0; _i < arguments.length; _i++) {
1435
- args[_i] = arguments[_i];
1242
+ }, {
1243
+ key: "multiExpansion",
1244
+ value: function multiExpansion(other) {
1245
+ return this.expansionArrow(2)(other);
1246
+ }
1247
+ }, {
1248
+ key: "powerExpansion",
1249
+ value: function powerExpansion(other) {
1250
+ return this.expansionArrow(3)(other);
1251
+ }
1252
+ }, {
1253
+ key: "explosion",
1254
+ value: function explosion(other) {
1255
+ return PowiainaNum.BEAF(this, other, 1, 3);
1256
+ }
1257
+ }, {
1258
+ key: "megotion",
1259
+ value: function megotion(other) {
1260
+ return PowiainaNum.BEAF(this, other, 1, 1, 2);
1261
+ }
1262
+ }, {
1263
+ key: "powiaination",
1264
+ value: function powiaination(other) {
1265
+ return PowiainaNum.BEAF(this, other, 1, 1, 1, 2);
1266
+ }
1267
+ }, {
1268
+ key: "abs",
1269
+ value:
1270
+ //#endregion
1271
+ //#region comparsion
1272
+ function abs() {
1273
+ var obj = this.clone();
1274
+ if (obj.sign < 0) obj.sign *= -1;
1275
+ return obj;
1436
1276
  }
1437
- var max = PowiainaNum.POSITIVE_INFINITY;
1438
- for (var i = 0; i < args.length; i++) {
1439
- if (max.gt(args[i])) {
1440
- max = new PowiainaNum(args[i]).clone();
1277
+ }, {
1278
+ key: "clampMin",
1279
+ value:
1280
+ /**
1281
+ * Restrict a number be not lower than a number
1282
+ *
1283
+ * It's also an alias of `PowiainaNum.max`.
1284
+ * @returns restricted number
1285
+ */
1286
+ function clampMin() {
1287
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1288
+ args[_key2] = arguments[_key2];
1441
1289
  }
1290
+ return PowiainaNum.max.apply(PowiainaNum, [this].concat(args));
1442
1291
  }
1443
- return max;
1444
- };
1445
- /**
1446
- * Restrict a number be not lower than a number
1447
- *
1448
- * It's also an alias of `PowiainaNum.max`.
1449
- * @returns restricted number
1450
- */
1451
- PowiainaNum.clampMin = function () {
1452
- var args = [];
1453
- for (var _i = 0; _i < arguments.length; _i++) {
1454
- args[_i] = arguments[_i];
1455
- }
1456
- return PowiainaNum.max.apply(PowiainaNum, args);
1457
- };
1458
- /**
1459
- * Restrict a number be not lower than a number
1460
- *
1461
- * It's also an alias of `PowiainaNum.max`.
1462
- * @returns restricted number
1463
- */
1464
- PowiainaNum.prototype.clampMin = function () {
1465
- var args = [];
1466
- for (var _i = 0; _i < arguments.length; _i++) {
1467
- args[_i] = arguments[_i];
1468
- }
1469
- return PowiainaNum.max.apply(PowiainaNum, __spreadArray([this], args, false));
1470
- };
1471
- /**
1472
- * Restrict a number be not higher than a number
1473
- *
1474
- * It's also an alias of `PowiainaNum.min`.
1475
- * @returns restricted number
1476
- */
1477
- PowiainaNum.clampMax = function () {
1478
- var args = [];
1479
- for (var _i = 0; _i < arguments.length; _i++) {
1480
- args[_i] = arguments[_i];
1481
- }
1482
- return PowiainaNum.min.apply(PowiainaNum, args);
1483
- };
1484
- /**
1485
- * Restrict a number be not higher than a number
1486
- *
1487
- * It's also an alias of `PowiainaNum.min`.
1488
- * @returns restricted number
1489
- */
1490
- PowiainaNum.prototype.clampMax = function () {
1491
- var args = [];
1492
- for (var _i = 0; _i < arguments.length; _i++) {
1493
- args[_i] = arguments[_i];
1494
- }
1495
- return PowiainaNum.min.apply(PowiainaNum, __spreadArray([this], args, false));
1496
- };
1497
- /**
1498
- * A combination of minimum and maximum: the value returned by clamp is normally 'this', but it won't go below 'min' and it won't go above 'max'.
1499
- * Therefore, if 'this' < 'min', then 'min' is returned, and if 'this' > 'max', then 'max' is returned.
1500
- */
1501
- PowiainaNum.prototype.clamp = function (min, max) {
1502
- return this.max(min).min(max);
1503
- };
1504
- PowiainaNum.prototype.max = function () {
1505
- var args = [];
1506
- for (var _i = 0; _i < arguments.length; _i++) {
1507
- args[_i] = arguments[_i];
1508
- }
1509
- return PowiainaNum.max.apply(PowiainaNum, __spreadArray([this], args, false));
1510
- };
1511
- PowiainaNum.prototype.min = function () {
1512
- var args = [];
1513
- for (var _i = 0; _i < arguments.length; _i++) {
1514
- args[_i] = arguments[_i];
1515
- }
1516
- return PowiainaNum.min.apply(PowiainaNum, __spreadArray([this], args, false));
1517
- };
1518
- /**
1519
- * Compare what PowiainaNum's absolute value is max
1520
- * @param args
1521
- * @returns absolute value max number's absolute value
1522
- */
1523
- PowiainaNum.prototype.maxabs = function () {
1524
- var args = [];
1525
- for (var _i = 0; _i < arguments.length; _i++) {
1526
- args[_i] = arguments[_i];
1527
- }
1528
- var other = args.map(function (x) {
1529
- return new PowiainaNum(x).abs();
1530
- });
1531
- return PowiainaNum.max.apply(PowiainaNum, __spreadArray([this.abs()], other, false));
1532
- };
1533
- PowiainaNum.prototype.minabs = function () {
1534
- var args = [];
1535
- for (var _i = 0; _i < arguments.length; _i++) {
1536
- args[_i] = arguments[_i];
1292
+ /**
1293
+ * Restrict a number be not higher than a number
1294
+ *
1295
+ * It's also an alias of `PowiainaNum.min`.
1296
+ * @returns restricted number
1297
+ */
1298
+ }, {
1299
+ key: "clampMax",
1300
+ value:
1301
+ /**
1302
+ * Restrict a number be not higher than a number
1303
+ *
1304
+ * It's also an alias of `PowiainaNum.min`.
1305
+ * @returns restricted number
1306
+ */
1307
+ function clampMax() {
1308
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1309
+ args[_key3] = arguments[_key3];
1310
+ }
1311
+ return PowiainaNum.min.apply(PowiainaNum, [this].concat(args));
1537
1312
  }
1538
- var other = args.map(function (x) {
1539
- return new PowiainaNum(x).abs();
1540
- });
1541
- return PowiainaNum.min.apply(PowiainaNum, __spreadArray([this.abs()], other, false));
1542
- };
1543
- PowiainaNum.prototype.cmpabs = function (x) {
1544
- var other = new PowiainaNum(x).abs();
1545
- return this.abs().cmp(other);
1546
- };
1547
- PowiainaNum.prototype.compare = function (x) {
1548
- var other = new PowiainaNum(x);
1549
- if (this.isNaN() || other.isNaN()) return 2;
1550
- if (this.sign < other.sign) return -1;
1551
- if (this.sign > other.sign) return 1;
1552
- //this.sign = other.sign
1553
- var allneg = this.sign == -1 && other.sign == -1;
1554
- if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
1555
- if (other.small && !this.small) return 1 * (allneg ? -1 : 1);
1556
- var resultreverse = 1;
1557
- if (this.small && other.small) resultreverse *= -1;
1558
- if (allneg) resultreverse *= -1;
1559
- var result = 0;
1560
- for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
1561
- var op1 = this.array[this.array.length - 1 - i];
1562
- var op2 = other.array[other.array.length - 1 - i];
1563
- var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
1564
- if (cmp == 1) {
1565
- result = 1;
1566
- break;
1567
- } else if (cmp == -1) {
1568
- result = -1;
1569
- break;
1570
- }
1571
- }
1572
- return result * resultreverse + 1 - 1;
1573
- };
1574
- PowiainaNum.prototype.cmp = function (other) {
1575
- return this.compare(other);
1576
- };
1577
- PowiainaNum.prototype.eq = function (other) {
1578
- return this.cmp(other) === 0;
1579
- };
1580
- PowiainaNum.prototype.neq = function (other) {
1581
- return this.cmp(other) !== 0;
1582
- };
1583
- PowiainaNum.prototype.lt = function (other) {
1584
- return this.cmp(other) === -1;
1585
- };
1586
- PowiainaNum.prototype.lte = function (other) {
1587
- return this.cmp(other) <= 0;
1588
- };
1589
- PowiainaNum.prototype.gt = function (other) {
1590
- return this.cmp(other) == 1;
1591
- };
1592
- PowiainaNum.prototype.gte = function (other) {
1593
- var t = this.cmp(other);
1594
- return t == 0 || t == 1;
1595
- };
1596
- PowiainaNum.prototype.eq_tolerance = function (value, tolerance) {
1597
- if (tolerance === void 0) {
1598
- tolerance = 1e-7;
1313
+ /**
1314
+ * A combination of minimum and maximum: the value returned by clamp is normally 'this', but it won't go below 'min' and it won't go above 'max'.
1315
+ * Therefore, if 'this' < 'min', then 'min' is returned, and if 'this' > 'max', then 'max' is returned.
1316
+ */
1317
+ }, {
1318
+ key: "clamp",
1319
+ value: function clamp(min, max) {
1320
+ return this.max(min).min(max);
1599
1321
  }
1600
- var dec = new PowiainaNum(value);
1601
- return this.sub(dec).lte(this.max(dec).mul(tolerance));
1602
- };
1603
- //#endregion
1604
- //#region geometry
1605
- PowiainaNum.prototype.sin = function () {
1606
- var x = this.clone();
1607
- if (x.isneg()) {
1608
- return x.neg().sin().neg();
1609
- }
1610
- var y = x.mod(7074237752028440);
1611
- return PowiainaNum.fromNumber(Math.sin(y.toNumber()));
1612
- };
1613
- PowiainaNum.prototype.cos = function () {
1614
- return this.sub(Math.PI / 2).sin();
1615
- };
1616
- PowiainaNum.prototype.tan = function () {
1617
- return this.sin().div(this.cos());
1618
- };
1619
- PowiainaNum.prototype.cot = function () {
1620
- return this.cos().div(this.sin());
1621
- };
1622
- PowiainaNum.prototype.sec = function () {
1623
- return this.cos().rec();
1624
- };
1625
- PowiainaNum.prototype.csc = function () {
1626
- return this.sin().rec();
1627
- };
1628
- //#endregion
1629
- //#region neg, rec, floor, ceil, round, trunc, sign
1630
- PowiainaNum.prototype.neg = function () {
1631
- var a = this.clone();
1632
- a.sign *= -1;
1633
- a.normalize();
1634
- return a;
1635
- };
1636
- PowiainaNum.prototype.rec = function () {
1637
- var a = this.clone();
1638
- a.small = !a.small;
1639
- return a;
1640
- };
1641
- PowiainaNum.prototype.floor = function () {
1642
- if (this.isInt()) return this.clone();
1643
- if (this.small) {
1644
- if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
1645
- }
1646
- var r = this.abs();
1647
- r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
1648
- return r;
1649
- };
1650
- PowiainaNum.prototype.ceil = function () {
1651
- if (this.isInt()) return this.clone();
1652
- if (this.small) {
1653
- if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
1654
- }
1655
- var r = this.abs();
1656
- r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
1657
- r.sign = this.sign;
1658
- return r;
1659
- };
1660
- PowiainaNum.prototype.round = function () {
1661
- if (this.isInt()) return this.clone();
1662
- if (this.small) {
1663
- if (this.sign == 1) {
1664
- if (this.rec().lte(2)) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
1665
- } else {
1666
- if (this.abs().rec().lte(2)) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
1322
+ }, {
1323
+ key: "max",
1324
+ value: function max() {
1325
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1326
+ args[_key4] = arguments[_key4];
1667
1327
  }
1328
+ return PowiainaNum.max.apply(PowiainaNum, [this].concat(args));
1668
1329
  }
1669
- var r = this.abs();
1670
- r.array[0].repeat = Math.round(r.array[0].repeat);
1671
- r.sign = this.sign;
1672
- return r;
1673
- };
1674
- /**
1675
- * Work like `Math.trunc`,
1676
- *
1677
- * if `this > 0`, return `floor(this)`
1678
- *
1679
- * if `this < 0`, return `ceil(this)`
1680
- *
1681
- * @example
1682
- * new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
1683
- * new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
1684
- * @returns
1685
- */
1686
- PowiainaNum.prototype.trunc = function () {
1687
- var y = this.clone();
1688
- return y.gte(0) ? y.floor() : y.ceil();
1689
- };
1690
- /**
1691
- * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
1692
- */
1693
- PowiainaNum.sign = function (a) {
1694
- return new PowiainaNum(a).sign;
1695
- };
1696
- //#endregion
1697
- //#region judge-numbers
1698
- PowiainaNum.prototype.isNaN = function () {
1699
- return isNaN(this.getOperator(0));
1700
- };
1701
- PowiainaNum.prototype.isZero = function () {
1702
- return Boolean(this.small && !isFinite(this.getOperator(0)));
1703
- };
1704
- PowiainaNum.prototype.isFinite = function () {
1705
- return Boolean(this.small || isFinite(this.getOperator(0))) && !this.isNaN();
1706
- };
1707
- PowiainaNum.prototype.isInfi = function () {
1708
- return this.rec().isZero();
1709
- };
1710
- PowiainaNum.prototype.isInfiNaN = function () {
1711
- return this.isInfi() || this.isNaN();
1712
- };
1713
- PowiainaNum.prototype.isInt = function () {
1714
- if (this.isZero()) return true;
1715
- if (!this.small && Number.isInteger(this.getOperator(0))) return true;
1716
- if (this.abs().gte(MSI / 2)) return true;
1717
- return false;
1718
- };
1719
- PowiainaNum.prototype.ispos = function () {
1720
- return this.sign > 0;
1721
- };
1722
- PowiainaNum.prototype.isneg = function () {
1723
- return this.sign < 0;
1724
- };
1725
- PowiainaNum.isNaN = function (x) {
1726
- return new PowiainaNum(x).isNaN();
1727
- };
1728
- //#endregion
1729
- /**
1730
- * Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
1731
- * @returns normalized number
1732
- */
1733
- PowiainaNum.prototype.normalize = function () {
1734
- //TODO: normalize
1735
- var renormalize = true;
1736
- var x = this;
1737
- for (var i_1 = 0; i_1 < this.array.length; i_1++) {
1738
- // Check what is infinity
1739
- if (this.array[i_1].repeat == Infinity) {
1740
- this.array = [{
1741
- arrow: 0,
1742
- expans: 1,
1743
- megota: 1,
1744
- repeat: Infinity
1745
- }];
1746
- this.layer = 0;
1747
- return this;
1748
- }
1749
- }
1750
- for (var i = 1; i < x.array.length; ++i) {
1751
- var e = x.array[i];
1752
- if (e.arrow === null || e.arrow === undefined) {
1753
- e.arrow = 0;
1754
- }
1755
- if (e.expans === null || e.expans === undefined) {
1756
- e.expans = 1;
1757
- }
1758
- if (e.megota === null || e.megota === undefined) {
1759
- e.megota = 1;
1760
- }
1761
- if (isNaN(e.arrow) || isNaN(e.repeat) || isNaN(e.expans) || isNaN(e.megota)) {
1762
- x.array = [newOperator(NaN, 0, 1, 1)];
1763
- return x;
1330
+ }, {
1331
+ key: "min",
1332
+ value: function min() {
1333
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1334
+ args[_key5] = arguments[_key5];
1764
1335
  }
1765
- if (!isFinite(e.repeat) || !isFinite(e.megota)) {
1766
- x.array = [newOperator(Infinity, 0, 1, 1)];
1767
- return x;
1336
+ return PowiainaNum.min.apply(PowiainaNum, [this].concat(args));
1337
+ }
1338
+ /**
1339
+ * Compare what PowiainaNum's absolute value is max
1340
+ * @param args
1341
+ * @returns absolute value max number's absolute value
1342
+ */
1343
+ }, {
1344
+ key: "maxabs",
1345
+ value: function maxabs() {
1346
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1347
+ args[_key6] = arguments[_key6];
1348
+ }
1349
+ var other = args.map(function (x) {
1350
+ return new PowiainaNum(x).abs();
1351
+ });
1352
+ return PowiainaNum.max.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
1353
+ }
1354
+ }, {
1355
+ key: "minabs",
1356
+ value: function minabs() {
1357
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
1358
+ args[_key7] = arguments[_key7];
1768
1359
  }
1769
- if (!Number.isInteger(e.arrow)) e.arrow = Math.floor(e.arrow);
1770
- if (!Number.isInteger(e.repeat)) e.repeat = Math.floor(e.repeat);
1771
- if (!Number.isInteger(e.expans)) e.expans = Math.floor(e.expans);
1772
- if (!Number.isInteger(e.megota)) e.megota = Math.floor(e.megota);
1773
- }
1774
- if (!x.array.length) {
1775
- x.small = !x.small;
1776
- x.array = [newOperator(Infinity)]; // if no array set zero
1777
- }
1778
- do {
1779
- renormalize = false;
1780
- // Sort arrays.
1781
- this.array.sort(arraySortFunction);
1782
- for (i = 1; i < x.array.length - 1; ++i) {
1783
- if (x.array[i].arrow == x.array[i + 1].arrow && x.array[i].expans == x.array[i + 1].expans && x.array[i].megota == x.array[i + 1].megota) {
1784
- // same array's merge
1785
- x.array[i].repeat += x.array[i + 1].repeat;
1786
- x.array.splice(i + 1, 1);
1787
- --i;
1788
- renormalize = true;
1360
+ var other = args.map(function (x) {
1361
+ return new PowiainaNum(x).abs();
1362
+ });
1363
+ return PowiainaNum.min.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
1364
+ }
1365
+ }, {
1366
+ key: "cmpabs",
1367
+ value: function cmpabs(x) {
1368
+ var other = new PowiainaNum(x).abs();
1369
+ return this.abs().cmp(other);
1370
+ }
1371
+ }, {
1372
+ key: "compare",
1373
+ value: function compare(x) {
1374
+ var other = new PowiainaNum(x);
1375
+ if (this.isNaN() || other.isNaN()) return 2;
1376
+ if (this.sign < other.sign) return -1;
1377
+ if (this.sign > other.sign) return 1;
1378
+ //this.sign = other.sign
1379
+ var allneg = this.sign == -1 && other.sign == -1;
1380
+ if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
1381
+ if (other.small && !this.small) return 1 * (allneg ? -1 : 1);
1382
+ var resultreverse = 1;
1383
+ if (this.small && other.small) resultreverse *= -1;
1384
+ if (allneg) resultreverse *= -1;
1385
+ var result = 0;
1386
+ for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
1387
+ var op1 = this.array[this.array.length - 1 - i];
1388
+ var op2 = other.array[other.array.length - 1 - i];
1389
+ var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
1390
+ if (cmp == 1) {
1391
+ result = 1;
1392
+ break;
1393
+ } else if (cmp == -1) {
1394
+ result = -1;
1395
+ break;
1789
1396
  }
1790
1397
  }
1791
- for (i = 1; i < x.array.length; ++i) {
1792
- // If there is a 0 repeat operator, remove it.
1793
- if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
1794
- x.array.splice(i, 1);
1795
- --i;
1796
- continue;
1797
- }
1798
- // If there is a operator which arrow 0 and brace count >=2
1799
- // replace it as arrow replacement operaotr
1800
- if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
1801
- x.array[i].arrow = Infinity;
1802
- x.array[i].valuereplaced = 0;
1803
- x.array[i].expans = x.array[i].expans - 1;
1804
- }
1805
- }
1806
- if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
1807
- // for any 10^a but a >log10(MSI), replace to regular 10^a
1808
- if (this.array.length >= 2 && this.array[1].arrow == 1 && this.array[1].repeat >= 1 && this.array[0].repeat < MSI_LOG10) {
1809
- this.setOperator(this.array[1].repeat - 1, 1);
1810
- this.setOperator(Math.pow(10, this.array[0].repeat), 0);
1811
- renormalize = true;
1812
- }
1813
- if (this.getOperator(0) > MSI && isFinite(this.getOperator(0))) {
1814
- this.setOperator(this.getOperator(1) + 1, 1);
1815
- this.setOperator(Math.log10(this.getOperator(0)), 0);
1816
- renormalize = true;
1817
- }
1818
- if (this.array[this.array.length - 1].megota > MSI) {
1819
- this.layer++;
1820
- this.array = [newOperator(this.array[this.array.length - 1].megota)];
1821
- renormalize = true;
1822
- } else if (this.layer && this.array.length == 1 && this.array[0].arrow === 0) {
1823
- this.layer--;
1824
- this.array = [newOperator(10), newOperator(1, 10, 10, this.array[0].repeat)];
1825
- renormalize = true;
1826
- }
1827
- // for a<1, turn into reciprocate
1828
- if (this.array.length == 1 && this.array[0].repeat < 1) {
1829
- this.array[0].repeat = 1 / this.array[0].repeat;
1830
- this.small = !this.small;
1831
- renormalize = true;
1832
- }
1833
- while (x.array.length >= 2 && x.array[0].repeat == 1 && x.array[1].repeat) {
1834
- // for any 10{X}10{X} 1, turn into 10{X}10
1835
- // [1, [R=sth, A=sth, E=sth, M=sth]]
1836
- if (x.array[1].repeat > 1) {
1837
- x.array[1].repeat--;
1838
- } else {
1839
- x.array.splice(1, 1);
1840
- }
1841
- x.array[0].repeat = 10;
1842
- renormalize = true;
1843
- }
1844
- if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat > 1 &&
1845
- //10^^^ 10
1846
- isFinite(x.array[1].arrow)) {
1847
- // for any (10{A sample=2})^k 1e9, turn into (10{A})^k-1 (10{A-1})^1e9-1 10
1848
- // But dont convert when a is infinite
1849
- // [1e9, [R=K, A=2, sth, sth]]
1850
- x.array[1].repeat--;
1851
- x.array.splice(1, 0, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
1852
- x.array[0].repeat = 10;
1853
- renormalize = true;
1854
- }
1855
- if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1 &&
1856
- //10^^^ 10
1857
- isFinite(x.array[1].arrow)) {
1858
- // for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
1859
- // But dont convert when a is infinite
1860
- // [1e9, [R=1, A=2, sth, sth]]
1861
- x.array.splice(1, 1, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
1862
- x.array[0].repeat = 10;
1863
- renormalize = true;
1864
- }
1865
- // for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
1866
- if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow !== Infinity) {
1867
- x.array[1].arrow++;
1868
- x.array[0].repeat = x.array[1].repeat;
1869
- x.array[1].repeat = 1;
1870
- renormalize = true;
1871
- }
1872
- // for any (10{x})^1e16 10, turn into (10{1,2}) 1e16
1873
- if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow === Infinity) {
1874
- x.array[1].arrow = 1;
1875
- x.array[1].expans++;
1876
- x.array[0].repeat = x.array[1].repeat;
1877
- x.array[1].repeat = 1;
1878
- renormalize = true;
1879
- }
1880
- } while (renormalize);
1881
- return this;
1882
- };
1883
- //#region operators
1884
- /**
1885
- * @returns number will return the index of the operator in array. return as x.5 if it's between the xth and x+1th operators.
1886
- */
1887
- PowiainaNum.prototype.getOperatorIndex = function (arrow, expans, megota) {
1888
- if (expans === void 0) {
1889
- expans = 1;
1398
+ return result * resultreverse + 1 - 1;
1399
+ }
1400
+ }, {
1401
+ key: "cmp",
1402
+ value: function cmp(other) {
1403
+ return this.compare(other);
1404
+ }
1405
+ }, {
1406
+ key: "eq",
1407
+ value: function eq(other) {
1408
+ return this.cmp(other) === 0;
1409
+ }
1410
+ }, {
1411
+ key: "neq",
1412
+ value: function neq(other) {
1413
+ return this.cmp(other) !== 0;
1414
+ }
1415
+ }, {
1416
+ key: "lt",
1417
+ value: function lt(other) {
1418
+ return this.cmp(other) === -1;
1419
+ }
1420
+ }, {
1421
+ key: "lte",
1422
+ value: function lte(other) {
1423
+ return this.cmp(other) <= 0;
1424
+ }
1425
+ }, {
1426
+ key: "gt",
1427
+ value: function gt(other) {
1428
+ return this.cmp(other) == 1;
1429
+ }
1430
+ }, {
1431
+ key: "gte",
1432
+ value: function gte(other) {
1433
+ var t = this.cmp(other);
1434
+ return t == 0 || t == 1;
1435
+ }
1436
+ }, {
1437
+ key: "eq_tolerance",
1438
+ value: function eq_tolerance(value) {
1439
+ var tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-7;
1440
+ var dec = new PowiainaNum(value);
1441
+ return this.sub(dec).lte(this.max(dec).mul(tolerance));
1442
+ }
1443
+ //#endregion
1444
+ //#region geometry
1445
+ }, {
1446
+ key: "sin",
1447
+ value: function sin() {
1448
+ var x = this.clone();
1449
+ if (x.isneg()) {
1450
+ return x.neg().sin().neg();
1451
+ }
1452
+ var y = x.mod(7074237752028440);
1453
+ return PowiainaNum.fromNumber(Math.sin(y.toNumber()));
1454
+ }
1455
+ }, {
1456
+ key: "cos",
1457
+ value: function cos() {
1458
+ return this.sub(Math.PI / 2).sin();
1459
+ }
1460
+ }, {
1461
+ key: "tan",
1462
+ value: function tan() {
1463
+ return this.sin().div(this.cos());
1464
+ }
1465
+ }, {
1466
+ key: "cot",
1467
+ value: function cot() {
1468
+ return this.cos().div(this.sin());
1469
+ }
1470
+ }, {
1471
+ key: "sec",
1472
+ value: function sec() {
1473
+ return this.cos().rec();
1474
+ }
1475
+ }, {
1476
+ key: "csc",
1477
+ value: function csc() {
1478
+ return this.sin().rec();
1479
+ }
1480
+ //#endregion
1481
+ //#region neg, rec, floor, ceil, round, trunc, sign
1482
+ }, {
1483
+ key: "neg",
1484
+ value: function neg() {
1485
+ var a = this.clone();
1486
+ a.sign *= -1;
1487
+ a.normalize();
1488
+ return a;
1890
1489
  }
1891
- if (megota === void 0) {
1892
- megota = 1;
1490
+ }, {
1491
+ key: "rec",
1492
+ value: function rec() {
1493
+ var a = this.clone();
1494
+ a.small = !a.small;
1495
+ return a;
1893
1496
  }
1894
- for (var i = 0; i < this.array.length; i++) {
1895
- var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1896
- if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1897
- if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
1497
+ }, {
1498
+ key: "floor",
1499
+ value: function floor() {
1500
+ if (this.isInt()) return this.clone();
1501
+ if (this.small) {
1502
+ if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
1503
+ }
1504
+ var r = this.abs();
1505
+ r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
1506
+ return r;
1898
1507
  }
1899
- return this.array.length - 0.5;
1900
- };
1901
- /**
1902
- * @returns number repeats of operators with given arguments.
1903
- */
1904
- PowiainaNum.prototype.getOperator = function (arrow, expans, megota) {
1905
- if (expans === void 0) {
1906
- expans = 1;
1508
+ }, {
1509
+ key: "ceil",
1510
+ value: function ceil() {
1511
+ if (this.isInt()) return this.clone();
1512
+ if (this.small) {
1513
+ if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
1514
+ }
1515
+ var r = this.abs();
1516
+ r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
1517
+ r.sign = this.sign;
1518
+ return r;
1907
1519
  }
1908
- if (megota === void 0) {
1909
- megota = 1;
1520
+ }, {
1521
+ key: "round",
1522
+ value: function round() {
1523
+ if (this.isInt()) return this.clone();
1524
+ if (this.small) {
1525
+ if (this.sign == 1) {
1526
+ if (this.rec().lte(2)) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
1527
+ } else {
1528
+ if (this.abs().rec().lte(2)) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
1529
+ }
1530
+ }
1531
+ var r = this.abs();
1532
+ r.array[0].repeat = Math.round(r.array[0].repeat);
1533
+ r.sign = this.sign;
1534
+ return r;
1910
1535
  }
1911
- var index = this.getOperatorIndex(arrow, expans, megota);
1912
- if (!this.array[index]) return 0;
1913
- return this.array[index].repeat;
1914
- };
1915
- /**
1916
- * Modify the repeat of operator
1917
- * @param number val the repeat of operator will modify to array.
1918
- * @returns bool Is the operators array changed?
1919
- */
1920
- PowiainaNum.prototype.setOperator = function (val, arrow, expans, megota) {
1921
- if (expans === void 0) {
1922
- expans = 1;
1923
- }
1924
- if (megota === void 0) {
1925
- megota = 1;
1926
- }
1927
- // if (arrow!=0&&val==0) return false;
1928
- var index = this.getOperatorIndex(arrow, expans, megota);
1929
- if (!this.array[index]) {
1930
- this.array.splice(Math.ceil(index), 0, {
1931
- arrow: arrow,
1932
- expans: expans,
1933
- megota: megota,
1934
- valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1935
- repeat: val
1936
- });
1937
- return true;
1536
+ /**
1537
+ * Work like `Math.trunc`,
1538
+ *
1539
+ * if `this > 0`, return `floor(this)`
1540
+ *
1541
+ * if `this < 0`, return `ceil(this)`
1542
+ *
1543
+ * @example
1544
+ * new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
1545
+ * new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
1546
+ * @returns
1547
+ */
1548
+ }, {
1549
+ key: "trunc",
1550
+ value: function trunc() {
1551
+ var y = this.clone();
1552
+ return y.gte(0) ? y.floor() : y.ceil();
1938
1553
  }
1939
- this.array[index].repeat = val;
1940
- // this.normalize()
1941
- return false;
1942
- };
1943
- //#endregion
1944
- /**
1945
- * @returns a PowiainaNum object which deep copied from `this` object.
1946
- */
1947
- PowiainaNum.prototype.clone = function () {
1948
- var obj = new PowiainaNum();
1949
- obj.resetFromObject(this);
1950
- return obj;
1951
- };
1952
- /**
1953
- * Set `this` from a object(deep-copy)
1954
- * @param powlikeObject
1955
- * @returns
1956
- */
1957
- PowiainaNum.prototype.resetFromObject = function (powlikeObject) {
1958
- this.array = [];
1959
- for (var i = 0; i < powlikeObject.array.length; i++) {
1960
- this.array[i] = {
1961
- arrow: powlikeObject.array[i].arrow,
1962
- expans: powlikeObject.array[i].expans,
1963
- megota: powlikeObject.array[i].megota,
1964
- repeat: powlikeObject.array[i].repeat,
1965
- valuereplaced: powlikeObject.array[i].valuereplaced
1554
+ /**
1555
+ * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
1556
+ */
1557
+ }, {
1558
+ key: "isNaN",
1559
+ value: function (_isNaN) {
1560
+ function isNaN() {
1561
+ return _isNaN.apply(this, arguments);
1562
+ }
1563
+ isNaN.toString = function () {
1564
+ return _isNaN.toString();
1966
1565
  };
1967
- }
1968
- this.small = powlikeObject.small;
1969
- this.sign = powlikeObject.sign;
1970
- this.layer = powlikeObject.layer;
1971
- return this;
1972
- };
1973
- //#region converters
1974
- /**
1975
- * Convert `this` to Javascript `number`
1976
- *
1977
- * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1978
- */
1979
- PowiainaNum.prototype.toNumber = function () {
1980
- if (this.sign == -1) return -this.neg().toNumber();
1981
- if (this.small) return 1 / this.rec().toNumber();
1982
- if (this.array.length > 2) return Infinity;
1983
- if (this.array.length == 1) return this.array[0].repeat;else if (this.array.length == 2 && this.array[1].arrow == 1 && this.array[1].expans == 1 && this.array[1].megota == 1 && this.array[1].repeat == 1) return Math.pow(10, this.getOperator(0));
1984
- return NaN;
1985
- };
1986
- /**
1987
- * Convert `this` to a string
1988
- */
1989
- PowiainaNum.prototype.toString = function () {
1990
- if (this.isNaN()) return "NaN";
1991
- if (this.sign == -1) return "-".concat(this.neg().toString());
1992
- if (this.small) {
1993
- if (this.isZero()) return "0";
1994
- return "/".concat(this.rec().toString());
1995
- }
1996
- if (this.isInfi()) return "Infinity";
1997
- // P^a (10{arrow,expans,megota})^repeation base
1998
- var res = "";
1999
- if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
2000
- for (var i = this.array.length - 1; i >= 0; i--) {
2001
- var oper = this.array[i];
2002
- var calc = "10{".concat(oper.arrow === Infinity ? "!" : oper.arrow).concat(oper.expans > 1 || oper.megota > 1 ? ",".concat(oper.expans === Infinity ? "!" : oper.expans) : "").concat(oper.megota > 1 ? ",".concat(oper.megota) : "", "}");
2003
- if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
2004
- calc = "e".repeat(oper.repeat);
2005
- } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
2006
- calc = oper.repeat.toString();
2007
- } else if (oper.repeat > 1) {
2008
- calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
2009
- } else {
2010
- calc = "".concat(calc);
2011
- }
2012
- res += "".concat(calc);
2013
- }
2014
- return res;
2015
- };
2016
- PowiainaNum.fromNumber = function (x) {
2017
- var obj = new PowiainaNum(); // NaN
2018
- if (x < 0) obj.sign = -1; // negative
2019
- else if (x == 0) {
2020
- obj.sign = 0;
2021
- obj.small = true;
2022
- obj.array = [newOperator(Infinity, 0)];
2023
- return obj;
2024
- } else if (x > 0) obj.sign = 1;
2025
- var y = Math.abs(x);
2026
- if (y == Infinity) {
2027
- obj.array = [newOperator(Infinity, 0)];
2028
- } else if (y >= MSI_REC && y < 1) {
2029
- obj.small = true;
2030
- obj.array = [newOperator(1 / y, 0)];
2031
- } else if (y < MSI_REC) {
2032
- obj.small = true;
2033
- obj.array = [newOperator(-Math.log10(y), 0), newOperator(1, 1)];
2034
- } else if (y <= MSI) {
2035
- obj.array = [newOperator(y, 0)];
2036
- } else {
2037
- obj.setOperator(Math.log10(y), 0);
2038
- obj.array = [newOperator(Math.log10(y), 0), newOperator(1, 1)];
2039
- }
2040
- return obj;
2041
- };
2042
- /**
2043
- * Convert `this` to a JSON object
2044
- * @returns a JSON object
2045
- */
2046
- PowiainaNum.prototype.toJSON = function () {
2047
- return "PN" + this.toString();
2048
- };
2049
- PowiainaNum.fromString = function (input) {
2050
- var _b, _c, _d, _e, _f, _g;
2051
- var x = new PowiainaNum();
2052
- // Judge the string was a number
2053
- if (input.startsWith("PN")) input = input.substring(2);
2054
- if (!isNaN(Number(input))) {
2055
- var res = Number(input);
2056
- var a_1 = false;
2057
- if (res == 0) {
2058
- if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
2059
- a_1 = true;
1566
+ return isNaN;
1567
+ }(
1568
+ //#endregion
1569
+ //#region judge-numbers
1570
+ function () {
1571
+ return isNaN(this.getOperator(0));
1572
+ })
1573
+ }, {
1574
+ key: "isZero",
1575
+ value: function isZero() {
1576
+ return Boolean(this.small && !isFinite(this.getOperator(0)));
1577
+ }
1578
+ }, {
1579
+ key: "isFinite",
1580
+ value: function (_isFinite) {
1581
+ function isFinite() {
1582
+ return _isFinite.apply(this, arguments);
1583
+ }
1584
+ isFinite.toString = function () {
1585
+ return _isFinite.toString();
1586
+ };
1587
+ return isFinite;
1588
+ }(function () {
1589
+ return Boolean(this.small || isFinite(this.getOperator(0))) && !this.isNaN();
1590
+ })
1591
+ }, {
1592
+ key: "isInfi",
1593
+ value: function isInfi() {
1594
+ return this.rec().isZero();
1595
+ }
1596
+ }, {
1597
+ key: "isInfiNaN",
1598
+ value: function isInfiNaN() {
1599
+ return this.isInfi() || this.isNaN();
1600
+ }
1601
+ }, {
1602
+ key: "isInt",
1603
+ value: function isInt() {
1604
+ if (this.isZero()) return true;
1605
+ if (!this.small && Number.isInteger(this.getOperator(0))) return true;
1606
+ if (this.abs().gte(MSI / 2)) return true;
1607
+ return false;
1608
+ }
1609
+ }, {
1610
+ key: "ispos",
1611
+ value: function ispos() {
1612
+ return this.sign > 0;
1613
+ }
1614
+ }, {
1615
+ key: "isneg",
1616
+ value: function isneg() {
1617
+ return this.sign < 0;
1618
+ }
1619
+ }, {
1620
+ key: "normalize",
1621
+ value:
1622
+ //#endregion
1623
+ /**
1624
+ * Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
1625
+ * @returns normalized number
1626
+ */
1627
+ function normalize() {
1628
+ //TODO: normalize
1629
+ var renormalize = true;
1630
+ var x = this;
1631
+ for (var _i = 0; _i < this.array.length; _i++) {
1632
+ // Check what is infinity
1633
+ if (this.array[_i].repeat == Infinity) {
1634
+ this.array = [{
1635
+ arrow: 0,
1636
+ expans: 1,
1637
+ megota: 1,
1638
+ repeat: Infinity
1639
+ }];
1640
+ this.layer = 0;
1641
+ return this;
2060
1642
  }
2061
- } else {
2062
- a_1 = true;
2063
- }
2064
- if (!a_1) {
2065
- var m = input.search(/e/);
2066
- var exponent = input.substring((m == -1 ? input.length : m) + 1);
2067
- var mantissa = input.substring(0, m == -1 ? undefined : m);
2068
- var mantissaME = [0, 0];
2069
- // Handle mantissa to ME
2070
- mantissaME[1] = Number(exponent ? exponent : "0");
2071
- // Is regular number gte 1:
2072
- if (Number(mantissa) >= 1) {
2073
- // check The mantissa is very long?
2074
- var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
2075
- var log10int = Math.floor(log10mant) - 1;
2076
- var log10float = log10mant - log10int;
2077
- mantissaME[0] = Math.pow(10, log10float);
2078
- mantissaME[1] += log10float;
2079
- } else {
2080
- // If not , count how many zeros until reached non-zero numbers
2081
- var zeros = countLeadingZerosAfterDecimal(mantissa);
2082
- mantissa = mantissa.substring(mantissa.search(/[1-9]/));
2083
- mantissa = mantissa.charAt(0) + "." + mantissa.substring(1);
2084
- zeros += 1;
2085
- mantissaME[0] = Number(mantissa);
2086
- mantissaME[1] += -zeros;
2087
- }
2088
- // We'll get [a, b] which respents a*10^b;
2089
- // actually b < 0; So we can ^-1
2090
- // /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
2091
- return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
2092
- }
2093
- if (isFinite(res) && a_1) {
2094
- x = PowiainaNum.fromNumber(Number(input));
2095
- return x;
2096
1643
  }
2097
- }
2098
- input = replaceETo10(input);
2099
- if (!isPowiainaNum.test(input)) {
2100
- throw powiainaNumError + "malformed input: " + input;
2101
- }
2102
- var negateIt = false;
2103
- var recipIt = false;
2104
- if (input[0] == "-" || input[0] == "+") {
2105
- var numSigns = input.search(/[^-\+]/);
2106
- var signs = input.substring(0, numSigns);
2107
- negateIt = ((_c = (_b = signs.match(/-/g)) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) % 2 == 1;
2108
- input = input.substring(numSigns);
2109
- }
2110
- if (input[0] == "/") {
2111
- var numSigns = input.search(/[^\/]/);
2112
- var signs = input.substring(0, numSigns);
2113
- recipIt = ((_e = (_d = signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2114
- input = input.substring(numSigns);
2115
- }
2116
- if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
2117
- x.sign = 1;
2118
- x.array = [newOperator(0)];
2119
- var a, b, c, d;
2120
- if (input[0] == "P") {
2121
- if (input[1] == "^") {
2122
- a = input.substring(2).search(/[^0-9]/) + 2;
2123
- x.layer = Number(input.substring(2, a));
2124
- input = input.substring(a + 1);
2125
- } else {
2126
- a = input.search(/[^P]/);
2127
- x.layer = a;
2128
- input = input.substring(a);
2129
- }
2130
- }
2131
- while (input) {
2132
- if (/^(\(?10[\^\{])/.test(input)) {
2133
- /*
2134
- 10^ - 匹配
2135
- 10{ - 匹配
2136
- (10^ - 匹配
2137
- (10{ - 匹配
2138
- 10x - 不匹配(最后一个字符不是 ^ 或 {)
2139
- 110^ - 不匹配(不是以 10 开头)
2140
- */
2141
- if (input[0] == "(") input = input.substring(1);
2142
- //cutted, 10^.... or 10{....
2143
- var arrows, expans, megota;
2144
- if (input[2] == "^") {
2145
- a = input.substring(2).search(/[^\^]/);
2146
- //cut input to ^^...^^, and search how numbers
2147
- arrows = a;
2148
- // 10^^^
2149
- b = a + 2; // b points to after ^'s.
2150
- } else {
2151
- // 10{...}
2152
- a = input.indexOf("}");
2153
- // select contents between {...}
2154
- var tmp = input.substring(3, a).split(",");
2155
- arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
2156
- expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
2157
- megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
2158
- b = a + 1;
2159
- // b points to after }.
1644
+ for (var i = 1; i < x.array.length; ++i) {
1645
+ var e = x.array[i];
1646
+ if (e.arrow === null || e.arrow === undefined) {
1647
+ e.arrow = 0;
1648
+ }
1649
+ if (e.expans === null || e.expans === undefined) {
1650
+ e.expans = 1;
1651
+ }
1652
+ if (e.megota === null || e.megota === undefined) {
1653
+ e.megota = 1;
1654
+ }
1655
+ if (isNaN(e.arrow) || isNaN(e.repeat) || isNaN(e.expans) || isNaN(e.megota)) {
1656
+ x.array = [newOperator(NaN, 0, 1, 1)];
1657
+ return x;
1658
+ }
1659
+ if (!isFinite(e.repeat) || !isFinite(e.megota)) {
1660
+ x.array = [newOperator(Infinity, 0, 1, 1)];
1661
+ return x;
1662
+ }
1663
+ if (!Number.isInteger(e.arrow)) e.arrow = Math.floor(e.arrow);
1664
+ if (!Number.isInteger(e.repeat)) e.repeat = Math.floor(e.repeat);
1665
+ if (!Number.isInteger(e.expans)) e.expans = Math.floor(e.expans);
1666
+ if (!Number.isInteger(e.megota)) e.megota = Math.floor(e.megota);
1667
+ }
1668
+ if (!x.array.length) {
1669
+ x.small = !x.small;
1670
+ x.array = [newOperator(Infinity)]; // if no array set zero
1671
+ }
1672
+ do {
1673
+ renormalize = false;
1674
+ // Sort arrays.
1675
+ this.array.sort(arraySortFunction);
1676
+ for (i = 1; i < x.array.length - 1; ++i) {
1677
+ if (x.array[i].arrow == x.array[i + 1].arrow && x.array[i].expans == x.array[i + 1].expans && x.array[i].megota == x.array[i + 1].megota) {
1678
+ // same array's merge
1679
+ x.array[i].repeat += x.array[i + 1].repeat;
1680
+ x.array.splice(i + 1, 1);
1681
+ --i;
1682
+ renormalize = true;
2160
1683
  }
2161
- input = input.substring(b);
2162
- if (input[0] == ")") {
2163
- // )^....<Space>
2164
- a = input.indexOf(" ");
2165
- c = Number(input.substring(2, a)); // Select contents between )^....<Space>
2166
- input = input.substring(a + 1); // c points to after <Space>
2167
- } else {
2168
- c = 1; // There is only spaces, count as <ONE>
1684
+ }
1685
+ for (i = 1; i < x.array.length; ++i) {
1686
+ // If there is a 0 repeat operator, remove it.
1687
+ if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
1688
+ x.array.splice(i, 1);
1689
+ --i;
1690
+ continue;
2169
1691
  }
2170
- if (arrows == 1 && expans == 1 && megota == 1) {
2171
- if (x.array.length >= 2 && x.array[1].arrow == 1) {
2172
- x.array[1].repeat += c;
2173
- } else {
2174
- x.array.splice(1, 0, newOperator(c, 1, expans, megota));
2175
- }
2176
- } else if (arrows == 2 && expans == 1 && megota == 1) {
2177
- a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2178
- b = x.array[0].repeat;
2179
- if (b >= 1e10) ++a;
2180
- if (b >= 10) ++a;
2181
- x.array[0].repeat = a;
2182
- if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
2183
- d = x.getOperatorIndex(2);
2184
- if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
2185
- } else if (isFinite(arrows)) {
2186
- a = x.getOperator(arrows - 1);
2187
- b = x.getOperator(arrows - 2);
2188
- if (b >= 10) ++a;
2189
- d = x.getOperatorIndex(arrows);
2190
- x.array.splice(1, Math.ceil(d) - 1);
2191
- x.array[0].repeat = a;
2192
- if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
2193
- } else {
2194
- x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
1692
+ // If there is a operator which arrow 0 and brace count >=2
1693
+ // replace it as arrow replacement operaotr
1694
+ if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
1695
+ x.array[i].arrow = Infinity;
1696
+ x.array[i].valuereplaced = 0;
1697
+ x.array[i].expans = x.array[i].expans - 1;
2195
1698
  }
2196
- } else {
2197
- break;
2198
1699
  }
2199
- }
2200
- a = input.split(/[Ee]/);
2201
- b = [x.array[0].repeat, 0];
2202
- c = 1;
2203
- for (var i_2 = a.length - 1; i_2 >= 0; --i_2) {
2204
- //The things that are already there
2205
- if (b[0] < MSI_LOG10 && b[1] === 0) {
2206
- b[0] = Math.pow(10, c * b[0]);
2207
- } else if (c == -1) {
2208
- if (b[1] === 0) {
2209
- b[0] = Math.pow(10, c * b[0]);
2210
- } else if (b[1] == 1 && b[0] <= Math.log10(Number.MAX_VALUE)) {
2211
- b[0] = Math.pow(10, c * Math.pow(10, b[0]));
1700
+ if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
1701
+ // for any 10^a but a >log10(MSI), replace to regular 10^a
1702
+ if (this.array.length >= 2 && this.array[1].arrow == 1 && this.array[1].repeat >= 1 && this.array[0].repeat < MSI_LOG10) {
1703
+ this.setOperator(this.array[1].repeat - 1, 1);
1704
+ this.setOperator(Math.pow(10, this.array[0].repeat), 0);
1705
+ renormalize = true;
1706
+ }
1707
+ if (this.getOperator(0) > MSI && isFinite(this.getOperator(0))) {
1708
+ this.setOperator(this.getOperator(1) + 1, 1);
1709
+ this.setOperator(Math.log10(this.getOperator(0)), 0);
1710
+ renormalize = true;
1711
+ }
1712
+ if (this.array[this.array.length - 1].megota > MSI) {
1713
+ this.layer++;
1714
+ this.array = [newOperator(this.array[this.array.length - 1].megota)];
1715
+ renormalize = true;
1716
+ } else if (this.layer && this.array.length == 1 && this.array[0].arrow === 0) {
1717
+ this.layer--;
1718
+ this.array = [newOperator(10), newOperator(1, 10, 10, this.array[0].repeat)];
1719
+ renormalize = true;
1720
+ }
1721
+ // for a<1, turn into reciprocate
1722
+ if (this.array.length == 1 && this.array[0].repeat < 1) {
1723
+ this.array[0].repeat = 1 / this.array[0].repeat;
1724
+ this.small = !this.small;
1725
+ renormalize = true;
1726
+ }
1727
+ // for any 10{X>9e15}10, replace into 10{!}X;
1728
+ if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
1729
+ this.array[0].repeat = this.array[1].arrow;
1730
+ this.array[1] = newOperator(1, Infinity, this.array[1].expans, this.array[1].megota);
1731
+ }
1732
+ while (x.array.length >= 2 && x.array[0].repeat == 1 && x.array[1].repeat) {
1733
+ // for any 10{X}10{X} 1, turn into 10{X}10
1734
+ // [1, [R=sth, A=sth, E=sth, M=sth]]
1735
+ if (x.array[1].repeat > 1) {
1736
+ x.array[1].repeat--;
2212
1737
  } else {
2213
- b[0] = 0;
1738
+ x.array.splice(1, 1);
2214
1739
  }
2215
- b[1] = 0;
2216
- } else {
2217
- b[1]++;
1740
+ x.array[0].repeat = 10;
1741
+ renormalize = true;
2218
1742
  }
2219
- //Multiplying coefficient
2220
- var decimalPointPos = a[i_2].indexOf(".");
2221
- var intPartLen = decimalPointPos == -1 ? a[i_2].length : decimalPointPos;
2222
- if (b[1] === 0) {
2223
- if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(a[i_2].substring(0, intPartLen)), b[1] = 1;else if (a[i_2]) b[0] *= Number(a[i_2]);
2224
- } else {
2225
- d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[i_2].substring(0, intPartLen)) : a[i_2] ? Math.log10(Number(a[i_2])) : 0;
2226
- if (b[1] == 1) {
2227
- b[0] += d;
2228
- } else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
2229
- b[0] += Math.log10(1 + Math.pow(10, Math.log10(d) - b[0]));
2230
- }
1743
+ if (x.array.length >= 2 && x.array.length < PowiainaNum.maxOps && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat > 1 &&
1744
+ //10^^^ 10
1745
+ isFinite(x.array[1].arrow)) {
1746
+ // for any (10{A sample=2})^k 1e9, turn into (10{A})^k-1 (10{A-1})^1e9-1 10
1747
+ // But dont convert when a is infinite
1748
+ // [1e9, [R=K, A=2, sth, sth]]
1749
+ x.array[1].repeat--;
1750
+ x.array.splice(1, 0, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
1751
+ x.array[0].repeat = 10;
1752
+ renormalize = true;
2231
1753
  }
2232
- //Carrying
2233
- if (b[0] < MSI_LOG10 && b[1]) {
2234
- b[0] = Math.pow(10, b[0]);
2235
- b[1]--;
2236
- } else if (b[0] > MSI) {
2237
- b[0] = Math.log10(b[0]);
2238
- b[1]++;
1754
+ if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1 &&
1755
+ //10^^^ 10
1756
+ isFinite(x.array[1].arrow)) {
1757
+ // for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
1758
+ // But dont convert when a is infinite
1759
+ // [1e9, [R=1, A=2, sth, sth]]
1760
+ x.array.splice(1, 1, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
1761
+ x.array[0].repeat = 10;
1762
+ renormalize = true;
2239
1763
  }
1764
+ // for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
1765
+ if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow !== Infinity) {
1766
+ x.array[1].arrow++;
1767
+ x.array[0].repeat = x.array[1].repeat;
1768
+ x.array[1].repeat = 1;
1769
+ renormalize = true;
1770
+ }
1771
+ // for any (10{x})^1e16 10, turn into (10{1,2}) 1e16
1772
+ if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow === Infinity) {
1773
+ x.array[1].arrow = 1;
1774
+ x.array[1].expans++;
1775
+ x.array[0].repeat = x.array[1].repeat;
1776
+ x.array[1].repeat = 1;
1777
+ renormalize = true;
1778
+ }
1779
+ } while (renormalize);
1780
+ return this;
1781
+ }
1782
+ //#region operators
1783
+ /**
1784
+ * @returns number will return the index of the operator in array. return as x.5 if it's between the xth and x+1th operators.
1785
+ */
1786
+ }, {
1787
+ key: "getOperatorIndex",
1788
+ value: function getOperatorIndex(arrow) {
1789
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1790
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1791
+ for (var i = 0; i < this.array.length; i++) {
1792
+ var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1793
+ if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1794
+ if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
2240
1795
  }
2241
- x.array[0].repeat = b[0];
2242
- if (b[1]) {
2243
- if (x.array.length >= 2 && x.array[1].arrow == 1 && x.array[1].expans == 1 && x.array[1].megota == 1) x.array[1].repeat += b[1];else x.array.splice(1, 0, newOperator(b[1], 1, 1, 1));
2244
- }
1796
+ return this.array.length - 0.5;
2245
1797
  }
2246
- if (negateIt) x.sign *= -1;
2247
- if (recipIt) x.small = !x.small;
2248
- x.normalize();
2249
- x.normalize();
2250
- return x;
2251
- };
2252
- PowiainaNum.fromObject = function (powlikeObject) {
2253
- var obj = new PowiainaNum();
2254
- obj.array = [];
2255
- if (isExpantaNumArray(powlikeObject)) {
2256
- for (var i = 0; i < powlikeObject.length; i++) {
2257
- obj.array[i] = {
2258
- arrow: powlikeObject[i][0],
2259
- expans: 1,
2260
- megota: 1,
2261
- repeat: powlikeObject[i][1]
2262
- };
1798
+ /**
1799
+ * @returns number repeats of operators with given arguments.
1800
+ */
1801
+ }, {
1802
+ key: "getOperator",
1803
+ value: function getOperator(arrow) {
1804
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1805
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1806
+ var index = this.getOperatorIndex(arrow, expans, megota);
1807
+ if (!this.array[index]) return 0;
1808
+ return this.array[index].repeat;
1809
+ }
1810
+ /**
1811
+ * Modify the repeat of operator
1812
+ * @param number val the repeat of operator will modify to array.
1813
+ * @returns bool Is the operators array changed?
1814
+ */
1815
+ }, {
1816
+ key: "setOperator",
1817
+ value: function setOperator(val, arrow) {
1818
+ var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1819
+ var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1820
+ // if (arrow!=0&&val==0) return false;
1821
+ var index = this.getOperatorIndex(arrow, expans, megota);
1822
+ if (!this.array[index]) {
1823
+ this.array.splice(Math.ceil(index), 0, {
1824
+ arrow: arrow,
1825
+ expans: expans,
1826
+ megota: megota,
1827
+ valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1828
+ repeat: val
1829
+ });
1830
+ return true;
2263
1831
  }
2264
- obj.small = false;
2265
- obj.sign = 1;
2266
- obj.layer = 0;
1832
+ this.array[index].repeat = val;
1833
+ // this.normalize()
1834
+ return false;
1835
+ }
1836
+ //#endregion
1837
+ /**
1838
+ * @returns a PowiainaNum object which deep copied from `this` object.
1839
+ */
1840
+ }, {
1841
+ key: "clone",
1842
+ value: function clone() {
1843
+ var obj = new PowiainaNum();
1844
+ obj.resetFromObject(this);
2267
1845
  return obj;
2268
- } else {
1846
+ }
1847
+ /**
1848
+ * Set `this` from a object(deep-copy)
1849
+ * @param powlikeObject
1850
+ * @returns
1851
+ */
1852
+ }, {
1853
+ key: "resetFromObject",
1854
+ value: function resetFromObject(powlikeObject) {
1855
+ this.array = [];
2269
1856
  for (var i = 0; i < powlikeObject.array.length; i++) {
2270
- obj.array[i] = {
1857
+ this.array[i] = {
2271
1858
  arrow: powlikeObject.array[i].arrow,
2272
1859
  expans: powlikeObject.array[i].expans,
2273
1860
  megota: powlikeObject.array[i].megota,
@@ -2275,17 +1862,75 @@
2275
1862
  valuereplaced: powlikeObject.array[i].valuereplaced
2276
1863
  };
2277
1864
  }
2278
- obj.small = powlikeObject.small;
2279
- obj.sign = powlikeObject.sign;
2280
- obj.layer = powlikeObject.layer;
2281
- return obj;
1865
+ this.small = powlikeObject.small;
1866
+ this.sign = powlikeObject.sign;
1867
+ this.layer = powlikeObject.layer;
1868
+ return this;
2282
1869
  }
2283
- };
2284
- Object.defineProperty(PowiainaNum.prototype, "arr01", {
1870
+ //#region converters
1871
+ /**
1872
+ * Convert `this` to Javascript `number`
1873
+ *
1874
+ * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1875
+ */
1876
+ }, {
1877
+ key: "toNumber",
1878
+ value: function toNumber() {
1879
+ if (this.sign == -1) return -this.neg().toNumber();
1880
+ if (this.small) return 1 / this.rec().toNumber();
1881
+ if (this.array.length > 2) return Infinity;
1882
+ if (this.array.length == 1) return this.array[0].repeat;else if (this.array.length == 2 && this.array[1].arrow == 1 && this.array[1].expans == 1 && this.array[1].megota == 1 && this.array[1].repeat == 1) return Math.pow(10, this.getOperator(0));
1883
+ return NaN;
1884
+ }
1885
+ /**
1886
+ * Convert `this` to a string
1887
+ */
1888
+ }, {
1889
+ key: "toString",
1890
+ value: function toString() {
1891
+ if (this.isNaN()) return "NaN";
1892
+ if (this.sign == -1) return "-".concat(this.neg().toString());
1893
+ if (this.small) {
1894
+ if (this.isZero()) return "0";
1895
+ return "/".concat(this.rec().toString());
1896
+ }
1897
+ if (this.isInfi()) return "Infinity";
1898
+ // P^a (10{arrow,expans,megota})^repeation base
1899
+ var res = "";
1900
+ if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
1901
+ for (var i = this.array.length - 1; i >= 0; i--) {
1902
+ var oper = this.array[i];
1903
+ var calc = "10{".concat(oper.arrow === Infinity ? "!" : oper.arrow).concat(oper.expans > 1 || oper.megota > 1 ? ",".concat(oper.expans === Infinity ? "!" : oper.expans) : "").concat(oper.megota > 1 ? ",".concat(oper.megota) : "", "}");
1904
+ if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
1905
+ calc = "e".repeat(oper.repeat);
1906
+ } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
1907
+ calc = oper.repeat.toString();
1908
+ } else if (oper.repeat > 1) {
1909
+ calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1910
+ } else {
1911
+ calc = "".concat(calc);
1912
+ }
1913
+ res += "".concat(calc);
1914
+ }
1915
+ return res;
1916
+ }
1917
+ }, {
1918
+ key: "toJSON",
1919
+ value:
1920
+ /**
1921
+ * Convert `this` to a JSON object
1922
+ * @returns a JSON object
1923
+ */
1924
+ function toJSON() {
1925
+ return "PN" + this.toString();
1926
+ }
1927
+ }, {
1928
+ key: "arr01",
1929
+ get:
2285
1930
  /**
2286
1931
  * A property array value for version 0.1.x PowiainaNum.
2287
1932
  */
2288
- get: function get() {
1933
+ function get() {
2289
1934
  var res = [0];
2290
1935
  for (var i = 0; i < this.array.length; i++) {
2291
1936
  if (i == 0) res[0] = this.array[i].repeat;else {
@@ -2302,227 +1947,860 @@
2302
1947
  }
2303
1948
  }
2304
1949
  return res;
2305
- },
2306
- enumerable: false,
2307
- configurable: true
2308
- });
2309
- var _a;
2310
- _a = Symbol.toStringTag;
2311
- //#endregion
2312
- //#region constants
2313
- /**
2314
- * Zero
2315
- */
2316
- PowiainaNum.ZERO = new PowiainaNum({
2317
- array: [{
2318
- arrow: 0,
2319
- expans: 1,
2320
- megota: 1,
2321
- repeat: Infinity
2322
- }],
2323
- small: true,
2324
- layer: 0,
2325
- sign: 0
2326
- });
2327
- /**
2328
- * One
2329
- */
2330
- PowiainaNum.ONE = new PowiainaNum({
2331
- array: [{
2332
- arrow: 0,
2333
- expans: 1,
2334
- megota: 1,
2335
- repeat: 1
2336
- }],
2337
- small: false,
2338
- layer: 0,
2339
- sign: 1
2340
- });
2341
- /**
2342
- * The value of the largest integer n such that n and n + 1 are both
2343
- * exactly representable as a Number value = 9007199254740991 = 2^53 − 1.
2344
- */
2345
- PowiainaNum.MSI = new PowiainaNum(MSI);
2346
- /**
2347
- * MSI's reciprocate value, = 1/9007199254740991.
2348
- */
2349
- PowiainaNum.MSI_REC = function () {
2350
- var obj = new PowiainaNum(MSI);
2351
- obj.small = true;
2352
- return obj;
2353
- }();
2354
- /**
2355
- * 10^(MSI) = 10^9007199254740991.
2356
- */
2357
- PowiainaNum.E_MSI = new PowiainaNum({
2358
- array: [{
2359
- arrow: 0,
2360
- expans: 1,
2361
- megota: 1,
2362
- repeat: MSI
2363
- }, {
2364
- arrow: 1,
2365
- expans: 1,
2366
- megota: 1,
2367
- repeat: 1
2368
- }],
2369
- small: false,
2370
- layer: 0,
2371
- sign: 1
2372
- });
2373
- /**
2374
- * 10^10^(MSI) = 10^10^9007199254740991.
2375
- */
2376
- PowiainaNum.EE_MSI = new PowiainaNum({
2377
- array: [{
2378
- arrow: 0,
2379
- expans: 1,
2380
- megota: 1,
2381
- repeat: MSI
2382
- }, {
2383
- arrow: 1,
2384
- expans: 1,
2385
- megota: 1,
2386
- repeat: 2
2387
- }],
2388
- small: false,
2389
- layer: 0,
2390
- sign: 1
2391
- });
2392
- /**
2393
- * 10^(MSI) 's reciprocate value, = 10^-9007199254740991.
2394
- */
2395
- PowiainaNum.E_MSI_REC = new PowiainaNum({
2396
- array: [{
2397
- arrow: 0,
2398
- expans: 1,
2399
- megota: 1,
2400
- repeat: MSI
2401
- }, {
2402
- arrow: 1,
2403
- expans: 1,
2404
- megota: 1,
2405
- repeat: 1
2406
- }],
2407
- small: true,
2408
- layer: 0,
2409
- sign: 1
2410
- });
2411
- /**
2412
- * Tetrated MSI, = 10↑↑9007199254740991.
2413
- */
2414
- PowiainaNum.TETRATED_MSI = new PowiainaNum({
2415
- array: [{
2416
- arrow: 0,
2417
- expans: 1,
2418
- megota: 1,
2419
- repeat: 1e10
2420
- }, {
2421
- arrow: 1,
2422
- expans: 1,
2423
- megota: 1,
2424
- repeat: MSI - 2
2425
- }],
2426
- small: false,
2427
- layer: 0,
2428
- sign: 1
2429
- });
2430
- /**
2431
- * Pentated MSI, = 10↑↑↑9007199254740991.
2432
- */
2433
- PowiainaNum.PENTATED_MSI = new PowiainaNum({
2434
- array: [{
2435
- arrow: 0,
2436
- expans: 1,
2437
- megota: 1,
2438
- repeat: 10
2439
- }, {
2440
- arrow: 2,
2441
- expans: 1,
2442
- megota: 1,
2443
- repeat: MSI - 1
2444
- }],
2445
- small: false,
2446
- layer: 0,
2447
- sign: 1
2448
- });
2449
- /**
2450
- * Tritri, = 3↑↑↑3 = power tower with height 7625597484987 base 3.
2451
- */
2452
- PowiainaNum.TRITRI = new PowiainaNum({
2453
- small: false,
2454
- layer: 0,
2455
- sign: 1,
2456
- array: [newOperator(3638334640023.7783, 0, 1, 1), newOperator(7625587484984, 1, 1, 1)]
2457
- });
2458
- /**
2459
- * The Graham's Number, = G^64(4)
2460
- *
2461
- * = 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{
2462
- * 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3↑↑↑↑3
2463
- * }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
2464
- * }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
2465
- */
2466
- PowiainaNum.GRAHAMS_NUMBER = new PowiainaNum("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783");
2467
- /**
2468
- * Positive Infinity.
2469
- */
2470
- PowiainaNum.POSITIVE_INFINITY = new PowiainaNum(Infinity);
2471
- /**
2472
- * Negative Infinity.
2473
- */
2474
- PowiainaNum.NEGATIVE_INFINITY = new PowiainaNum(-Infinity);
2475
- PowiainaNum.NaN = new PowiainaNum({
2476
- array: [{
2477
- arrow: 0,
2478
- expans: 1,
2479
- megota: 1,
2480
- repeat: NaN
2481
- }],
2482
- small: false,
2483
- layer: 0,
2484
- sign: 0
2485
- });
2486
- /**
2487
- * The mathematical constant e. This is Euler's number, the base of natural logarithms.
2488
- */
2489
- PowiainaNum.E = new PowiainaNum(Math.E);
2490
- /**
2491
- * The natural logarithm of 2 = ln(2).
2492
- */
2493
- PowiainaNum.LN2 = new PowiainaNum(Math.LN2);
2494
- /**
2495
- * The natural logarithm of 10.
2496
- */
2497
- PowiainaNum.LN10 = new PowiainaNum(Math.LN10);
2498
- /**
2499
- * The base-2 logarithm of e = log_2(e).
2500
- */
2501
- PowiainaNum.LOG2E = new PowiainaNum(Math.LOG2E);
2502
- /**
2503
- * The base-10 logarithm of e = log_10(e).
2504
- */
2505
- PowiainaNum.LOG10E = new PowiainaNum(Math.LOG10E);
2506
- /**
2507
- * Pi(). This is the ratio of the circumference of a circle to its diameter.
2508
- */
2509
- PowiainaNum.PI = new PowiainaNum(Math.PI);
2510
- /**
2511
- * The square root of 0.5, or, equivalently, one divided by the square root of 2.
2512
- *
2513
- * = (√2)/2 = √(0.5)
2514
- */
2515
- PowiainaNum.SQRT1_2 = new PowiainaNum(Math.SQRT1_2);
2516
- /**
2517
- * The square root of 2 = √2.
2518
- */
2519
- PowiainaNum.SQRT2 = new PowiainaNum(Math.SQRT2);
2520
- PowiainaNum.maxOps = 100;
2521
- PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
2522
- //#endregion
2523
- PowiainaNum.arrowFuncMap = new Map();
2524
- return PowiainaNum;
1950
+ }
1951
+ }], [{
1952
+ key: "add",
1953
+ value: function add(t, other) {
1954
+ return new PowiainaNum(t).add(other);
1955
+ }
1956
+ }, {
1957
+ key: "sub",
1958
+ value: function sub(t, other) {
1959
+ return new PowiainaNum(t).sub(other);
1960
+ }
1961
+ }, {
1962
+ key: "mul",
1963
+ value: function mul(t, other) {
1964
+ return new PowiainaNum(t).mul(other);
1965
+ }
1966
+ }, {
1967
+ key: "div",
1968
+ value: function div(t, other) {
1969
+ return new PowiainaNum(t).div(other);
1970
+ }
1971
+ }, {
1972
+ key: "pow",
1973
+ value: function pow(t, other) {
1974
+ return new PowiainaNum(t).pow(other);
1975
+ }
1976
+ }, {
1977
+ key: "root",
1978
+ value: function root(t, other) {
1979
+ return new PowiainaNum(t).root(other);
1980
+ }
1981
+ }, {
1982
+ key: "sqrt",
1983
+ value: function sqrt(t) {
1984
+ return new PowiainaNum(t).sqrt();
1985
+ }
1986
+ }, {
1987
+ key: "cbrt",
1988
+ value: function cbrt(t) {
1989
+ return new PowiainaNum(t).cbrt();
1990
+ }
1991
+ }, {
1992
+ key: "log10",
1993
+ value: function log10(t) {
1994
+ return new PowiainaNum(t).log10();
1995
+ }
1996
+ }, {
1997
+ key: "log",
1998
+ value: function log(t) {
1999
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2000
+ return new PowiainaNum(t).log(base);
2001
+ }
2002
+ }, {
2003
+ key: "pLog10",
2004
+ value: function pLog10(t) {
2005
+ return new PowiainaNum(t).pLog10();
2006
+ }
2007
+ }, {
2008
+ key: "exp",
2009
+ value: function exp(x) {
2010
+ var y = new PowiainaNum(x);
2011
+ return y.pow_base(Math.E);
2012
+ }
2013
+ }, {
2014
+ key: "factorial",
2015
+ value: function factorial(x) {
2016
+ return new PowiainaNum(x).factorial();
2017
+ }
2018
+ }, {
2019
+ key: "gamma",
2020
+ value: function gamma(x) {
2021
+ return new PowiainaNum(x).gamma();
2022
+ }
2023
+ }, {
2024
+ key: "lambertw",
2025
+ value: function lambertw(x) {
2026
+ var principal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2027
+ return new PowiainaNum(x).lambertw(principal);
2028
+ }
2029
+ }, {
2030
+ key: "tetrate",
2031
+ value: function tetrate(t, other2) {
2032
+ var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
2033
+ return new PowiainaNum(t).tetrate(other2, payload);
2034
+ }
2035
+ }, {
2036
+ key: "tetrate_10",
2037
+ value: function tetrate_10(other2) {
2038
+ return PowiainaNum.fromNumber(10).tetrate(other2);
2039
+ }
2040
+ }, {
2041
+ key: "arrowMSI",
2042
+ value: function arrowMSI(arrowsNum) {
2043
+ return new PowiainaNum("10{".concat(arrowsNum, "}").concat(MSI));
2044
+ }
2045
+ }, {
2046
+ key: "hyper",
2047
+ value: function hyper(arr) {
2048
+ var z = new PowiainaNum(arr);
2049
+ if (z.eq(0)) return function (x, y) {
2050
+ return new PowiainaNum(y).eq(0) ? new PowiainaNum(x) : new PowiainaNum(x).add(1);
2051
+ };
2052
+ if (z.eq(1)) return PowiainaNum.add;else if (z.eq(2)) return PowiainaNum.mul;else if (z.eq(3)) return PowiainaNum.pow;else {
2053
+ return function (x, y) {
2054
+ return new PowiainaNum(x).arrow(z.sub(2))(y);
2055
+ };
2056
+ }
2057
+ }
2058
+ }, {
2059
+ key: "expansion",
2060
+ value: function expansion(t, other) {
2061
+ return new PowiainaNum(t).expansion(other);
2062
+ }
2063
+ }, {
2064
+ key: "multiExpansion",
2065
+ value: function multiExpansion(t, other) {
2066
+ return new PowiainaNum(t).multiExpansion(other);
2067
+ }
2068
+ }, {
2069
+ key: "powerExpansion",
2070
+ value: function powerExpansion(t, other) {
2071
+ return new PowiainaNum(t).powerExpansion(other);
2072
+ }
2073
+ }, {
2074
+ key: "BEAF",
2075
+ value: function BEAF(base2, power2) {
2076
+ var arrow2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
2077
+ var expans2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
2078
+ var megota2 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
2079
+ var powiaina2 = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
2080
+ var depth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
2081
+ // console.warn(
2082
+ // "This function is unstable when calculating numbers greater than *megotion*",
2083
+ // );
2084
+ var base = new PowiainaNum(base2);
2085
+ var power = new PowiainaNum(power2);
2086
+ function readArg(a) {
2087
+ var _b;
2088
+ return new PowiainaNum((_b = [arrow2, expans2, megota2, powiaina2][a]) !== null && _b !== void 0 ? _b : 1);
2089
+ }
2090
+ if (base.eq(1)) return new PowiainaNum(1);
2091
+ if (power.eq(1)) return new PowiainaNum(base);
2092
+ if (power.isZero()) return new PowiainaNum(1);
2093
+ if (base.lt(0)) return PowiainaNum.NaN.clone();
2094
+ // // check infinite
2095
+ // let sufpowiaina = args.slice(4);
2096
+ // if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
2097
+ // return PowiainaNum.POSITIVE_INFINITY;
2098
+ // }
2099
+ if (new PowiainaNum(powiaina2).gte(3)) return PowiainaNum.POSITIVE_INFINITY.clone();
2100
+ if (readArg(0).eq(1) && readArg(1).eq(1) && readArg(2).eq(1)) {
2101
+ return base.pow(power);
2102
+ }
2103
+ if (readArg(0).eq(2) && readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
2104
+ return base.tetrate(power);
2105
+ }
2106
+ if (readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
2107
+ return base.arrow(readArg(0))(power);
2108
+ }
2109
+ if (readArg(1).eq(2) && readArg(2).eq(1) && readArg(3).eq(1)) {
2110
+ return base.expansionArrow(readArg(0))(power);
2111
+ }
2112
+ var arrow = readArg(0).toNumber();
2113
+ var expans = readArg(1);
2114
+ var megota = readArg(2);
2115
+ var powiaina = readArg(3);
2116
+ if (powiaina.eq(2)) {
2117
+ if (arrow != 1) return PowiainaNum.POSITIVE_INFINITY.clone();
2118
+ if (expans.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
2119
+ if (megota.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
2120
+ if (power.gte(MSI)) return PowiainaNum.POSITIVE_INFINITY.clone();
2121
+ var r = new PowiainaNum(10);
2122
+ r.layer = power.toNumber();
2123
+ r.normalize();
2124
+ return r;
2125
+ }
2126
+ function convertOperator(arrows, expans, megota) {
2127
+ var a = arrows;
2128
+ var e = expans;
2129
+ var m = megota;
2130
+ if (a == 0 && e > 1) {
2131
+ return [1 / 0, e - 1, m];
2132
+ }
2133
+ if (a == 0 && e == 1 && m > 1) {
2134
+ return [1, 1 / 0, m - 1];
2135
+ }
2136
+ return [a, e, m];
2137
+ }
2138
+ if (megota.gt(MSI)) {
2139
+ var temp = new PowiainaNum(megota);
2140
+ temp.layer++;
2141
+ temp.normalize();
2142
+ return temp;
2143
+ }
2144
+ function infToBang(x) {
2145
+ if (!isFinite(x)) return "!";
2146
+ return x.toString();
2147
+ }
2148
+ function getMSIForm(arrow, expans, megota) {
2149
+ return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
2150
+ }
2151
+ var t = base.clone();
2152
+ var arrows = new PowiainaNum(readArg(0));
2153
+ var result = function (other2) {
2154
+ var _r, _r2;
2155
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2156
+ console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
2157
+ var other = new PowiainaNum(other2);
2158
+ var r;
2159
+ if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
2160
+ if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
2161
+ if (t.eq(PowiainaNum.ZERO)) {
2162
+ if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
2163
+ return PowiainaNum.NaN.clone();
2164
+ }
2165
+ if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
2166
+ if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
2167
+ if (other.eq(PowiainaNum.ONE)) return t.clone();
2168
+ if (arrows.eq(0)) {
2169
+ return PowiainaNum.BEAF(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
2170
+ // {this, this, power, expans-1, megota}
2171
+ }
2172
+ if (megota.eq(0)) {
2173
+ return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
2174
+ }
2175
+ // expans > 9e15, that using 10{?, x}, x=expans;
2176
+ if (expans.gt(MSI)) {
2177
+ r = new PowiainaNum(expans);
2178
+ r.setOperator(r.getOperator(1, Infinity, megota.toNumber()) + 1, 1, Infinity, megota.toNumber());
2179
+ return r;
2180
+ }
2181
+ // arrow > 9e15, that using 10{x,2}, x=arrow;
2182
+ if (arrows.gt(PowiainaNum.MSI)) {
2183
+ r = arrows.clone();
2184
+ r.setOperator(r.getOperator(Infinity, expans.toNumber(), megota.toNumber()) + 1, Infinity, expans.toNumber(), megota.toNumber());
2185
+ return r;
2186
+ }
2187
+ var arrowsNum = arrows.toNumber();
2188
+ // arrow < 9e15
2189
+ // 10{x}2 = 10{x-1}10
2190
+ if (other.eq(2)) return PowiainaNum.BEAF(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
2191
+ if (t.max(other).gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber()))) return t.max(other);
2192
+ if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
2193
+ if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
2194
+ r = t.clone();
2195
+ r.setOperator(r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1, arrowsNum, expans.toNumber(), megota.toNumber());
2196
+ r.normalize();
2197
+ } else if (t.gt(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))))) {
2198
+ r = new PowiainaNum(t.getOperator.apply(t, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
2199
+ } else {
2200
+ r = PowiainaNum.ZERO;
2201
+ }
2202
+ var j = r.add(other);
2203
+ j.setOperator(j.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) + 1, arrowsNum, expans.toNumber(), megota.toNumber());
2204
+ j.normalize();
2205
+ return j;
2206
+ }
2207
+ if (depth >= PowiainaNum.maxOps + 10) {
2208
+ return new PowiainaNum({
2209
+ small: false,
2210
+ sign: 1,
2211
+ layer: 0,
2212
+ array: [newOperator(10, 0), newOperator(1, arrowsNum, expans.toNumber(), megota.toNumber())]
2213
+ });
2214
+ }
2215
+ var y = other.toNumber();
2216
+ var f = Math.floor(y);
2217
+ var arrows_m1 = arrows.sub(PowiainaNum.ONE);
2218
+ r = PowiainaNum.BEAF(t, y - f, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
2219
+ var i = 0;
2220
+ for (var m = new PowiainaNum(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())))); f !== 0 && r.lt(m) && i < 100; i++) {
2221
+ if (f > 0) {
2222
+ r = PowiainaNum.BEAF(base, r, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
2223
+ --f;
2224
+ }
2225
+ }
2226
+ if (i == 100) f = 0;
2227
+ (_r = r).setOperator.apply(_r, [(_r2 = r).getOperator.apply(_r2, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))) + f].concat(_toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
2228
+ r.normalize();
2229
+ return r;
2230
+ }(power, depth);
2231
+ console.log("".concat("-".repeat(depth), " = ").concat(result));
2232
+ return result;
2233
+ }
2234
+ }, {
2235
+ key: "abs",
2236
+ value: function abs(x) {
2237
+ return new PowiainaNum(x).abs();
2238
+ }
2239
+ /**
2240
+ * Select the largest number of arguments.
2241
+ */
2242
+ }, {
2243
+ key: "max",
2244
+ value: function max() {
2245
+ var max = PowiainaNum.NEGATIVE_INFINITY;
2246
+ for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
2247
+ args[_key8] = arguments[_key8];
2248
+ }
2249
+ for (var i = 0; i < args.length; i++) {
2250
+ if (max.lt(args[i])) {
2251
+ max = new PowiainaNum(args[i]).clone();
2252
+ }
2253
+ }
2254
+ return max;
2255
+ }
2256
+ /**
2257
+ * Select the smallest number of arguments.
2258
+ */
2259
+ }, {
2260
+ key: "min",
2261
+ value: function min() {
2262
+ var max = PowiainaNum.POSITIVE_INFINITY;
2263
+ for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
2264
+ args[_key9] = arguments[_key9];
2265
+ }
2266
+ for (var i = 0; i < args.length; i++) {
2267
+ if (max.gt(args[i])) {
2268
+ max = new PowiainaNum(args[i]).clone();
2269
+ }
2270
+ }
2271
+ return max;
2272
+ }
2273
+ /**
2274
+ * Restrict a number be not lower than a number
2275
+ *
2276
+ * It's also an alias of `PowiainaNum.max`.
2277
+ * @returns restricted number
2278
+ */
2279
+ }, {
2280
+ key: "clampMin",
2281
+ value: function clampMin() {
2282
+ return PowiainaNum.max.apply(PowiainaNum, arguments);
2283
+ }
2284
+ }, {
2285
+ key: "clampMax",
2286
+ value: function clampMax() {
2287
+ return PowiainaNum.min.apply(PowiainaNum, arguments);
2288
+ }
2289
+ }, {
2290
+ key: "sign",
2291
+ value: function sign(a) {
2292
+ return new PowiainaNum(a).sign;
2293
+ }
2294
+ }, {
2295
+ key: "isNaN",
2296
+ value: function isNaN(x) {
2297
+ return new PowiainaNum(x).isNaN();
2298
+ }
2299
+ }, {
2300
+ key: "fromNumber",
2301
+ value: function fromNumber(x) {
2302
+ var obj = new PowiainaNum(); // NaN
2303
+ if (x < 0) obj.sign = -1; // negative
2304
+ else if (x == 0) {
2305
+ obj.sign = 0;
2306
+ obj.small = true;
2307
+ obj.array = [newOperator(Infinity, 0)];
2308
+ return obj;
2309
+ } else if (x > 0) obj.sign = 1;
2310
+ var y = Math.abs(x);
2311
+ if (y == Infinity) {
2312
+ obj.array = [newOperator(Infinity, 0)];
2313
+ } else if (y >= MSI_REC && y < 1) {
2314
+ obj.small = true;
2315
+ obj.array = [newOperator(1 / y, 0)];
2316
+ } else if (y < MSI_REC) {
2317
+ obj.small = true;
2318
+ obj.array = [newOperator(-Math.log10(y), 0), newOperator(1, 1)];
2319
+ } else if (y <= MSI) {
2320
+ obj.array = [newOperator(y, 0)];
2321
+ } else {
2322
+ obj.setOperator(Math.log10(y), 0);
2323
+ obj.array = [newOperator(Math.log10(y), 0), newOperator(1, 1)];
2324
+ }
2325
+ return obj;
2326
+ }
2327
+ }, {
2328
+ key: "fromString",
2329
+ value: function fromString(input) {
2330
+ var _b, _c, _d, _e, _f, _g;
2331
+ var x = new PowiainaNum();
2332
+ // Judge the string was a number
2333
+ if (input.startsWith("PN")) input = input.substring(2);
2334
+ if (!isNaN(Number(input))) {
2335
+ var res = Number(input);
2336
+ var _a2 = false;
2337
+ if (res == 0) {
2338
+ if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
2339
+ _a2 = true;
2340
+ }
2341
+ } else {
2342
+ _a2 = true;
2343
+ }
2344
+ if (!_a2) {
2345
+ var m = input.search(/e/);
2346
+ var exponent = input.substring((m == -1 ? input.length : m) + 1);
2347
+ var mantissa = input.substring(0, m == -1 ? undefined : m);
2348
+ var mantissaME = [0, 0];
2349
+ // Handle mantissa to ME
2350
+ mantissaME[1] = Number(exponent ? exponent : "0");
2351
+ // Is regular number gte 1:
2352
+ if (Number(mantissa) >= 1) {
2353
+ // check The mantissa is very long?
2354
+ var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
2355
+ var log10int = Math.floor(log10mant) - 1;
2356
+ var log10float = log10mant - log10int;
2357
+ mantissaME[0] = Math.pow(10, log10float);
2358
+ mantissaME[1] += log10float;
2359
+ } else {
2360
+ // If not , count how many zeros until reached non-zero numbers
2361
+ var zeros = countLeadingZerosAfterDecimal(mantissa);
2362
+ mantissa = mantissa.substring(mantissa.search(/[1-9]/));
2363
+ mantissa = mantissa.charAt(0) + "." + mantissa.substring(1);
2364
+ zeros += 1;
2365
+ mantissaME[0] = Number(mantissa);
2366
+ mantissaME[1] += -zeros;
2367
+ }
2368
+ // We'll get [a, b] which respents a*10^b;
2369
+ // actually b < 0; So we can ^-1
2370
+ // /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
2371
+ return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
2372
+ }
2373
+ if (isFinite(res) && _a2) {
2374
+ x = PowiainaNum.fromNumber(Number(input));
2375
+ return x;
2376
+ }
2377
+ }
2378
+ // Check legacy PowiainaNum 0.1.x number format
2379
+ if (input.indexOf("l") !== -1 && input.indexOf("s") !== -1 && input.indexOf("a") !== -1) {
2380
+ var obj = parseLegacyPowiainaNumString(input);
2381
+ if (!obj || obj.sValue !== 0 && obj.sValue !== 1 && obj.sValue !== -1) throw powiainaNumError + "malformed input: " + input;
2382
+ x = PowiainaNum.fromObject(obj.array);
2383
+ x.layer = obj.lValue;
2384
+ x.sign = obj.sValue;
2385
+ x.small = false;
2386
+ x.normalize();
2387
+ return x;
2388
+ }
2389
+ input = replaceETo10(input);
2390
+ if (!isPowiainaNum.test(input)) {
2391
+ throw powiainaNumError + "malformed input: " + input;
2392
+ }
2393
+ var negateIt = false;
2394
+ var recipIt = false;
2395
+ if (input[0] == "-" || input[0] == "+") {
2396
+ var numSigns = input.search(/[^-\+]/);
2397
+ var signs = input.substring(0, numSigns);
2398
+ negateIt = ((_c = (_b = signs.match(/-/g)) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) % 2 == 1;
2399
+ input = input.substring(numSigns);
2400
+ }
2401
+ if (input[0] == "/") {
2402
+ var numSigns = input.search(/[^\/]/);
2403
+ var signs = input.substring(0, numSigns);
2404
+ recipIt = ((_e = (_d = signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2405
+ input = input.substring(numSigns);
2406
+ }
2407
+ if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
2408
+ x.sign = 1;
2409
+ x.array = [newOperator(0)];
2410
+ var a, b, c, d;
2411
+ if (input[0] == "P") {
2412
+ if (input[1] == "^") {
2413
+ a = input.substring(2).search(/[^0-9]/) + 2;
2414
+ x.layer = Number(input.substring(2, a));
2415
+ input = input.substring(a + 1);
2416
+ } else {
2417
+ a = input.search(/[^P]/);
2418
+ x.layer = a;
2419
+ input = input.substring(a);
2420
+ }
2421
+ }
2422
+ while (input) {
2423
+ if (/^(\(?10[\^\{])/.test(input)) {
2424
+ /*
2425
+ 10^ - 匹配
2426
+ 10{ - 匹配
2427
+ (10^ - 匹配
2428
+ (10{ - 匹配
2429
+ 10x - 不匹配(最后一个字符不是 ^ 或 {)
2430
+ 110^ - 不匹配(不是以 10 开头)
2431
+ */
2432
+ if (input[0] == "(") input = input.substring(1);
2433
+ //cutted, 10^.... or 10{....
2434
+ var arrows, expans, megota;
2435
+ if (input[2] == "^") {
2436
+ a = input.substring(2).search(/[^\^]/);
2437
+ //cut input to ^^...^^, and search how numbers
2438
+ arrows = a;
2439
+ // 10^^^
2440
+ b = a + 2; // b points to after ^'s.
2441
+ } else {
2442
+ // 10{...}
2443
+ a = input.indexOf("}");
2444
+ // select contents between {...}
2445
+ var tmp = input.substring(3, a).split(",");
2446
+ arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
2447
+ expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
2448
+ megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
2449
+ b = a + 1;
2450
+ // b points to after }.
2451
+ }
2452
+ input = input.substring(b);
2453
+ if (input[0] == ")") {
2454
+ // )^....<Space>
2455
+ a = input.indexOf(" ");
2456
+ c = Number(input.substring(2, a)); // Select contents between )^....<Space>
2457
+ input = input.substring(a + 1); // c points to after <Space>
2458
+ } else {
2459
+ c = 1; // There is only spaces, count as <ONE>
2460
+ }
2461
+ if (arrows == 1 && expans == 1 && megota == 1) {
2462
+ if (x.array.length >= 2 && x.array[1].arrow == 1) {
2463
+ x.array[1].repeat += c;
2464
+ } else {
2465
+ x.array.splice(1, 0, newOperator(c, 1, expans, megota));
2466
+ }
2467
+ } else if (arrows == 2 && expans == 1 && megota == 1) {
2468
+ a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2469
+ b = x.array[0].repeat;
2470
+ if (b >= 1e10) ++a;
2471
+ if (b >= 10) ++a;
2472
+ x.array[0].repeat = a;
2473
+ if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
2474
+ d = x.getOperatorIndex(2);
2475
+ if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
2476
+ } else if (isFinite(arrows)) {
2477
+ a = x.getOperator(arrows - 1);
2478
+ b = x.getOperator(arrows - 2);
2479
+ if (b >= 10) ++a;
2480
+ d = x.getOperatorIndex(arrows);
2481
+ x.array.splice(1, Math.ceil(d) - 1);
2482
+ x.array[0].repeat = a;
2483
+ if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
2484
+ } else {
2485
+ x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
2486
+ }
2487
+ } else {
2488
+ break;
2489
+ }
2490
+ }
2491
+ a = input.split(/[Ee]/);
2492
+ b = [x.array[0].repeat, 0];
2493
+ c = 1;
2494
+ for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
2495
+ //The things that are already there
2496
+ if (b[0] < MSI_LOG10 && b[1] === 0) {
2497
+ b[0] = Math.pow(10, c * b[0]);
2498
+ } else if (c == -1) {
2499
+ if (b[1] === 0) {
2500
+ b[0] = Math.pow(10, c * b[0]);
2501
+ } else if (b[1] == 1 && b[0] <= Math.log10(Number.MAX_VALUE)) {
2502
+ b[0] = Math.pow(10, c * Math.pow(10, b[0]));
2503
+ } else {
2504
+ b[0] = 0;
2505
+ }
2506
+ b[1] = 0;
2507
+ } else {
2508
+ b[1]++;
2509
+ }
2510
+ //Multiplying coefficient
2511
+ var decimalPointPos = a[_i2].indexOf(".");
2512
+ var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
2513
+ if (b[1] === 0) {
2514
+ if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(a[_i2].substring(0, intPartLen)), b[1] = 1;else if (a[_i2]) b[0] *= Number(a[_i2]);
2515
+ } else {
2516
+ d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
2517
+ if (b[1] == 1) {
2518
+ b[0] += d;
2519
+ } else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
2520
+ b[0] += Math.log10(1 + Math.pow(10, Math.log10(d) - b[0]));
2521
+ }
2522
+ }
2523
+ //Carrying
2524
+ if (b[0] < MSI_LOG10 && b[1]) {
2525
+ b[0] = Math.pow(10, b[0]);
2526
+ b[1]--;
2527
+ } else if (b[0] > MSI) {
2528
+ b[0] = Math.log10(b[0]);
2529
+ b[1]++;
2530
+ }
2531
+ }
2532
+ x.array[0].repeat = b[0];
2533
+ if (b[1]) {
2534
+ if (x.array.length >= 2 && x.array[1].arrow == 1 && x.array[1].expans == 1 && x.array[1].megota == 1) x.array[1].repeat += b[1];else x.array.splice(1, 0, newOperator(b[1], 1, 1, 1));
2535
+ }
2536
+ }
2537
+ if (negateIt) x.sign *= -1;
2538
+ if (recipIt) x.small = !x.small;
2539
+ x.normalize();
2540
+ x.normalize();
2541
+ return x;
2542
+ }
2543
+ }, {
2544
+ key: "fromObject",
2545
+ value: function fromObject(powlikeObject) {
2546
+ var obj = new PowiainaNum();
2547
+ obj.array = [];
2548
+ if (isExpantaNumArray(powlikeObject)) {
2549
+ for (var i = 0; i < powlikeObject.length; i++) {
2550
+ obj.array[i] = {
2551
+ arrow: powlikeObject[i][0],
2552
+ expans: 1,
2553
+ megota: 1,
2554
+ repeat: powlikeObject[i][1]
2555
+ };
2556
+ }
2557
+ obj.small = false;
2558
+ obj.sign = 1;
2559
+ obj.layer = 0;
2560
+ return obj;
2561
+ } else if (isPowiainaNum01XArray(powlikeObject)) {
2562
+ var arrayobj = powlikeObject;
2563
+ obj.array[0] = newOperator(arrayobj[0]);
2564
+ for (var _i3 = 1; _i3 < arrayobj.length; _i3++) {
2565
+ var b = arrayobj[_i3];
2566
+ obj.array[1] = newOperator(b[1], replaceXToInfinity(b[0]), replaceXToInfinity(b[2]), b[3]);
2567
+ }
2568
+ obj.small = false;
2569
+ obj.sign = 1;
2570
+ obj.layer = 0;
2571
+ return obj;
2572
+ } else {
2573
+ for (var _i4 = 0; _i4 < powlikeObject.array.length; _i4++) {
2574
+ obj.array[_i4] = {
2575
+ arrow: powlikeObject.array[_i4].arrow,
2576
+ expans: powlikeObject.array[_i4].expans,
2577
+ megota: powlikeObject.array[_i4].megota,
2578
+ repeat: powlikeObject.array[_i4].repeat,
2579
+ valuereplaced: powlikeObject.array[_i4].valuereplaced
2580
+ };
2581
+ }
2582
+ obj.small = powlikeObject.small;
2583
+ obj.sign = powlikeObject.sign;
2584
+ obj.layer = powlikeObject.layer;
2585
+ return obj;
2586
+ }
2587
+ }
2588
+ }]);
2589
+ }();
2590
+ _a = Symbol.toStringTag;
2591
+ //#endregion
2592
+ //#region constants
2593
+ /**
2594
+ * Zero
2595
+ */
2596
+ PowiainaNum.ZERO = new PowiainaNum({
2597
+ array: [{
2598
+ arrow: 0,
2599
+ expans: 1,
2600
+ megota: 1,
2601
+ repeat: Infinity
2602
+ }],
2603
+ small: true,
2604
+ layer: 0,
2605
+ sign: 0
2606
+ });
2607
+ /**
2608
+ * One
2609
+ */
2610
+ PowiainaNum.ONE = new PowiainaNum({
2611
+ array: [{
2612
+ arrow: 0,
2613
+ expans: 1,
2614
+ megota: 1,
2615
+ repeat: 1
2616
+ }],
2617
+ small: false,
2618
+ layer: 0,
2619
+ sign: 1
2620
+ });
2621
+ /**
2622
+ * The value of the largest integer n such that n and n + 1 are both
2623
+ * exactly representable as a Number value = 9007199254740991 = 2^53 − 1.
2624
+ */
2625
+ PowiainaNum.MSI = new PowiainaNum(MSI);
2626
+ /**
2627
+ * MSI's reciprocate value, = 1/9007199254740991.
2628
+ */
2629
+ PowiainaNum.MSI_REC = function () {
2630
+ var obj = new PowiainaNum(MSI);
2631
+ obj.small = true;
2632
+ return obj;
2525
2633
  }();
2634
+ /**
2635
+ * 10^(MSI) = 10^9007199254740991.
2636
+ */
2637
+ PowiainaNum.E_MSI = new PowiainaNum({
2638
+ array: [{
2639
+ arrow: 0,
2640
+ expans: 1,
2641
+ megota: 1,
2642
+ repeat: MSI
2643
+ }, {
2644
+ arrow: 1,
2645
+ expans: 1,
2646
+ megota: 1,
2647
+ repeat: 1
2648
+ }],
2649
+ small: false,
2650
+ layer: 0,
2651
+ sign: 1
2652
+ });
2653
+ /**
2654
+ * 10^10^(MSI) = 10^10^9007199254740991.
2655
+ */
2656
+ PowiainaNum.EE_MSI = new PowiainaNum({
2657
+ array: [{
2658
+ arrow: 0,
2659
+ expans: 1,
2660
+ megota: 1,
2661
+ repeat: MSI
2662
+ }, {
2663
+ arrow: 1,
2664
+ expans: 1,
2665
+ megota: 1,
2666
+ repeat: 2
2667
+ }],
2668
+ small: false,
2669
+ layer: 0,
2670
+ sign: 1
2671
+ });
2672
+ /**
2673
+ * 10^(MSI) 's reciprocate value, = 10^-9007199254740991.
2674
+ */
2675
+ PowiainaNum.E_MSI_REC = new PowiainaNum({
2676
+ array: [{
2677
+ arrow: 0,
2678
+ expans: 1,
2679
+ megota: 1,
2680
+ repeat: MSI
2681
+ }, {
2682
+ arrow: 1,
2683
+ expans: 1,
2684
+ megota: 1,
2685
+ repeat: 1
2686
+ }],
2687
+ small: true,
2688
+ layer: 0,
2689
+ sign: 1
2690
+ });
2691
+ /**
2692
+ * Tetrated MSI, = 10↑↑9007199254740991.
2693
+ */
2694
+ PowiainaNum.TETRATED_MSI = new PowiainaNum({
2695
+ array: [{
2696
+ arrow: 0,
2697
+ expans: 1,
2698
+ megota: 1,
2699
+ repeat: 1e10
2700
+ }, {
2701
+ arrow: 1,
2702
+ expans: 1,
2703
+ megota: 1,
2704
+ repeat: MSI - 2
2705
+ }],
2706
+ small: false,
2707
+ layer: 0,
2708
+ sign: 1
2709
+ });
2710
+ /**
2711
+ * Pentated MSI, = 10↑↑↑9007199254740991.
2712
+ */
2713
+ PowiainaNum.PENTATED_MSI = new PowiainaNum({
2714
+ array: [{
2715
+ arrow: 0,
2716
+ expans: 1,
2717
+ megota: 1,
2718
+ repeat: 10
2719
+ }, {
2720
+ arrow: 2,
2721
+ expans: 1,
2722
+ megota: 1,
2723
+ repeat: MSI - 1
2724
+ }],
2725
+ small: false,
2726
+ layer: 0,
2727
+ sign: 1
2728
+ });
2729
+ /**
2730
+ * Tritri, = 3↑↑↑3 = power tower with height 7625597484987 base 3.
2731
+ */
2732
+ PowiainaNum.TRITRI = new PowiainaNum({
2733
+ small: false,
2734
+ layer: 0,
2735
+ sign: 1,
2736
+ array: [newOperator(3638334640023.7783, 0, 1, 1), newOperator(7625587484984, 1, 1, 1)]
2737
+ });
2738
+ /**
2739
+ * The Graham's Number, = G^64(4)
2740
+ *
2741
+ * = 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{
2742
+ * 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3↑↑↑↑3
2743
+ * }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
2744
+ * }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
2745
+ */
2746
+ PowiainaNum.GRAHAMS_NUMBER = new PowiainaNum("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783");
2747
+ /**
2748
+ * Positive Infinity.
2749
+ */
2750
+ PowiainaNum.POSITIVE_INFINITY = new PowiainaNum(Infinity);
2751
+ /**
2752
+ * Negative Infinity.
2753
+ */
2754
+ PowiainaNum.NEGATIVE_INFINITY = new PowiainaNum(-Infinity);
2755
+ PowiainaNum.NaN = new PowiainaNum({
2756
+ array: [{
2757
+ arrow: 0,
2758
+ expans: 1,
2759
+ megota: 1,
2760
+ repeat: NaN
2761
+ }],
2762
+ small: false,
2763
+ layer: 0,
2764
+ sign: 0
2765
+ });
2766
+ /**
2767
+ * The mathematical constant e. This is Euler's number, the base of natural logarithms.
2768
+ */
2769
+ PowiainaNum.E = new PowiainaNum(Math.E);
2770
+ /**
2771
+ * The natural logarithm of 2 = ln(2).
2772
+ */
2773
+ PowiainaNum.LN2 = new PowiainaNum(Math.LN2);
2774
+ /**
2775
+ * The natural logarithm of 10.
2776
+ */
2777
+ PowiainaNum.LN10 = new PowiainaNum(Math.LN10);
2778
+ /**
2779
+ * The base-2 logarithm of e = log_2(e).
2780
+ */
2781
+ PowiainaNum.LOG2E = new PowiainaNum(Math.LOG2E);
2782
+ /**
2783
+ * The base-10 logarithm of e = log_10(e).
2784
+ */
2785
+ PowiainaNum.LOG10E = new PowiainaNum(Math.LOG10E);
2786
+ /**
2787
+ * Pi(). This is the ratio of the circumference of a circle to its diameter.
2788
+ */
2789
+ PowiainaNum.PI = new PowiainaNum(Math.PI);
2790
+ /**
2791
+ * The square root of 0.5, or, equivalently, one divided by the square root of 2.
2792
+ *
2793
+ * = (√2)/2 = √(0.5)
2794
+ */
2795
+ PowiainaNum.SQRT1_2 = new PowiainaNum(Math.SQRT1_2);
2796
+ /**
2797
+ * The square root of 2 = √2.
2798
+ */
2799
+ PowiainaNum.SQRT2 = new PowiainaNum(Math.SQRT2);
2800
+ PowiainaNum.maxOps = 100;
2801
+ PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
2802
+ //#endregion
2803
+ PowiainaNum.arrowFuncMap = new Map();
2526
2804
 
2527
2805
  exports.arraySortFunction = arraySortFunction;
2528
2806
  exports["default"] = PowiainaNum;