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.
@@ -66,6 +66,8 @@ function _unsupportedIterableToArray(r, a) {
66
66
 
67
67
  /* Author: VeryrrDefine 0.2.0-beta.1.1*/
68
68
  var _a;
69
+ //#endregion
70
+ //#region constants
69
71
  var powiainaNumError = "[PowiainaNum 0.2 error]";
70
72
  var MSI = 9007199254740991;
71
73
  var MSI_LOG10 = 15.954589770191003;
@@ -73,6 +75,8 @@ var MSI_REC = 1.1102230246251568e-16;
73
75
  var LONG_STRING_MIN_LENGTH = 17;
74
76
  var EXP_E_REC = 1.444667861009766;
75
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+))$/;
78
+ var BE_REGEX = /^((\d+(\.\d*)?|\d*\.\d+)?([EeFf]([-\+]?)))*(0|\d+(\.\d*)?|\d*\.\d+)$/;
79
+ //#endregion
76
80
  //#region some useful functions
77
81
  function newOperator(r) {
78
82
  var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -86,6 +90,29 @@ function newOperator(r) {
86
90
  valuereplaced: a == Infinity ? 0 : e == Infinity ? 1 : -1
87
91
  };
88
92
  }
93
+ function removeCommasOutsideBraces(input) {
94
+ var result = "";
95
+ var inBraces = false;
96
+ for (var i = 0; i < input.length; i++) {
97
+ var _char = input[i];
98
+ if (_char === "{") {
99
+ inBraces = true;
100
+ result += _char;
101
+ } else if (_char === "}") {
102
+ inBraces = false;
103
+ result += _char;
104
+ } else if (_char === ",") {
105
+ // 只有在花括号内部才保留逗号
106
+ if (inBraces) {
107
+ result += _char;
108
+ }
109
+ // 如果在花括号外部,就不添加到结果中(相当于删除)
110
+ } else {
111
+ result += _char;
112
+ }
113
+ }
114
+ return result;
115
+ }
89
116
  // parse 0.1.x PowiainaNum.js string
90
117
  function parseLegacyPowiainaNumString(str) {
91
118
  var pattern = /l(\d+)\s+s(\d+)\s+a(\[.*\])/;
@@ -118,7 +145,7 @@ function compareTuples() {
118
145
  function replaceETo10(str) {
119
146
  // 使用正则表达式匹配 (e^数字) 的模式
120
147
  // 正则解释:\(e\^(\d+)\) 匹配 (e^数字),其中 \d+ 匹配一个或多个数字
121
- return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)\x20*PT/g, "(10^)^$1 ");
148
+ return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)[Pp][Tt]/g, "(10^)^$1 ");
122
149
  }
123
150
  /**
124
151
  * 把一个字符串很长的数进行以10为底的对数
@@ -172,8 +199,10 @@ var OMEGA = 0.56714329040978387299997; // W(1, 0)
172
199
  // The evaluation can become inaccurate very close to the branch point
173
200
  // Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
174
201
  function f_lambertw(z) {
175
- var tol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
176
- var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
202
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
203
+ var pr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
204
+ var tol = t;
205
+ var principal = pr;
177
206
  var w;
178
207
  var wn;
179
208
  if (!Number.isFinite(z)) {
@@ -336,16 +365,26 @@ var PowiainaNum = /*#__PURE__*/function () {
336
365
  this.small = false;
337
366
  this.sign = 0;
338
367
  this.layer = 0;
339
- if (typeof arg1 == "undefined") ; else if (typeof arg1 == "number") {
340
- var obj = PowiainaNum.fromNumber(arg1);
341
- this.resetFromObject(obj);
342
- } else if (_typeof(arg1) == "object") {
343
- var _obj = PowiainaNum.fromObject(arg1);
344
- this.resetFromObject(_obj);
345
- } else if (typeof arg1 == "string") {
346
- var _obj2 = PowiainaNum.fromString(arg1);
347
- this.resetFromObject(_obj2);
348
- } else ;
368
+ if (PowiainaNum.blankArgumentConstructorReturnZero) {
369
+ this.resetFromObject(PowiainaNum.ZERO);
370
+ }
371
+ try {
372
+ if (typeof arg1 == "undefined") {} else if (typeof arg1 == "number") {
373
+ var obj = PowiainaNum.fromNumber(arg1);
374
+ this.resetFromObject(obj);
375
+ } else if (_typeof(arg1) == "object") {
376
+ var _obj = PowiainaNum.fromObject(arg1);
377
+ this.resetFromObject(_obj);
378
+ } else if (typeof arg1 == "string") {
379
+ var _obj2 = PowiainaNum.fromString(arg1);
380
+ this.resetFromObject(_obj2);
381
+ } else {
382
+ var isn = arg1;
383
+ }
384
+ } catch (e) {
385
+ console.error("Malformed input");
386
+ console.error(e);
387
+ }
349
388
  }
350
389
  //#region 4 Basic calculates.
351
390
  /**
@@ -356,7 +395,7 @@ var PowiainaNum = /*#__PURE__*/function () {
356
395
  key: "add",
357
396
  value: function add(other) {
358
397
  var _b, _c, _d, _e;
359
- var x = this.clone();
398
+ var x = this.clone().normalize();
360
399
  var y = new PowiainaNum(other);
361
400
  // inf + -inf = nan
362
401
  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();
@@ -417,7 +456,7 @@ var PowiainaNum = /*#__PURE__*/function () {
417
456
  mult *= -1;
418
457
  }
419
458
  if (t == 0) throw Error("Encounter a calculate error");
420
- r = new PowiainaNum();
459
+ r = PowiainaNum.NaN.clone();
421
460
  r.sign = 1;
422
461
  if (l > MSI_LOG10 || l < -MSI_LOG10) {
423
462
  r.array = [newOperator(l, 0), newOperator(1, 1)];
@@ -428,11 +467,21 @@ var PowiainaNum = /*#__PURE__*/function () {
428
467
  r.sign *= mult;
429
468
  return r;
430
469
  }
470
+ }, {
471
+ key: "plus",
472
+ value: function plus(other) {
473
+ return this.add(other);
474
+ }
431
475
  }, {
432
476
  key: "sub",
433
477
  value: function sub(a) {
434
478
  return this.add(new PowiainaNum(a).neg());
435
479
  }
480
+ }, {
481
+ key: "minus",
482
+ value: function minus(other) {
483
+ return this.sub(other);
484
+ }
436
485
  }, {
437
486
  key: "mul",
438
487
  value: function mul(other) {
@@ -466,12 +515,22 @@ var PowiainaNum = /*#__PURE__*/function () {
466
515
  r.sign = x.sign * y.sign;
467
516
  return r;
468
517
  }
518
+ }, {
519
+ key: "times",
520
+ value: function times(other) {
521
+ return this.mul(other);
522
+ }
469
523
  }, {
470
524
  key: "div",
471
525
  value: function div(other) {
472
526
  var x = new PowiainaNum(other).rec();
473
527
  return this.mul(x);
474
528
  }
529
+ }, {
530
+ key: "divide",
531
+ value: function divide(other) {
532
+ return this.div(other);
533
+ }
475
534
  }, {
476
535
  key: "mod",
477
536
  value: function mod(x) {
@@ -479,14 +538,20 @@ var PowiainaNum = /*#__PURE__*/function () {
479
538
  var division = this.div(other);
480
539
  return division.sub(division.floor()).mul(other);
481
540
  }
541
+ }, {
542
+ key: "modulus",
543
+ value: function modulus(x) {
544
+ return this.mod(x);
545
+ }
546
+ }, {
547
+ key: "pow10",
548
+ value:
482
549
  //#endregion
483
550
  //#region power
484
551
  /**
485
552
  * @returns 10 to the power of `this`
486
553
  */
487
- }, {
488
- key: "pow10",
489
- value: function pow10() {
554
+ function pow10() {
490
555
  var _b, _c;
491
556
  var r = this.clone();
492
557
  // inf & nan check
@@ -516,8 +581,16 @@ var PowiainaNum = /*#__PURE__*/function () {
516
581
  if (!other.isFinite()) return other.clone();
517
582
  if (!this.isFinite()) return this.clone();
518
583
  if (this.eq(10)) return other.pow10();
584
+ if (other.isneg()) return this.pow(other.neg()).rec();
519
585
  if (this.isneg()) {
520
- if (!other.isInt()) return PowiainaNum.NaN.clone();
586
+ if (!other.isInt()) {
587
+ if (other.small) {
588
+ if (other.rec().div(2).eq(1)) {
589
+ return this.neg().pow(other).neg();
590
+ }
591
+ }
592
+ return PowiainaNum.NaN.clone();
593
+ }
521
594
  var r = this.abs().pow(other);
522
595
  r.sign = function () {
523
596
  var a = other.mod(2).round();
@@ -594,6 +667,16 @@ var PowiainaNum = /*#__PURE__*/function () {
594
667
  var other = new PowiainaNum(base);
595
668
  return this.log10().div(other.log10());
596
669
  }
670
+ }, {
671
+ key: "log2",
672
+ value: function log2() {
673
+ return this.log(2);
674
+ }
675
+ }, {
676
+ key: "logBase",
677
+ value: function logBase(a) {
678
+ return this.log(a);
679
+ }
597
680
  }, {
598
681
  key: "ln",
599
682
  value: function ln() {
@@ -701,7 +784,8 @@ var PowiainaNum = /*#__PURE__*/function () {
701
784
  //Code from break_eternity.js
702
785
  //Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
703
786
  function lambertw() {
704
- var principal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
787
+ var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
788
+ var principal = princ;
705
789
  if (this.lt(-0.3678794411710499)) {
706
790
  return PowiainaNum.NaN.clone(); //complex
707
791
  } else if (principal) {
@@ -719,9 +803,9 @@ var PowiainaNum = /*#__PURE__*/function () {
719
803
  if (this.sign === 1) {
720
804
  return PowiainaNum.NaN.clone(); //complex
721
805
  }
722
- if (this.layer === 0) {
806
+ if (this.lt(9e15)) {
723
807
  return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
724
- } else if (this.layer == 1) {
808
+ } else if (this.lt(PowiainaNum.E_MSI)) {
725
809
  return d_lambertw(this, 1e-10, false);
726
810
  } else {
727
811
  return this.neg().rec().lambertw().neg();
@@ -742,7 +826,9 @@ var PowiainaNum = /*#__PURE__*/function () {
742
826
  var payl = new PowiainaNum(payload);
743
827
  if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
744
828
  if (t.eq(1)) return PowiainaNum.ONE.clone();
745
- if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
829
+ if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
830
+ other = other.add(payl.slog(t));
831
+ }
746
832
  var negln;
747
833
  if (other.isInfi() && other.sign > 0) {
748
834
  if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
@@ -1072,9 +1158,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1072
1158
  // base^base^... = x? (? bases)
1073
1159
  var r = 0;
1074
1160
  // 计算x与base的差距
1075
- var t = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1076
- if (t > 3) {
1077
- var l = t - 3;
1161
+ var distanceLayerOf = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1162
+ if (distanceLayerOf > 3) {
1163
+ var l = distanceLayerOf - 3;
1078
1164
  r += l;
1079
1165
  x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
1080
1166
  }
@@ -1116,18 +1202,18 @@ var PowiainaNum = /*#__PURE__*/function () {
1116
1202
  }
1117
1203
  }, {
1118
1204
  key: "pentate",
1119
- value: function pentate(other) {
1120
- return this.arrow(3)(other);
1205
+ value: function pentate(other, payload) {
1206
+ return this.arrow(3)(other, payload);
1121
1207
  }
1122
1208
  }, {
1123
1209
  key: "hexate",
1124
- value: function hexate(other) {
1125
- return this.arrow(4)(other);
1210
+ value: function hexate(other, payload) {
1211
+ return this.arrow(4)(other, payload);
1126
1212
  }
1127
1213
  }, {
1128
1214
  key: "pent",
1129
- value: function pent(other) {
1130
- return this.arrow(3)(other);
1215
+ value: function pent(other, payload) {
1216
+ return this.arrow(3)(other, payload);
1131
1217
  }
1132
1218
  }, {
1133
1219
  key: "penta_log",
@@ -1135,6 +1221,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1135
1221
  var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
1136
1222
  return this.anyarrow_log(3)(base);
1137
1223
  }
1224
+ }, {
1225
+ key: "expansion",
1226
+ value:
1138
1227
  /**
1139
1228
  * Expansion, which is `this`{{1}}`other2`.
1140
1229
  *
@@ -1142,9 +1231,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1142
1231
  *
1143
1232
  * @url https://googology.fandom.com/wiki/Expansion
1144
1233
  */
1145
- }, {
1146
- key: "expansion",
1147
- value: function expansion(other2) {
1234
+ function expansion(other2) {
1148
1235
  var other = new PowiainaNum(other2);
1149
1236
  var t = this.clone();
1150
1237
  if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
@@ -1457,6 +1544,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1457
1544
  var t = this.cmp(other);
1458
1545
  return t == 0 || t == 1;
1459
1546
  }
1547
+ }, {
1548
+ key: "equals",
1549
+ value: function equals(other) {
1550
+ return this.eq(other);
1551
+ }
1552
+ }, {
1553
+ key: "notEquals",
1554
+ value: function notEquals(other) {
1555
+ return this.neq(other);
1556
+ }
1460
1557
  }, {
1461
1558
  key: "eq_tolerance",
1462
1559
  value: function eq_tolerance(value) {
@@ -1518,6 +1615,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1518
1615
  a.small = !a.small;
1519
1616
  return a;
1520
1617
  }
1618
+ }, {
1619
+ key: "recip",
1620
+ value: function recip() {
1621
+ return this.rec();
1622
+ }
1623
+ }, {
1624
+ key: "reciprocate",
1625
+ value: function reciprocate() {
1626
+ return this.rec();
1627
+ }
1521
1628
  }, {
1522
1629
  key: "floor",
1523
1630
  value: function floor() {
@@ -1558,6 +1665,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1558
1665
  r.sign = this.sign;
1559
1666
  return r;
1560
1667
  }
1668
+ }, {
1669
+ key: "trunc",
1670
+ value:
1561
1671
  /**
1562
1672
  * Work like `Math.trunc`,
1563
1673
  *
@@ -1570,15 +1680,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1570
1680
  * new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
1571
1681
  * @returns
1572
1682
  */
1573
- }, {
1574
- key: "trunc",
1575
- value: function trunc() {
1683
+ function trunc() {
1576
1684
  var y = this.clone();
1577
1685
  return y.gte(0) ? y.floor() : y.ceil();
1578
1686
  }
1579
- /**
1580
- * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
1581
- */
1582
1687
  }, {
1583
1688
  key: "isNaN",
1584
1689
  value: function (_isNaN) {
@@ -1641,10 +1746,164 @@ var PowiainaNum = /*#__PURE__*/function () {
1641
1746
  value: function isneg() {
1642
1747
  return this.sign < 0;
1643
1748
  }
1749
+ }, {
1750
+ key: "getOperatorIndex",
1751
+ value:
1752
+ //#endregion
1753
+ //#region operators
1754
+ /**
1755
+ * @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.
1756
+ */
1757
+ function getOperatorIndex(arrow) {
1758
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1759
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1760
+ for (var i = 0; i < this.array.length; i++) {
1761
+ var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1762
+ if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1763
+ if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
1764
+ }
1765
+ return this.array.length - 0.5;
1766
+ }
1767
+ /**
1768
+ * @returns number repeats of operators with given arguments.
1769
+ */
1770
+ }, {
1771
+ key: "getOperator",
1772
+ value: function getOperator(arrow) {
1773
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1774
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1775
+ var index = this.getOperatorIndex(arrow, expans, megota);
1776
+ if (!this.array[index]) return 0;
1777
+ return this.array[index].repeat;
1778
+ }
1779
+ /**
1780
+ * Modify the repeat of operator
1781
+ * @param number val the repeat of operator will modify to array.
1782
+ * @returns bool Is the operators array changed?
1783
+ */
1784
+ }, {
1785
+ key: "setOperator",
1786
+ value: function setOperator(val, arrow) {
1787
+ var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1788
+ var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1789
+ // if (arrow!=0&&val==0) return false;
1790
+ var index = this.getOperatorIndex(arrow, expans, megota);
1791
+ if (!this.array[index]) {
1792
+ this.array.splice(Math.ceil(index), 0, {
1793
+ arrow: arrow,
1794
+ expans: expans,
1795
+ megota: megota,
1796
+ valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1797
+ repeat: val
1798
+ });
1799
+ return true;
1800
+ }
1801
+ this.array[index].repeat = val;
1802
+ // this.normalize()
1803
+ return false;
1804
+ }
1805
+ //#endregion
1806
+ //#region converters
1807
+ /**
1808
+ * Convert `this` to Javascript `number`
1809
+ *
1810
+ * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1811
+ */
1812
+ }, {
1813
+ key: "toNumber",
1814
+ value: function toNumber() {
1815
+ if (this.sign == -1) return -this.neg().toNumber();
1816
+ if (this.small) return 1 / this.rec().toNumber();
1817
+ if (this.array.length > 2) return Infinity;
1818
+ 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));
1819
+ return NaN;
1820
+ }
1821
+ /**
1822
+ * Convert `this` to a string
1823
+ */
1824
+ }, {
1825
+ key: "toString_core",
1826
+ value: function toString_core() {
1827
+ if (this.isNaN()) return "NaN";
1828
+ if (this.sign == -1) return "-".concat(this.neg().toString());
1829
+ if (this.small) {
1830
+ if (this.isZero()) return "0";
1831
+ return "/".concat(this.rec().toString());
1832
+ }
1833
+ if (this.isInfi()) return "Infinity";
1834
+ // P^a (10{arrow,expans,megota})^repeation base
1835
+ var res = "";
1836
+ if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
1837
+ for (var i = this.array.length - 1; i >= 0; i--) {
1838
+ var oper = this.array[i];
1839
+ 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) : "", "}");
1840
+ if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
1841
+ calc = "e".repeat(oper.repeat);
1842
+ } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
1843
+ calc = oper.repeat.toString();
1844
+ } else if (oper.repeat > 1) {
1845
+ calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1846
+ } else {
1847
+ calc = "".concat(calc);
1848
+ }
1849
+ res += "".concat(calc);
1850
+ }
1851
+ return res;
1852
+ }
1853
+ }, {
1854
+ key: "toString",
1855
+ value: function toString() {
1856
+ try {
1857
+ return this.toString_core();
1858
+ } catch (_b) {
1859
+ console.error("Checked error when converting to string");
1860
+ return "NaN";
1861
+ }
1862
+ }
1863
+ }, {
1864
+ key: "toJSON",
1865
+ value:
1866
+ /**
1867
+ * Convert `this` to a JSON object
1868
+ * @returns a JSON object
1869
+ */
1870
+ function toJSON() {
1871
+ return "PN" + this.toString();
1872
+ }
1873
+ }, {
1874
+ key: "arr01",
1875
+ get:
1876
+ /**
1877
+ * A property array value for version 0.1.x PowiainaNum.
1878
+ */
1879
+ function get() {
1880
+ var res = [0];
1881
+ for (var i = 0; i < this.array.length; i++) {
1882
+ if (i == 0) res[0] = this.array[i].repeat;else {
1883
+ // @ts-ignore
1884
+ res[i] = [0, 0, 0, 0];
1885
+ // @ts-ignore
1886
+ res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
1887
+ // @ts-ignore
1888
+ res[i][1] = this.array[i].repeat;
1889
+ // @ts-ignore
1890
+ res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
1891
+ // @ts-ignore
1892
+ res[i][3] = this.array[i].megota;
1893
+ }
1894
+ }
1895
+ return res;
1896
+ }
1897
+ //#endregion
1898
+ //#region useless functions
1899
+ /**
1900
+ * This function is for NaNe308, if you want to calculate G(x), use this function directly.
1901
+ */
1644
1902
  }, {
1645
1903
  key: "normalize",
1646
1904
  value:
1647
1905
  //#endregion
1906
+ //#region other functions
1648
1907
  /**
1649
1908
  * Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
1650
1909
  * @returns normalized number
@@ -1653,9 +1912,14 @@ var PowiainaNum = /*#__PURE__*/function () {
1653
1912
  //TODO: normalize
1654
1913
  var renormalize = true;
1655
1914
  var x = this;
1656
- for (var _i = 0; _i < this.array.length; _i++) {
1915
+ if (this.array === undefined) {
1916
+ x.array = [newOperator(NaN, 0, 1, 1)];
1917
+ }
1918
+ if (this.sign === undefined) this.sign = 0;
1919
+ if (this.layer === undefined) this.layer = 0;
1920
+ for (var i = 0; i < this.array.length; i++) {
1657
1921
  // Check what is infinity
1658
- if (this.array[_i].repeat == Infinity) {
1922
+ if (this.array[i].repeat == Infinity) {
1659
1923
  this.array = [{
1660
1924
  arrow: 0,
1661
1925
  expans: 1,
@@ -1666,8 +1930,8 @@ var PowiainaNum = /*#__PURE__*/function () {
1666
1930
  return this;
1667
1931
  }
1668
1932
  }
1669
- for (var i = 1; i < x.array.length; ++i) {
1670
- var e = x.array[i];
1933
+ for (var _i = 1; _i < x.array.length; ++_i) {
1934
+ var e = x.array[_i];
1671
1935
  if (e.arrow === null || e.arrow === undefined) {
1672
1936
  e.arrow = 0;
1673
1937
  }
@@ -1698,28 +1962,28 @@ var PowiainaNum = /*#__PURE__*/function () {
1698
1962
  renormalize = false;
1699
1963
  // Sort arrays.
1700
1964
  this.array.sort(arraySortFunction);
1701
- for (i = 1; i < x.array.length - 1; ++i) {
1702
- 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) {
1965
+ for (var _i2 = 1; _i2 < x.array.length - 1; ++_i2) {
1966
+ 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) {
1703
1967
  // same array's merge
1704
- x.array[i].repeat += x.array[i + 1].repeat;
1705
- x.array.splice(i + 1, 1);
1706
- --i;
1968
+ x.array[_i2].repeat += x.array[_i2 + 1].repeat;
1969
+ x.array.splice(_i2 + 1, 1);
1970
+ --_i2;
1707
1971
  renormalize = true;
1708
1972
  }
1709
1973
  }
1710
- for (i = 1; i < x.array.length; ++i) {
1974
+ for (var _i3 = 1; _i3 < x.array.length; ++_i3) {
1711
1975
  // If there is a 0 repeat operator, remove it.
1712
- if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
1713
- x.array.splice(i, 1);
1714
- --i;
1976
+ if (x.array[_i3].arrow !== 0 && (x.array[_i3].repeat === 0 || x.array[_i3].repeat === null || x.array[_i3].repeat === undefined)) {
1977
+ x.array.splice(_i3, 1);
1978
+ --_i3;
1715
1979
  continue;
1716
1980
  }
1717
1981
  // If there is a operator which arrow 0 and brace count >=2
1718
1982
  // replace it as arrow replacement operaotr
1719
- if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
1720
- x.array[i].arrow = Infinity;
1721
- x.array[i].valuereplaced = 0;
1722
- x.array[i].expans = x.array[i].expans - 1;
1983
+ if (x.array[_i3].arrow == 0 && x.array[_i3].expans >= 2) {
1984
+ x.array[_i3].arrow = Infinity;
1985
+ x.array[_i3].valuereplaced = 0;
1986
+ x.array[_i3].expans = x.array[_i3].expans - 1;
1723
1987
  }
1724
1988
  }
1725
1989
  if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
@@ -1749,6 +2013,11 @@ var PowiainaNum = /*#__PURE__*/function () {
1749
2013
  this.small = !this.small;
1750
2014
  renormalize = true;
1751
2015
  }
2016
+ // for a = 1, small should false.
2017
+ if (this.array.length == 1 && this.array[0].repeat == 1 && this.small) {
2018
+ this.small = false;
2019
+ renormalize = true;
2020
+ }
1752
2021
  // for any 10{X>9e15}10, replace into 10{!}X;
1753
2022
  if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
1754
2023
  this.array[0].repeat = this.array[1].arrow;
@@ -1804,61 +2073,6 @@ var PowiainaNum = /*#__PURE__*/function () {
1804
2073
  } while (renormalize);
1805
2074
  return this;
1806
2075
  }
1807
- //#region operators
1808
- /**
1809
- * @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.
1810
- */
1811
- }, {
1812
- key: "getOperatorIndex",
1813
- value: function getOperatorIndex(arrow) {
1814
- var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1815
- var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1816
- for (var i = 0; i < this.array.length; i++) {
1817
- var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1818
- if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1819
- if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
1820
- }
1821
- return this.array.length - 0.5;
1822
- }
1823
- /**
1824
- * @returns number repeats of operators with given arguments.
1825
- */
1826
- }, {
1827
- key: "getOperator",
1828
- value: function getOperator(arrow) {
1829
- var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1830
- var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1831
- var index = this.getOperatorIndex(arrow, expans, megota);
1832
- if (!this.array[index]) return 0;
1833
- return this.array[index].repeat;
1834
- }
1835
- /**
1836
- * Modify the repeat of operator
1837
- * @param number val the repeat of operator will modify to array.
1838
- * @returns bool Is the operators array changed?
1839
- */
1840
- }, {
1841
- key: "setOperator",
1842
- value: function setOperator(val, arrow) {
1843
- var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1844
- var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1845
- // if (arrow!=0&&val==0) return false;
1846
- var index = this.getOperatorIndex(arrow, expans, megota);
1847
- if (!this.array[index]) {
1848
- this.array.splice(Math.ceil(index), 0, {
1849
- arrow: arrow,
1850
- expans: expans,
1851
- megota: megota,
1852
- valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1853
- repeat: val
1854
- });
1855
- return true;
1856
- }
1857
- this.array[index].repeat = val;
1858
- // this.normalize()
1859
- return false;
1860
- }
1861
- //#endregion
1862
2076
  /**
1863
2077
  * @returns a PowiainaNum object which deep copied from `this` object.
1864
2078
  */
@@ -1877,6 +2091,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1877
2091
  }, {
1878
2092
  key: "resetFromObject",
1879
2093
  value: function resetFromObject(powlikeObject) {
2094
+ if (!powlikeObject.array) {
2095
+ return;
2096
+ }
1880
2097
  this.array = [];
1881
2098
  for (var i = 0; i < powlikeObject.array.length; i++) {
1882
2099
  this.array[i] = {
@@ -1892,107 +2109,56 @@ var PowiainaNum = /*#__PURE__*/function () {
1892
2109
  this.layer = powlikeObject.layer;
1893
2110
  return this;
1894
2111
  }
1895
- //#region converters
1896
- /**
1897
- * Convert `this` to Javascript `number`
1898
- *
1899
- * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1900
- */
1901
- }, {
1902
- key: "toNumber",
1903
- value: function toNumber() {
1904
- if (this.sign == -1) return -this.neg().toNumber();
1905
- if (this.small) return 1 / this.rec().toNumber();
1906
- if (this.array.length > 2) return Infinity;
1907
- 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));
1908
- return NaN;
1909
- }
1910
- /**
1911
- * Convert `this` to a string
1912
- */
1913
- }, {
1914
- key: "toString",
1915
- value: function toString() {
1916
- if (this.isNaN()) return "NaN";
1917
- if (this.sign == -1) return "-".concat(this.neg().toString());
1918
- if (this.small) {
1919
- if (this.isZero()) return "0";
1920
- return "/".concat(this.rec().toString());
1921
- }
1922
- if (this.isInfi()) return "Infinity";
1923
- // P^a (10{arrow,expans,megota})^repeation base
1924
- var res = "";
1925
- if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
1926
- for (var i = this.array.length - 1; i >= 0; i--) {
1927
- var oper = this.array[i];
1928
- 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) : "", "}");
1929
- if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
1930
- calc = "e".repeat(oper.repeat);
1931
- } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
1932
- calc = oper.repeat.toString();
1933
- } else if (oper.repeat > 1) {
1934
- calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1935
- } else {
1936
- calc = "".concat(calc);
1937
- }
1938
- res += "".concat(calc);
1939
- }
1940
- return res;
1941
- }
1942
- }, {
1943
- key: "toJSON",
1944
- value:
1945
- /**
1946
- * Convert `this` to a JSON object
1947
- * @returns a JSON object
1948
- */
1949
- function toJSON() {
1950
- return "PN" + this.toString();
1951
- }
1952
- }, {
1953
- key: "arr01",
1954
- get:
1955
- /**
1956
- * A property array value for version 0.1.x PowiainaNum.
1957
- */
1958
- function get() {
1959
- var res = [0];
1960
- for (var i = 0; i < this.array.length; i++) {
1961
- if (i == 0) res[0] = this.array[i].repeat;else {
1962
- // @ts-ignore
1963
- res[i] = [0, 0, 0, 0];
1964
- // @ts-ignore
1965
- res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
1966
- // @ts-ignore
1967
- res[i][1] = this.array[i].repeat;
1968
- // @ts-ignore
1969
- res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
1970
- // @ts-ignore
1971
- res[i][3] = this.array[i].megota;
1972
- }
1973
- }
1974
- return res;
1975
- }
1976
2112
  }], [{
1977
2113
  key: "add",
1978
2114
  value: function add(t, other) {
1979
2115
  return new PowiainaNum(t).add(other);
1980
2116
  }
2117
+ }, {
2118
+ key: "plus",
2119
+ value: function plus(t, other) {
2120
+ return new PowiainaNum(t).add(other);
2121
+ }
1981
2122
  }, {
1982
2123
  key: "sub",
1983
2124
  value: function sub(t, other) {
1984
2125
  return new PowiainaNum(t).sub(other);
1985
2126
  }
2127
+ }, {
2128
+ key: "minus",
2129
+ value: function minus(t, other) {
2130
+ return new PowiainaNum(t).sub(other);
2131
+ }
1986
2132
  }, {
1987
2133
  key: "mul",
1988
2134
  value: function mul(t, other) {
1989
2135
  return new PowiainaNum(t).mul(other);
1990
2136
  }
2137
+ }, {
2138
+ key: "times",
2139
+ value: function times(t, other) {
2140
+ return new PowiainaNum(t).mul(other);
2141
+ }
1991
2142
  }, {
1992
2143
  key: "div",
1993
2144
  value: function div(t, other) {
1994
2145
  return new PowiainaNum(t).div(other);
1995
2146
  }
2147
+ }, {
2148
+ key: "divide",
2149
+ value: function divide(t, other) {
2150
+ return new PowiainaNum(t).div(other);
2151
+ }
2152
+ }, {
2153
+ key: "mod",
2154
+ value: function mod(x, y) {
2155
+ return new PowiainaNum(x).mod(y);
2156
+ }
2157
+ }, {
2158
+ key: "modulus",
2159
+ value: function modulus(x, y) {
2160
+ return new PowiainaNum(x).mod(y);
2161
+ }
1996
2162
  }, {
1997
2163
  key: "pow",
1998
2164
  value: function pow(t, other) {
@@ -2024,6 +2190,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2024
2190
  var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2025
2191
  return new PowiainaNum(t).log(base);
2026
2192
  }
2193
+ }, {
2194
+ key: "log2",
2195
+ value: function log2(t) {
2196
+ return new PowiainaNum(t).log2();
2197
+ }
2198
+ }, {
2199
+ key: "logBase",
2200
+ value: function logBase(t) {
2201
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2202
+ return new PowiainaNum(t).log(base);
2203
+ }
2027
2204
  }, {
2028
2205
  key: "pLog10",
2029
2206
  value: function pLog10(t) {
@@ -2175,6 +2352,27 @@ var PowiainaNum = /*#__PURE__*/function () {
2175
2352
  };
2176
2353
  }
2177
2354
  }
2355
+ }, {
2356
+ key: "pentate",
2357
+ value: function pentate(x, other, payload) {
2358
+ return new PowiainaNum(x).arrow(3)(other, payload);
2359
+ }
2360
+ }, {
2361
+ key: "hexate",
2362
+ value: function hexate(x, other, payload) {
2363
+ return new PowiainaNum(x).arrow(4)(other, payload);
2364
+ }
2365
+ }, {
2366
+ key: "pent",
2367
+ value: function pent(x, other, payload) {
2368
+ return new PowiainaNum(x).arrow(3)(other, payload);
2369
+ }
2370
+ }, {
2371
+ key: "penta_log",
2372
+ value: function penta_log(x) {
2373
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
2374
+ return new PowiainaNum(x).anyarrow_log(3)(base);
2375
+ }
2178
2376
  }, {
2179
2377
  key: "expansion",
2180
2378
  value: function expansion(t, other) {
@@ -2426,6 +2624,84 @@ var PowiainaNum = /*#__PURE__*/function () {
2426
2624
  value: function clampMax() {
2427
2625
  return PowiainaNum.min.apply(PowiainaNum, arguments);
2428
2626
  }
2627
+ }, {
2628
+ key: "eq",
2629
+ value: function eq(a, o) {
2630
+ return new PowiainaNum(a).eq(o);
2631
+ }
2632
+ }, {
2633
+ key: "equals",
2634
+ value: function equals(a, o) {
2635
+ return new PowiainaNum(a).eq(o);
2636
+ }
2637
+ }, {
2638
+ key: "neq",
2639
+ value: function neq(a, o) {
2640
+ return new PowiainaNum(a).neq(o);
2641
+ }
2642
+ }, {
2643
+ key: "notEquals",
2644
+ value: function notEquals(a, o) {
2645
+ return new PowiainaNum(a).notEquals(o);
2646
+ }
2647
+ }, {
2648
+ key: "lt",
2649
+ value: function lt(a, o) {
2650
+ return new PowiainaNum(a).lt(o);
2651
+ }
2652
+ }, {
2653
+ key: "gt",
2654
+ value: function gt(a, o) {
2655
+ return new PowiainaNum(a).gt(o);
2656
+ }
2657
+ }, {
2658
+ key: "lte",
2659
+ value: function lte(a, o) {
2660
+ return new PowiainaNum(a).lte(o);
2661
+ }
2662
+ }, {
2663
+ key: "gte",
2664
+ value: function gte(a, o) {
2665
+ return new PowiainaNum(a).gte(o);
2666
+ }
2667
+ }, {
2668
+ key: "rec",
2669
+ value: function rec(t) {
2670
+ return new PowiainaNum(t).rec();
2671
+ }
2672
+ }, {
2673
+ key: "recip",
2674
+ value: function recip(t) {
2675
+ return new PowiainaNum(t).rec();
2676
+ }
2677
+ }, {
2678
+ key: "reciprocate",
2679
+ value: function reciprocate(t) {
2680
+ return new PowiainaNum(t).rec();
2681
+ }
2682
+ }, {
2683
+ key: "floor",
2684
+ value: function floor(x) {
2685
+ return new PowiainaNum(x).floor();
2686
+ }
2687
+ }, {
2688
+ key: "ceil",
2689
+ value: function ceil(x) {
2690
+ return new PowiainaNum(x).ceil();
2691
+ }
2692
+ }, {
2693
+ key: "round",
2694
+ value: function round(x) {
2695
+ return new PowiainaNum(x).round();
2696
+ }
2697
+ }, {
2698
+ key: "trunc",
2699
+ value: function trunc(x) {
2700
+ return new PowiainaNum(x).trunc();
2701
+ }
2702
+ /**
2703
+ * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
2704
+ */
2429
2705
  }, {
2430
2706
  key: "sign",
2431
2707
  value: function sign(a) {
@@ -2440,6 +2716,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2440
2716
  key: "fromNumber",
2441
2717
  value: function fromNumber(x) {
2442
2718
  var obj = new PowiainaNum(); // NaN
2719
+ obj.resetFromObject({
2720
+ array: [{
2721
+ arrow: 0,
2722
+ expans: 1,
2723
+ megota: 1,
2724
+ repeat: NaN
2725
+ }],
2726
+ small: false,
2727
+ layer: 0,
2728
+ sign: 0
2729
+ });
2443
2730
  if (x < 0) obj.sign = -1; // negative
2444
2731
  else if (x == 0) {
2445
2732
  obj.sign = 0;
@@ -2467,10 +2754,26 @@ var PowiainaNum = /*#__PURE__*/function () {
2467
2754
  }, {
2468
2755
  key: "fromString",
2469
2756
  value: function fromString(input) {
2757
+ if (PowiainaNum.usingBreakEternityLikeFromString && BE_REGEX.test(input)) {
2758
+ /*
2759
+ * 0i00000000a7 says that eee-3000 will wrongly parse to 1. So i added this
2760
+ */
2761
+ var a = input.match(/(e+-)(\d+(.\d+)?)/);
2762
+ if (a) {
2763
+ var e_s = a[1].length;
2764
+ input = "e-" + "e".repeat(e_s - 1) + a[2];
2765
+ }
2766
+ }
2767
+ return this.fromString_core(input);
2768
+ }
2769
+ }, {
2770
+ key: "fromString_core",
2771
+ value: function fromString_core(input) {
2470
2772
  var _b, _c, _d, _e, _f, _g;
2471
- var x = new PowiainaNum();
2773
+ var x = new PowiainaNum(NaN);
2472
2774
  // Judge the string was a number
2473
2775
  if (input.startsWith("PN")) input = input.substring(2);
2776
+ if (input == "NaN") return PowiainaNum.NaN.clone();
2474
2777
  input = input.replace(/J\^(\d+)/g, "(10{!})^$1");
2475
2778
  input = input.replace(/J/g, "10{!}");
2476
2779
  input = input.replace(/K\^(\d+)/g, "(10{1,2})^$1");
@@ -2486,15 +2789,15 @@ var PowiainaNum = /*#__PURE__*/function () {
2486
2789
  }
2487
2790
  if (!isNaN(Number(input))) {
2488
2791
  var res = Number(input);
2489
- var _a3 = false;
2792
+ var a = false;
2490
2793
  if (res == 0) {
2491
2794
  if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
2492
- _a3 = true;
2795
+ a = true;
2493
2796
  }
2494
2797
  } else {
2495
- _a3 = true;
2798
+ a = true;
2496
2799
  }
2497
- if (!_a3) {
2800
+ if (!a) {
2498
2801
  var m = input.search(/e/);
2499
2802
  var exponent = input.substring((m == -1 ? input.length : m) + 1);
2500
2803
  var mantissa = input.substring(0, m == -1 ? undefined : m);
@@ -2523,7 +2826,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2523
2826
  // /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
2524
2827
  return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
2525
2828
  }
2526
- if (isFinite(res) && _a3) {
2829
+ if (isFinite(res) && a) {
2527
2830
  x = PowiainaNum.fromNumber(Number(input));
2528
2831
  return x;
2529
2832
  }
@@ -2540,6 +2843,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2540
2843
  return x;
2541
2844
  }
2542
2845
  input = replaceETo10(input);
2846
+ input = removeCommasOutsideBraces(input);
2543
2847
  if (!isPowiainaNum.test(input)) {
2544
2848
  throw powiainaNumError + "malformed input: " + input;
2545
2849
  }
@@ -2552,28 +2856,31 @@ var PowiainaNum = /*#__PURE__*/function () {
2552
2856
  input = input.substring(numSigns);
2553
2857
  }
2554
2858
  if (input[0] == "/") {
2555
- var numSigns = input.search(/[^\/]/);
2556
- var signs = input.substring(0, numSigns);
2557
- recipIt = ((_e = (_d = signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2558
- input = input.substring(numSigns);
2859
+ var _numSigns = input.search(/[^\/]/);
2860
+ var _signs = input.substring(0, _numSigns);
2861
+ recipIt = ((_e = (_d = _signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2862
+ input = input.substring(_numSigns);
2559
2863
  }
2560
2864
  if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
2561
2865
  x.sign = 1;
2562
2866
  x.array = [newOperator(0)];
2563
- var a, b, c, d;
2867
+ var _a3, b, c, d;
2564
2868
  if (input[0] == "P") {
2565
2869
  if (input[1] == "^") {
2566
- a = input.substring(2).search(/[^0-9]/) + 2;
2567
- x.layer = Number(input.substring(2, a));
2568
- input = input.substring(a + 1);
2870
+ _a3 = input.substring(2).search(/[^0-9]/) + 2;
2871
+ x.layer = Number(input.substring(2, _a3));
2872
+ input = input.substring(_a3 + 1);
2569
2873
  } else {
2570
- a = input.search(/[^P]/);
2571
- x.layer = a;
2572
- input = input.substring(a);
2874
+ _a3 = input.search(/[^P]/);
2875
+ x.layer = _a3;
2876
+ input = input.substring(_a3);
2573
2877
  }
2574
2878
  }
2575
2879
  while (input) {
2576
2880
  if (/^(\(?10[\^\{])/.test(input)) {
2881
+ var arrows = void 0,
2882
+ expans = void 0,
2883
+ megota = void 0;
2577
2884
  /*
2578
2885
  10^ - 匹配
2579
2886
  10{ - 匹配
@@ -2584,30 +2891,29 @@ var PowiainaNum = /*#__PURE__*/function () {
2584
2891
  */
2585
2892
  if (input[0] == "(") input = input.substring(1);
2586
2893
  //cutted, 10^.... or 10{....
2587
- var arrows, expans, megota;
2588
2894
  if (input[2] == "^") {
2589
- a = input.substring(2).search(/[^\^]/);
2895
+ _a3 = input.substring(2).search(/[^\^]/);
2590
2896
  //cut input to ^^...^^, and search how numbers
2591
- arrows = a;
2897
+ arrows = _a3;
2592
2898
  // 10^^^
2593
- b = a + 2; // b points to after ^'s.
2899
+ b = _a3 + 2; // b points to after ^'s.
2594
2900
  } else {
2595
2901
  // 10{...}
2596
- a = input.indexOf("}");
2902
+ _a3 = input.indexOf("}");
2597
2903
  // select contents between {...}
2598
- var tmp = input.substring(3, a).split(",");
2904
+ var tmp = input.substring(3, _a3).split(",");
2599
2905
  arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
2600
2906
  expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
2601
2907
  megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
2602
- b = a + 1;
2908
+ b = _a3 + 1;
2603
2909
  // b points to after }.
2604
2910
  }
2605
2911
  input = input.substring(b);
2606
2912
  if (input[0] == ")") {
2607
2913
  // )^....<Space>
2608
- a = input.indexOf(" ");
2609
- c = Number(input.substring(2, a)); // Select contents between )^....<Space>
2610
- input = input.substring(a + 1); // c points to after <Space>
2914
+ _a3 = input.indexOf(" ");
2915
+ c = Number(input.substring(2, _a3)); // Select contents between )^....<Space>
2916
+ input = input.substring(_a3 + 1); // c points to after <Space>
2611
2917
  } else {
2612
2918
  c = 1; // There is only spaces, count as <ONE>
2613
2919
  }
@@ -2618,21 +2924,21 @@ var PowiainaNum = /*#__PURE__*/function () {
2618
2924
  x.array.splice(1, 0, newOperator(c, 1, expans, megota));
2619
2925
  }
2620
2926
  } else if (arrows == 2 && expans == 1 && megota == 1) {
2621
- a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2927
+ _a3 = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2622
2928
  b = x.array[0].repeat;
2623
- if (b >= 1e10) ++a;
2624
- if (b >= 10) ++a;
2625
- x.array[0].repeat = a;
2929
+ if (b >= 1e10) ++_a3;
2930
+ if (b >= 10) ++_a3;
2931
+ x.array[0].repeat = _a3;
2626
2932
  if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
2627
2933
  d = x.getOperatorIndex(2);
2628
2934
  if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
2629
2935
  } else if (isFinite(arrows)) {
2630
- a = x.getOperator(arrows - 1);
2936
+ _a3 = x.getOperator(arrows - 1);
2631
2937
  b = x.getOperator(arrows - 2);
2632
- if (b >= 10) ++a;
2938
+ if (b >= 10) ++_a3;
2633
2939
  d = x.getOperatorIndex(arrows);
2634
2940
  x.array.splice(1, Math.ceil(d) - 1);
2635
- x.array[0].repeat = a;
2941
+ x.array[0].repeat = _a3;
2636
2942
  if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
2637
2943
  } else {
2638
2944
  x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
@@ -2641,10 +2947,10 @@ var PowiainaNum = /*#__PURE__*/function () {
2641
2947
  break;
2642
2948
  }
2643
2949
  }
2644
- a = input.split(/[Ee]/);
2950
+ _a3 = input.split(/[Ee]/);
2645
2951
  b = [x.array[0].repeat, 0];
2646
2952
  c = 1;
2647
- for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
2953
+ for (var i = _a3.length - 1; i >= 0; --i) {
2648
2954
  //The things that are already there
2649
2955
  if (b[0] < MSI_LOG10 && b[1] === 0) {
2650
2956
  b[0] = Math.pow(10, c * b[0]);
@@ -2661,12 +2967,12 @@ var PowiainaNum = /*#__PURE__*/function () {
2661
2967
  b[1]++;
2662
2968
  }
2663
2969
  //Multiplying coefficient
2664
- var decimalPointPos = a[_i2].indexOf(".");
2665
- var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
2970
+ var decimalPointPos = _a3[i].indexOf(".");
2971
+ var intPartLen = decimalPointPos == -1 ? _a3[i].length : decimalPointPos;
2666
2972
  if (b[1] === 0) {
2667
- 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]);
2973
+ 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]);
2668
2974
  } else {
2669
- d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
2975
+ d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(_a3[i].substring(0, intPartLen)) : _a3[i] ? Math.log10(Number(_a3[i])) : 0;
2670
2976
  if (b[1] == 1) {
2671
2977
  b[0] += d;
2672
2978
  } else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
@@ -2697,6 +3003,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2697
3003
  key: "fromObject",
2698
3004
  value: function fromObject(powlikeObject) {
2699
3005
  var obj = new PowiainaNum();
3006
+ obj.resetFromObject({
3007
+ array: [{
3008
+ arrow: 0,
3009
+ expans: 1,
3010
+ megota: 1,
3011
+ repeat: NaN
3012
+ }],
3013
+ small: false,
3014
+ layer: 0,
3015
+ sign: 0
3016
+ });
2700
3017
  obj.array = [];
2701
3018
  if (isExpantaNumArray(powlikeObject)) {
2702
3019
  for (var i = 0; i < powlikeObject.length; i++) {
@@ -2714,8 +3031,8 @@ var PowiainaNum = /*#__PURE__*/function () {
2714
3031
  } else if (isPowiainaNum01XArray(powlikeObject)) {
2715
3032
  var arrayobj = powlikeObject;
2716
3033
  obj.array[0] = newOperator(arrayobj[0]);
2717
- for (var _i3 = 1; _i3 < arrayobj.length; _i3++) {
2718
- var b = arrayobj[_i3];
3034
+ for (var _i4 = 1; _i4 < arrayobj.length; _i4++) {
3035
+ var b = arrayobj[_i4];
2719
3036
  obj.array[1] = newOperator(b[1], replaceXToInfinity(b[0]), replaceXToInfinity(b[2]), b[3]);
2720
3037
  }
2721
3038
  obj.small = false;
@@ -2723,21 +3040,21 @@ var PowiainaNum = /*#__PURE__*/function () {
2723
3040
  obj.layer = 0;
2724
3041
  return obj;
2725
3042
  } else {
2726
- for (var _i4 = 0; _i4 < powlikeObject.array.length; _i4++) {
2727
- obj.array[_i4] = {
2728
- arrow: powlikeObject.array[_i4].arrow,
2729
- expans: powlikeObject.array[_i4].expans,
2730
- megota: powlikeObject.array[_i4].megota,
2731
- repeat: powlikeObject.array[_i4].repeat,
2732
- valuereplaced: powlikeObject.array[_i4].valuereplaced
2733
- };
2734
- }
2735
- obj.small = powlikeObject.small;
2736
- obj.sign = powlikeObject.sign;
2737
- obj.layer = powlikeObject.layer;
3043
+ obj.resetFromObject(powlikeObject);
2738
3044
  return obj;
2739
3045
  }
2740
3046
  }
3047
+ }, {
3048
+ key: "grahalFunction",
3049
+ value: function grahalFunction(layers2) {
3050
+ var layers = new PowiainaNum(layers2);
3051
+ if (!layers.isInt() || layers.lt(0) || layers.isNaN()) return PowiainaNum.NaN.clone();
3052
+ if (layers.eq(1)) return new PowiainaNum("10^^^(10^)^7625597484984 3638334640023.7783");else if (layers.lte(MSI)) {
3053
+ return new PowiainaNum("(10{!})^".concat(layers.toNumber(), " 10^^^(10^)^7625597484984 3638334640023.7783"));
3054
+ } else {
3055
+ return PowiainaNum.BEAF(3, layers, 1, 2);
3056
+ }
3057
+ }
2741
3058
  }]);
2742
3059
  }();
2743
3060
  _a = Symbol.toStringTag;
@@ -2954,6 +3271,15 @@ PowiainaNum.maxOps = 100;
2954
3271
  PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
2955
3272
  //#endregion
2956
3273
  PowiainaNum.arrowFuncMap = new Map();
3274
+ //#region configurations
3275
+ /**
3276
+ * 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.
3277
+ */
3278
+ PowiainaNum.usingBreakEternityLikeFromString = false;
3279
+ /**
3280
+ * If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
3281
+ */
3282
+ PowiainaNum.blankArgumentConstructorReturnZero = false;
2957
3283
 
2958
3284
  exports.arraySortFunction = arraySortFunction;
2959
3285
  exports["default"] = PowiainaNum;