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.
@@ -7,6 +7,9 @@ function _arrayLikeToArray(r, a) {
7
7
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
8
8
  return n;
9
9
  }
10
+ function _arrayWithHoles(r) {
11
+ if (Array.isArray(r)) return r;
12
+ }
10
13
  function _arrayWithoutHoles(r) {
11
14
  if (Array.isArray(r)) return _arrayLikeToArray(r);
12
15
  }
@@ -27,9 +30,42 @@ function _createClass(e, r, t) {
27
30
  function _iterableToArray(r) {
28
31
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
29
32
  }
33
+ function _iterableToArrayLimit(r, l) {
34
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
35
+ if (null != t) {
36
+ var e,
37
+ n,
38
+ i,
39
+ u,
40
+ a = [],
41
+ f = !0,
42
+ o = !1;
43
+ try {
44
+ if (i = (t = t.call(r)).next, 0 === l) {
45
+ if (Object(t) !== t) return;
46
+ f = !1;
47
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
48
+ } catch (r) {
49
+ o = !0, n = r;
50
+ } finally {
51
+ try {
52
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
53
+ } finally {
54
+ if (o) throw n;
55
+ }
56
+ }
57
+ return a;
58
+ }
59
+ }
60
+ function _nonIterableRest() {
61
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
+ }
30
63
  function _nonIterableSpread() {
31
64
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
32
65
  }
66
+ function _slicedToArray(r, e) {
67
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
68
+ }
33
69
  function _toConsumableArray(r) {
34
70
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
35
71
  }
@@ -384,6 +420,7 @@ var PowiainaNum = /*#__PURE__*/function () {
384
420
  } catch (e) {
385
421
  console.error("Malformed input");
386
422
  console.error(e);
423
+ if (PowiainaNum.throwErrorOnResultNaN && PowiainaNum.isNaN(this)) throw new Error("NaN");
387
424
  }
388
425
  }
389
426
  //#region 4 Basic calculates.
@@ -398,7 +435,10 @@ var PowiainaNum = /*#__PURE__*/function () {
398
435
  var x = this.clone().normalize();
399
436
  var y = new PowiainaNum(other);
400
437
  // inf + -inf = nan
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();
438
+ if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.POSITIVE_INFINITY)) {
439
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
440
+ return PowiainaNum.NaN.clone();
441
+ }
402
442
  // inf & nan check
403
443
  if (!x.isFinite()) return x.clone();
404
444
  if (!y.isFinite()) return y.clone();
@@ -495,7 +535,10 @@ var PowiainaNum = /*#__PURE__*/function () {
495
535
  var y = new PowiainaNum(other);
496
536
  // inf * -inf = -inf
497
537
  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();
498
- if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
538
+ if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) {
539
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
540
+ return PowiainaNum.NaN.clone();
541
+ }
499
542
  if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
500
543
  // inf & nan check
501
544
  if (!x.isFinite()) return x.clone();
@@ -600,6 +643,7 @@ var PowiainaNum = /*#__PURE__*/function () {
600
643
  return this.neg().pow(other).neg();
601
644
  }
602
645
  }
646
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
603
647
  return PowiainaNum.NaN.clone();
604
648
  }
605
649
  var r = this.abs().pow(other);
@@ -629,6 +673,7 @@ var PowiainaNum = /*#__PURE__*/function () {
629
673
  } else if (other.rec().mod(2).eq(1)) {
630
674
  return this.neg().log10().mul(other).pow10().neg();
631
675
  }
676
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
632
677
  return PowiainaNum.NaN.clone();
633
678
  }
634
679
  }, {
@@ -656,7 +701,10 @@ var PowiainaNum = /*#__PURE__*/function () {
656
701
  }, {
657
702
  key: "log10",
658
703
  value: function log10() {
659
- if (this.isneg()) return PowiainaNum.NaN.clone();
704
+ if (this.isneg()) {
705
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
706
+ return PowiainaNum.NaN.clone();
707
+ }
660
708
  if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
661
709
  if (this.small) {
662
710
  var _x = this.clone();
@@ -798,6 +846,7 @@ var PowiainaNum = /*#__PURE__*/function () {
798
846
  var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
799
847
  var principal = princ;
800
848
  if (this.lt(-0.3678794411710499)) {
849
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
801
850
  return PowiainaNum.NaN.clone(); //complex
802
851
  } else if (principal) {
803
852
  if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
@@ -812,6 +861,7 @@ var PowiainaNum = /*#__PURE__*/function () {
812
861
  }
813
862
  } else {
814
863
  if (this.sign === -1) {
864
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
815
865
  return PowiainaNum.NaN.clone(); //complex
816
866
  }
817
867
  if (this.lt(9e15)) {
@@ -835,7 +885,10 @@ var PowiainaNum = /*#__PURE__*/function () {
835
885
  var t = this.clone();
836
886
  var other = new PowiainaNum(other2);
837
887
  var payl = new PowiainaNum(payload);
838
- if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
888
+ if (t.isNaN() || other.isNaN() || payl.isNaN()) {
889
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
890
+ return PowiainaNum.NaN.clone();
891
+ }
839
892
  if (t.eq(1)) return PowiainaNum.ONE.clone();
840
893
  if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
841
894
  other = other.add(payl.slog(t));
@@ -846,14 +899,23 @@ var PowiainaNum = /*#__PURE__*/function () {
846
899
  negln = this.log().neg();
847
900
  return negln.lambertw().div(negln);
848
901
  }
849
- if (other.lte(-2)) return PowiainaNum.NaN.clone();
902
+ if (other.lte(-2)) {
903
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
904
+ return PowiainaNum.NaN.clone();
905
+ }
850
906
  if (t.isZero()) {
851
- if (other.isZero()) return PowiainaNum.NaN.clone();
907
+ if (other.isZero()) {
908
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
909
+ return PowiainaNum.NaN.clone();
910
+ }
852
911
  if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
853
912
  return PowiainaNum.ONE.clone();
854
913
  }
855
914
  if (t.eq(PowiainaNum.ONE)) {
856
- if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
915
+ if (other.eq(PowiainaNum.ONE.neg())) {
916
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
917
+ return PowiainaNum.NaN.clone();
918
+ }
857
919
  return PowiainaNum.ONE.clone();
858
920
  }
859
921
  if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
@@ -927,7 +989,10 @@ var PowiainaNum = /*#__PURE__*/function () {
927
989
  if (b.lt(EXP_E_REC)) {
928
990
  var a = b.tetrate(Infinity);
929
991
  if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
930
- if (x.gt(a)) return PowiainaNum.NaN.clone();
992
+ if (x.gt(a)) {
993
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
994
+ return PowiainaNum.NaN.clone();
995
+ }
931
996
  }
932
997
  if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
933
998
  if (x.gt(b)) return x;
@@ -971,13 +1036,17 @@ var PowiainaNum = /*#__PURE__*/function () {
971
1036
  }
972
1037
  }
973
1038
  if (x.gt(10)) return new PowiainaNum(r);
1039
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
974
1040
  return PowiainaNum.NaN.clone();
975
1041
  }
976
1042
  }, {
977
1043
  key: "ssqrt",
978
1044
  value: function ssqrt() {
979
1045
  var x = this.clone();
980
- if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
1046
+ if (x.lt(1 / EXP_E_REC)) {
1047
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1048
+ return PowiainaNum.NaN.clone();
1049
+ }
981
1050
  if (!x.isFinite()) return x;
982
1051
  if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
983
1052
  if (x.gt(PowiainaNum.EE_MSI)) {
@@ -1028,6 +1097,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1028
1097
  if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
1029
1098
  console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
1030
1099
  return function () {
1100
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1031
1101
  return PowiainaNum.NaN.clone();
1032
1102
  };
1033
1103
  }
@@ -1053,6 +1123,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1053
1123
  if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1054
1124
  if (t.eq(PowiainaNum.ZERO)) {
1055
1125
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1126
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1056
1127
  return PowiainaNum.NaN.clone();
1057
1128
  }
1058
1129
  if (payload.neq(PowiainaNum.ONE)) other = other.add(payload.anyarrow_log(arrows)(t));
@@ -1132,6 +1203,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1132
1203
  throw new Error(powiainaNumError + "Not implemented");
1133
1204
  }
1134
1205
  if (!arrow.isInt() || arrow.lt(0)) return function () {
1206
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1135
1207
  return PowiainaNum.NaN.clone();
1136
1208
  };
1137
1209
  if (arrow.eq(0)) return function (base) {
@@ -1165,7 +1237,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1165
1237
  return x.sub(x.getOperator(arrowsNum - 1));
1166
1238
  }
1167
1239
  }
1168
- if (x.lt(PowiainaNum.ZERO.clone())) return PowiainaNum.NaN.clone();
1240
+ if (x.lt(PowiainaNum.ZERO.clone())) {
1241
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1242
+ return PowiainaNum.NaN.clone();
1243
+ }
1169
1244
  // base^base^... = x? (? bases)
1170
1245
  var r = 0;
1171
1246
  // 计算x与base的差距
@@ -1189,6 +1264,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1189
1264
  }
1190
1265
  }
1191
1266
  if (x.gt(10)) return new PowiainaNum(r);
1267
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1192
1268
  return PowiainaNum.NaN.clone();
1193
1269
  };
1194
1270
  }
@@ -1248,7 +1324,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1248
1324
  if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
1249
1325
  if (other.eq(PowiainaNum.ONE)) return this.clone();
1250
1326
  if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1251
- if (!this.isInt()) return PowiainaNum.NaN.clone();
1327
+ if (!this.isInt()) {
1328
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1329
+ return PowiainaNum.NaN.clone();
1330
+ }
1252
1331
  if (this.eq(2)) return new PowiainaNum(4);
1253
1332
  if (other.eq(0)) return PowiainaNum.ONE.clone();
1254
1333
  var r;
@@ -1288,6 +1367,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1288
1367
  var arrow = new PowiainaNum(arrow2);
1289
1368
  var t = this.clone();
1290
1369
  if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
1370
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1291
1371
  return PowiainaNum.NaN.clone();
1292
1372
  };
1293
1373
  if (arrow.eq(0)) return function (other) {
@@ -1302,9 +1382,13 @@ var PowiainaNum = /*#__PURE__*/function () {
1302
1382
  var other = new PowiainaNum(other2);
1303
1383
  var r;
1304
1384
  if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
1305
- if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1385
+ if (other.lt(PowiainaNum.ZERO)) {
1386
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1387
+ return PowiainaNum.NaN.clone();
1388
+ }
1306
1389
  if (t.eq(PowiainaNum.ZERO)) {
1307
1390
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1391
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1308
1392
  return PowiainaNum.NaN.clone();
1309
1393
  }
1310
1394
  if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
@@ -1493,7 +1577,8 @@ var PowiainaNum = /*#__PURE__*/function () {
1493
1577
  /**
1494
1578
  * -1: `this` is smaller
1495
1579
  * 0: equals
1496
- * 1: `x` is bigger
1580
+ * 1: `x` is smaller
1581
+ * 2: NaN
1497
1582
  */
1498
1583
  }, {
1499
1584
  key: "compare",
@@ -1502,6 +1587,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1502
1587
  if (this.isNaN() || other.isNaN()) return 2;
1503
1588
  if (this.sign < other.sign) return -1;
1504
1589
  if (this.sign > other.sign) return 1;
1590
+ var t = this;
1505
1591
  //this.sign = other.sign
1506
1592
  var allneg = this.sign == -1 && other.sign == -1;
1507
1593
  if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
@@ -1513,6 +1599,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1513
1599
  for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
1514
1600
  var op1 = this.array[this.array.length - 1 - i];
1515
1601
  var op2 = other.array[other.array.length - 1 - i];
1602
+ if (op1.repeat === Infinity && op2.repeat === Infinity) {
1603
+ if (t.small === other.small) return 0;
1604
+ return other.small ? 1 : -1;
1605
+ }
1516
1606
  if (op1.repeat === Infinity) {
1517
1607
  result = 1;
1518
1608
  break;
@@ -2043,8 +2133,20 @@ var PowiainaNum = /*#__PURE__*/function () {
2043
2133
  this.small = false;
2044
2134
  renormalize = true;
2045
2135
  }
2046
- // for any 10{X>9e15}10, replace into 10{!}X;
2047
- if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
2136
+ // for any 10{!}^t x, replace to 10{!}^t-1 10{x}10
2137
+ if (this.array.length >= 2 && !isFinite(this.array[1].arrow)) {
2138
+ if (this.array[1].repeat > 1) {
2139
+ this.array.push(newOperator(this.array[1].repeat - 1, 1 / 0, this.array[1].expans, this.array[1].megota));
2140
+ this.array[1].repeat = 1;
2141
+ this.array[1].arrow = this.array[0].repeat;
2142
+ this.array[0].repeat = 10;
2143
+ } else {
2144
+ this.array[1].arrow = this.array[0].repeat;
2145
+ this.array[0].repeat = 10;
2146
+ }
2147
+ }
2148
+ // for any 10{X>9e15}10 finite, replace into 10{!}X;
2149
+ if (this.array.length >= 2 && this.array[1].arrow >= MSI && isFinite(this.array[1].arrow)) {
2048
2150
  this.array[0].repeat = this.array[1].arrow;
2049
2151
  this.array[1] = newOperator(1, Infinity, this.array[1].expans, this.array[1].megota);
2050
2152
  }
@@ -2070,16 +2172,6 @@ var PowiainaNum = /*#__PURE__*/function () {
2070
2172
  x.array[0].repeat = 10;
2071
2173
  renormalize = true;
2072
2174
  }
2073
- if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1 &&
2074
- //10^^^ 10
2075
- isFinite(x.array[1].arrow)) {
2076
- // for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
2077
- // But dont convert when a is infinite
2078
- // [1e9, [R=1, A=2, sth, sth]]
2079
- x.array.splice(1, 1, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
2080
- x.array[0].repeat = 10;
2081
- renormalize = true;
2082
- }
2083
2175
  // for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
2084
2176
  if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow !== Infinity) {
2085
2177
  x.array[1].arrow++;
@@ -2453,13 +2545,19 @@ var PowiainaNum = /*#__PURE__*/function () {
2453
2545
  if (base.eq(1)) return new PowiainaNum(1);
2454
2546
  if (power.eq(1)) return new PowiainaNum(base);
2455
2547
  if (power.isZero()) return new PowiainaNum(1);
2456
- if (base.lt(0)) return PowiainaNum.NaN.clone();
2548
+ if (base.lt(0)) {
2549
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
2550
+ return PowiainaNum.NaN.clone();
2551
+ }
2457
2552
  // // check infinite
2458
2553
  // let sufpowiaina = args.slice(4);
2459
2554
  // if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
2460
2555
  // return PowiainaNum.POSITIVE_INFINITY;
2461
2556
  // }
2462
2557
  if (new PowiainaNum(powiaina2).gte(3)) return PowiainaNum.POSITIVE_INFINITY.clone();
2558
+ if (readArg(0).eq(0) && readArg(1).eq(1) && readArg(2).eq(1)) {
2559
+ return base.mul(power);
2560
+ }
2463
2561
  if (readArg(0).eq(1) && readArg(1).eq(1) && readArg(2).eq(1)) {
2464
2562
  return base.pow(power);
2465
2563
  }
@@ -2509,12 +2607,16 @@ var PowiainaNum = /*#__PURE__*/function () {
2509
2607
  return x.toString();
2510
2608
  }
2511
2609
  function getMSIForm(arrow, expans, megota) {
2512
- return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
2610
+ var _convertOperator = convertOperator(arrow, expans, megota),
2611
+ _convertOperator2 = _slicedToArray(_convertOperator, 3),
2612
+ a = _convertOperator2[0],
2613
+ e = _convertOperator2[1],
2614
+ m = _convertOperator2[2];
2615
+ return "10{".concat(infToBang(a), ",").concat(infToBang(e), ",").concat(m, "}").concat(MSI);
2513
2616
  }
2514
2617
  var t = base.clone();
2515
2618
  var arrows = new PowiainaNum(readArg(0));
2516
2619
  var result = function (other2) {
2517
- var _r, _r2;
2518
2620
  var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2519
2621
  console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
2520
2622
  var other = new PowiainaNum(other2);
@@ -2523,21 +2625,26 @@ var PowiainaNum = /*#__PURE__*/function () {
2523
2625
  if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
2524
2626
  if (t.eq(PowiainaNum.ZERO)) {
2525
2627
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
2628
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
2526
2629
  return PowiainaNum.NaN.clone();
2527
2630
  }
2528
2631
  if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
2529
2632
  if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
2530
2633
  if (other.eq(PowiainaNum.ONE)) return t.clone();
2531
2634
  if (arrows.eq(0)) {
2532
- return PowiainaNum.BEAF(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
2635
+ return PowiainaNum.BEAF_core(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
2533
2636
  // {this, this, power, expans-1, megota}
2534
2637
  }
2535
2638
  if (expans.eq(0)) {
2536
- return PowiainaNum.BEAF(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
2639
+ return PowiainaNum.BEAF_core(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
2537
2640
  // {this, this, this, power, megota-1}
2538
2641
  }
2539
2642
  if (megota.eq(0)) {
2540
- return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
2643
+ return PowiainaNum.BEAF_core(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
2644
+ }
2645
+ // megota < 9e15, not implemented
2646
+ if (megota.gt(MSI)) {
2647
+ throw new Error("Not implemeneted");
2541
2648
  }
2542
2649
  // expans > 9e15, that using 10{?, x}, x=expans;
2543
2650
  if (expans.gt(MSI)) {
@@ -2554,15 +2661,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2554
2661
  var arrowsNum = arrows.toNumber();
2555
2662
  // arrow < 9e15
2556
2663
  // 10{x}2 = 10{x-1}10
2557
- if (other.eq(2)) return PowiainaNum.BEAF(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
2664
+ if (other.eq(2)) return PowiainaNum.BEAF_core(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
2558
2665
  if (t.max(other).gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber()))) return t.max(other);
2559
- if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
2666
+ // arrow < 9e15
2667
+ // 10{x}2 = 10{x-1}10
2668
+ if (t.gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
2560
2669
  if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
2561
2670
  r = t.clone();
2562
2671
  r.setOperator(r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1, arrowsNum, expans.toNumber(), megota.toNumber());
2563
2672
  r.normalize();
2564
- } else if (t.gt(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))))) {
2565
- r = new PowiainaNum(t.getOperator.apply(t, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
2673
+ } else if (t.gt(getMSIForm(arrowsNum - 1, expans.toNumber(), megota.toNumber()))) {
2674
+ r = new PowiainaNum(t.getOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()));
2566
2675
  } else {
2567
2676
  r = PowiainaNum.ZERO;
2568
2677
  }
@@ -2582,17 +2691,114 @@ var PowiainaNum = /*#__PURE__*/function () {
2582
2691
  var y = other.toNumber();
2583
2692
  var f = Math.floor(y);
2584
2693
  var arrows_m1 = arrows.sub(PowiainaNum.ONE);
2585
- r = PowiainaNum.BEAF(t, y - f, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
2694
+ r = PowiainaNum.BEAF_core(t, y - f, arrows_m1, expans, megota, powiaina, depth + 1);
2695
+ // r = t.arrow(arrows_m1)(y - f, payload, depth + 1);
2586
2696
  var i = 0;
2587
- 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++) {
2697
+ for (var m = getMSIForm(arrowsNum - 1, expans.toNumber(), megota.toNumber()); f !== 0 && r.lt(m) && i < 100; i++) {
2588
2698
  if (f > 0) {
2589
- r = PowiainaNum.BEAF(base, r, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
2699
+ r = PowiainaNum.BEAF_core(t, r, arrows_m1, expans, megota, powiaina, depth + 1);
2590
2700
  --f;
2591
2701
  }
2592
2702
  }
2593
2703
  if (i == 100) f = 0;
2594
- (_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()))));
2704
+ r.setOperator(r.getOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()) + f, arrowsNum - 1, expans.toNumber(), megota.toNumber());
2595
2705
  r.normalize();
2706
+ // if (
2707
+ // t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) ||
2708
+ // other.gt(MSI)
2709
+ // ) {
2710
+ // if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
2711
+ // r = t.clone();
2712
+ // r.setOperator(
2713
+ // r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1,
2714
+ // arrowsNum,
2715
+ // expans.toNumber(),
2716
+ // megota.toNumber()
2717
+ // );
2718
+ // r.normalize();
2719
+ // } else if (
2720
+ // t.gt(
2721
+ // getMSIForm(
2722
+ // ...convertOperator(
2723
+ // arrowsNum - 1,
2724
+ // expans.toNumber(),
2725
+ // megota.toNumber()
2726
+ // )
2727
+ // )
2728
+ // )
2729
+ // ) {
2730
+ // r = new PowiainaNum(
2731
+ // t.getOperator(
2732
+ // ...convertOperator(
2733
+ // arrowsNum - 1,
2734
+ // expans.toNumber(),
2735
+ // megota.toNumber()
2736
+ // )
2737
+ // )
2738
+ // );
2739
+ // } else {
2740
+ // r = PowiainaNum.ZERO;
2741
+ // }
2742
+ // const j = r.add(other);
2743
+ // j.setOperator(
2744
+ // j.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) + 1,
2745
+ // arrowsNum,
2746
+ // expans.toNumber(),
2747
+ // megota.toNumber()
2748
+ // );
2749
+ // j.normalize();
2750
+ // return j;
2751
+ // }
2752
+ // const y = other.toNumber();
2753
+ // let f = Math.floor(y);
2754
+ // const arrows_m1 = arrows.sub(PowiainaNum.ONE);
2755
+ // r = PowiainaNum.BEAF(
2756
+ // t,
2757
+ // y - f,
2758
+ // arrows_m1.toNumber(),
2759
+ // expans,
2760
+ // megota,
2761
+ // powiaina2,
2762
+ // depth + 1
2763
+ // );
2764
+ // let i = 0;
2765
+ // for (
2766
+ // const m = new PowiainaNum(
2767
+ // getMSIForm(
2768
+ // ...convertOperator(
2769
+ // arrowsNum - 1,
2770
+ // expans.toNumber(),
2771
+ // megota.toNumber()
2772
+ // )
2773
+ // )
2774
+ // );
2775
+ // f !== 0 && r.lt(m) && i < 100;
2776
+ // i++
2777
+ // ) {
2778
+ // if (f > 0) {
2779
+ // r = PowiainaNum.BEAF(
2780
+ // base,
2781
+ // r,
2782
+ // arrows_m1.toNumber(),
2783
+ // expans,
2784
+ // megota,
2785
+ // powiaina2,
2786
+ // depth + 1
2787
+ // );
2788
+ // --f;
2789
+ // }
2790
+ // }
2791
+ // if (i == 100) f = 0;
2792
+ // r.setOperator(
2793
+ // r.getOperator(
2794
+ // ...convertOperator(
2795
+ // arrowsNum - 1,
2796
+ // expans.toNumber(),
2797
+ // megota.toNumber()
2798
+ // )
2799
+ // ) + f,
2800
+ // ...convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())
2801
+ // );
2596
2802
  return r;
2597
2803
  }(power, depth);
2598
2804
  console.log("".concat("-".repeat(depth), " = ").concat(result));
@@ -2744,7 +2950,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2744
2950
  }, {
2745
2951
  key: "fromNumber",
2746
2952
  value: function fromNumber(x) {
2747
- var obj = new PowiainaNum(); // NaN
2953
+ var obj = new PowiainaNum();
2748
2954
  obj.resetFromObject({
2749
2955
  array: [{
2750
2956
  arrow: 0,
@@ -2756,6 +2962,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2756
2962
  layer: 0,
2757
2963
  sign: 0
2758
2964
  });
2965
+ if (Number.isNaN(x)) return obj;
2759
2966
  if (x < 0) obj.sign = -1; // negative
2760
2967
  else if (x == 0) {
2761
2968
  obj.sign = 0;
@@ -3302,13 +3509,18 @@ PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
3302
3509
  PowiainaNum.arrowFuncMap = new Map();
3303
3510
  //#region configurations
3304
3511
  /**
3305
- * 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.
3512
+ * If you set this config to true,
3513
+ * 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.
3306
3514
  */
3307
- PowiainaNum.usingBreakEternityLikeFromString = false;
3515
+ PowiainaNum.usingBreakEternityLikeFromString = true;
3308
3516
  /**
3309
3517
  * If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
3310
3518
  */
3311
3519
  PowiainaNum.blankArgumentConstructorReturnZero = false;
3520
+ /**
3521
+ * If you set this config to true, when calucation returns NaN, the program will throw error.
3522
+ */
3523
+ PowiainaNum.throwErrorOnResultNaN = false;
3312
3524
 
3313
3525
  exports.arraySortFunction = arraySortFunction;
3314
3526
  exports["default"] = PowiainaNum;