powiaina_num.js 0.2.12 → 0.2.14

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,27 @@ 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
+ if (PowiainaNum.throwErrorOnResultNaN && PowiainaNum.isNaN(this)) throw new Error("NaN");
388
+ }
349
389
  }
350
390
  //#region 4 Basic calculates.
351
391
  /**
@@ -356,10 +396,13 @@ var PowiainaNum = /*#__PURE__*/function () {
356
396
  key: "add",
357
397
  value: function add(other) {
358
398
  var _b, _c, _d, _e;
359
- var x = this.clone();
399
+ var x = this.clone().normalize();
360
400
  var y = new PowiainaNum(other);
361
401
  // inf + -inf = nan
362
- 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();
402
+ if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.POSITIVE_INFINITY)) {
403
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
404
+ return PowiainaNum.NaN.clone();
405
+ }
363
406
  // inf & nan check
364
407
  if (!x.isFinite()) return x.clone();
365
408
  if (!y.isFinite()) return y.clone();
@@ -399,40 +442,56 @@ var PowiainaNum = /*#__PURE__*/function () {
399
442
  if (isFinite(temp) && temp !== 0) {
400
443
  return PowiainaNum.fromNumber(temp);
401
444
  }
402
- var mult = 1;
445
+ var signMult = 1;
446
+ /**Calculate numbers [1, 9e15] (useless) */
403
447
  if (!a.small && !b.small && !((_b = a.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) && !((_c = b.array[1]) === null || _c === void 0 ? void 0 : _c.repeat) && a.sign == b.sign) {
404
448
  return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
405
449
  }
450
+ // Calculate a & b's 10-logarithm
406
451
  var alog10 = (a.small ? -1 : 1) * (((_d = a.array[1]) === null || _d === void 0 ? void 0 : _d.repeat) ? a.array[0].repeat : Math.log10(a.array[0].repeat));
407
452
  var blog10 = (b.small ? -1 : 1) * (((_e = b.array[1]) === null || _e === void 0 ? void 0 : _e.repeat) ? b.array[0].repeat : Math.log10(b.array[0].repeat));
408
453
  if (alog10 - blog10 > MSI_LOG10) return a;
454
+ /**
455
+ * Offset, a number can make 10^ a+off calculatable not very small or big
456
+ */
409
457
  var offset = -Math.floor(alog10); //a number can make a+off in [0,1)
410
- var r,
411
- l = 0,
412
- t;
413
- t = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
414
- if (t > 0) l = Math.log10(t) - offset;
415
- if (t < 0) {
416
- l = Math.log10(-t) - offset;
417
- mult *= -1;
418
- }
419
- if (t == 0) throw Error("Encounter a calculate error");
420
- r = new PowiainaNum();
421
- r.sign = 1;
422
- if (l > MSI_LOG10 || l < -MSI_LOG10) {
423
- r.array = [newOperator(l, 0), newOperator(1, 1)];
458
+ var resultLogarithm = 0;
459
+ /** 10^(a+off) + 10^(b+off). */
460
+ var offsetedResult = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
461
+ if (offsetedResult > 0) resultLogarithm = Math.log10(offsetedResult) - offset;
462
+ if (offsetedResult < 0) {
463
+ resultLogarithm = Math.log10(-offsetedResult) - offset;
464
+ signMult *= -1;
465
+ }
466
+ if (offsetedResult == 0) return PowiainaNum.ZERO.clone();
467
+ var resultPN = PowiainaNum.NaN.clone();
468
+ resultPN.sign = 1;
469
+ /** abs(resultLogarithm) > 15.9, use 10^x form. */
470
+ if (resultLogarithm > MSI_LOG10 || resultLogarithm < -MSI_LOG10) {
471
+ resultPN.array = [newOperator(resultLogarithm, 0), newOperator(1, 1)];
472
+ /**otherwise, use 10** abs(resultLogarithm) */
424
473
  } else {
425
- r.array = [newOperator(Math.pow(10, Math.abs(l)), 0)];
474
+ resultPN.array = [newOperator(Math.pow(10, Math.abs(resultLogarithm)), 0)];
426
475
  }
427
- r.small = l < 0 ? true : false;
428
- r.sign *= mult;
429
- return r;
476
+ resultPN.small = resultLogarithm < 0 ? true : false;
477
+ resultPN.sign *= signMult;
478
+ return resultPN;
479
+ }
480
+ }, {
481
+ key: "plus",
482
+ value: function plus(other) {
483
+ return this.add(other);
430
484
  }
431
485
  }, {
432
486
  key: "sub",
433
487
  value: function sub(a) {
434
488
  return this.add(new PowiainaNum(a).neg());
435
489
  }
490
+ }, {
491
+ key: "minus",
492
+ value: function minus(other) {
493
+ return this.sub(other);
494
+ }
436
495
  }, {
437
496
  key: "mul",
438
497
  value: function mul(other) {
@@ -440,7 +499,10 @@ var PowiainaNum = /*#__PURE__*/function () {
440
499
  var y = new PowiainaNum(other);
441
500
  // inf * -inf = -inf
442
501
  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();
443
- if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
502
+ if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) {
503
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
504
+ return PowiainaNum.NaN.clone();
505
+ }
444
506
  if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
445
507
  // inf & nan check
446
508
  if (!x.isFinite()) return x.clone();
@@ -466,12 +528,22 @@ var PowiainaNum = /*#__PURE__*/function () {
466
528
  r.sign = x.sign * y.sign;
467
529
  return r;
468
530
  }
531
+ }, {
532
+ key: "times",
533
+ value: function times(other) {
534
+ return this.mul(other);
535
+ }
469
536
  }, {
470
537
  key: "div",
471
538
  value: function div(other) {
472
539
  var x = new PowiainaNum(other).rec();
473
540
  return this.mul(x);
474
541
  }
542
+ }, {
543
+ key: "divide",
544
+ value: function divide(other) {
545
+ return this.div(other);
546
+ }
475
547
  }, {
476
548
  key: "mod",
477
549
  value: function mod(x) {
@@ -479,34 +551,45 @@ var PowiainaNum = /*#__PURE__*/function () {
479
551
  var division = this.div(other);
480
552
  return division.sub(division.floor()).mul(other);
481
553
  }
554
+ }, {
555
+ key: "modulus",
556
+ value: function modulus(x) {
557
+ return this.mod(x);
558
+ }
559
+ }, {
560
+ key: "pow10",
561
+ value:
482
562
  //#endregion
483
563
  //#region power
484
564
  /**
485
565
  * @returns 10 to the power of `this`
486
566
  */
487
- }, {
488
- key: "pow10",
489
- value: function pow10() {
567
+ function pow10() {
490
568
  var _b, _c;
491
- var r = this.clone();
569
+ var thisObject = this.clone();
492
570
  // inf & nan check
493
571
  if (!this.isFinite()) return this.clone();
494
- if (r.isneg()) {
572
+ /** when 10^(t), t<0, use 10^(-t) reciprocate. */
573
+ if (thisObject.isneg()) {
495
574
  // 10^(-x) = 1/(10^x)
496
- r.sign *= -1;
497
- return r.pow10().rec();
575
+ thisObject.sign *= -1;
576
+ return thisObject.pow10().rec();
498
577
  }
499
- if (r.lte(308.25471555991675)) {
500
- return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
578
+ /**if t lessthan log10 2^1024, use fromNumber. */
579
+ if (thisObject.lte(308.25471555991675)) {
580
+ return PowiainaNum.fromNumber(Math.pow(10, thisObject.toNumber()));
501
581
  }
502
- if (r.small) {
503
- if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
504
- return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
582
+ /**calculate directly */
583
+ if (thisObject.small) {
584
+ if (thisObject.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
585
+ return new PowiainaNum(Math.pow(10, Math.pow(thisObject.array[0].repeat, -1)));
505
586
  }
506
- if (r.gt(PowiainaNum.TETRATED_MSI)) return r;
507
- r.setOperator(((_c = (_b = r.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
508
- r.normalize();
509
- return r;
587
+ /** indistinguishable above 10^^9e15 */
588
+ if (thisObject.gt(PowiainaNum.TETRATED_MSI)) return thisObject;
589
+ /**otherwise add 10^ directly */
590
+ thisObject.setOperator(((_c = (_b = thisObject.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
591
+ thisObject.normalize();
592
+ return thisObject;
510
593
  }
511
594
  }, {
512
595
  key: "pow",
@@ -516,8 +599,17 @@ var PowiainaNum = /*#__PURE__*/function () {
516
599
  if (!other.isFinite()) return other.clone();
517
600
  if (!this.isFinite()) return this.clone();
518
601
  if (this.eq(10)) return other.pow10();
602
+ if (other.isneg()) return this.pow(other.neg()).rec();
519
603
  if (this.isneg()) {
520
- if (!other.isInt()) return PowiainaNum.NaN.clone();
604
+ if (!other.isInt()) {
605
+ if (other.small) {
606
+ if (other.rec().div(2).eq(1)) {
607
+ return this.neg().pow(other).neg();
608
+ }
609
+ }
610
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
611
+ return PowiainaNum.NaN.clone();
612
+ }
521
613
  var r = this.abs().pow(other);
522
614
  r.sign = function () {
523
615
  var a = other.mod(2).round();
@@ -545,6 +637,7 @@ var PowiainaNum = /*#__PURE__*/function () {
545
637
  } else if (other.rec().mod(2).eq(1)) {
546
638
  return this.neg().log10().mul(other).pow10().neg();
547
639
  }
640
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
548
641
  return PowiainaNum.NaN.clone();
549
642
  }
550
643
  }, {
@@ -572,7 +665,10 @@ var PowiainaNum = /*#__PURE__*/function () {
572
665
  }, {
573
666
  key: "log10",
574
667
  value: function log10() {
575
- if (this.isneg()) return PowiainaNum.NaN.clone();
668
+ if (this.isneg()) {
669
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
670
+ return PowiainaNum.NaN.clone();
671
+ }
576
672
  if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
577
673
  if (this.small) {
578
674
  var _x = this.clone();
@@ -594,6 +690,16 @@ var PowiainaNum = /*#__PURE__*/function () {
594
690
  var other = new PowiainaNum(base);
595
691
  return this.log10().div(other.log10());
596
692
  }
693
+ }, {
694
+ key: "log2",
695
+ value: function log2() {
696
+ return this.log(2);
697
+ }
698
+ }, {
699
+ key: "logBase",
700
+ value: function logBase(a) {
701
+ return this.log(a);
702
+ }
597
703
  }, {
598
704
  key: "ln",
599
705
  value: function ln() {
@@ -701,8 +807,10 @@ var PowiainaNum = /*#__PURE__*/function () {
701
807
  //Code from break_eternity.js
702
808
  //Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
703
809
  function lambertw() {
704
- var principal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
810
+ var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
811
+ var principal = princ;
705
812
  if (this.lt(-0.3678794411710499)) {
813
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
706
814
  return PowiainaNum.NaN.clone(); //complex
707
815
  } else if (principal) {
708
816
  if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
@@ -716,12 +824,13 @@ var PowiainaNum = /*#__PURE__*/function () {
716
824
  return this.log();
717
825
  }
718
826
  } else {
719
- if (this.sign === 1) {
827
+ if (this.sign === -1) {
828
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
720
829
  return PowiainaNum.NaN.clone(); //complex
721
830
  }
722
- if (this.layer === 0) {
831
+ if (this.lt(9e15)) {
723
832
  return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
724
- } else if (this.layer == 1) {
833
+ } else if (this.lt(PowiainaNum.E_MSI)) {
725
834
  return d_lambertw(this, 1e-10, false);
726
835
  } else {
727
836
  return this.neg().rec().lambertw().neg();
@@ -740,23 +849,37 @@ var PowiainaNum = /*#__PURE__*/function () {
740
849
  var t = this.clone();
741
850
  var other = new PowiainaNum(other2);
742
851
  var payl = new PowiainaNum(payload);
743
- if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
852
+ if (t.isNaN() || other.isNaN() || payl.isNaN()) {
853
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
854
+ return PowiainaNum.NaN.clone();
855
+ }
744
856
  if (t.eq(1)) return PowiainaNum.ONE.clone();
745
- if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
857
+ if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
858
+ other = other.add(payl.slog(t));
859
+ }
746
860
  var negln;
747
861
  if (other.isInfi() && other.sign > 0) {
748
862
  if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
749
863
  negln = this.log().neg();
750
864
  return negln.lambertw().div(negln);
751
865
  }
752
- if (other.lte(-2)) return PowiainaNum.NaN.clone();
866
+ if (other.lte(-2)) {
867
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
868
+ return PowiainaNum.NaN.clone();
869
+ }
753
870
  if (t.isZero()) {
754
- if (other.isZero()) return PowiainaNum.NaN.clone();
871
+ if (other.isZero()) {
872
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
873
+ return PowiainaNum.NaN.clone();
874
+ }
755
875
  if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
756
876
  return PowiainaNum.ONE.clone();
757
877
  }
758
878
  if (t.eq(PowiainaNum.ONE)) {
759
- if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
879
+ if (other.eq(PowiainaNum.ONE.neg())) {
880
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
881
+ return PowiainaNum.NaN.clone();
882
+ }
760
883
  return PowiainaNum.ONE.clone();
761
884
  }
762
885
  if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
@@ -830,7 +953,10 @@ var PowiainaNum = /*#__PURE__*/function () {
830
953
  if (b.lt(EXP_E_REC)) {
831
954
  var a = b.tetrate(Infinity);
832
955
  if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
833
- if (x.gt(a)) return PowiainaNum.NaN.clone();
956
+ if (x.gt(a)) {
957
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
958
+ return PowiainaNum.NaN.clone();
959
+ }
834
960
  }
835
961
  if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
836
962
  if (x.gt(b)) return x;
@@ -874,13 +1000,17 @@ var PowiainaNum = /*#__PURE__*/function () {
874
1000
  }
875
1001
  }
876
1002
  if (x.gt(10)) return new PowiainaNum(r);
1003
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
877
1004
  return PowiainaNum.NaN.clone();
878
1005
  }
879
1006
  }, {
880
1007
  key: "ssqrt",
881
1008
  value: function ssqrt() {
882
1009
  var x = this.clone();
883
- if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
1010
+ if (x.lt(1 / EXP_E_REC)) {
1011
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1012
+ return PowiainaNum.NaN.clone();
1013
+ }
884
1014
  if (!x.isFinite()) return x;
885
1015
  if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
886
1016
  if (x.gt(PowiainaNum.EE_MSI)) {
@@ -931,6 +1061,7 @@ var PowiainaNum = /*#__PURE__*/function () {
931
1061
  if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
932
1062
  console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
933
1063
  return function () {
1064
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
934
1065
  return PowiainaNum.NaN.clone();
935
1066
  };
936
1067
  }
@@ -956,6 +1087,7 @@ var PowiainaNum = /*#__PURE__*/function () {
956
1087
  if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
957
1088
  if (t.eq(PowiainaNum.ZERO)) {
958
1089
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1090
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
959
1091
  return PowiainaNum.NaN.clone();
960
1092
  }
961
1093
  if (payload.neq(PowiainaNum.ONE)) other = other.add(payload.anyarrow_log(arrows)(t));
@@ -1035,6 +1167,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1035
1167
  throw new Error(powiainaNumError + "Not implemented");
1036
1168
  }
1037
1169
  if (!arrow.isInt() || arrow.lt(0)) return function () {
1170
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1038
1171
  return PowiainaNum.NaN.clone();
1039
1172
  };
1040
1173
  if (arrow.eq(0)) return function (base) {
@@ -1068,13 +1201,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1068
1201
  return x.sub(x.getOperator(arrowsNum - 1));
1069
1202
  }
1070
1203
  }
1071
- if (x.lt(PowiainaNum.ZERO.clone())) return PowiainaNum.NaN.clone();
1204
+ if (x.lt(PowiainaNum.ZERO.clone())) {
1205
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1206
+ return PowiainaNum.NaN.clone();
1207
+ }
1072
1208
  // base^base^... = x? (? bases)
1073
1209
  var r = 0;
1074
1210
  // 计算x与base的差距
1075
- var t = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1076
- if (t > 3) {
1077
- var l = t - 3;
1211
+ var distanceLayerOf = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
1212
+ if (distanceLayerOf > 3) {
1213
+ var l = distanceLayerOf - 3;
1078
1214
  r += l;
1079
1215
  x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
1080
1216
  }
@@ -1092,6 +1228,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1092
1228
  }
1093
1229
  }
1094
1230
  if (x.gt(10)) return new PowiainaNum(r);
1231
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1095
1232
  return PowiainaNum.NaN.clone();
1096
1233
  };
1097
1234
  }
@@ -1116,18 +1253,18 @@ var PowiainaNum = /*#__PURE__*/function () {
1116
1253
  }
1117
1254
  }, {
1118
1255
  key: "pentate",
1119
- value: function pentate(other) {
1120
- return this.arrow(3)(other);
1256
+ value: function pentate(other, payload) {
1257
+ return this.arrow(3)(other, payload);
1121
1258
  }
1122
1259
  }, {
1123
1260
  key: "hexate",
1124
- value: function hexate(other) {
1125
- return this.arrow(4)(other);
1261
+ value: function hexate(other, payload) {
1262
+ return this.arrow(4)(other, payload);
1126
1263
  }
1127
1264
  }, {
1128
1265
  key: "pent",
1129
- value: function pent(other) {
1130
- return this.arrow(3)(other);
1266
+ value: function pent(other, payload) {
1267
+ return this.arrow(3)(other, payload);
1131
1268
  }
1132
1269
  }, {
1133
1270
  key: "penta_log",
@@ -1135,6 +1272,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1135
1272
  var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
1136
1273
  return this.anyarrow_log(3)(base);
1137
1274
  }
1275
+ }, {
1276
+ key: "expansion",
1277
+ value:
1138
1278
  /**
1139
1279
  * Expansion, which is `this`{{1}}`other2`.
1140
1280
  *
@@ -1142,15 +1282,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1142
1282
  *
1143
1283
  * @url https://googology.fandom.com/wiki/Expansion
1144
1284
  */
1145
- }, {
1146
- key: "expansion",
1147
- value: function expansion(other2) {
1285
+ function expansion(other2) {
1148
1286
  var other = new PowiainaNum(other2);
1149
1287
  var t = this.clone();
1150
1288
  if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
1151
1289
  if (other.eq(PowiainaNum.ONE)) return this.clone();
1152
1290
  if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
1153
- if (!this.isInt()) return PowiainaNum.NaN.clone();
1291
+ if (!this.isInt()) {
1292
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1293
+ return PowiainaNum.NaN.clone();
1294
+ }
1154
1295
  if (this.eq(2)) return new PowiainaNum(4);
1155
1296
  if (other.eq(0)) return PowiainaNum.ONE.clone();
1156
1297
  var r;
@@ -1190,6 +1331,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1190
1331
  var arrow = new PowiainaNum(arrow2);
1191
1332
  var t = this.clone();
1192
1333
  if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
1334
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1193
1335
  return PowiainaNum.NaN.clone();
1194
1336
  };
1195
1337
  if (arrow.eq(0)) return function (other) {
@@ -1204,9 +1346,13 @@ var PowiainaNum = /*#__PURE__*/function () {
1204
1346
  var other = new PowiainaNum(other2);
1205
1347
  var r;
1206
1348
  if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
1207
- if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
1349
+ if (other.lt(PowiainaNum.ZERO)) {
1350
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1351
+ return PowiainaNum.NaN.clone();
1352
+ }
1208
1353
  if (t.eq(PowiainaNum.ZERO)) {
1209
1354
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
1355
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
1210
1356
  return PowiainaNum.NaN.clone();
1211
1357
  }
1212
1358
  if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
@@ -1392,6 +1538,12 @@ var PowiainaNum = /*#__PURE__*/function () {
1392
1538
  var other = new PowiainaNum(x).abs();
1393
1539
  return this.abs().cmp(other);
1394
1540
  }
1541
+ /**
1542
+ * -1: `this` is smaller
1543
+ * 0: equals
1544
+ * 1: `x` is smaller
1545
+ * 2: NaN
1546
+ */
1395
1547
  }, {
1396
1548
  key: "compare",
1397
1549
  value: function compare(x) {
@@ -1399,6 +1551,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1399
1551
  if (this.isNaN() || other.isNaN()) return 2;
1400
1552
  if (this.sign < other.sign) return -1;
1401
1553
  if (this.sign > other.sign) return 1;
1554
+ var t = this;
1402
1555
  //this.sign = other.sign
1403
1556
  var allneg = this.sign == -1 && other.sign == -1;
1404
1557
  if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
@@ -1410,6 +1563,18 @@ var PowiainaNum = /*#__PURE__*/function () {
1410
1563
  for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
1411
1564
  var op1 = this.array[this.array.length - 1 - i];
1412
1565
  var op2 = other.array[other.array.length - 1 - i];
1566
+ if (op1.repeat === Infinity && op2.repeat === Infinity) {
1567
+ if (t.small === other.small) return 0;
1568
+ return other.small ? 1 : -1;
1569
+ }
1570
+ if (op1.repeat === Infinity) {
1571
+ result = 1;
1572
+ break;
1573
+ }
1574
+ if (op2.repeat === Infinity) {
1575
+ result = -1;
1576
+ break;
1577
+ }
1413
1578
  var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
1414
1579
  if (cmp == 1) {
1415
1580
  result = 1;
@@ -1457,6 +1622,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1457
1622
  var t = this.cmp(other);
1458
1623
  return t == 0 || t == 1;
1459
1624
  }
1625
+ }, {
1626
+ key: "equals",
1627
+ value: function equals(other) {
1628
+ return this.eq(other);
1629
+ }
1630
+ }, {
1631
+ key: "notEquals",
1632
+ value: function notEquals(other) {
1633
+ return this.neq(other);
1634
+ }
1460
1635
  }, {
1461
1636
  key: "eq_tolerance",
1462
1637
  value: function eq_tolerance(value) {
@@ -1466,6 +1641,7 @@ var PowiainaNum = /*#__PURE__*/function () {
1466
1641
  }
1467
1642
  //#endregion
1468
1643
  //#region geometry
1644
+ /**this function is indistinguishable above 4503599627370496*/
1469
1645
  }, {
1470
1646
  key: "sin",
1471
1647
  value: function sin() {
@@ -1518,6 +1694,16 @@ var PowiainaNum = /*#__PURE__*/function () {
1518
1694
  a.small = !a.small;
1519
1695
  return a;
1520
1696
  }
1697
+ }, {
1698
+ key: "recip",
1699
+ value: function recip() {
1700
+ return this.rec();
1701
+ }
1702
+ }, {
1703
+ key: "reciprocate",
1704
+ value: function reciprocate() {
1705
+ return this.rec();
1706
+ }
1521
1707
  }, {
1522
1708
  key: "floor",
1523
1709
  value: function floor() {
@@ -1558,6 +1744,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1558
1744
  r.sign = this.sign;
1559
1745
  return r;
1560
1746
  }
1747
+ }, {
1748
+ key: "trunc",
1749
+ value:
1561
1750
  /**
1562
1751
  * Work like `Math.trunc`,
1563
1752
  *
@@ -1570,15 +1759,10 @@ var PowiainaNum = /*#__PURE__*/function () {
1570
1759
  * new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
1571
1760
  * @returns
1572
1761
  */
1573
- }, {
1574
- key: "trunc",
1575
- value: function trunc() {
1762
+ function trunc() {
1576
1763
  var y = this.clone();
1577
1764
  return y.gte(0) ? y.floor() : y.ceil();
1578
1765
  }
1579
- /**
1580
- * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
1581
- */
1582
1766
  }, {
1583
1767
  key: "isNaN",
1584
1768
  value: function (_isNaN) {
@@ -1641,10 +1825,164 @@ var PowiainaNum = /*#__PURE__*/function () {
1641
1825
  value: function isneg() {
1642
1826
  return this.sign < 0;
1643
1827
  }
1828
+ }, {
1829
+ key: "getOperatorIndex",
1830
+ value:
1831
+ //#endregion
1832
+ //#region operators
1833
+ /**
1834
+ * @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.
1835
+ */
1836
+ function getOperatorIndex(arrow) {
1837
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1838
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1839
+ for (var i = 0; i < this.array.length; i++) {
1840
+ var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
1841
+ if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
1842
+ if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
1843
+ }
1844
+ return this.array.length - 0.5;
1845
+ }
1846
+ /**
1847
+ * @returns number repeats of operators with given arguments.
1848
+ */
1849
+ }, {
1850
+ key: "getOperator",
1851
+ value: function getOperator(arrow) {
1852
+ var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1853
+ var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1854
+ var index = this.getOperatorIndex(arrow, expans, megota);
1855
+ if (!this.array[index]) return 0;
1856
+ return this.array[index].repeat;
1857
+ }
1858
+ /**
1859
+ * Modify the repeat of operator
1860
+ * @param number val the repeat of operator will modify to array.
1861
+ * @returns bool Is the operators array changed?
1862
+ */
1863
+ }, {
1864
+ key: "setOperator",
1865
+ value: function setOperator(val, arrow) {
1866
+ var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1867
+ var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1868
+ // if (arrow!=0&&val==0) return false;
1869
+ var index = this.getOperatorIndex(arrow, expans, megota);
1870
+ if (!this.array[index]) {
1871
+ this.array.splice(Math.ceil(index), 0, {
1872
+ arrow: arrow,
1873
+ expans: expans,
1874
+ megota: megota,
1875
+ valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
1876
+ repeat: val
1877
+ });
1878
+ return true;
1879
+ }
1880
+ this.array[index].repeat = val;
1881
+ // this.normalize()
1882
+ return false;
1883
+ }
1884
+ //#endregion
1885
+ //#region converters
1886
+ /**
1887
+ * Convert `this` to Javascript `number`
1888
+ *
1889
+ * returns `Infinity` when the number is greater than `Number.MAX_VALUE`
1890
+ */
1891
+ }, {
1892
+ key: "toNumber",
1893
+ value: function toNumber() {
1894
+ if (this.sign == -1) return -this.neg().toNumber();
1895
+ if (this.small) return 1 / this.rec().toNumber();
1896
+ if (this.array.length > 2) return Infinity;
1897
+ 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));
1898
+ return NaN;
1899
+ }
1900
+ /**
1901
+ * Convert `this` to a string
1902
+ */
1903
+ }, {
1904
+ key: "toString_core",
1905
+ value: function toString_core() {
1906
+ if (this.isNaN()) return "NaN";
1907
+ if (this.sign == -1) return "-".concat(this.neg().toString());
1908
+ if (this.small) {
1909
+ if (this.isZero()) return "0";
1910
+ return "/".concat(this.rec().toString());
1911
+ }
1912
+ if (this.isInfi()) return "Infinity";
1913
+ // P^a (10{arrow,expans,megota})^repeation base
1914
+ var res = "";
1915
+ if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
1916
+ for (var i = this.array.length - 1; i >= 0; i--) {
1917
+ var oper = this.array[i];
1918
+ 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) : "", "}");
1919
+ if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
1920
+ calc = "e".repeat(oper.repeat);
1921
+ } else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
1922
+ calc = oper.repeat.toString();
1923
+ } else if (oper.repeat > 1) {
1924
+ calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
1925
+ } else {
1926
+ calc = "".concat(calc);
1927
+ }
1928
+ res += "".concat(calc);
1929
+ }
1930
+ return res;
1931
+ }
1932
+ }, {
1933
+ key: "toString",
1934
+ value: function toString() {
1935
+ try {
1936
+ return this.toString_core();
1937
+ } catch (_b) {
1938
+ console.error("Checked error when converting to string");
1939
+ return "NaN";
1940
+ }
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
+ //#endregion
1977
+ //#region useless functions
1978
+ /**
1979
+ * This function is for NaNe308, if you want to calculate G(x), use this function directly.
1980
+ */
1644
1981
  }, {
1645
1982
  key: "normalize",
1646
1983
  value:
1647
1984
  //#endregion
1985
+ //#region other functions
1648
1986
  /**
1649
1987
  * Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
1650
1988
  * @returns normalized number
@@ -1653,9 +1991,14 @@ var PowiainaNum = /*#__PURE__*/function () {
1653
1991
  //TODO: normalize
1654
1992
  var renormalize = true;
1655
1993
  var x = this;
1656
- for (var _i = 0; _i < this.array.length; _i++) {
1994
+ if (this.array === undefined) {
1995
+ x.array = [newOperator(NaN, 0, 1, 1)];
1996
+ }
1997
+ if (this.sign === undefined) this.sign = 0;
1998
+ if (this.layer === undefined) this.layer = 0;
1999
+ for (var i = 0; i < this.array.length; i++) {
1657
2000
  // Check what is infinity
1658
- if (this.array[_i].repeat == Infinity) {
2001
+ if (this.array[i].repeat == Infinity) {
1659
2002
  this.array = [{
1660
2003
  arrow: 0,
1661
2004
  expans: 1,
@@ -1666,8 +2009,8 @@ var PowiainaNum = /*#__PURE__*/function () {
1666
2009
  return this;
1667
2010
  }
1668
2011
  }
1669
- for (var i = 1; i < x.array.length; ++i) {
1670
- var e = x.array[i];
2012
+ for (var _i = 1; _i < x.array.length; ++_i) {
2013
+ var e = x.array[_i];
1671
2014
  if (e.arrow === null || e.arrow === undefined) {
1672
2015
  e.arrow = 0;
1673
2016
  }
@@ -1698,28 +2041,28 @@ var PowiainaNum = /*#__PURE__*/function () {
1698
2041
  renormalize = false;
1699
2042
  // Sort arrays.
1700
2043
  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) {
2044
+ for (var _i2 = 1; _i2 < x.array.length - 1; ++_i2) {
2045
+ 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
2046
  // same array's merge
1704
- x.array[i].repeat += x.array[i + 1].repeat;
1705
- x.array.splice(i + 1, 1);
1706
- --i;
2047
+ x.array[_i2].repeat += x.array[_i2 + 1].repeat;
2048
+ x.array.splice(_i2 + 1, 1);
2049
+ --_i2;
1707
2050
  renormalize = true;
1708
2051
  }
1709
2052
  }
1710
- for (i = 1; i < x.array.length; ++i) {
2053
+ for (var _i3 = 1; _i3 < x.array.length; ++_i3) {
1711
2054
  // 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;
2055
+ if (x.array[_i3].arrow !== 0 && (x.array[_i3].repeat === 0 || x.array[_i3].repeat === null || x.array[_i3].repeat === undefined)) {
2056
+ x.array.splice(_i3, 1);
2057
+ --_i3;
1715
2058
  continue;
1716
2059
  }
1717
2060
  // If there is a operator which arrow 0 and brace count >=2
1718
2061
  // 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;
2062
+ if (x.array[_i3].arrow == 0 && x.array[_i3].expans >= 2) {
2063
+ x.array[_i3].arrow = Infinity;
2064
+ x.array[_i3].valuereplaced = 0;
2065
+ x.array[_i3].expans = x.array[_i3].expans - 1;
1723
2066
  }
1724
2067
  }
1725
2068
  if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
@@ -1749,6 +2092,11 @@ var PowiainaNum = /*#__PURE__*/function () {
1749
2092
  this.small = !this.small;
1750
2093
  renormalize = true;
1751
2094
  }
2095
+ // for a = 1, small should false.
2096
+ if (this.array.length == 1 && this.array[0].repeat == 1 && this.small) {
2097
+ this.small = false;
2098
+ renormalize = true;
2099
+ }
1752
2100
  // for any 10{X>9e15}10, replace into 10{!}X;
1753
2101
  if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
1754
2102
  this.array[0].repeat = this.array[1].arrow;
@@ -1804,61 +2152,6 @@ var PowiainaNum = /*#__PURE__*/function () {
1804
2152
  } while (renormalize);
1805
2153
  return this;
1806
2154
  }
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
2155
  /**
1863
2156
  * @returns a PowiainaNum object which deep copied from `this` object.
1864
2157
  */
@@ -1877,6 +2170,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1877
2170
  }, {
1878
2171
  key: "resetFromObject",
1879
2172
  value: function resetFromObject(powlikeObject) {
2173
+ if (!powlikeObject.array) {
2174
+ return;
2175
+ }
1880
2176
  this.array = [];
1881
2177
  for (var i = 0; i < powlikeObject.array.length; i++) {
1882
2178
  this.array[i] = {
@@ -1892,107 +2188,56 @@ var PowiainaNum = /*#__PURE__*/function () {
1892
2188
  this.layer = powlikeObject.layer;
1893
2189
  return this;
1894
2190
  }
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
2191
  }], [{
1977
2192
  key: "add",
1978
2193
  value: function add(t, other) {
1979
2194
  return new PowiainaNum(t).add(other);
1980
2195
  }
2196
+ }, {
2197
+ key: "plus",
2198
+ value: function plus(t, other) {
2199
+ return new PowiainaNum(t).add(other);
2200
+ }
1981
2201
  }, {
1982
2202
  key: "sub",
1983
2203
  value: function sub(t, other) {
1984
2204
  return new PowiainaNum(t).sub(other);
1985
2205
  }
2206
+ }, {
2207
+ key: "minus",
2208
+ value: function minus(t, other) {
2209
+ return new PowiainaNum(t).sub(other);
2210
+ }
1986
2211
  }, {
1987
2212
  key: "mul",
1988
2213
  value: function mul(t, other) {
1989
2214
  return new PowiainaNum(t).mul(other);
1990
2215
  }
2216
+ }, {
2217
+ key: "times",
2218
+ value: function times(t, other) {
2219
+ return new PowiainaNum(t).mul(other);
2220
+ }
1991
2221
  }, {
1992
2222
  key: "div",
1993
2223
  value: function div(t, other) {
1994
2224
  return new PowiainaNum(t).div(other);
1995
2225
  }
2226
+ }, {
2227
+ key: "divide",
2228
+ value: function divide(t, other) {
2229
+ return new PowiainaNum(t).div(other);
2230
+ }
2231
+ }, {
2232
+ key: "mod",
2233
+ value: function mod(x, y) {
2234
+ return new PowiainaNum(x).mod(y);
2235
+ }
2236
+ }, {
2237
+ key: "modulus",
2238
+ value: function modulus(x, y) {
2239
+ return new PowiainaNum(x).mod(y);
2240
+ }
1996
2241
  }, {
1997
2242
  key: "pow",
1998
2243
  value: function pow(t, other) {
@@ -2024,6 +2269,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2024
2269
  var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2025
2270
  return new PowiainaNum(t).log(base);
2026
2271
  }
2272
+ }, {
2273
+ key: "log2",
2274
+ value: function log2(t) {
2275
+ return new PowiainaNum(t).log2();
2276
+ }
2277
+ }, {
2278
+ key: "logBase",
2279
+ value: function logBase(t) {
2280
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
2281
+ return new PowiainaNum(t).log(base);
2282
+ }
2027
2283
  }, {
2028
2284
  key: "pLog10",
2029
2285
  value: function pLog10(t) {
@@ -2175,6 +2431,27 @@ var PowiainaNum = /*#__PURE__*/function () {
2175
2431
  };
2176
2432
  }
2177
2433
  }
2434
+ }, {
2435
+ key: "pentate",
2436
+ value: function pentate(x, other, payload) {
2437
+ return new PowiainaNum(x).arrow(3)(other, payload);
2438
+ }
2439
+ }, {
2440
+ key: "hexate",
2441
+ value: function hexate(x, other, payload) {
2442
+ return new PowiainaNum(x).arrow(4)(other, payload);
2443
+ }
2444
+ }, {
2445
+ key: "pent",
2446
+ value: function pent(x, other, payload) {
2447
+ return new PowiainaNum(x).arrow(3)(other, payload);
2448
+ }
2449
+ }, {
2450
+ key: "penta_log",
2451
+ value: function penta_log(x) {
2452
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
2453
+ return new PowiainaNum(x).anyarrow_log(3)(base);
2454
+ }
2178
2455
  }, {
2179
2456
  key: "expansion",
2180
2457
  value: function expansion(t, other) {
@@ -2230,7 +2507,10 @@ var PowiainaNum = /*#__PURE__*/function () {
2230
2507
  if (base.eq(1)) return new PowiainaNum(1);
2231
2508
  if (power.eq(1)) return new PowiainaNum(base);
2232
2509
  if (power.isZero()) return new PowiainaNum(1);
2233
- if (base.lt(0)) return PowiainaNum.NaN.clone();
2510
+ if (base.lt(0)) {
2511
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
2512
+ return PowiainaNum.NaN.clone();
2513
+ }
2234
2514
  // // check infinite
2235
2515
  // let sufpowiaina = args.slice(4);
2236
2516
  // if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
@@ -2273,9 +2553,6 @@ var PowiainaNum = /*#__PURE__*/function () {
2273
2553
  if (a == 0 && e == 1 && m > 1) {
2274
2554
  return [1, 1 / 0, m - 1];
2275
2555
  }
2276
- if (e == 0 && m > 1) {
2277
- return [1, 1 / 0, m - 1];
2278
- }
2279
2556
  return [a, e, m];
2280
2557
  }
2281
2558
  if (megota.gt(MSI)) {
@@ -2289,8 +2566,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2289
2566
  return x.toString();
2290
2567
  }
2291
2568
  function getMSIForm(arrow, expans, megota) {
2292
- var conv = convertOperator(arrow, expans, megota);
2293
- return "10{".concat(infToBang(conv[0]), ",").concat(infToBang(conv[1]), ",").concat(conv[2], "}").concat(MSI);
2569
+ return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
2294
2570
  }
2295
2571
  var t = base.clone();
2296
2572
  var arrows = new PowiainaNum(readArg(0));
@@ -2298,20 +2574,13 @@ var PowiainaNum = /*#__PURE__*/function () {
2298
2574
  var _r, _r2;
2299
2575
  var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2300
2576
  console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
2301
- if (depth >= 200) {
2302
- return new PowiainaNum({
2303
- layer: 0,
2304
- array: [newOperator(10), newOperator(1, new PowiainaNum(arrow2).clampMax(MSI).toNumber(), new PowiainaNum(expans2).clampMax(MSI).toNumber(), new PowiainaNum(megota2).clampMax(MSI).toNumber())],
2305
- sign: 1,
2306
- small: false
2307
- }).normalize();
2308
- }
2309
2577
  var other = new PowiainaNum(other2);
2310
2578
  var r;
2311
2579
  if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
2312
2580
  if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
2313
2581
  if (t.eq(PowiainaNum.ZERO)) {
2314
2582
  if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
2583
+ if (PowiainaNum.throwErrorOnResultNaN) throw new Error("NaN");
2315
2584
  return PowiainaNum.NaN.clone();
2316
2585
  }
2317
2586
  if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
@@ -2323,7 +2592,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2323
2592
  }
2324
2593
  if (expans.eq(0)) {
2325
2594
  return PowiainaNum.BEAF(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
2326
- // {this, this, power, expans-1, megota}
2595
+ // {this, this, this, power, megota-1}
2327
2596
  }
2328
2597
  if (megota.eq(0)) {
2329
2598
  return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
@@ -2442,6 +2711,84 @@ var PowiainaNum = /*#__PURE__*/function () {
2442
2711
  value: function clampMax() {
2443
2712
  return PowiainaNum.min.apply(PowiainaNum, arguments);
2444
2713
  }
2714
+ }, {
2715
+ key: "eq",
2716
+ value: function eq(a, o) {
2717
+ return new PowiainaNum(a).eq(o);
2718
+ }
2719
+ }, {
2720
+ key: "equals",
2721
+ value: function equals(a, o) {
2722
+ return new PowiainaNum(a).eq(o);
2723
+ }
2724
+ }, {
2725
+ key: "neq",
2726
+ value: function neq(a, o) {
2727
+ return new PowiainaNum(a).neq(o);
2728
+ }
2729
+ }, {
2730
+ key: "notEquals",
2731
+ value: function notEquals(a, o) {
2732
+ return new PowiainaNum(a).notEquals(o);
2733
+ }
2734
+ }, {
2735
+ key: "lt",
2736
+ value: function lt(a, o) {
2737
+ return new PowiainaNum(a).lt(o);
2738
+ }
2739
+ }, {
2740
+ key: "gt",
2741
+ value: function gt(a, o) {
2742
+ return new PowiainaNum(a).gt(o);
2743
+ }
2744
+ }, {
2745
+ key: "lte",
2746
+ value: function lte(a, o) {
2747
+ return new PowiainaNum(a).lte(o);
2748
+ }
2749
+ }, {
2750
+ key: "gte",
2751
+ value: function gte(a, o) {
2752
+ return new PowiainaNum(a).gte(o);
2753
+ }
2754
+ }, {
2755
+ key: "rec",
2756
+ value: function rec(t) {
2757
+ return new PowiainaNum(t).rec();
2758
+ }
2759
+ }, {
2760
+ key: "recip",
2761
+ value: function recip(t) {
2762
+ return new PowiainaNum(t).rec();
2763
+ }
2764
+ }, {
2765
+ key: "reciprocate",
2766
+ value: function reciprocate(t) {
2767
+ return new PowiainaNum(t).rec();
2768
+ }
2769
+ }, {
2770
+ key: "floor",
2771
+ value: function floor(x) {
2772
+ return new PowiainaNum(x).floor();
2773
+ }
2774
+ }, {
2775
+ key: "ceil",
2776
+ value: function ceil(x) {
2777
+ return new PowiainaNum(x).ceil();
2778
+ }
2779
+ }, {
2780
+ key: "round",
2781
+ value: function round(x) {
2782
+ return new PowiainaNum(x).round();
2783
+ }
2784
+ }, {
2785
+ key: "trunc",
2786
+ value: function trunc(x) {
2787
+ return new PowiainaNum(x).trunc();
2788
+ }
2789
+ /**
2790
+ * @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
2791
+ */
2445
2792
  }, {
2446
2793
  key: "sign",
2447
2794
  value: function sign(a) {
@@ -2455,7 +2802,19 @@ var PowiainaNum = /*#__PURE__*/function () {
2455
2802
  }, {
2456
2803
  key: "fromNumber",
2457
2804
  value: function fromNumber(x) {
2458
- var obj = new PowiainaNum(); // NaN
2805
+ var obj = new PowiainaNum();
2806
+ obj.resetFromObject({
2807
+ array: [{
2808
+ arrow: 0,
2809
+ expans: 1,
2810
+ megota: 1,
2811
+ repeat: NaN
2812
+ }],
2813
+ small: false,
2814
+ layer: 0,
2815
+ sign: 0
2816
+ });
2817
+ if (Number.isNaN(x)) return obj;
2459
2818
  if (x < 0) obj.sign = -1; // negative
2460
2819
  else if (x == 0) {
2461
2820
  obj.sign = 0;
@@ -2483,10 +2842,26 @@ var PowiainaNum = /*#__PURE__*/function () {
2483
2842
  }, {
2484
2843
  key: "fromString",
2485
2844
  value: function fromString(input) {
2845
+ if (PowiainaNum.usingBreakEternityLikeFromString && BE_REGEX.test(input)) {
2846
+ /*
2847
+ * 0i00000000a7 says that eee-3000 will wrongly parse to 1. So i added this
2848
+ */
2849
+ var a = input.match(/(e+-)(\d+(.\d+)?)/);
2850
+ if (a) {
2851
+ var e_s = a[1].length;
2852
+ input = "e-" + "e".repeat(e_s - 1) + a[2];
2853
+ }
2854
+ }
2855
+ return this.fromString_core(input);
2856
+ }
2857
+ }, {
2858
+ key: "fromString_core",
2859
+ value: function fromString_core(input) {
2486
2860
  var _b, _c, _d, _e, _f, _g;
2487
- var x = new PowiainaNum();
2861
+ var x = new PowiainaNum(NaN);
2488
2862
  // Judge the string was a number
2489
2863
  if (input.startsWith("PN")) input = input.substring(2);
2864
+ if (input == "NaN") return PowiainaNum.NaN.clone();
2490
2865
  input = input.replace(/J\^(\d+)/g, "(10{!})^$1");
2491
2866
  input = input.replace(/J/g, "10{!}");
2492
2867
  input = input.replace(/K\^(\d+)/g, "(10{1,2})^$1");
@@ -2497,17 +2872,20 @@ var PowiainaNum = /*#__PURE__*/function () {
2497
2872
  input = input.replace(/M/g, "10{!,2}");
2498
2873
  input = input.replace(/N\^(\d+)/g, "(10{1,!})^$1");
2499
2874
  input = input.replace(/N/g, "10{1,!}");
2875
+ if (/^.*e-.*(e|\^).*/.test(input)) {
2876
+ input = "/10^" + input.substring(input.indexOf("e-"));
2877
+ }
2500
2878
  if (!isNaN(Number(input))) {
2501
2879
  var res = Number(input);
2502
- var _a3 = false;
2880
+ var a = false;
2503
2881
  if (res == 0) {
2504
2882
  if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
2505
- _a3 = true;
2883
+ a = true;
2506
2884
  }
2507
2885
  } else {
2508
- _a3 = true;
2886
+ a = true;
2509
2887
  }
2510
- if (!_a3) {
2888
+ if (!a) {
2511
2889
  var m = input.search(/e/);
2512
2890
  var exponent = input.substring((m == -1 ? input.length : m) + 1);
2513
2891
  var mantissa = input.substring(0, m == -1 ? undefined : m);
@@ -2517,11 +2895,11 @@ var PowiainaNum = /*#__PURE__*/function () {
2517
2895
  // Is regular number gte 1:
2518
2896
  if (Number(mantissa) >= 1) {
2519
2897
  // check The mantissa is very long?
2520
- var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
2521
- var log10int = Math.floor(log10mant);
2522
- var log10float = log10mant - log10int;
2898
+ var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa)); // sample 10
2899
+ var log10int = Math.floor(log10mant); // sample 1
2900
+ var log10float = log10mant - log10int; // sample 0;
2523
2901
  mantissaME[0] = Math.pow(10, log10float);
2524
- mantissaME[1] += log10float;
2902
+ mantissaME[1] += log10int;
2525
2903
  } else {
2526
2904
  // If not , count how many zeros until reached non-zero numbers
2527
2905
  var zeros = countLeadingZerosAfterDecimal(mantissa);
@@ -2536,7 +2914,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2536
2914
  // /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
2537
2915
  return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
2538
2916
  }
2539
- if (isFinite(res) && _a3) {
2917
+ if (isFinite(res) && a) {
2540
2918
  x = PowiainaNum.fromNumber(Number(input));
2541
2919
  return x;
2542
2920
  }
@@ -2553,6 +2931,7 @@ var PowiainaNum = /*#__PURE__*/function () {
2553
2931
  return x;
2554
2932
  }
2555
2933
  input = replaceETo10(input);
2934
+ input = removeCommasOutsideBraces(input);
2556
2935
  if (!isPowiainaNum.test(input)) {
2557
2936
  throw powiainaNumError + "malformed input: " + input;
2558
2937
  }
@@ -2565,28 +2944,31 @@ var PowiainaNum = /*#__PURE__*/function () {
2565
2944
  input = input.substring(numSigns);
2566
2945
  }
2567
2946
  if (input[0] == "/") {
2568
- var numSigns = input.search(/[^\/]/);
2569
- var signs = input.substring(0, numSigns);
2570
- recipIt = ((_e = (_d = signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2571
- input = input.substring(numSigns);
2947
+ var _numSigns = input.search(/[^\/]/);
2948
+ var _signs = input.substring(0, _numSigns);
2949
+ recipIt = ((_e = (_d = _signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
2950
+ input = input.substring(_numSigns);
2572
2951
  }
2573
2952
  if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
2574
2953
  x.sign = 1;
2575
2954
  x.array = [newOperator(0)];
2576
- var a, b, c, d;
2955
+ var _a3, b, c, d;
2577
2956
  if (input[0] == "P") {
2578
2957
  if (input[1] == "^") {
2579
- a = input.substring(2).search(/[^0-9]/) + 2;
2580
- x.layer = Number(input.substring(2, a));
2581
- input = input.substring(a + 1);
2958
+ _a3 = input.substring(2).search(/[^0-9]/) + 2;
2959
+ x.layer = Number(input.substring(2, _a3));
2960
+ input = input.substring(_a3 + 1);
2582
2961
  } else {
2583
- a = input.search(/[^P]/);
2584
- x.layer = a;
2585
- input = input.substring(a);
2962
+ _a3 = input.search(/[^P]/);
2963
+ x.layer = _a3;
2964
+ input = input.substring(_a3);
2586
2965
  }
2587
2966
  }
2588
2967
  while (input) {
2589
2968
  if (/^(\(?10[\^\{])/.test(input)) {
2969
+ var arrows = void 0,
2970
+ expans = void 0,
2971
+ megota = void 0;
2590
2972
  /*
2591
2973
  10^ - 匹配
2592
2974
  10{ - 匹配
@@ -2597,30 +2979,29 @@ var PowiainaNum = /*#__PURE__*/function () {
2597
2979
  */
2598
2980
  if (input[0] == "(") input = input.substring(1);
2599
2981
  //cutted, 10^.... or 10{....
2600
- var arrows, expans, megota;
2601
2982
  if (input[2] == "^") {
2602
- a = input.substring(2).search(/[^\^]/);
2983
+ _a3 = input.substring(2).search(/[^\^]/);
2603
2984
  //cut input to ^^...^^, and search how numbers
2604
- arrows = a;
2985
+ arrows = _a3;
2605
2986
  // 10^^^
2606
- b = a + 2; // b points to after ^'s.
2987
+ b = _a3 + 2; // b points to after ^'s.
2607
2988
  } else {
2608
2989
  // 10{...}
2609
- a = input.indexOf("}");
2990
+ _a3 = input.indexOf("}");
2610
2991
  // select contents between {...}
2611
- var tmp = input.substring(3, a).split(",");
2992
+ var tmp = input.substring(3, _a3).split(",");
2612
2993
  arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
2613
2994
  expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
2614
2995
  megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
2615
- b = a + 1;
2996
+ b = _a3 + 1;
2616
2997
  // b points to after }.
2617
2998
  }
2618
2999
  input = input.substring(b);
2619
3000
  if (input[0] == ")") {
2620
3001
  // )^....<Space>
2621
- a = input.indexOf(" ");
2622
- c = Number(input.substring(2, a)); // Select contents between )^....<Space>
2623
- input = input.substring(a + 1); // c points to after <Space>
3002
+ _a3 = input.indexOf(" ");
3003
+ c = Number(input.substring(2, _a3)); // Select contents between )^....<Space>
3004
+ input = input.substring(_a3 + 1); // c points to after <Space>
2624
3005
  } else {
2625
3006
  c = 1; // There is only spaces, count as <ONE>
2626
3007
  }
@@ -2631,21 +3012,21 @@ var PowiainaNum = /*#__PURE__*/function () {
2631
3012
  x.array.splice(1, 0, newOperator(c, 1, expans, megota));
2632
3013
  }
2633
3014
  } else if (arrows == 2 && expans == 1 && megota == 1) {
2634
- a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
3015
+ _a3 = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
2635
3016
  b = x.array[0].repeat;
2636
- if (b >= 1e10) ++a;
2637
- if (b >= 10) ++a;
2638
- x.array[0].repeat = a;
3017
+ if (b >= 1e10) ++_a3;
3018
+ if (b >= 10) ++_a3;
3019
+ x.array[0].repeat = _a3;
2639
3020
  if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
2640
3021
  d = x.getOperatorIndex(2);
2641
3022
  if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
2642
3023
  } else if (isFinite(arrows)) {
2643
- a = x.getOperator(arrows - 1);
3024
+ _a3 = x.getOperator(arrows - 1);
2644
3025
  b = x.getOperator(arrows - 2);
2645
- if (b >= 10) ++a;
3026
+ if (b >= 10) ++_a3;
2646
3027
  d = x.getOperatorIndex(arrows);
2647
3028
  x.array.splice(1, Math.ceil(d) - 1);
2648
- x.array[0].repeat = a;
3029
+ x.array[0].repeat = _a3;
2649
3030
  if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
2650
3031
  } else {
2651
3032
  x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
@@ -2654,10 +3035,10 @@ var PowiainaNum = /*#__PURE__*/function () {
2654
3035
  break;
2655
3036
  }
2656
3037
  }
2657
- a = input.split(/[Ee]/);
3038
+ _a3 = input.split(/[Ee]/);
2658
3039
  b = [x.array[0].repeat, 0];
2659
3040
  c = 1;
2660
- for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
3041
+ for (var i = _a3.length - 1; i >= 0; --i) {
2661
3042
  //The things that are already there
2662
3043
  if (b[0] < MSI_LOG10 && b[1] === 0) {
2663
3044
  b[0] = Math.pow(10, c * b[0]);
@@ -2674,12 +3055,12 @@ var PowiainaNum = /*#__PURE__*/function () {
2674
3055
  b[1]++;
2675
3056
  }
2676
3057
  //Multiplying coefficient
2677
- var decimalPointPos = a[_i2].indexOf(".");
2678
- var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
3058
+ var decimalPointPos = _a3[i].indexOf(".");
3059
+ var intPartLen = decimalPointPos == -1 ? _a3[i].length : decimalPointPos;
2679
3060
  if (b[1] === 0) {
2680
- 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]);
3061
+ 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]);
2681
3062
  } else {
2682
- d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
3063
+ d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(_a3[i].substring(0, intPartLen)) : _a3[i] ? Math.log10(Number(_a3[i])) : 0;
2683
3064
  if (b[1] == 1) {
2684
3065
  b[0] += d;
2685
3066
  } else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
@@ -2710,6 +3091,17 @@ var PowiainaNum = /*#__PURE__*/function () {
2710
3091
  key: "fromObject",
2711
3092
  value: function fromObject(powlikeObject) {
2712
3093
  var obj = new PowiainaNum();
3094
+ obj.resetFromObject({
3095
+ array: [{
3096
+ arrow: 0,
3097
+ expans: 1,
3098
+ megota: 1,
3099
+ repeat: NaN
3100
+ }],
3101
+ small: false,
3102
+ layer: 0,
3103
+ sign: 0
3104
+ });
2713
3105
  obj.array = [];
2714
3106
  if (isExpantaNumArray(powlikeObject)) {
2715
3107
  for (var i = 0; i < powlikeObject.length; i++) {
@@ -2727,8 +3119,8 @@ var PowiainaNum = /*#__PURE__*/function () {
2727
3119
  } else if (isPowiainaNum01XArray(powlikeObject)) {
2728
3120
  var arrayobj = powlikeObject;
2729
3121
  obj.array[0] = newOperator(arrayobj[0]);
2730
- for (var _i3 = 1; _i3 < arrayobj.length; _i3++) {
2731
- var b = arrayobj[_i3];
3122
+ for (var _i4 = 1; _i4 < arrayobj.length; _i4++) {
3123
+ var b = arrayobj[_i4];
2732
3124
  obj.array[1] = newOperator(b[1], replaceXToInfinity(b[0]), replaceXToInfinity(b[2]), b[3]);
2733
3125
  }
2734
3126
  obj.small = false;
@@ -2736,21 +3128,21 @@ var PowiainaNum = /*#__PURE__*/function () {
2736
3128
  obj.layer = 0;
2737
3129
  return obj;
2738
3130
  } else {
2739
- for (var _i4 = 0; _i4 < powlikeObject.array.length; _i4++) {
2740
- obj.array[_i4] = {
2741
- arrow: powlikeObject.array[_i4].arrow,
2742
- expans: powlikeObject.array[_i4].expans,
2743
- megota: powlikeObject.array[_i4].megota,
2744
- repeat: powlikeObject.array[_i4].repeat,
2745
- valuereplaced: powlikeObject.array[_i4].valuereplaced
2746
- };
2747
- }
2748
- obj.small = powlikeObject.small;
2749
- obj.sign = powlikeObject.sign;
2750
- obj.layer = powlikeObject.layer;
3131
+ obj.resetFromObject(powlikeObject);
2751
3132
  return obj;
2752
3133
  }
2753
3134
  }
3135
+ }, {
3136
+ key: "grahalFunction",
3137
+ value: function grahalFunction(layers2) {
3138
+ var layers = new PowiainaNum(layers2);
3139
+ if (!layers.isInt() || layers.lt(0) || layers.isNaN()) return PowiainaNum.NaN.clone();
3140
+ if (layers.eq(1)) return new PowiainaNum("10^^^(10^)^7625597484984 3638334640023.7783");else if (layers.lte(MSI)) {
3141
+ return new PowiainaNum("(10{!})^".concat(layers.toNumber(), " 10^^^(10^)^7625597484984 3638334640023.7783"));
3142
+ } else {
3143
+ return PowiainaNum.BEAF(3, layers, 1, 2);
3144
+ }
3145
+ }
2754
3146
  }]);
2755
3147
  }();
2756
3148
  _a = Symbol.toStringTag;
@@ -2967,6 +3359,20 @@ PowiainaNum.maxOps = 100;
2967
3359
  PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
2968
3360
  //#endregion
2969
3361
  PowiainaNum.arrowFuncMap = new Map();
3362
+ //#region configurations
3363
+ /**
3364
+ * If you set this config to true,
3365
+ * 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.
3366
+ */
3367
+ PowiainaNum.usingBreakEternityLikeFromString = true;
3368
+ /**
3369
+ * If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
3370
+ */
3371
+ PowiainaNum.blankArgumentConstructorReturnZero = false;
3372
+ /**
3373
+ * If you set this config to true, when calucation returns NaN, the program will throw error.
3374
+ */
3375
+ PowiainaNum.throwErrorOnResultNaN = false;
2970
3376
 
2971
3377
  exports.arraySortFunction = arraySortFunction;
2972
3378
  exports["default"] = PowiainaNum;