powiaina_num.js 0.2.13 → 0.2.15

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.
@@ -3,6 +3,9 @@ function _arrayLikeToArray(r, a) {
3
3
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
4
4
  return n;
5
5
  }
6
+ function _arrayWithHoles(r) {
7
+ if (Array.isArray(r)) return r;
8
+ }
6
9
  function _arrayWithoutHoles(r) {
7
10
  if (Array.isArray(r)) return _arrayLikeToArray(r);
8
11
  }
@@ -23,9 +26,42 @@ function _createClass(e, r, t) {
23
26
  function _iterableToArray(r) {
24
27
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
25
28
  }
29
+ function _iterableToArrayLimit(r, l) {
30
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
31
+ if (null != t) {
32
+ var e,
33
+ n,
34
+ i,
35
+ u,
36
+ a = [],
37
+ f = !0,
38
+ o = !1;
39
+ try {
40
+ if (i = (t = t.call(r)).next, 0 === l) {
41
+ if (Object(t) !== t) return;
42
+ f = !1;
43
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
44
+ } catch (r) {
45
+ o = !0, n = r;
46
+ } finally {
47
+ try {
48
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
49
+ } finally {
50
+ if (o) throw n;
51
+ }
52
+ }
53
+ return a;
54
+ }
55
+ }
56
+ function _nonIterableRest() {
57
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ }
26
59
  function _nonIterableSpread() {
27
60
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
28
61
  }
62
+ function _slicedToArray(r, e) {
63
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
64
+ }
29
65
  function _toConsumableArray(r) {
30
66
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
31
67
  }
@@ -380,6 +416,7 @@ var PowiainaNum = /*#__PURE__*/function () {
380
416
  } catch (e) {
381
417
  console.error("Malformed input");
382
418
  console.error(e);
419
+ if (PowiainaNum.throwErrorOnResultNaN && PowiainaNum.isNaN(this)) throw new Error("NaN");
383
420
  }
384
421
  }
385
422
  //#region 4 Basic calculates.
@@ -394,7 +431,10 @@ var PowiainaNum = /*#__PURE__*/function () {
394
431
  var x = this.clone().normalize();
395
432
  var y = new PowiainaNum(other);
396
433
  // inf + -inf = nan
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();
434
+ if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.POSITIVE_INFINITY)) {
435
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
436
+ return PowiainaNum.NaN.clone();
437
+ }
398
438
  // inf & nan check
399
439
  if (!x.isFinite()) return x.clone();
400
440
  if (!y.isFinite()) return y.clone();
@@ -491,7 +531,10 @@ var PowiainaNum = /*#__PURE__*/function () {
491
531
  var y = new PowiainaNum(other);
492
532
  // inf * -inf = -inf
493
533
  if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || y.eq(PowiainaNum.POSITIVE_INFINITY) && x.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.NEGATIVE_INFINITY.clone();
494
- if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
534
+ if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) {
535
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
536
+ return PowiainaNum.NaN.clone();
537
+ }
495
538
  if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
496
539
  // inf & nan check
497
540
  if (!x.isFinite()) return x.clone();
@@ -596,6 +639,7 @@ var PowiainaNum = /*#__PURE__*/function () {
596
639
  return this.neg().pow(other).neg();
597
640
  }
598
641
  }
642
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
599
643
  return PowiainaNum.NaN.clone();
600
644
  }
601
645
  var r = this.abs().pow(other);
@@ -625,6 +669,7 @@ var PowiainaNum = /*#__PURE__*/function () {
625
669
  } else if (other.rec().mod(2).eq(1)) {
626
670
  return this.neg().log10().mul(other).pow10().neg();
627
671
  }
672
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
628
673
  return PowiainaNum.NaN.clone();
629
674
  }
630
675
  }, {
@@ -652,7 +697,10 @@ var PowiainaNum = /*#__PURE__*/function () {
652
697
  }, {
653
698
  key: "log10",
654
699
  value: function log10() {
655
- if (this.isneg()) return PowiainaNum.NaN.clone();
700
+ if (this.isneg()) {
701
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
702
+ return PowiainaNum.NaN.clone();
703
+ }
656
704
  if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
657
705
  if (this.small) {
658
706
  var _x = this.clone();
@@ -794,6 +842,7 @@ var PowiainaNum = /*#__PURE__*/function () {
794
842
  var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
795
843
  var principal = princ;
796
844
  if (this.lt(-0.3678794411710499)) {
845
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
797
846
  return PowiainaNum.NaN.clone(); //complex
798
847
  } else if (principal) {
799
848
  if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
@@ -808,6 +857,7 @@ var PowiainaNum = /*#__PURE__*/function () {
808
857
  }
809
858
  } else {
810
859
  if (this.sign === -1) {
860
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
811
861
  return PowiainaNum.NaN.clone(); //complex
812
862
  }
813
863
  if (this.lt(9e15)) {
@@ -831,7 +881,10 @@ var PowiainaNum = /*#__PURE__*/function () {
831
881
  var t = this.clone();
832
882
  var other = new PowiainaNum(other2);
833
883
  var payl = new PowiainaNum(payload);
834
- if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
884
+ if (t.isNaN() || other.isNaN() || payl.isNaN()) {
885
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
886
+ return PowiainaNum.NaN.clone();
887
+ }
835
888
  if (t.eq(1)) return PowiainaNum.ONE.clone();
836
889
  if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
837
890
  other = other.add(payl.slog(t));
@@ -842,14 +895,23 @@ var PowiainaNum = /*#__PURE__*/function () {
842
895
  negln = this.log().neg();
843
896
  return negln.lambertw().div(negln);
844
897
  }
845
- if (other.lte(-2)) return PowiainaNum.NaN.clone();
898
+ if (other.lte(-2)) {
899
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
900
+ return PowiainaNum.NaN.clone();
901
+ }
846
902
  if (t.isZero()) {
847
- if (other.isZero()) return PowiainaNum.NaN.clone();
903
+ if (other.isZero()) {
904
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
905
+ return PowiainaNum.NaN.clone();
906
+ }
848
907
  if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
849
908
  return PowiainaNum.ONE.clone();
850
909
  }
851
910
  if (t.eq(PowiainaNum.ONE)) {
852
- if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
911
+ if (other.eq(PowiainaNum.ONE.neg())) {
912
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
913
+ return PowiainaNum.NaN.clone();
914
+ }
853
915
  return PowiainaNum.ONE.clone();
854
916
  }
855
917
  if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
@@ -923,7 +985,10 @@ var PowiainaNum = /*#__PURE__*/function () {
923
985
  if (b.lt(EXP_E_REC)) {
924
986
  var a = b.tetrate(Infinity);
925
987
  if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
926
- if (x.gt(a)) return PowiainaNum.NaN.clone();
988
+ if (x.gt(a)) {
989
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
990
+ return PowiainaNum.NaN.clone();
991
+ }
927
992
  }
928
993
  if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
929
994
  if (x.gt(b)) return x;
@@ -967,13 +1032,17 @@ var PowiainaNum = /*#__PURE__*/function () {
967
1032
  }
968
1033
  }
969
1034
  if (x.gt(10)) return new PowiainaNum(r);
1035
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
970
1036
  return PowiainaNum.NaN.clone();
971
1037
  }
972
1038
  }, {
973
1039
  key: "ssqrt",
974
1040
  value: function ssqrt() {
975
1041
  var x = this.clone();
976
- if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
1042
+ if (x.lt(1 / EXP_E_REC)) {
1043
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1044
+ return PowiainaNum.NaN.clone();
1045
+ }
977
1046
  if (!x.isFinite()) return x;
978
1047
  if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
979
1048
  if (x.gt(PowiainaNum.EE_MSI)) {
@@ -1024,6 +1093,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1024
1093
  if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
1025
1094
  console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
1026
1095
  return function () {
1096
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1027
1097
  return PowiainaNum.NaN.clone();
1028
1098
  };
1029
1099
  }
@@ -1049,6 +1119,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1049
1119
  if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1050
1120
  if (t.eq(PowiainaNum.ZERO)) {
1051
1121
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1122
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1052
1123
  return PowiainaNum.NaN.clone();
1053
1124
  }
1054
1125
  if (payload.neq(PowiainaNum.ONE)) other = other.add(payload.anyarrow_log(arrows)(t));
@@ -1128,6 +1199,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1128
1199
  throw new Error(powiainaNumError + "Not implemented");
1129
1200
  }
1130
1201
  if (!arrow.isInt() || arrow.lt(0)) return function () {
1202
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1131
1203
  return PowiainaNum.NaN.clone();
1132
1204
  };
1133
1205
  if (arrow.eq(0)) return function (base) {
@@ -1161,7 +1233,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1161
1233
  return x.sub(x.getOperator(arrowsNum - 1));
1162
1234
  }
1163
1235
  }
1164
- if (x.lt(PowiainaNum.ZERO.clone())) return PowiainaNum.NaN.clone();
1236
+ if (x.lt(PowiainaNum.ZERO.clone())) {
1237
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1238
+ return PowiainaNum.NaN.clone();
1239
+ }
1165
1240
  // base^base^... = x? (? bases)
1166
1241
  var r = 0;
1167
1242
  // 计算x与base的差距
@@ -1185,6 +1260,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1185
1260
  }
1186
1261
  }
1187
1262
  if (x.gt(10)) return new PowiainaNum(r);
1263
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1188
1264
  return PowiainaNum.NaN.clone();
1189
1265
  };
1190
1266
  }
@@ -1244,7 +1320,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1244
1320
  if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
1245
1321
  if (other.eq(PowiainaNum.ONE)) return this.clone();
1246
1322
  if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1247
- if (!this.isInt()) return PowiainaNum.NaN.clone();
1323
+ if (!this.isInt()) {
1324
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1325
+ return PowiainaNum.NaN.clone();
1326
+ }
1248
1327
  if (this.eq(2)) return new PowiainaNum(4);
1249
1328
  if (other.eq(0)) return PowiainaNum.ONE.clone();
1250
1329
  var r;
@@ -1284,6 +1363,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1284
1363
  var arrow = new PowiainaNum(arrow2);
1285
1364
  var t = this.clone();
1286
1365
  if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
1366
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1287
1367
  return PowiainaNum.NaN.clone();
1288
1368
  };
1289
1369
  if (arrow.eq(0)) return function (other) {
@@ -1298,9 +1378,13 @@ var PowiainaNum = /*#__PURE__*/function () {
1298
1378
  var other = new PowiainaNum(other2);
1299
1379
  var r;
1300
1380
  if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
1301
- if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1381
+ if (other.lt(PowiainaNum.ZERO)) {
1382
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1383
+ return PowiainaNum.NaN.clone();
1384
+ }
1302
1385
  if (t.eq(PowiainaNum.ZERO)) {
1303
1386
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1387
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1304
1388
  return PowiainaNum.NaN.clone();
1305
1389
  }
1306
1390
  if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
@@ -1489,7 +1573,8 @@ var PowiainaNum = /*#__PURE__*/function () {
1489
1573
  /**
1490
1574
  * -1: `this` is smaller
1491
1575
  * 0: equals
1492
- * 1: `x` is bigger
1576
+ * 1: `x` is smaller
1577
+ * 2: NaN
1493
1578
  */
1494
1579
  }, {
1495
1580
  key: "compare",
@@ -1498,6 +1583,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1498
1583
  if (this.isNaN() || other.isNaN()) return 2;
1499
1584
  if (this.sign < other.sign) return -1;
1500
1585
  if (this.sign > other.sign) return 1;
1586
+ var t = this;
1501
1587
  //this.sign = other.sign
1502
1588
  var allneg = this.sign == -1 && other.sign == -1;
1503
1589
  if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
@@ -1509,6 +1595,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1509
1595
  for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
1510
1596
  var op1 = this.array[this.array.length - 1 - i];
1511
1597
  var op2 = other.array[other.array.length - 1 - i];
1598
+ if (op1.repeat === Infinity && op2.repeat === Infinity) {
1599
+ if (t.small === other.small) return 0;
1600
+ return other.small ? 1 : -1;
1601
+ }
1512
1602
  if (op1.repeat === Infinity) {
1513
1603
  result = 1;
1514
1604
  break;
@@ -2039,8 +2129,20 @@ var PowiainaNum = /*#__PURE__*/function () {
2039
2129
  this.small = false;
2040
2130
  renormalize = true;
2041
2131
  }
2042
- // for any 10{X>9e15}10, replace into 10{!}X;
2043
- if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
2132
+ // for any 10{!}^t x, replace to 10{!}^t-1 10{x}10
2133
+ if (this.array.length >= 2 && !isFinite(this.array[1].arrow)) {
2134
+ if (this.array[1].repeat > 1) {
2135
+ this.array.push(newOperator(this.array[1].repeat - 1, 1 / 0, this.array[1].expans, this.array[1].megota));
2136
+ this.array[1].repeat = 1;
2137
+ this.array[1].arrow = this.array[0].repeat;
2138
+ this.array[0].repeat = 10;
2139
+ } else {
2140
+ this.array[1].arrow = this.array[0].repeat;
2141
+ this.array[0].repeat = 10;
2142
+ }
2143
+ }
2144
+ // for any 10{X>9e15}10 finite, replace into 10{!}X;
2145
+ if (this.array.length >= 2 && this.array[1].arrow >= MSI && isFinite(this.array[1].arrow)) {
2044
2146
  this.array[0].repeat = this.array[1].arrow;
2045
2147
  this.array[1] = newOperator(1, Infinity, this.array[1].expans, this.array[1].megota);
2046
2148
  }
@@ -2066,16 +2168,6 @@ var PowiainaNum = /*#__PURE__*/function () {
2066
2168
  x.array[0].repeat = 10;
2067
2169
  renormalize = true;
2068
2170
  }
2069
- if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1 &&
2070
- //10^^^ 10
2071
- isFinite(x.array[1].arrow)) {
2072
- // for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
2073
- // But dont convert when a is infinite
2074
- // [1e9, [R=1, A=2, sth, sth]]
2075
- x.array.splice(1, 1, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
2076
- x.array[0].repeat = 10;
2077
- renormalize = true;
2078
- }
2079
2171
  // for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
2080
2172
  if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow !== Infinity) {
2081
2173
  x.array[1].arrow++;
@@ -2449,13 +2541,19 @@ var PowiainaNum = /*#__PURE__*/function () {
2449
2541
  if (base.eq(1)) return new PowiainaNum(1);
2450
2542
  if (power.eq(1)) return new PowiainaNum(base);
2451
2543
  if (power.isZero()) return new PowiainaNum(1);
2452
- if (base.lt(0)) return PowiainaNum.NaN.clone();
2544
+ if (base.lt(0)) {
2545
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
2546
+ return PowiainaNum.NaN.clone();
2547
+ }
2453
2548
  // // check infinite
2454
2549
  // let sufpowiaina = args.slice(4);
2455
2550
  // if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
2456
2551
  // return PowiainaNum.POSITIVE_INFINITY;
2457
2552
  // }
2458
2553
  if (new PowiainaNum(powiaina2).gte(3)) return PowiainaNum.POSITIVE_INFINITY.clone();
2554
+ if (readArg(0).eq(0) && readArg(1).eq(1) && readArg(2).eq(1)) {
2555
+ return base.mul(power);
2556
+ }
2459
2557
  if (readArg(0).eq(1) && readArg(1).eq(1) && readArg(2).eq(1)) {
2460
2558
  return base.pow(power);
2461
2559
  }
@@ -2505,12 +2603,16 @@ var PowiainaNum = /*#__PURE__*/function () {
2505
2603
  return x.toString();
2506
2604
  }
2507
2605
  function getMSIForm(arrow, expans, megota) {
2508
- return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
2606
+ var _convertOperator = convertOperator(arrow, expans, megota),
2607
+ _convertOperator2 = _slicedToArray(_convertOperator, 3),
2608
+ a = _convertOperator2[0],
2609
+ e = _convertOperator2[1],
2610
+ m = _convertOperator2[2];
2611
+ return "10{".concat(infToBang(a), ",").concat(infToBang(e), ",").concat(m, "}").concat(MSI);
2509
2612
  }
2510
2613
  var t = base.clone();
2511
2614
  var arrows = new PowiainaNum(readArg(0));
2512
2615
  var result = function (other2) {
2513
- var _r, _r2;
2514
2616
  var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2515
2617
  console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
2516
2618
  var other = new PowiainaNum(other2);
@@ -2519,21 +2621,26 @@ var PowiainaNum = /*#__PURE__*/function () {
2519
2621
  if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
2520
2622
  if (t.eq(PowiainaNum.ZERO)) {
2521
2623
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
2624
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
2522
2625
  return PowiainaNum.NaN.clone();
2523
2626
  }
2524
2627
  if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
2525
2628
  if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
2526
2629
  if (other.eq(PowiainaNum.ONE)) return t.clone();
2527
2630
  if (arrows.eq(0)) {
2528
- return PowiainaNum.BEAF(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
2631
+ return PowiainaNum.BEAF_core(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
2529
2632
  // {this, this, power, expans-1, megota}
2530
2633
  }
2531
2634
  if (expans.eq(0)) {
2532
- return PowiainaNum.BEAF(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
2635
+ return PowiainaNum.BEAF_core(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
2533
2636
  // {this, this, this, power, megota-1}
2534
2637
  }
2535
2638
  if (megota.eq(0)) {
2536
- return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
2639
+ return PowiainaNum.BEAF_core(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
2640
+ }
2641
+ // megota < 9e15, not implemented
2642
+ if (megota.gt(MSI)) {
2643
+ throw new Error("Not implemeneted");
2537
2644
  }
2538
2645
  // expans > 9e15, that using 10{?, x}, x=expans;
2539
2646
  if (expans.gt(MSI)) {
@@ -2550,15 +2657,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2550
2657
  var arrowsNum = arrows.toNumber();
2551
2658
  // arrow < 9e15
2552
2659
  // 10{x}2 = 10{x-1}10
2553
- if (other.eq(2)) return PowiainaNum.BEAF(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
2660
+ if (other.eq(2)) return PowiainaNum.BEAF_core(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
2554
2661
  if (t.max(other).gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber()))) return t.max(other);
2555
- if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
2662
+ // arrow < 9e15
2663
+ // 10{x}2 = 10{x-1}10
2664
+ if (t.gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
2556
2665
  if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
2557
2666
  r = t.clone();
2558
2667
  r.setOperator(r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1, arrowsNum, expans.toNumber(), megota.toNumber());
2559
2668
  r.normalize();
2560
- } else if (t.gt(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))))) {
2561
- r = new PowiainaNum(t.getOperator.apply(t, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
2669
+ } else if (t.gt(getMSIForm(arrowsNum - 1, expans.toNumber(), megota.toNumber()))) {
2670
+ r = new PowiainaNum(t.getOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()));
2562
2671
  } else {
2563
2672
  r = PowiainaNum.ZERO;
2564
2673
  }
@@ -2578,17 +2687,114 @@ var PowiainaNum = /*#__PURE__*/function () {
2578
2687
  var y = other.toNumber();
2579
2688
  var f = Math.floor(y);
2580
2689
  var arrows_m1 = arrows.sub(PowiainaNum.ONE);
2581
- r = PowiainaNum.BEAF(t, y - f, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
2690
+ r = PowiainaNum.BEAF_core(t, y - f, arrows_m1, expans, megota, powiaina, depth + 1);
2691
+ // r = t.arrow(arrows_m1)(y - f, payload, depth + 1);
2582
2692
  var i = 0;
2583
- for (var m = new PowiainaNum(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())))); f !== 0 && r.lt(m) && i < 100; i++) {
2693
+ for (var m = getMSIForm(arrowsNum - 1, expans.toNumber(), megota.toNumber()); f !== 0 && r.lt(m) && i < 100; i++) {
2584
2694
  if (f > 0) {
2585
- r = PowiainaNum.BEAF(base, r, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
2695
+ r = PowiainaNum.BEAF_core(t, r, arrows_m1, expans, megota, powiaina, depth + 1);
2586
2696
  --f;
2587
2697
  }
2588
2698
  }
2589
2699
  if (i == 100) f = 0;
2590
- (_r = r).setOperator.apply(_r, [(_r2 = r).getOperator.apply(_r2, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))) + f].concat(_toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
2700
+ r.setOperator(r.getOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()) + f, arrowsNum - 1, expans.toNumber(), megota.toNumber());
2591
2701
  r.normalize();
2702
+ // if (
2703
+ // t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) ||
2704
+ // other.gt(MSI)
2705
+ // ) {
2706
+ // if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
2707
+ // r = t.clone();
2708
+ // r.setOperator(
2709
+ // r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1,
2710
+ // arrowsNum,
2711
+ // expans.toNumber(),
2712
+ // megota.toNumber()
2713
+ // );
2714
+ // r.normalize();
2715
+ // } else if (
2716
+ // t.gt(
2717
+ // getMSIForm(
2718
+ // ...convertOperator(
2719
+ // arrowsNum - 1,
2720
+ // expans.toNumber(),
2721
+ // megota.toNumber()
2722
+ // )
2723
+ // )
2724
+ // )
2725
+ // ) {
2726
+ // r = new PowiainaNum(
2727
+ // t.getOperator(
2728
+ // ...convertOperator(
2729
+ // arrowsNum - 1,
2730
+ // expans.toNumber(),
2731
+ // megota.toNumber()
2732
+ // )
2733
+ // )
2734
+ // );
2735
+ // } else {
2736
+ // r = PowiainaNum.ZERO;
2737
+ // }
2738
+ // const j = r.add(other);
2739
+ // j.setOperator(
2740
+ // j.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) + 1,
2741
+ // arrowsNum,
2742
+ // expans.toNumber(),
2743
+ // megota.toNumber()
2744
+ // );
2745
+ // j.normalize();
2746
+ // return j;
2747
+ // }
2748
+ // const y = other.toNumber();
2749
+ // let f = Math.floor(y);
2750
+ // const arrows_m1 = arrows.sub(PowiainaNum.ONE);
2751
+ // r = PowiainaNum.BEAF(
2752
+ // t,
2753
+ // y - f,
2754
+ // arrows_m1.toNumber(),
2755
+ // expans,
2756
+ // megota,
2757
+ // powiaina2,
2758
+ // depth + 1
2759
+ // );
2760
+ // let i = 0;
2761
+ // for (
2762
+ // const m = new PowiainaNum(
2763
+ // getMSIForm(
2764
+ // ...convertOperator(
2765
+ // arrowsNum - 1,
2766
+ // expans.toNumber(),
2767
+ // megota.toNumber()
2768
+ // )
2769
+ // )
2770
+ // );
2771
+ // f !== 0 && r.lt(m) && i < 100;
2772
+ // i++
2773
+ // ) {
2774
+ // if (f > 0) {
2775
+ // r = PowiainaNum.BEAF(
2776
+ // base,
2777
+ // r,
2778
+ // arrows_m1.toNumber(),
2779
+ // expans,
2780
+ // megota,
2781
+ // powiaina2,
2782
+ // depth + 1
2783
+ // );
2784
+ // --f;
2785
+ // }
2786
+ // }
2787
+ // if (i == 100) f = 0;
2788
+ // r.setOperator(
2789
+ // r.getOperator(
2790
+ // ...convertOperator(
2791
+ // arrowsNum - 1,
2792
+ // expans.toNumber(),
2793
+ // megota.toNumber()
2794
+ // )
2795
+ // ) + f,
2796
+ // ...convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())
2797
+ // );
2592
2798
  return r;
2593
2799
  }(power, depth);
2594
2800
  console.log("".concat("-".repeat(depth), " = ").concat(result));
@@ -2740,7 +2946,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2740
2946
  }, {
2741
2947
  key: "fromNumber",
2742
2948
  value: function fromNumber(x) {
2743
- var obj = new PowiainaNum(); // NaN
2949
+ var obj = new PowiainaNum();
2744
2950
  obj.resetFromObject({
2745
2951
  array: [{
2746
2952
  arrow: 0,
@@ -2752,6 +2958,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2752
2958
  layer: 0,
2753
2959
  sign: 0
2754
2960
  });
2961
+ if (Number.isNaN(x)) return obj;
2755
2962
  if (x < 0) obj.sign = -1; // negative
2756
2963
  else if (x == 0) {
2757
2964
  obj.sign = 0;
@@ -3298,12 +3505,17 @@ PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
3298
3505
  PowiainaNum.arrowFuncMap = new Map();
3299
3506
  //#region configurations
3300
3507
  /**
3301
- * 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.
3508
+ * If you set this config to true,
3509
+ * 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.
3302
3510
  */
3303
- PowiainaNum.usingBreakEternityLikeFromString = false;
3511
+ PowiainaNum.usingBreakEternityLikeFromString = true;
3304
3512
  /**
3305
3513
  * If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
3306
3514
  */
3307
3515
  PowiainaNum.blankArgumentConstructorReturnZero = false;
3516
+ /**
3517
+ * If you set this config to true, when calucation returns NaN, the program will throw error.
3518
+ */
3519
+ PowiainaNum.throwErrorOnResultNaN = false;
3308
3520
 
3309
3521
  export { arraySortFunction, PowiainaNum as default, mergeSameArrays };