powiaina_num.js 0.2.9 → 0.2.10

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.
@@ -62,6 +62,8 @@ function _unsupportedIterableToArray(r, a) {
62
62
 
63
63
  /* Author: VeryrrDefine 0.2.0-beta.1.1*/
64
64
  var _a;
65
+ //#endregion
66
+ //#region constants
65
67
  var powiainaNumError = "[PowiainaNum 0.2 error]";
66
68
  var MSI = 9007199254740991;
67
69
  var MSI_LOG10 = 15.954589770191003;
@@ -69,6 +71,8 @@ var MSI_REC = 1.1102230246251568e-16;
69
71
  var LONG_STRING_MIN_LENGTH = 17;
70
72
  var EXP_E_REC = 1.444667861009766;
71
73
  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+))$/;
74
+ var BE_REGEX = /^((\d+(\.\d*)?|\d*\.\d+)?([EeFf]([-\+]?)))*(0|\d+(\.\d*)?|\d*\.\d+)$/;
75
+ //#endregion
72
76
  //#region some useful functions
73
77
  function newOperator(r) {
74
78
  var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -82,6 +86,29 @@ function newOperator(r) {
82
86
  valuereplaced: a == Infinity ? 0 : e == Infinity ? 1 : -1
83
87
  };
84
88
  }
89
+ function removeCommasOutsideBraces(input) {
90
+ var result = "";
91
+ var inBraces = false;
92
+ for (var i = 0; i < input.length; i++) {
93
+ var _char = input[i];
94
+ if (_char === "{") {
95
+ inBraces = true;
96
+ result += _char;
97
+ } else if (_char === "}") {
98
+ inBraces = false;
99
+ result += _char;
100
+ } else if (_char === ",") {
101
+ // 只有在花括号内部才保留逗号
102
+ if (inBraces) {
103
+ result += _char;
104
+ }
105
+ // 如果在花括号外部,就不添加到结果中(相当于删除)
106
+ } else {
107
+ result += _char;
108
+ }
109
+ }
110
+ return result;
111
+ }
85
112
  // parse 0.1.x PowiainaNum.js string
86
113
  function parseLegacyPowiainaNumString(str) {
87
114
  var pattern = /l(\d+)\s+s(\d+)\s+a(\[.*\])/;
@@ -114,7 +141,7 @@ function compareTuples() {
114
141
  function replaceETo10(str) {
115
142
  // 使用正则表达式匹配 (e^数字) 的模式
116
143
  // 正则解释:\(e\^(\d+)\) 匹配 (e^数字),其中 \d+ 匹配一个或多个数字
117
- return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)\x20*PT/g, "(10^)^$1 ");
144
+ return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)[Pp][Tt]/g, "(10^)^$1 ");
118
145
  }
119
146
  /**
120
147
  * 把一个字符串很长的数进行以10为底的对数
@@ -168,8 +195,10 @@ var OMEGA = 0.56714329040978387299997; // W(1, 0)
168
195
  // The evaluation can become inaccurate very close to the branch point
169
196
  // Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
170
197
  function f_lambertw(z) {
171
- var tol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
172
- var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
198
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
199
+ var pr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
200
+ var tol = t;
201
+ var principal = pr;
173
202
  var w;
174
203
  var wn;
175
204
  if (!Number.isFinite(z)) {
@@ -332,16 +361,26 @@ var PowiainaNum = /*#__PURE__*/function () {
332
361
  this.small = false;
333
362
  this.sign = 0;
334
363
  this.layer = 0;
335
- if (typeof arg1 == "undefined") ; else if (typeof arg1 == "number") {
336
- var obj = PowiainaNum.fromNumber(arg1);
337
- this.resetFromObject(obj);
338
- } else if (_typeof(arg1) == "object") {
339
- var _obj = PowiainaNum.fromObject(arg1);
340
- this.resetFromObject(_obj);
341
- } else if (typeof arg1 == "string") {
342
- var _obj2 = PowiainaNum.fromString(arg1);
343
- this.resetFromObject(_obj2);
344
- } else ;
364
+ if (PowiainaNum.blankArgumentConstructorReturnZero) {
365
+ this.resetFromObject(PowiainaNum.ZERO);
366
+ }
367
+ try {
368
+ if (typeof arg1 == "undefined") {} else if (typeof arg1 == "number") {
369
+ var obj = PowiainaNum.fromNumber(arg1);
370
+ this.resetFromObject(obj);
371
+ } else if (_typeof(arg1) == "object") {
372
+ var _obj = PowiainaNum.fromObject(arg1);
373
+ this.resetFromObject(_obj);
374
+ } else if (typeof arg1 == "string") {
375
+ var _obj2 = PowiainaNum.fromString(arg1);
376
+ this.resetFromObject(_obj2);
377
+ } else {
378
+ var isn = arg1;
379
+ }
380
+ } catch (e) {
381
+ console.error("Malformed input");
382
+ console.error(e);
383
+ }
345
384
  }
346
385
  //#region 4 Basic calculates.
347
386
  /**
@@ -352,7 +391,7 @@ var PowiainaNum = /*#__PURE__*/function () {
352
391
  key: "add",
353
392
  value: function add(other) {
354
393
  var _b, _c, _d, _e;
355
- var x = this.clone();
394
+ var x = this.clone().normalize();
356
395
  var y = new PowiainaNum(other);
357
396
  // inf + -inf = nan
358
397
  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();
@@ -413,7 +452,7 @@ var PowiainaNum = /*#__PURE__*/function () {
413
452
  mult *= -1;
414
453
  }
415
454
  if (t == 0) throw Error("Encounter a calculate error");
416
- r = new PowiainaNum();
455
+ r = PowiainaNum.NaN.clone();
417
456
  r.sign = 1;
418
457
  if (l > MSI_LOG10 || l < -MSI_LOG10) {
419
458
  r.array = [newOperator(l, 0), newOperator(1, 1)];
@@ -424,11 +463,21 @@ var PowiainaNum = /*#__PURE__*/function () {
424
463
  r.sign *= mult;
425
464
  return r;
426
465
  }
466
+ }, {
467
+ key: "plus",
468
+ value: function plus(other) {
469
+ return this.add(other);
470
+ }
427
471
  }, {
428
472
  key: "sub",
429
473
  value: function sub(a) {
430
474
  return this.add(new PowiainaNum(a).neg());
431
475
  }
476
+ }, {
477
+ key: "minus",
478
+ value: function minus(other) {
479
+ return this.sub(other);
480
+ }
432
481
  }, {
433
482
  key: "mul",
434
483
  value: function mul(other) {
@@ -462,12 +511,22 @@ var PowiainaNum = /*#__PURE__*/function () {
462
511
  r.sign = x.sign * y.sign;
463
512
  return r;
464
513
  }
514
+ }, {
515
+ key: "times",
516
+ value: function times(other) {
517
+ return this.mul(other);
518
+ }
465
519
  }, {
466
520
  key: "div",
467
521
  value: function div(other) {
468
522
  var x = new PowiainaNum(other).rec();
469
523
  return this.mul(x);
470
524
  }
525
+ }, {
526
+ key: "divide",
527
+ value: function divide(other) {
528
+ return this.div(other);
529
+ }
471
530
  }, {
472
531
  key: "mod",
473
532
  value: function mod(x) {
@@ -475,14 +534,20 @@ var PowiainaNum = /*#__PURE__*/function () {
475
534
  var division = this.div(other);
476
535
  return division.sub(division.floor()).mul(other);
477
536
  }
537
+ }, {
538
+ key: "modulus",
539
+ value: function modulus(x) {
540
+ return this.mod(x);
541
+ }
542
+ }, {
543
+ key: "pow10",
544
+ value:
478
545
  //#endregion
479
546
  //#region power
480
547
  /**
481
548
  * @returns 10 to the power of `this`
482
549
  */
483
- }, {
484
- key: "pow10",
485
- value: function pow10() {
550
+ function pow10() {
486
551
  var _b, _c;
487
552
  var r = this.clone();
488
553
  // inf & nan check
@@ -512,8 +577,16 @@ var PowiainaNum = /*#__PURE__*/function () {
512
577
  if (!other.isFinite()) return other.clone();
513
578
  if (!this.isFinite()) return this.clone();
514
579
  if (this.eq(10)) return other.pow10();
580
+ if (other.isneg()) return this.pow(other.neg()).rec();
515
581
  if (this.isneg()) {
516
- if (!other.isInt()) return PowiainaNum.NaN.clone();
582
+ if (!other.isInt()) {
583
+ if (other.small) {
584
+ if (other.rec().div(2).eq(1)) {
585
+ return this.neg().pow(other).neg();
586
+ }
587
+ }
588
+ return PowiainaNum.NaN.clone();
589
+ }
517
590
  var r = this.abs().pow(other);
518
591
  r.sign = function () {
519
592
  var a = other.mod(2).round();
@@ -590,6 +663,16 @@ var PowiainaNum = /*#__PURE__*/function () {
590
663
  var other = new PowiainaNum(base);
591
664
  return this.log10().div(other.log10());
592
665
  }
666
+ }, {
667
+ key: "log2",
668
+ value: function log2() {
669
+ return this.log(2);
670
+ }
671
+ }, {
672
+ key: "logBase",
673
+ value: function logBase(a) {
674
+ return this.log(a);
675
+ }
593
676
  }, {
594
677
  key: "ln",
595
678
  value: function ln() {
@@ -697,7 +780,8 @@ var PowiainaNum = /*#__PURE__*/function () {
697
780
  //Code from break_eternity.js
698
781
  //Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
699
782
  function lambertw() {
700
- var principal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
783
+ var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
784
+ var principal = princ;
701
785
  if (this.lt(-0.3678794411710499)) {
702
786
  return PowiainaNum.NaN.clone(); //complex
703
787
  } else if (principal) {
@@ -715,9 +799,9 @@ var PowiainaNum = /*#__PURE__*/function () {
715
799
  if (this.sign === 1) {
716
800
  return PowiainaNum.NaN.clone(); //complex
717
801
  }
718
- if (this.layer === 0) {
802
+ if (this.lt(9e15)) {
719
803
  return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
720
- } else if (this.layer == 1) {
804
+ } else if (this.lt(PowiainaNum.E_MSI)) {
721
805
  return d_lambertw(this, 1e-10, false);
722
806
  } else {
723
807
  return this.neg().rec().lambertw().neg();
@@ -738,7 +822,9 @@ var PowiainaNum = /*#__PURE__*/function () {
738
822
  var payl = new PowiainaNum(payload);
739
823
  if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
740
824
  if (t.eq(1)) return PowiainaNum.ONE.clone();
741
- if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
825
+ if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
826
+ other = other.add(payl.slog(t));
827
+ }
742
828
  var negln;
743
829
  if (other.isInfi() && other.sign > 0) {
744
830
  if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
@@ -1068,9 +1154,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1068
1154
  // base^base^... = x? (? bases)
1069
1155
  var r = 0;
1070
1156
  // 计算x与base的差距
1071
- var t = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1072
- if (t > 3) {
1073
- var l = t - 3;
1157
+ var distanceLayerOf = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1158
+ if (distanceLayerOf > 3) {
1159
+ var l = distanceLayerOf - 3;
1074
1160
  r += l;
1075
1161
  x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
1076
1162
  }
@@ -1112,18 +1198,18 @@ var PowiainaNum = /*#__PURE__*/function () {
1112
1198
  }
1113
1199
  }, {
1114
1200
  key: "pentate",
1115
- value: function pentate(other) {
1116
- return this.arrow(3)(other);
1201
+ value: function pentate(other, payload) {
1202
+ return this.arrow(3)(other, payload);
1117
1203
  }
1118
1204
  }, {
1119
1205
  key: "hexate",
1120
- value: function hexate(other) {
1121
- return this.arrow(4)(other);
1206
+ value: function hexate(other, payload) {
1207
+ return this.arrow(4)(other, payload);
1122
1208
  }
1123
1209
  }, {
1124
1210
  key: "pent",
1125
- value: function pent(other) {
1126
- return this.arrow(3)(other);
1211
+ value: function pent(other, payload) {
1212
+ return this.arrow(3)(other, payload);
1127
1213
  }
1128
1214
  }, {
1129
1215
  key: "penta_log",
@@ -1131,6 +1217,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1131
1217
  var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
1132
1218
  return this.anyarrow_log(3)(base);
1133
1219
  }
1220
+ }, {
1221
+ key: "expansion",
1222
+ value:
1134
1223
  /**
1135
1224
  * Expansion, which is `this`{{1}}`other2`.
1136
1225
  *
@@ -1138,9 +1227,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1138
1227
  *
1139
1228
  * @url https://googology.fandom.com/wiki/Expansion
1140
1229
  */
1141
- }, {
1142
- key: "expansion",
1143
- value: function expansion(other2) {
1230
+ function expansion(other2) {
1144
1231
  var other = new PowiainaNum(other2);
1145
1232
  var t = this.clone();
1146
1233
  if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
@@ -1453,6 +1540,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1453
1540
  var t = this.cmp(other);
1454
1541
  return t == 0 || t == 1;
1455
1542
  }
1543
+ }, {
1544
+ key: "equals",
1545
+ value: function equals(other) {
1546
+ return this.eq(other);
1547
+ }
1548
+ }, {
1549
+ key: "notEquals",
1550
+ value: function notEquals(other) {
1551
+ return this.neq(other);
1552
+ }
1456
1553
  }, {
1457
1554
  key: "eq_tolerance",
1458
1555
  value: function eq_tolerance(value) {
@@ -1514,6 +1611,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1514
1611
  a.small = !a.small;
1515
1612
  return a;
1516
1613
  }
1614
+ }, {
1615
+ key: "recip",
1616
+ value: function recip() {
1617
+ return this.rec();
1618
+ }
1619
+ }, {
1620
+ key: "reciprocate",
1621
+ value: function reciprocate() {
1622
+ return this.rec();
1623
+ }
1517
1624
  }, {
1518
1625
  key: "floor",
1519
1626
  value: function floor() {
@@ -1554,6 +1661,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1554
1661
  r.sign = this.sign;
1555
1662
  return r;
1556
1663
  }
1664
+ }, {
1665
+ key: "trunc",
1666
+ value:
1557
1667
  /**
1558
1668
  * Work like `Math.trunc`,
1559
1669
  *
@@ -1566,15 +1676,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1566
1676
  * new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
1567
1677
  * @returns
1568
1678
  */
1569
- }, {
1570
- key: "trunc",
1571
- value: function trunc() {
1679
+ function trunc() {
1572
1680
  var y = this.clone();
1573
1681
  return y.gte(0) ? y.floor() : y.ceil();
1574
1682
  }
1575
- /**
1576
- * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
1577
- */
1578
1683
  }, {
1579
1684
  key: "isNaN",
1580
1685
  value: function (_isNaN) {
@@ -1637,10 +1742,164 @@ var PowiainaNum = /*#__PURE__*/function () {
1637
1742
  value: function isneg() {
1638
1743
  return this.sign < 0;
1639
1744
  }
1745
+ }, {
1746
+ key: "getOperatorIndex",
1747
+ value:
1748
+ //#endregion
1749
+ //#region operators
1750
+ /**
1751
+ * @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.
1752
+ */
1753
+ function getOperatorIndex(arrow) {
1754
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1755
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1756
+ for (var i = 0; i < this.array.length; i++) {
1757
+ var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1758
+ if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1759
+ if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
1760
+ }
1761
+ return this.array.length - 0.5;
1762
+ }
1763
+ /**
1764
+ * @returns number repeats of operators with given arguments.
1765
+ */
1766
+ }, {
1767
+ key: "getOperator",
1768
+ value: function getOperator(arrow) {
1769
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1770
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1771
+ var index = this.getOperatorIndex(arrow, expans, megota);
1772
+ if (!this.array[index]) return 0;
1773
+ return this.array[index].repeat;
1774
+ }
1775
+ /**
1776
+ * Modify the repeat of operator
1777
+ * @param number val the repeat of operator will modify to array.
1778
+ * @returns bool Is the operators array changed?
1779
+ */
1780
+ }, {
1781
+ key: "setOperator",
1782
+ value: function setOperator(val, arrow) {
1783
+ var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1784
+ var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1785
+ // if (arrow!=0&&val==0) return false;
1786
+ var index = this.getOperatorIndex(arrow, expans, megota);
1787
+ if (!this.array[index]) {
1788
+ this.array.splice(Math.ceil(index), 0, {
1789
+ arrow: arrow,
1790
+ expans: expans,
1791
+ megota: megota,
1792
+ valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1793
+ repeat: val
1794
+ });
1795
+ return true;
1796
+ }
1797
+ this.array[index].repeat = val;
1798
+ // this.normalize()
1799
+ return false;
1800
+ }
1801
+ //#endregion
1802
+ //#region converters
1803
+ /**
1804
+ * Convert `this` to Javascript `number`
1805
+ *
1806
+ * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1807
+ */
1808
+ }, {
1809
+ key: "toNumber",
1810
+ value: function toNumber() {
1811
+ if (this.sign == -1) return -this.neg().toNumber();
1812
+ if (this.small) return 1 / this.rec().toNumber();
1813
+ if (this.array.length > 2) return Infinity;
1814
+ 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));
1815
+ return NaN;
1816
+ }
1817
+ /**
1818
+ * Convert `this` to a string
1819
+ */
1820
+ }, {
1821
+ key: "toString_core",
1822
+ value: function toString_core() {
1823
+ if (this.isNaN()) return "NaN";
1824
+ if (this.sign == -1) return "-".concat(this.neg().toString());
1825
+ if (this.small) {
1826
+ if (this.isZero()) return "0";
1827
+ return "/".concat(this.rec().toString());
1828
+ }
1829
+ if (this.isInfi()) return "Infinity";
1830
+ // P^a (10{arrow,expans,megota})^repeation base
1831
+ var res = "";
1832
+ if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
1833
+ for (var i = this.array.length - 1; i >= 0; i--) {
1834
+ var oper = this.array[i];
1835
+ 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) : "", "}");
1836
+ if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
1837
+ calc = "e".repeat(oper.repeat);
1838
+ } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
1839
+ calc = oper.repeat.toString();
1840
+ } else if (oper.repeat > 1) {
1841
+ calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1842
+ } else {
1843
+ calc = "".concat(calc);
1844
+ }
1845
+ res += "".concat(calc);
1846
+ }
1847
+ return res;
1848
+ }
1849
+ }, {
1850
+ key: "toString",
1851
+ value: function toString() {
1852
+ try {
1853
+ return this.toString_core();
1854
+ } catch (_b) {
1855
+ console.error("Checked error when converting to string");
1856
+ return "NaN";
1857
+ }
1858
+ }
1859
+ }, {
1860
+ key: "toJSON",
1861
+ value:
1862
+ /**
1863
+ * Convert `this` to a JSON object
1864
+ * @returns a JSON object
1865
+ */
1866
+ function toJSON() {
1867
+ return "PN" + this.toString();
1868
+ }
1869
+ }, {
1870
+ key: "arr01",
1871
+ get:
1872
+ /**
1873
+ * A property array value for version 0.1.x PowiainaNum.
1874
+ */
1875
+ function get() {
1876
+ var res = [0];
1877
+ for (var i = 0; i < this.array.length; i++) {
1878
+ if (i == 0) res[0] = this.array[i].repeat;else {
1879
+ // @ts-ignore
1880
+ res[i] = [0, 0, 0, 0];
1881
+ // @ts-ignore
1882
+ res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
1883
+ // @ts-ignore
1884
+ res[i][1] = this.array[i].repeat;
1885
+ // @ts-ignore
1886
+ res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
1887
+ // @ts-ignore
1888
+ res[i][3] = this.array[i].megota;
1889
+ }
1890
+ }
1891
+ return res;
1892
+ }
1893
+ //#endregion
1894
+ //#region useless functions
1895
+ /**
1896
+ * This function is for NaNe308, if you want to calculate G(x), use this function directly.
1897
+ */
1640
1898
  }, {
1641
1899
  key: "normalize",
1642
1900
  value:
1643
1901
  //#endregion
1902
+ //#region other functions
1644
1903
  /**
1645
1904
  * Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
1646
1905
  * @returns normalized number
@@ -1649,9 +1908,14 @@ var PowiainaNum = /*#__PURE__*/function () {
1649
1908
  //TODO: normalize
1650
1909
  var renormalize = true;
1651
1910
  var x = this;
1652
- for (var _i = 0; _i < this.array.length; _i++) {
1911
+ if (this.array === undefined) {
1912
+ x.array = [newOperator(NaN, 0, 1, 1)];
1913
+ }
1914
+ if (this.sign === undefined) this.sign = 0;
1915
+ if (this.layer === undefined) this.layer = 0;
1916
+ for (var i = 0; i < this.array.length; i++) {
1653
1917
  // Check what is infinity
1654
- if (this.array[_i].repeat == Infinity) {
1918
+ if (this.array[i].repeat == Infinity) {
1655
1919
  this.array = [{
1656
1920
  arrow: 0,
1657
1921
  expans: 1,
@@ -1662,8 +1926,8 @@ var PowiainaNum = /*#__PURE__*/function () {
1662
1926
  return this;
1663
1927
  }
1664
1928
  }
1665
- for (var i = 1; i < x.array.length; ++i) {
1666
- var e = x.array[i];
1929
+ for (var _i = 1; _i < x.array.length; ++_i) {
1930
+ var e = x.array[_i];
1667
1931
  if (e.arrow === null || e.arrow === undefined) {
1668
1932
  e.arrow = 0;
1669
1933
  }
@@ -1694,28 +1958,28 @@ var PowiainaNum = /*#__PURE__*/function () {
1694
1958
  renormalize = false;
1695
1959
  // Sort arrays.
1696
1960
  this.array.sort(arraySortFunction);
1697
- for (i = 1; i < x.array.length - 1; ++i) {
1698
- 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) {
1961
+ for (var _i2 = 1; _i2 < x.array.length - 1; ++_i2) {
1962
+ if (x.array[_i2].arrow == x.array[_i2 + 1].arrow && x.array[_i2].expans == x.array[_i2 + 1].expans && x.array[_i2].megota == x.array[_i2 + 1].megota) {
1699
1963
  // same array's merge
1700
- x.array[i].repeat += x.array[i + 1].repeat;
1701
- x.array.splice(i + 1, 1);
1702
- --i;
1964
+ x.array[_i2].repeat += x.array[_i2 + 1].repeat;
1965
+ x.array.splice(_i2 + 1, 1);
1966
+ --_i2;
1703
1967
  renormalize = true;
1704
1968
  }
1705
1969
  }
1706
- for (i = 1; i < x.array.length; ++i) {
1970
+ for (var _i3 = 1; _i3 < x.array.length; ++_i3) {
1707
1971
  // If there is a 0 repeat operator, remove it.
1708
- if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
1709
- x.array.splice(i, 1);
1710
- --i;
1972
+ if (x.array[_i3].arrow !== 0 && (x.array[_i3].repeat === 0 || x.array[_i3].repeat === null || x.array[_i3].repeat === undefined)) {
1973
+ x.array.splice(_i3, 1);
1974
+ --_i3;
1711
1975
  continue;
1712
1976
  }
1713
1977
  // If there is a operator which arrow 0 and brace count >=2
1714
1978
  // replace it as arrow replacement operaotr
1715
- if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
1716
- x.array[i].arrow = Infinity;
1717
- x.array[i].valuereplaced = 0;
1718
- x.array[i].expans = x.array[i].expans - 1;
1979
+ if (x.array[_i3].arrow == 0 && x.array[_i3].expans >= 2) {
1980
+ x.array[_i3].arrow = Infinity;
1981
+ x.array[_i3].valuereplaced = 0;
1982
+ x.array[_i3].expans = x.array[_i3].expans - 1;
1719
1983
  }
1720
1984
  }
1721
1985
  if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
@@ -1745,6 +2009,11 @@ var PowiainaNum = /*#__PURE__*/function () {
1745
2009
  this.small = !this.small;
1746
2010
  renormalize = true;
1747
2011
  }
2012
+ // for a = 1, small should false.
2013
+ if (this.array.length == 1 && this.array[0].repeat == 1 && this.small) {
2014
+ this.small = false;
2015
+ renormalize = true;
2016
+ }
1748
2017
  // for any 10{X>9e15}10, replace into 10{!}X;
1749
2018
  if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
1750
2019
  this.array[0].repeat = this.array[1].arrow;
@@ -1800,61 +2069,6 @@ var PowiainaNum = /*#__PURE__*/function () {
1800
2069
  } while (renormalize);
1801
2070
  return this;
1802
2071
  }
1803
- //#region operators
1804
- /**
1805
- * @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.
1806
- */
1807
- }, {
1808
- key: "getOperatorIndex",
1809
- value: function getOperatorIndex(arrow) {
1810
- var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1811
- var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1812
- for (var i = 0; i < this.array.length; i++) {
1813
- var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1814
- if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1815
- if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
1816
- }
1817
- return this.array.length - 0.5;
1818
- }
1819
- /**
1820
- * @returns number repeats of operators with given arguments.
1821
- */
1822
- }, {
1823
- key: "getOperator",
1824
- value: function getOperator(arrow) {
1825
- var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1826
- var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1827
- var index = this.getOperatorIndex(arrow, expans, megota);
1828
- if (!this.array[index]) return 0;
1829
- return this.array[index].repeat;
1830
- }
1831
- /**
1832
- * Modify the repeat of operator
1833
- * @param number val the repeat of operator will modify to array.
1834
- * @returns bool Is the operators array changed?
1835
- */
1836
- }, {
1837
- key: "setOperator",
1838
- value: function setOperator(val, arrow) {
1839
- var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1840
- var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1841
- // if (arrow!=0&&val==0) return false;
1842
- var index = this.getOperatorIndex(arrow, expans, megota);
1843
- if (!this.array[index]) {
1844
- this.array.splice(Math.ceil(index), 0, {
1845
- arrow: arrow,
1846
- expans: expans,
1847
- megota: megota,
1848
- valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1849
- repeat: val
1850
- });
1851
- return true;
1852
- }
1853
- this.array[index].repeat = val;
1854
- // this.normalize()
1855
- return false;
1856
- }
1857
- //#endregion
1858
2072
  /**
1859
2073
  * @returns a PowiainaNum object which deep copied from `this` object.
1860
2074
  */
@@ -1873,6 +2087,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1873
2087
  }, {
1874
2088
  key: "resetFromObject",
1875
2089
  value: function resetFromObject(powlikeObject) {
2090
+ if (!powlikeObject.array) {
2091
+ return;
2092
+ }
1876
2093
  this.array = [];
1877
2094
  for (var i = 0; i < powlikeObject.array.length; i++) {
1878
2095
  this.array[i] = {
@@ -1888,107 +2105,56 @@ var PowiainaNum = /*#__PURE__*/function () {
1888
2105
  this.layer = powlikeObject.layer;
1889
2106
  return this;
1890
2107
  }
1891
- //#region converters
1892
- /**
1893
- * Convert `this` to Javascript `number`
1894
- *
1895
- * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1896
- */
1897
- }, {
1898
- key: "toNumber",
1899
- value: function toNumber() {
1900
- if (this.sign == -1) return -this.neg().toNumber();
1901
- if (this.small) return 1 / this.rec().toNumber();
1902
- if (this.array.length > 2) return Infinity;
1903
- 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));
1904
- return NaN;
1905
- }
1906
- /**
1907
- * Convert `this` to a string
1908
- */
1909
- }, {
1910
- key: "toString",
1911
- value: function toString() {
1912
- if (this.isNaN()) return "NaN";
1913
- if (this.sign == -1) return "-".concat(this.neg().toString());
1914
- if (this.small) {
1915
- if (this.isZero()) return "0";
1916
- return "/".concat(this.rec().toString());
1917
- }
1918
- if (this.isInfi()) return "Infinity";
1919
- // P^a (10{arrow,expans,megota})^repeation base
1920
- var res = "";
1921
- if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
1922
- for (var i = this.array.length - 1; i >= 0; i--) {
1923
- var oper = this.array[i];
1924
- 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) : "", "}");
1925
- if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
1926
- calc = "e".repeat(oper.repeat);
1927
- } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
1928
- calc = oper.repeat.toString();
1929
- } else if (oper.repeat > 1) {
1930
- calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1931
- } else {
1932
- calc = "".concat(calc);
1933
- }
1934
- res += "".concat(calc);
1935
- }
1936
- return res;
1937
- }
1938
- }, {
1939
- key: "toJSON",
1940
- value:
1941
- /**
1942
- * Convert `this` to a JSON object
1943
- * @returns a JSON object
1944
- */
1945
- function toJSON() {
1946
- return "PN" + this.toString();
1947
- }
1948
- }, {
1949
- key: "arr01",
1950
- get:
1951
- /**
1952
- * A property array value for version 0.1.x PowiainaNum.
1953
- */
1954
- function get() {
1955
- var res = [0];
1956
- for (var i = 0; i < this.array.length; i++) {
1957
- if (i == 0) res[0] = this.array[i].repeat;else {
1958
- // @ts-ignore
1959
- res[i] = [0, 0, 0, 0];
1960
- // @ts-ignore
1961
- res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
1962
- // @ts-ignore
1963
- res[i][1] = this.array[i].repeat;
1964
- // @ts-ignore
1965
- res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
1966
- // @ts-ignore
1967
- res[i][3] = this.array[i].megota;
1968
- }
1969
- }
1970
- return res;
1971
- }
1972
2108
  }], [{
1973
2109
  key: "add",
1974
2110
  value: function add(t, other) {
1975
2111
  return new PowiainaNum(t).add(other);
1976
2112
  }
2113
+ }, {
2114
+ key: "plus",
2115
+ value: function plus(t, other) {
2116
+ return new PowiainaNum(t).add(other);
2117
+ }
1977
2118
  }, {
1978
2119
  key: "sub",
1979
2120
  value: function sub(t, other) {
1980
2121
  return new PowiainaNum(t).sub(other);
1981
2122
  }
2123
+ }, {
2124
+ key: "minus",
2125
+ value: function minus(t, other) {
2126
+ return new PowiainaNum(t).sub(other);
2127
+ }
1982
2128
  }, {
1983
2129
  key: "mul",
1984
2130
  value: function mul(t, other) {
1985
2131
  return new PowiainaNum(t).mul(other);
1986
2132
  }
2133
+ }, {
2134
+ key: "times",
2135
+ value: function times(t, other) {
2136
+ return new PowiainaNum(t).mul(other);
2137
+ }
1987
2138
  }, {
1988
2139
  key: "div",
1989
2140
  value: function div(t, other) {
1990
2141
  return new PowiainaNum(t).div(other);
1991
2142
  }
2143
+ }, {
2144
+ key: "divide",
2145
+ value: function divide(t, other) {
2146
+ return new PowiainaNum(t).div(other);
2147
+ }
2148
+ }, {
2149
+ key: "mod",
2150
+ value: function mod(x, y) {
2151
+ return new PowiainaNum(x).mod(y);
2152
+ }
2153
+ }, {
2154
+ key: "modulus",
2155
+ value: function modulus(x, y) {
2156
+ return new PowiainaNum(x).mod(y);
2157
+ }
1992
2158
  }, {
1993
2159
  key: "pow",
1994
2160
  value: function pow(t, other) {
@@ -2020,6 +2186,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2020
2186
  var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2021
2187
  return new PowiainaNum(t).log(base);
2022
2188
  }
2189
+ }, {
2190
+ key: "log2",
2191
+ value: function log2(t) {
2192
+ return new PowiainaNum(t).log2();
2193
+ }
2194
+ }, {
2195
+ key: "logBase",
2196
+ value: function logBase(t) {
2197
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2198
+ return new PowiainaNum(t).log(base);
2199
+ }
2023
2200
  }, {
2024
2201
  key: "pLog10",
2025
2202
  value: function pLog10(t) {
@@ -2171,6 +2348,27 @@ var PowiainaNum = /*#__PURE__*/function () {
2171
2348
  };
2172
2349
  }
2173
2350
  }
2351
+ }, {
2352
+ key: "pentate",
2353
+ value: function pentate(x, other, payload) {
2354
+ return new PowiainaNum(x).arrow(3)(other, payload);
2355
+ }
2356
+ }, {
2357
+ key: "hexate",
2358
+ value: function hexate(x, other, payload) {
2359
+ return new PowiainaNum(x).arrow(4)(other, payload);
2360
+ }
2361
+ }, {
2362
+ key: "pent",
2363
+ value: function pent(x, other, payload) {
2364
+ return new PowiainaNum(x).arrow(3)(other, payload);
2365
+ }
2366
+ }, {
2367
+ key: "penta_log",
2368
+ value: function penta_log(x) {
2369
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
2370
+ return new PowiainaNum(x).anyarrow_log(3)(base);
2371
+ }
2174
2372
  }, {
2175
2373
  key: "expansion",
2176
2374
  value: function expansion(t, other) {
@@ -2422,6 +2620,84 @@ var PowiainaNum = /*#__PURE__*/function () {
2422
2620
  value: function clampMax() {
2423
2621
  return PowiainaNum.min.apply(PowiainaNum, arguments);
2424
2622
  }
2623
+ }, {
2624
+ key: "eq",
2625
+ value: function eq(a, o) {
2626
+ return new PowiainaNum(a).eq(o);
2627
+ }
2628
+ }, {
2629
+ key: "equals",
2630
+ value: function equals(a, o) {
2631
+ return new PowiainaNum(a).eq(o);
2632
+ }
2633
+ }, {
2634
+ key: "neq",
2635
+ value: function neq(a, o) {
2636
+ return new PowiainaNum(a).neq(o);
2637
+ }
2638
+ }, {
2639
+ key: "notEquals",
2640
+ value: function notEquals(a, o) {
2641
+ return new PowiainaNum(a).notEquals(o);
2642
+ }
2643
+ }, {
2644
+ key: "lt",
2645
+ value: function lt(a, o) {
2646
+ return new PowiainaNum(a).lt(o);
2647
+ }
2648
+ }, {
2649
+ key: "gt",
2650
+ value: function gt(a, o) {
2651
+ return new PowiainaNum(a).gt(o);
2652
+ }
2653
+ }, {
2654
+ key: "lte",
2655
+ value: function lte(a, o) {
2656
+ return new PowiainaNum(a).lte(o);
2657
+ }
2658
+ }, {
2659
+ key: "gte",
2660
+ value: function gte(a, o) {
2661
+ return new PowiainaNum(a).gte(o);
2662
+ }
2663
+ }, {
2664
+ key: "rec",
2665
+ value: function rec(t) {
2666
+ return new PowiainaNum(t).rec();
2667
+ }
2668
+ }, {
2669
+ key: "recip",
2670
+ value: function recip(t) {
2671
+ return new PowiainaNum(t).rec();
2672
+ }
2673
+ }, {
2674
+ key: "reciprocate",
2675
+ value: function reciprocate(t) {
2676
+ return new PowiainaNum(t).rec();
2677
+ }
2678
+ }, {
2679
+ key: "floor",
2680
+ value: function floor(x) {
2681
+ return new PowiainaNum(x).floor();
2682
+ }
2683
+ }, {
2684
+ key: "ceil",
2685
+ value: function ceil(x) {
2686
+ return new PowiainaNum(x).ceil();
2687
+ }
2688
+ }, {
2689
+ key: "round",
2690
+ value: function round(x) {
2691
+ return new PowiainaNum(x).round();
2692
+ }
2693
+ }, {
2694
+ key: "trunc",
2695
+ value: function trunc(x) {
2696
+ return new PowiainaNum(x).trunc();
2697
+ }
2698
+ /**
2699
+ * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
2700
+ */
2425
2701
  }, {
2426
2702
  key: "sign",
2427
2703
  value: function sign(a) {
@@ -2436,6 +2712,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2436
2712
  key: "fromNumber",
2437
2713
  value: function fromNumber(x) {
2438
2714
  var obj = new PowiainaNum(); // NaN
2715
+ obj.resetFromObject({
2716
+ array: [{
2717
+ arrow: 0,
2718
+ expans: 1,
2719
+ megota: 1,
2720
+ repeat: NaN
2721
+ }],
2722
+ small: false,
2723
+ layer: 0,
2724
+ sign: 0
2725
+ });
2439
2726
  if (x < 0) obj.sign = -1; // negative
2440
2727
  else if (x == 0) {
2441
2728
  obj.sign = 0;
@@ -2463,10 +2750,26 @@ var PowiainaNum = /*#__PURE__*/function () {
2463
2750
  }, {
2464
2751
  key: "fromString",
2465
2752
  value: function fromString(input) {
2753
+ if (PowiainaNum.usingBreakEternityLikeFromString && BE_REGEX.test(input)) {
2754
+ /*
2755
+ * 0i00000000a7 says that eee-3000 will wrongly parse to 1. So i added this
2756
+ */
2757
+ var a = input.match(/(e+-)(\d+(.\d+)?)/);
2758
+ if (a) {
2759
+ var e_s = a[1].length;
2760
+ input = "e-" + "e".repeat(e_s - 1) + a[2];
2761
+ }
2762
+ }
2763
+ return this.fromString_core(input);
2764
+ }
2765
+ }, {
2766
+ key: "fromString_core",
2767
+ value: function fromString_core(input) {
2466
2768
  var _b, _c, _d, _e, _f, _g;
2467
- var x = new PowiainaNum();
2769
+ var x = new PowiainaNum(NaN);
2468
2770
  // Judge the string was a number
2469
2771
  if (input.startsWith("PN")) input = input.substring(2);
2772
+ if (input == "NaN") return PowiainaNum.NaN.clone();
2470
2773
  input = input.replace(/J\^(\d+)/g, "(10{!})^$1");
2471
2774
  input = input.replace(/J/g, "10{!}");
2472
2775
  input = input.replace(/K\^(\d+)/g, "(10{1,2})^$1");
@@ -2482,15 +2785,15 @@ var PowiainaNum = /*#__PURE__*/function () {
2482
2785
  }
2483
2786
  if (!isNaN(Number(input))) {
2484
2787
  var res = Number(input);
2485
- var _a3 = false;
2788
+ var a = false;
2486
2789
  if (res == 0) {
2487
2790
  if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
2488
- _a3 = true;
2791
+ a = true;
2489
2792
  }
2490
2793
  } else {
2491
- _a3 = true;
2794
+ a = true;
2492
2795
  }
2493
- if (!_a3) {
2796
+ if (!a) {
2494
2797
  var m = input.search(/e/);
2495
2798
  var exponent = input.substring((m == -1 ? input.length : m) + 1);
2496
2799
  var mantissa = input.substring(0, m == -1 ? undefined : m);
@@ -2519,7 +2822,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2519
2822
  // /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
2520
2823
  return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
2521
2824
  }
2522
- if (isFinite(res) && _a3) {
2825
+ if (isFinite(res) && a) {
2523
2826
  x = PowiainaNum.fromNumber(Number(input));
2524
2827
  return x;
2525
2828
  }
@@ -2536,6 +2839,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2536
2839
  return x;
2537
2840
  }
2538
2841
  input = replaceETo10(input);
2842
+ input = removeCommasOutsideBraces(input);
2539
2843
  if (!isPowiainaNum.test(input)) {
2540
2844
  throw powiainaNumError + "malformed input: " + input;
2541
2845
  }
@@ -2548,28 +2852,31 @@ var PowiainaNum = /*#__PURE__*/function () {
2548
2852
  input = input.substring(numSigns);
2549
2853
  }
2550
2854
  if (input[0] == "/") {
2551
- var numSigns = input.search(/[^\/]/);
2552
- var signs = input.substring(0, numSigns);
2553
- recipIt = ((_e = (_d = signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2554
- input = input.substring(numSigns);
2855
+ var _numSigns = input.search(/[^\/]/);
2856
+ var _signs = input.substring(0, _numSigns);
2857
+ recipIt = ((_e = (_d = _signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2858
+ input = input.substring(_numSigns);
2555
2859
  }
2556
2860
  if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
2557
2861
  x.sign = 1;
2558
2862
  x.array = [newOperator(0)];
2559
- var a, b, c, d;
2863
+ var _a3, b, c, d;
2560
2864
  if (input[0] == "P") {
2561
2865
  if (input[1] == "^") {
2562
- a = input.substring(2).search(/[^0-9]/) + 2;
2563
- x.layer = Number(input.substring(2, a));
2564
- input = input.substring(a + 1);
2866
+ _a3 = input.substring(2).search(/[^0-9]/) + 2;
2867
+ x.layer = Number(input.substring(2, _a3));
2868
+ input = input.substring(_a3 + 1);
2565
2869
  } else {
2566
- a = input.search(/[^P]/);
2567
- x.layer = a;
2568
- input = input.substring(a);
2870
+ _a3 = input.search(/[^P]/);
2871
+ x.layer = _a3;
2872
+ input = input.substring(_a3);
2569
2873
  }
2570
2874
  }
2571
2875
  while (input) {
2572
2876
  if (/^(\(?10[\^\{])/.test(input)) {
2877
+ var arrows = void 0,
2878
+ expans = void 0,
2879
+ megota = void 0;
2573
2880
  /*
2574
2881
  10^ - 匹配
2575
2882
  10{ - 匹配
@@ -2580,30 +2887,29 @@ var PowiainaNum = /*#__PURE__*/function () {
2580
2887
  */
2581
2888
  if (input[0] == "(") input = input.substring(1);
2582
2889
  //cutted, 10^.... or 10{....
2583
- var arrows, expans, megota;
2584
2890
  if (input[2] == "^") {
2585
- a = input.substring(2).search(/[^\^]/);
2891
+ _a3 = input.substring(2).search(/[^\^]/);
2586
2892
  //cut input to ^^...^^, and search how numbers
2587
- arrows = a;
2893
+ arrows = _a3;
2588
2894
  // 10^^^
2589
- b = a + 2; // b points to after ^'s.
2895
+ b = _a3 + 2; // b points to after ^'s.
2590
2896
  } else {
2591
2897
  // 10{...}
2592
- a = input.indexOf("}");
2898
+ _a3 = input.indexOf("}");
2593
2899
  // select contents between {...}
2594
- var tmp = input.substring(3, a).split(",");
2900
+ var tmp = input.substring(3, _a3).split(",");
2595
2901
  arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
2596
2902
  expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
2597
2903
  megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
2598
- b = a + 1;
2904
+ b = _a3 + 1;
2599
2905
  // b points to after }.
2600
2906
  }
2601
2907
  input = input.substring(b);
2602
2908
  if (input[0] == ")") {
2603
2909
  // )^....<Space>
2604
- a = input.indexOf(" ");
2605
- c = Number(input.substring(2, a)); // Select contents between )^....<Space>
2606
- input = input.substring(a + 1); // c points to after <Space>
2910
+ _a3 = input.indexOf(" ");
2911
+ c = Number(input.substring(2, _a3)); // Select contents between )^....<Space>
2912
+ input = input.substring(_a3 + 1); // c points to after <Space>
2607
2913
  } else {
2608
2914
  c = 1; // There is only spaces, count as <ONE>
2609
2915
  }
@@ -2614,21 +2920,21 @@ var PowiainaNum = /*#__PURE__*/function () {
2614
2920
  x.array.splice(1, 0, newOperator(c, 1, expans, megota));
2615
2921
  }
2616
2922
  } else if (arrows == 2 && expans == 1 && megota == 1) {
2617
- a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2923
+ _a3 = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2618
2924
  b = x.array[0].repeat;
2619
- if (b >= 1e10) ++a;
2620
- if (b >= 10) ++a;
2621
- x.array[0].repeat = a;
2925
+ if (b >= 1e10) ++_a3;
2926
+ if (b >= 10) ++_a3;
2927
+ x.array[0].repeat = _a3;
2622
2928
  if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
2623
2929
  d = x.getOperatorIndex(2);
2624
2930
  if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
2625
2931
  } else if (isFinite(arrows)) {
2626
- a = x.getOperator(arrows - 1);
2932
+ _a3 = x.getOperator(arrows - 1);
2627
2933
  b = x.getOperator(arrows - 2);
2628
- if (b >= 10) ++a;
2934
+ if (b >= 10) ++_a3;
2629
2935
  d = x.getOperatorIndex(arrows);
2630
2936
  x.array.splice(1, Math.ceil(d) - 1);
2631
- x.array[0].repeat = a;
2937
+ x.array[0].repeat = _a3;
2632
2938
  if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
2633
2939
  } else {
2634
2940
  x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
@@ -2637,10 +2943,10 @@ var PowiainaNum = /*#__PURE__*/function () {
2637
2943
  break;
2638
2944
  }
2639
2945
  }
2640
- a = input.split(/[Ee]/);
2946
+ _a3 = input.split(/[Ee]/);
2641
2947
  b = [x.array[0].repeat, 0];
2642
2948
  c = 1;
2643
- for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
2949
+ for (var i = _a3.length - 1; i >= 0; --i) {
2644
2950
  //The things that are already there
2645
2951
  if (b[0] < MSI_LOG10 && b[1] === 0) {
2646
2952
  b[0] = Math.pow(10, c * b[0]);
@@ -2657,12 +2963,12 @@ var PowiainaNum = /*#__PURE__*/function () {
2657
2963
  b[1]++;
2658
2964
  }
2659
2965
  //Multiplying coefficient
2660
- var decimalPointPos = a[_i2].indexOf(".");
2661
- var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
2966
+ var decimalPointPos = _a3[i].indexOf(".");
2967
+ var intPartLen = decimalPointPos == -1 ? _a3[i].length : decimalPointPos;
2662
2968
  if (b[1] === 0) {
2663
- 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]);
2969
+ if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(_a3[i].substring(0, intPartLen)), b[1] = 1;else if (_a3[i]) b[0] *= Number(_a3[i]);
2664
2970
  } else {
2665
- d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
2971
+ d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(_a3[i].substring(0, intPartLen)) : _a3[i] ? Math.log10(Number(_a3[i])) : 0;
2666
2972
  if (b[1] == 1) {
2667
2973
  b[0] += d;
2668
2974
  } else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
@@ -2693,6 +2999,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2693
2999
  key: "fromObject",
2694
3000
  value: function fromObject(powlikeObject) {
2695
3001
  var obj = new PowiainaNum();
3002
+ obj.resetFromObject({
3003
+ array: [{
3004
+ arrow: 0,
3005
+ expans: 1,
3006
+ megota: 1,
3007
+ repeat: NaN
3008
+ }],
3009
+ small: false,
3010
+ layer: 0,
3011
+ sign: 0
3012
+ });
2696
3013
  obj.array = [];
2697
3014
  if (isExpantaNumArray(powlikeObject)) {
2698
3015
  for (var i = 0; i < powlikeObject.length; i++) {
@@ -2710,8 +3027,8 @@ var PowiainaNum = /*#__PURE__*/function () {
2710
3027
  } else if (isPowiainaNum01XArray(powlikeObject)) {
2711
3028
  var arrayobj = powlikeObject;
2712
3029
  obj.array[0] = newOperator(arrayobj[0]);
2713
- for (var _i3 = 1; _i3 < arrayobj.length; _i3++) {
2714
- var b = arrayobj[_i3];
3030
+ for (var _i4 = 1; _i4 < arrayobj.length; _i4++) {
3031
+ var b = arrayobj[_i4];
2715
3032
  obj.array[1] = newOperator(b[1], replaceXToInfinity(b[0]), replaceXToInfinity(b[2]), b[3]);
2716
3033
  }
2717
3034
  obj.small = false;
@@ -2719,21 +3036,21 @@ var PowiainaNum = /*#__PURE__*/function () {
2719
3036
  obj.layer = 0;
2720
3037
  return obj;
2721
3038
  } else {
2722
- for (var _i4 = 0; _i4 < powlikeObject.array.length; _i4++) {
2723
- obj.array[_i4] = {
2724
- arrow: powlikeObject.array[_i4].arrow,
2725
- expans: powlikeObject.array[_i4].expans,
2726
- megota: powlikeObject.array[_i4].megota,
2727
- repeat: powlikeObject.array[_i4].repeat,
2728
- valuereplaced: powlikeObject.array[_i4].valuereplaced
2729
- };
2730
- }
2731
- obj.small = powlikeObject.small;
2732
- obj.sign = powlikeObject.sign;
2733
- obj.layer = powlikeObject.layer;
3039
+ obj.resetFromObject(powlikeObject);
2734
3040
  return obj;
2735
3041
  }
2736
3042
  }
3043
+ }, {
3044
+ key: "grahalFunction",
3045
+ value: function grahalFunction(layers2) {
3046
+ var layers = new PowiainaNum(layers2);
3047
+ if (!layers.isInt() || layers.lt(0) || layers.isNaN()) return PowiainaNum.NaN.clone();
3048
+ if (layers.eq(1)) return new PowiainaNum("10^^^(10^)^7625597484984 3638334640023.7783");else if (layers.lte(MSI)) {
3049
+ return new PowiainaNum("(10{!})^".concat(layers.toNumber(), " 10^^^(10^)^7625597484984 3638334640023.7783"));
3050
+ } else {
3051
+ return PowiainaNum.BEAF(3, layers, 1, 2);
3052
+ }
3053
+ }
2737
3054
  }]);
2738
3055
  }();
2739
3056
  _a = Symbol.toStringTag;
@@ -2950,5 +3267,14 @@ PowiainaNum.maxOps = 100;
2950
3267
  PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
2951
3268
  //#endregion
2952
3269
  PowiainaNum.arrowFuncMap = new Map();
3270
+ //#region configurations
3271
+ /**
3272
+ * If you set this config to true, the `fromString` method will try to parse the string to `PowiainaNum` class with `break_eternity.js` similar `fromString` method, if cannot parse correctly, the program will use `PowiainaNum.js` `fromString` method.
3273
+ */
3274
+ PowiainaNum.usingBreakEternityLikeFromString = false;
3275
+ /**
3276
+ * If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
3277
+ */
3278
+ PowiainaNum.blankArgumentConstructorReturnZero = false;
2953
3279
 
2954
3280
  export { arraySortFunction, PowiainaNum as default, mergeSameArrays };