powiaina_num.js 0.2.0-alpha.2.4 → 0.2.0-alpha.2.6

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.
@@ -324,19 +324,23 @@ var PowiainaNum = /*#__PURE__*/function () {
324
324
  }, {
325
325
  key: "pow10",
326
326
  value: function pow10() {
327
+ var _a, _b;
327
328
  var r = this.clone();
328
329
  // inf & nan check
329
330
  if (!this.isFinite()) return this.clone();
330
- if (r.lt(0)) {
331
+ if (r.isneg()) {
331
332
  // 10^(-x) = 1/(10^x)
332
333
  r.sign *= -1;
333
334
  return r.pow10().rec();
334
335
  }
336
+ if (r.lte(308.25471555991675)) {
337
+ return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
338
+ }
335
339
  if (r.small) {
336
340
  if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
337
- return new PowiainaNum(Math.pow(10, Math.pow(r.getOperator(0), -1)));
341
+ return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
338
342
  }
339
- r.setOperator(r.getOperator(1) + 1, 1);
343
+ r.setOperator(((_b = (_a = r.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0) + 1, 1);
340
344
  r.normalize();
341
345
  return r;
342
346
  }
@@ -347,7 +351,7 @@ var PowiainaNum = /*#__PURE__*/function () {
347
351
  if (!other.isFinite()) return other.clone();
348
352
  if (!this.isFinite()) return this.clone();
349
353
  if (this.eq(10)) return other.pow10();
350
- if (this.lt(0)) {
354
+ if (this.isneg()) {
351
355
  if (!other.isInt()) return PowiainaNum.NaN.clone();
352
356
  var r = this.abs().pow(other);
353
357
  r.sign = function () {
@@ -357,6 +361,13 @@ var PowiainaNum = /*#__PURE__*/function () {
357
361
  }();
358
362
  return r;
359
363
  }
364
+ var a = this.toNumber();
365
+ var b = other.toNumber();
366
+ var t = Math.pow(a, b);
367
+ if (isFinite(t)) {
368
+ // optimize?
369
+ return PowiainaNum.fromNumber(t);
370
+ }
360
371
  // log10(a^b) = b log10(a)
361
372
  return this.log10().mul(other).pow10();
362
373
  }
@@ -392,16 +403,17 @@ var PowiainaNum = /*#__PURE__*/function () {
392
403
  }, {
393
404
  key: "log10",
394
405
  value: function log10() {
395
- if (this.lt(0)) return PowiainaNum.NaN.clone();
406
+ var _a, _b;
407
+ if (this.isneg()) return PowiainaNum.NaN.clone();
396
408
  if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
397
409
  if (this.small) {
398
410
  var _x = this.clone();
399
411
  _x.small = !_x.small;
400
412
  return _x.log10().neg();
401
413
  }
402
- if (this.getOperator(1) == 0) return new PowiainaNum(Math.log10(this.getOperator(0)));
414
+ if ((_b = (_a = this.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0 == 0) return new PowiainaNum(Math.log10(this.array[0].repeat));
403
415
  var x = this.clone();
404
- x.setOperator(x.getOperator(1) - 1, 1);
416
+ x.array[1].repeat = x.array[1].repeat - 1;
405
417
  x.normalize();
406
418
  return x;
407
419
  }
@@ -527,7 +539,7 @@ var PowiainaNum = /*#__PURE__*/function () {
527
539
  return PowiainaNum.NaN.clone(); //complex
528
540
  }
529
541
  if (this.layer === 0) {
530
- return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0), 1e-10, false));
542
+ return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
531
543
  } else if (this.layer == 1) {
532
544
  return d_lambertw(this, 1e-10, false);
533
545
  } else {
@@ -588,7 +600,7 @@ var PowiainaNum = /*#__PURE__*/function () {
588
600
  if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
589
601
  }
590
602
  var r = this.abs();
591
- r.setOperator(Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0)), 0);
603
+ r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
592
604
  return r;
593
605
  }
594
606
  }, {
@@ -599,7 +611,7 @@ var PowiainaNum = /*#__PURE__*/function () {
599
611
  if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
600
612
  }
601
613
  var r = this.abs();
602
- r.setOperator(Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0)), 0);
614
+ r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
603
615
  r.sign = this.sign;
604
616
  return r;
605
617
  }
@@ -615,7 +627,7 @@ var PowiainaNum = /*#__PURE__*/function () {
615
627
  }
616
628
  }
617
629
  var r = this.abs();
618
- r.setOperator(Math.round(r.getOperator(0)), 0);
630
+ r.array[0].repeat = Math.round(r.array[0].repeat);
619
631
  r.sign = this.sign;
620
632
  return r;
621
633
  }
@@ -728,9 +740,19 @@ var PowiainaNum = /*#__PURE__*/function () {
728
740
  value: function isInt() {
729
741
  if (this.isZero()) return true;
730
742
  if (!this.small && Number.isInteger(this.getOperator(0))) return true;
731
- if (this.abs().gte(Math.pow(2, 52))) return true;
743
+ if (this.abs().gte(MSI / 2)) return true;
732
744
  return false;
733
745
  }
746
+ }, {
747
+ key: "ispos",
748
+ value: function ispos() {
749
+ return this.sign > 0;
750
+ }
751
+ }, {
752
+ key: "isneg",
753
+ value: function isneg() {
754
+ return this.sign < 0;
755
+ }
734
756
  }, {
735
757
  key: "normalize",
736
758
  value:
@@ -809,7 +831,6 @@ var PowiainaNum = /*#__PURE__*/function () {
809
831
  }
810
832
  if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
811
833
  if (this.getOperator(1) >= 1 && this.getOperator(0) < MSI_LOG10) {
812
- console.log(this.array);
813
834
  this.setOperator(this.getOperator(1) - 1, 1);
814
835
  this.setOperator(Math.pow(10, this.getOperator(0)), 0);
815
836
  renormalize = true;
@@ -860,6 +881,10 @@ var PowiainaNum = /*#__PURE__*/function () {
860
881
  value: function getOperatorIndex(arrow) {
861
882
  var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
862
883
  var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
884
+ if (this.array.length == 1 && arrow == 0) return 0;
885
+ if (this.array.length == 1 && arrow == 1) return 0.5;
886
+ if (this.array.length == 2 && arrow == 1) return 1;
887
+ if (this.array.length == 2 && arrow == 0) return 0;
863
888
  for (var i = 0; i < this.array.length; i++) {
864
889
  var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
865
890
  if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
@@ -938,7 +963,8 @@ var PowiainaNum = /*#__PURE__*/function () {
938
963
  value: function toNumber() {
939
964
  if (this.sign == -1) return -this.neg().toNumber();
940
965
  if (this.small) return 1 / this.rec().toNumber();
941
- if (this.getOperator(1) == 0) return this.getOperator(0);else if (this.getOperator(1) == 1) return Math.pow(10, this.getOperator(0));
966
+ if (this.array.length > 2) return Infinity;
967
+ 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));
942
968
  return NaN;
943
969
  }
944
970
  }, {
@@ -1096,9 +1122,6 @@ var PowiainaNum = /*#__PURE__*/function () {
1096
1122
  key: "fromString",
1097
1123
  value: function fromString(input) {
1098
1124
  var _a, _b, _c, _d, _e, _f;
1099
- if (!isPowiainaNum.test(input)) {
1100
- throw powiainaNumError + "malformed input: " + input;
1101
- }
1102
1125
  var x = new PowiainaNum();
1103
1126
  // Judge the string was a number
1104
1127
  // @ts-ignore
@@ -1109,6 +1132,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1109
1132
  return x;
1110
1133
  }
1111
1134
  }
1135
+ if (!isPowiainaNum.test(input)) {
1136
+ throw powiainaNumError + "malformed input: " + input;
1137
+ }
1112
1138
  var negateIt = false;
1113
1139
  var recipIt = false;
1114
1140
  if (input[0] == "-" || input[0] == "+") {
@@ -1329,6 +1355,22 @@ PowiainaNum.E_MSI_REC = new PowiainaNum({
1329
1355
  layer: 0,
1330
1356
  sign: 1
1331
1357
  });
1358
+ PowiainaNum.TETRATED_MSI = new PowiainaNum({
1359
+ array: [{
1360
+ arrow: 0,
1361
+ expans: 1,
1362
+ megota: 1,
1363
+ repeat: MSI
1364
+ }, {
1365
+ arrow: 1,
1366
+ expans: 1,
1367
+ megota: 1,
1368
+ repeat: MSI
1369
+ }],
1370
+ small: false,
1371
+ layer: 0,
1372
+ sign: 1
1373
+ });
1332
1374
  PowiainaNum.TRITRI = new PowiainaNum({
1333
1375
  small: false,
1334
1376
  layer: 0,
@@ -322,19 +322,23 @@ var PowiainaNum = /*#__PURE__*/function () {
322
322
  }, {
323
323
  key: "pow10",
324
324
  value: function pow10() {
325
+ var _a, _b;
325
326
  var r = this.clone();
326
327
  // inf & nan check
327
328
  if (!this.isFinite()) return this.clone();
328
- if (r.lt(0)) {
329
+ if (r.isneg()) {
329
330
  // 10^(-x) = 1/(10^x)
330
331
  r.sign *= -1;
331
332
  return r.pow10().rec();
332
333
  }
334
+ if (r.lte(308.25471555991675)) {
335
+ return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
336
+ }
333
337
  if (r.small) {
334
338
  if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
335
- return new PowiainaNum(Math.pow(10, Math.pow(r.getOperator(0), -1)));
339
+ return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
336
340
  }
337
- r.setOperator(r.getOperator(1) + 1, 1);
341
+ r.setOperator(((_b = (_a = r.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0) + 1, 1);
338
342
  r.normalize();
339
343
  return r;
340
344
  }
@@ -345,7 +349,7 @@ var PowiainaNum = /*#__PURE__*/function () {
345
349
  if (!other.isFinite()) return other.clone();
346
350
  if (!this.isFinite()) return this.clone();
347
351
  if (this.eq(10)) return other.pow10();
348
- if (this.lt(0)) {
352
+ if (this.isneg()) {
349
353
  if (!other.isInt()) return PowiainaNum.NaN.clone();
350
354
  var r = this.abs().pow(other);
351
355
  r.sign = function () {
@@ -355,6 +359,13 @@ var PowiainaNum = /*#__PURE__*/function () {
355
359
  }();
356
360
  return r;
357
361
  }
362
+ var a = this.toNumber();
363
+ var b = other.toNumber();
364
+ var t = Math.pow(a, b);
365
+ if (isFinite(t)) {
366
+ // optimize?
367
+ return PowiainaNum.fromNumber(t);
368
+ }
358
369
  // log10(a^b) = b log10(a)
359
370
  return this.log10().mul(other).pow10();
360
371
  }
@@ -390,16 +401,17 @@ var PowiainaNum = /*#__PURE__*/function () {
390
401
  }, {
391
402
  key: "log10",
392
403
  value: function log10() {
393
- if (this.lt(0)) return PowiainaNum.NaN.clone();
404
+ var _a, _b;
405
+ if (this.isneg()) return PowiainaNum.NaN.clone();
394
406
  if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
395
407
  if (this.small) {
396
408
  var _x = this.clone();
397
409
  _x.small = !_x.small;
398
410
  return _x.log10().neg();
399
411
  }
400
- if (this.getOperator(1) == 0) return new PowiainaNum(Math.log10(this.getOperator(0)));
412
+ if ((_b = (_a = this.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0 == 0) return new PowiainaNum(Math.log10(this.array[0].repeat));
401
413
  var x = this.clone();
402
- x.setOperator(x.getOperator(1) - 1, 1);
414
+ x.array[1].repeat = x.array[1].repeat - 1;
403
415
  x.normalize();
404
416
  return x;
405
417
  }
@@ -525,7 +537,7 @@ var PowiainaNum = /*#__PURE__*/function () {
525
537
  return PowiainaNum.NaN.clone(); //complex
526
538
  }
527
539
  if (this.layer === 0) {
528
- return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0), 1e-10, false));
540
+ return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
529
541
  } else if (this.layer == 1) {
530
542
  return d_lambertw(this, 1e-10, false);
531
543
  } else {
@@ -586,7 +598,7 @@ var PowiainaNum = /*#__PURE__*/function () {
586
598
  if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
587
599
  }
588
600
  var r = this.abs();
589
- r.setOperator(Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0)), 0);
601
+ r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
590
602
  return r;
591
603
  }
592
604
  }, {
@@ -597,7 +609,7 @@ var PowiainaNum = /*#__PURE__*/function () {
597
609
  if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
598
610
  }
599
611
  var r = this.abs();
600
- r.setOperator(Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0)), 0);
612
+ r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
601
613
  r.sign = this.sign;
602
614
  return r;
603
615
  }
@@ -613,7 +625,7 @@ var PowiainaNum = /*#__PURE__*/function () {
613
625
  }
614
626
  }
615
627
  var r = this.abs();
616
- r.setOperator(Math.round(r.getOperator(0)), 0);
628
+ r.array[0].repeat = Math.round(r.array[0].repeat);
617
629
  r.sign = this.sign;
618
630
  return r;
619
631
  }
@@ -726,9 +738,19 @@ var PowiainaNum = /*#__PURE__*/function () {
726
738
  value: function isInt() {
727
739
  if (this.isZero()) return true;
728
740
  if (!this.small && Number.isInteger(this.getOperator(0))) return true;
729
- if (this.abs().gte(Math.pow(2, 52))) return true;
741
+ if (this.abs().gte(MSI / 2)) return true;
730
742
  return false;
731
743
  }
744
+ }, {
745
+ key: "ispos",
746
+ value: function ispos() {
747
+ return this.sign > 0;
748
+ }
749
+ }, {
750
+ key: "isneg",
751
+ value: function isneg() {
752
+ return this.sign < 0;
753
+ }
732
754
  }, {
733
755
  key: "normalize",
734
756
  value:
@@ -807,7 +829,6 @@ var PowiainaNum = /*#__PURE__*/function () {
807
829
  }
808
830
  if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
809
831
  if (this.getOperator(1) >= 1 && this.getOperator(0) < MSI_LOG10) {
810
- console.log(this.array);
811
832
  this.setOperator(this.getOperator(1) - 1, 1);
812
833
  this.setOperator(Math.pow(10, this.getOperator(0)), 0);
813
834
  renormalize = true;
@@ -858,6 +879,10 @@ var PowiainaNum = /*#__PURE__*/function () {
858
879
  value: function getOperatorIndex(arrow) {
859
880
  var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
860
881
  var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
882
+ if (this.array.length == 1 && arrow == 0) return 0;
883
+ if (this.array.length == 1 && arrow == 1) return 0.5;
884
+ if (this.array.length == 2 && arrow == 1) return 1;
885
+ if (this.array.length == 2 && arrow == 0) return 0;
861
886
  for (var i = 0; i < this.array.length; i++) {
862
887
  var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
863
888
  if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
@@ -936,7 +961,8 @@ var PowiainaNum = /*#__PURE__*/function () {
936
961
  value: function toNumber() {
937
962
  if (this.sign == -1) return -this.neg().toNumber();
938
963
  if (this.small) return 1 / this.rec().toNumber();
939
- if (this.getOperator(1) == 0) return this.getOperator(0);else if (this.getOperator(1) == 1) return Math.pow(10, this.getOperator(0));
964
+ if (this.array.length > 2) return Infinity;
965
+ 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));
940
966
  return NaN;
941
967
  }
942
968
  }, {
@@ -1094,9 +1120,6 @@ var PowiainaNum = /*#__PURE__*/function () {
1094
1120
  key: "fromString",
1095
1121
  value: function fromString(input) {
1096
1122
  var _a, _b, _c, _d, _e, _f;
1097
- if (!isPowiainaNum.test(input)) {
1098
- throw powiainaNumError + "malformed input: " + input;
1099
- }
1100
1123
  var x = new PowiainaNum();
1101
1124
  // Judge the string was a number
1102
1125
  // @ts-ignore
@@ -1107,6 +1130,9 @@ var PowiainaNum = /*#__PURE__*/function () {
1107
1130
  return x;
1108
1131
  }
1109
1132
  }
1133
+ if (!isPowiainaNum.test(input)) {
1134
+ throw powiainaNumError + "malformed input: " + input;
1135
+ }
1110
1136
  var negateIt = false;
1111
1137
  var recipIt = false;
1112
1138
  if (input[0] == "-" || input[0] == "+") {
@@ -1327,6 +1353,22 @@ PowiainaNum.E_MSI_REC = new PowiainaNum({
1327
1353
  layer: 0,
1328
1354
  sign: 1
1329
1355
  });
1356
+ PowiainaNum.TETRATED_MSI = new PowiainaNum({
1357
+ array: [{
1358
+ arrow: 0,
1359
+ expans: 1,
1360
+ megota: 1,
1361
+ repeat: MSI
1362
+ }, {
1363
+ arrow: 1,
1364
+ expans: 1,
1365
+ megota: 1,
1366
+ repeat: MSI
1367
+ }],
1368
+ small: false,
1369
+ layer: 0,
1370
+ sign: 1
1371
+ });
1330
1372
  PowiainaNum.TRITRI = new PowiainaNum({
1331
1373
  small: false,
1332
1374
  layer: 0,
@@ -328,19 +328,23 @@
328
328
  }, {
329
329
  key: "pow10",
330
330
  value: function pow10() {
331
+ var _a, _b;
331
332
  var r = this.clone();
332
333
  // inf & nan check
333
334
  if (!this.isFinite()) return this.clone();
334
- if (r.lt(0)) {
335
+ if (r.isneg()) {
335
336
  // 10^(-x) = 1/(10^x)
336
337
  r.sign *= -1;
337
338
  return r.pow10().rec();
338
339
  }
340
+ if (r.lte(308.25471555991675)) {
341
+ return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
342
+ }
339
343
  if (r.small) {
340
344
  if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
341
- return new PowiainaNum(Math.pow(10, Math.pow(r.getOperator(0), -1)));
345
+ return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
342
346
  }
343
- r.setOperator(r.getOperator(1) + 1, 1);
347
+ r.setOperator(((_b = (_a = r.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0) + 1, 1);
344
348
  r.normalize();
345
349
  return r;
346
350
  }
@@ -351,7 +355,7 @@
351
355
  if (!other.isFinite()) return other.clone();
352
356
  if (!this.isFinite()) return this.clone();
353
357
  if (this.eq(10)) return other.pow10();
354
- if (this.lt(0)) {
358
+ if (this.isneg()) {
355
359
  if (!other.isInt()) return PowiainaNum.NaN.clone();
356
360
  var r = this.abs().pow(other);
357
361
  r.sign = function () {
@@ -361,6 +365,13 @@
361
365
  }();
362
366
  return r;
363
367
  }
368
+ var a = this.toNumber();
369
+ var b = other.toNumber();
370
+ var t = Math.pow(a, b);
371
+ if (isFinite(t)) {
372
+ // optimize?
373
+ return PowiainaNum.fromNumber(t);
374
+ }
364
375
  // log10(a^b) = b log10(a)
365
376
  return this.log10().mul(other).pow10();
366
377
  }
@@ -396,16 +407,17 @@
396
407
  }, {
397
408
  key: "log10",
398
409
  value: function log10() {
399
- if (this.lt(0)) return PowiainaNum.NaN.clone();
410
+ var _a, _b;
411
+ if (this.isneg()) return PowiainaNum.NaN.clone();
400
412
  if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
401
413
  if (this.small) {
402
414
  var _x = this.clone();
403
415
  _x.small = !_x.small;
404
416
  return _x.log10().neg();
405
417
  }
406
- if (this.getOperator(1) == 0) return new PowiainaNum(Math.log10(this.getOperator(0)));
418
+ if ((_b = (_a = this.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0 == 0) return new PowiainaNum(Math.log10(this.array[0].repeat));
407
419
  var x = this.clone();
408
- x.setOperator(x.getOperator(1) - 1, 1);
420
+ x.array[1].repeat = x.array[1].repeat - 1;
409
421
  x.normalize();
410
422
  return x;
411
423
  }
@@ -531,7 +543,7 @@
531
543
  return PowiainaNum.NaN.clone(); //complex
532
544
  }
533
545
  if (this.layer === 0) {
534
- return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0), 1e-10, false));
546
+ return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
535
547
  } else if (this.layer == 1) {
536
548
  return d_lambertw(this, 1e-10, false);
537
549
  } else {
@@ -592,7 +604,7 @@
592
604
  if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
593
605
  }
594
606
  var r = this.abs();
595
- r.setOperator(Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0)), 0);
607
+ r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
596
608
  return r;
597
609
  }
598
610
  }, {
@@ -603,7 +615,7 @@
603
615
  if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
604
616
  }
605
617
  var r = this.abs();
606
- r.setOperator(Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0)), 0);
618
+ r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
607
619
  r.sign = this.sign;
608
620
  return r;
609
621
  }
@@ -619,7 +631,7 @@
619
631
  }
620
632
  }
621
633
  var r = this.abs();
622
- r.setOperator(Math.round(r.getOperator(0)), 0);
634
+ r.array[0].repeat = Math.round(r.array[0].repeat);
623
635
  r.sign = this.sign;
624
636
  return r;
625
637
  }
@@ -732,9 +744,19 @@
732
744
  value: function isInt() {
733
745
  if (this.isZero()) return true;
734
746
  if (!this.small && Number.isInteger(this.getOperator(0))) return true;
735
- if (this.abs().gte(Math.pow(2, 52))) return true;
747
+ if (this.abs().gte(MSI / 2)) return true;
736
748
  return false;
737
749
  }
750
+ }, {
751
+ key: "ispos",
752
+ value: function ispos() {
753
+ return this.sign > 0;
754
+ }
755
+ }, {
756
+ key: "isneg",
757
+ value: function isneg() {
758
+ return this.sign < 0;
759
+ }
738
760
  }, {
739
761
  key: "normalize",
740
762
  value:
@@ -813,7 +835,6 @@
813
835
  }
814
836
  if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
815
837
  if (this.getOperator(1) >= 1 && this.getOperator(0) < MSI_LOG10) {
816
- console.log(this.array);
817
838
  this.setOperator(this.getOperator(1) - 1, 1);
818
839
  this.setOperator(Math.pow(10, this.getOperator(0)), 0);
819
840
  renormalize = true;
@@ -864,6 +885,10 @@
864
885
  value: function getOperatorIndex(arrow) {
865
886
  var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
866
887
  var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
888
+ if (this.array.length == 1 && arrow == 0) return 0;
889
+ if (this.array.length == 1 && arrow == 1) return 0.5;
890
+ if (this.array.length == 2 && arrow == 1) return 1;
891
+ if (this.array.length == 2 && arrow == 0) return 0;
867
892
  for (var i = 0; i < this.array.length; i++) {
868
893
  var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
869
894
  if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
@@ -942,7 +967,8 @@
942
967
  value: function toNumber() {
943
968
  if (this.sign == -1) return -this.neg().toNumber();
944
969
  if (this.small) return 1 / this.rec().toNumber();
945
- if (this.getOperator(1) == 0) return this.getOperator(0);else if (this.getOperator(1) == 1) return Math.pow(10, this.getOperator(0));
970
+ if (this.array.length > 2) return Infinity;
971
+ 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));
946
972
  return NaN;
947
973
  }
948
974
  }, {
@@ -1100,9 +1126,6 @@
1100
1126
  key: "fromString",
1101
1127
  value: function fromString(input) {
1102
1128
  var _a, _b, _c, _d, _e, _f;
1103
- if (!isPowiainaNum.test(input)) {
1104
- throw powiainaNumError + "malformed input: " + input;
1105
- }
1106
1129
  var x = new PowiainaNum();
1107
1130
  // Judge the string was a number
1108
1131
  // @ts-ignore
@@ -1113,6 +1136,9 @@
1113
1136
  return x;
1114
1137
  }
1115
1138
  }
1139
+ if (!isPowiainaNum.test(input)) {
1140
+ throw powiainaNumError + "malformed input: " + input;
1141
+ }
1116
1142
  var negateIt = false;
1117
1143
  var recipIt = false;
1118
1144
  if (input[0] == "-" || input[0] == "+") {
@@ -1333,6 +1359,22 @@
1333
1359
  layer: 0,
1334
1360
  sign: 1
1335
1361
  });
1362
+ PowiainaNum.TETRATED_MSI = new PowiainaNum({
1363
+ array: [{
1364
+ arrow: 0,
1365
+ expans: 1,
1366
+ megota: 1,
1367
+ repeat: MSI
1368
+ }, {
1369
+ arrow: 1,
1370
+ expans: 1,
1371
+ megota: 1,
1372
+ repeat: MSI
1373
+ }],
1374
+ small: false,
1375
+ layer: 0,
1376
+ sign: 1
1377
+ });
1336
1378
  PowiainaNum.TRITRI = new PowiainaNum({
1337
1379
  small: false,
1338
1380
  layer: 0,
@@ -1 +1 @@
1
- !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).PowiainaNum=e()}(this,(function(){"use strict";function r(r,a){for(var t=0;t<a.length;t++){var n=a[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,e(n.key),n)}}function e(r){var e=function(r,e){if("object"!=typeof r||!r)return r;var a=r[Symbol.toPrimitive];if(void 0!==a){var t=a.call(r,e||"default");if("object"!=typeof t)return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(r)}(r,"string");return"symbol"==typeof e?e:e+""}function a(r){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var t=9007199254740991,n=15.954589770191003,i=/^[-\+]*(Infinity|NaN|(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;function o(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;return{repeat:r,arrow:e,expans:a,megota:t,valuereplaced:e==1/0?0:a==1/0?1:-1}}function s(){for(var r=arguments.length,e=new Array(r),a=0;a<r;a++)e[a]=arguments[a];for(var t=0;t<Math.min(e[0].length,e[1].length);t++){var n=e[0][t],i=e[1][t];if(n<i)return-1;if(n>i)return 1}return 0}function l(r){return Math.log10(Number(r.substring(0,17)))+(r.length-17)}var u=.5671432904097838;function h(r){var e,a,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!Number.isFinite(r))return r;if(n){if(0===r)return r;if(1===r)return u;e=r<10?0:Math.log(r)-Math.log(Math.log(r))}else{if(0===r)return-1/0;e=r<=-.1?-2:Math.log(-r)-Math.log(-Math.log(-r))}for(var i=0;i<100;++i){if(a=(r*Math.exp(-e)+e*e)/(e+1),Math.abs(a-e)<t*Math.abs(a))return a;e=a}throw Error("Iteration failed to converge: ".concat(r.toString()))}function g(r){var e,a,t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(r.isInfinite())return r;if(o){if(r.eq(p.ZERO))return p.ZERO.clone();if(r.eq(p.ONE))return p.fromNumber(u);e=r.log()}else{if(r.eq(p.ZERO))return p.NEGATIVE_INFINITY.clone();e=r.neg().log()}for(var s=0;s<100;++s){if(a=e.neg().exp(),t=e.sub(r.mul(a)),(n=e.sub(t.div(e.add(1).sub(e.add(2).mul(t).div(e.mul(2).add(2)))))).sub(e).abs().lt(n.abs().mul(i)))return n;e=n}throw Error("Iteration failed to converge: ".concat(r.toString()))}var y,p=function(){function e(r){if(function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.array=[{arrow:0,expans:1,megota:1,repeat:NaN}],this.small=!1,this.sign=0,this.layer=0,void 0===r);else if("number"==typeof r){var t=e.fromNumber(r);this.resetFromObject(t)}else if("object"==a(r)){var n=e.fromObject(r);this.resetFromObject(n)}else if("string"==typeof r){var i=e.fromString(r);this.resetFromObject(i)}}return function(e,a,t){return a&&r(e.prototype,a),t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}(e,[{key:"add",value:function(r){var a,t,i,s,l,u,h=this.clone(),g=new e(r);if(h.eq(e.POSITIVE_INFINITY)&&g.eq(e.NEGATIVE_INFINITY)||h.eq(e.NEGATIVE_INFINITY)&&g.eq(e.POSITIVE_INFINITY))return e.NaN.clone();if(!h.isFinite())return h.clone();if(!g.isFinite())return g.clone();if(h.isZero())return g.clone();if(g.isZero())return h.clone();if(h.sign==-g.sign&&function(){var r=h.abs(),e=g.abs();return r.eq(e)}())return e.ZERO.clone();if(h.abs().lt(e.E_MSI_REC)||h.abs().gt(e.E_MSI)||g.abs().lt(e.E_MSI_REC)||g.abs().gt(e.E_MSI))return h.maxabs(g);if(-1==h.sign)return h.neg().add(g.neg()).neg();h.cmpabs(g)>0?(l=h,u=g):(u=h,l=g);var y=1;if(!(l.small||u.small||(null===(a=l.array[1])||void 0===a?void 0:a.repeat)||(null===(t=u.array[1])||void 0===t?void 0:t.repeat)||l.sign!=u.sign))return new e((l.array[0].repeat+u.array[0].repeat)*l.sign);var p=(l.small?-1:1)*((null===(i=l.array[1])||void 0===i?void 0:i.repeat)?l.array[0].repeat:Math.log10(l.array[0].repeat)),c=(u.small?-1:1)*((null===(s=u.array[1])||void 0===s?void 0:s.repeat)?u.array[0].repeat:Math.log10(u.array[0].repeat));if(p-c>n)return l;var f,m,v=-Math.floor(p),N=0;if((m=l.sign*Math.pow(10,p+v)+u.sign*Math.pow(10,c+v))>0&&(N=Math.log10(m)-v),m<0&&(N=Math.log10(-m)-v,y*=-1),0==m)throw Error("Encounter a calculate error");return(f=new e).sign=1,f.array=N>n||N<-n?[o(N,0),o(1,1)]:[o(Math.pow(10,N),0)],f.small=N<0,f.sign*=y,f}},{key:"sub",value:function(r){return this.add(new e(r).neg())}},{key:"mul",value:function(r){var a,t=this.clone(),n=new e(r);return t.eq(e.POSITIVE_INFINITY)&&n.eq(e.NEGATIVE_INFINITY)||n.eq(e.POSITIVE_INFINITY)&&t.eq(e.NEGATIVE_INFINITY)?e.NEGATIVE_INFINITY.clone():t.isInfinite()&&n.eq(e.ZERO)&&n.isInfinite()&&t.eq(e.ZERO)?e.NaN.clone():t.eq(e.NEGATIVE_INFINITY)&&n.eq(e.NEGATIVE_INFINITY)?e.POSITIVE_INFINITY.clone():t.isFinite()?n.isFinite()?t.isZero()||n.isZero()?e.ZERO.clone():((a=t.abs().log10().add(n.abs().log10()).pow10()).sign=t.sign*n.sign,a):n.clone():t.clone()}},{key:"div",value:function(r){var a=new e(r).rec();return this.mul(a)}},{key:"pow10",value:function(){var r=this.clone();return this.isFinite()?r.lt(0)?(r.sign*=-1,r.pow10().rec()):r.small?r.lt(e.MSI_REC)?e.ONE:new e(Math.pow(10,Math.pow(r.getOperator(0),-1))):(r.setOperator(r.getOperator(1)+1,1),r.normalize(),r):this.clone()}},{key:"pow",value:function(r){var a,t=new e(r);if(!t.isFinite())return t.clone();if(!this.isFinite())return this.clone();if(this.eq(10))return t.pow10();if(this.lt(0)){if(!t.isInt())return e.NaN.clone();var n=this.abs().pow(t);return n.sign=(a=t.mod(2).round()).eq(0)||a.eq(2)?1:-1,n}return this.log10().mul(t).pow10()}},{key:"pow_base",value:function(r){return new e(r).pow(this)}},{key:"root",value:function(r){var a=new e(r);return this.pow(a.rec())}},{key:"sqrt",value:function(){return this.pow(.5)}},{key:"cbrt",value:function(){return this.root(3)}},{key:"abs",value:function(){var r=this.clone();return r.sign<0&&(r.sign*=-1),r}},{key:"log10",value:function(){if(this.lt(0))return e.NaN.clone();if(this.isZero())return e.NEGATIVE_INFINITY.clone();if(this.small){var r=this.clone();return r.small=!r.small,r.log10().neg()}if(0==this.getOperator(1))return new e(Math.log10(this.getOperator(0)));var a=this.clone();return a.setOperator(a.getOperator(1)-1,1),a.normalize(),a}},{key:"log",value:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.E,a=new e(r);return this.log10().div(a.log10())}},{key:"exp",value:function(){return this.pow_base(Math.E)}},{key:"mod",value:function(r){var a=new e(r),t=this.div(a);return t.sub(t.floor()).mul(a)}},{key:"factorial",value:function(){return this.abs().lt(t)?this.add(1).gamma():this.abs().lt(e.E_MSI)?e.exp(this.mul(this.log10().sub(1))):e.exp(this)}},{key:"gamma",value:function(){if(this.small)return this.rec();if(this.lte(t)){if(this.lt(24))return e.fromNumber(function(r){if(!isFinite(r))return r;if(r<-50)return r===Math.trunc(r)?Number.NEGATIVE_INFINITY:0;for(var e=1;r<10;)e*=r,++r;var a=.9189385332046727;a+=((r-=1)+.5)*Math.log(r),a-=r;var t=r*r,n=r;return a+=1/(12*n),a-=1/(360*(n*=t)),a+=1/(1260*(n*=t)),a-=1/(1680*(n*=t)),a+=1/(1188*(n*=t)),a-=691/(360360*(n*=t)),a+=7/(1092*(n*=t)),a-=3617/(122400*(n*=t)),Math.exp(a)/e}(this.sign*this.getOperator(0)));var r=this.getOperator(0)-1,a=.9189385332046727;a+=(r+.5)*Math.log(r);var n=r*r,i=r,o=12*i,s=1/o,l=(a-=r)+s;if(l===a)return e.exp(a);if((l=(a=l)-(s=1/(o=360*(i*=n))))===a)return e.exp(a);a=l;var u=1/(o=1260*(i*=n));return a+=u,a-=u=1/(o=1680*(i*=n)),e.exp(a)}return this.gt(t)?e.exp(this.mul(this.log().sub(1))):e.exp(this)}},{key:"lambertw",value:function(){var r=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.lt(-.3678794411710499)?e.NaN.clone():r?this.abs().lt("1e-300")?new e(this):this.small?e.fromNumber(h(this.toNumber())):0===this.layer?e.fromNumber(h(this.sign*this.getOperator(0))):this.lt("eee15")?g(this):this.log():1===this.sign?e.NaN.clone():0===this.layer?e.fromNumber(h(this.sign*this.getOperator(0),1e-10,!1)):1==this.layer?g(this,1e-10,!1):this.neg().rec().lambertw().neg()}},{key:"max",value:function(r){var a=new e(r);return this.lt(a)?a.clone():this.clone()}},{key:"min",value:function(r){var a=new e(r);return this.gte(a)?a.clone():this.clone()}},{key:"maxabs",value:function(r){var a=new e(r).abs();return this.abs().lt(a)?a.clone():this.clone()}},{key:"minabs",value:function(r){var a=new e(r).abs();return this.abs().gt(a)?a.clone():this.clone()}},{key:"cmpabs",value:function(r){var a=new e(r).abs();return this.abs().cmp(a)}},{key:"neg",value:function(){var r=this.clone();return r.sign*=-1,r.normalize(),r}},{key:"rec",value:function(){var r=this.clone();return r.small=!r.small,r}},{key:"floor",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?e.ZERO.clone():e.ONE.neg().clone();var r=this.abs();return r.setOperator(Math[1==this.sign?"floor":"ceil"](r.getOperator(0)),0),r}},{key:"ceil",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?e.ONE.clone():e.ZERO.clone();var r=this.abs();return r.setOperator(Math[1==this.sign?"ceil":"floor"](r.getOperator(0)),0),r.sign=this.sign,r}},{key:"round",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?this.rec().lte(2)?e.ONE.clone():e.ZERO.clone():this.abs().rec().lte(2)?e.ZERO.clone():e.ONE.neg().clone();var r=this.abs();return r.setOperator(Math.round(r.getOperator(0)),0),r.sign=this.sign,r}},{key:"compare",value:function(r){var a=new e(r);if(this.isNaN()||a.isNaN())return 2;if(this.sign<a.sign)return-1;if(this.sign>a.sign)return 1;var t=-1==this.sign&&-1==a.sign;if(this.small&&!a.small)return-1*(t?-1:1);if(a.small&&!this.small)return 1*(t?-1:1);var n=1;this.small&&a.small&&(n*=-1),t&&(n*=-1);for(var i=0,o=0;this.array.length-1-o>=0&&a.array.length-1-o>=0;o++){var l=this.array[this.array.length-1-o],u=a.array[a.array.length-1-o],h=s([l.megota,l.expans,l.arrow,l.repeat],[u.megota,u.expans,u.arrow,u.repeat]);if(1==h){i=1;break}if(-1==h){i=-1;break}}return i*n+1-1}},{key:"cmp",value:function(r){return this.compare(r)}},{key:"eq",value:function(r){return 0===this.cmp(r)}},{key:"neq",value:function(r){return 0!==this.cmp(r)}},{key:"lt",value:function(r){return-1===this.cmp(r)}},{key:"lte",value:function(r){return this.cmp(r)<=0}},{key:"gt",value:function(r){return 1==this.cmp(r)}},{key:"gte",value:function(r){var e=this.cmp(r);return 0==e||1==e}},{key:"isNaN",value:function(r){function e(){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(){return isNaN(this.getOperator(0))}))},{key:"isZero",value:function(){return Boolean(this.small&&!isFinite(this.getOperator(0)))}},{key:"isFinite",value:function(r){function e(){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(){return Boolean(this.small||isFinite(this.getOperator(0)))&&!this.isNaN()}))},{key:"isInfinite",value:function(){return Boolean(!this.small&&!isFinite(this.getOperator(0)))||this.isNaN()}},{key:"isInt",value:function(){return!!this.isZero()||(!(this.small||!Number.isInteger(this.getOperator(0)))||!!this.abs().gte(Math.pow(2,52)))}},{key:"normalize",value:function(){for(var r=!0,a=this,i=0;i<this.array.length;i++)if(this.array[i].repeat==1/0)return this.array=[{arrow:0,expans:1,megota:1,repeat:1/0}],this.layer=0,this;for(var l=1;l<a.array.length;++l){var u=a.array[l];if(null!==u.arrow&&void 0!==u.arrow||(u.arrow=0),null!==u.expans&&void 0!==u.expans||(u.expans=1),null!==u.megota&&void 0!==u.megota||(u.megota=1),isNaN(u.arrow)||isNaN(u.repeat)||isNaN(u.expans)||isNaN(u.megota))return a.array=[o(NaN,0,1,1)],a;if(!isFinite(u.repeat)||!isFinite(u.megota))return a.array=[o(1/0,0,1,1)],a;Number.isInteger(u.arrow)||(u.arrow=Math.floor(u.arrow)),Number.isInteger(u.repeat)||(u.repeat=Math.floor(u.repeat)),Number.isInteger(u.expans)||(u.expans=Math.floor(u.expans)),Number.isInteger(u.megota)||(u.megota=Math.floor(u.megota))}do{for(r=!1,this.array.sort((function(r,e){return s([r.megota,r.expans,r.arrow],[e.megota,e.expans,e.arrow])})),l=1;l<a.array.length;++l)0===a.array[l].arrow||0!==a.array[l].repeat&&null!==a.array[l].repeat&&void 0!==a.array[l].repeat?0==a.array[l].arrow&&a.array[l].expans>=2&&(a.array[l].arrow=1/0,a.array[l].valuereplaced=0,a.array[l].expans=a.array[l].expans-1):(a.array.splice(l,1),--l);for(var h=1;h<this.array.length;h++)0==this.array[h].repeat&&(this.array.splice(h,1),h--);for(a.array.length||(a.small=!a.small,a.array=[o(1/0)]),a.array.length>e.maxOps&&a.array.splice(1,a.array.length-e.maxOps),this.getOperator(1)>=1&&this.getOperator(0)<n&&(console.log(this.array),this.setOperator(this.getOperator(1)-1,1),this.setOperator(Math.pow(10,this.getOperator(0)),0),r=!0),this.getOperator(0)>t&&(this.setOperator(this.getOperator(1)+1,1),this.setOperator(Math.log10(this.getOperator(0)),0),r=!0),1==this.array.length&&this.array[0].repeat<1&&(this.array[0].repeat=1/this.array[0].repeat,this.small=!this.small,r=!0);a.array.length>=2&&1==a.array[0].repeat&&a.array[1].repeat;)a.array[1].repeat>1?a.array[1].repeat--:a.array.splice(1,1),a.array[0].repeat=10,r=!0;for(a.array.length>=2&&a.array[0].repeat<t&&a.array[1].arrow>=2&&1==a.array[1].repeat&&(a.array.splice(1,1,o(a.array[0].repeat,a.array[1].arrow-1,a.array[1].expans,a.array[1].megota)),a.array[0].repeat=10,r=!0),l=1;l<a.array.length-1;++l)a.array[l].arrow==a.array[l+1].arrow&&a.array[l].expans==a.array[l+1].expans&&a.array[l].megota==a.array[l+1].megota&&(a.array[l].repeat+=a.array[l+1].repeat,a.array.splice(l+1,1),--l,r=!0)}while(r);return this}},{key:"getOperatorIndex",value:function(r){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=0;t<this.array.length;t++){var n=s([this.array[t].megota,this.array[t].expans,this.array[t].arrow],[a,e,r]);if(0==n)return t;if(1==n)return t-.5}return this.array.length-.5}},{key:"getOperator",value:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=this.getOperatorIndex(r,e,a);return this.array[t]?this.array[t].repeat:0}},{key:"setOperator",value:function(r,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=this.getOperatorIndex(e,a,t);return this.array[n]?(this.array[n].repeat=r,!1):(this.array.splice(Math.ceil(n),0,{arrow:e,expans:a,megota:t,valuereplaced:a===1/0?1:e==1/0?0:-1,repeat:r}),!0)}},{key:"clone",value:function(){var r=new e;return r.resetFromObject(this),r}},{key:"resetFromObject",value:function(r){this.array=[];for(var e=0;e<r.array.length;e++)this.array[e]={arrow:r.array[e].arrow,expans:r.array[e].expans,megota:r.array[e].megota,repeat:r.array[e].repeat,valuereplaced:r.array[e].valuereplaced};return this.small=r.small,this.sign=r.sign,this.layer=r.layer,this}},{key:"toNumber",value:function(){return-1==this.sign?-this.neg().toNumber():this.small?1/this.rec().toNumber():0==this.getOperator(1)?this.getOperator(0):1==this.getOperator(1)?Math.pow(10,this.getOperator(0)):NaN}},{key:"toString",value:function(){if(this.isNaN())return"NaN";if(-1==this.sign)return"-".concat(this.neg().toString());if(this.small)return this.eq(e.ZERO)?"0":"/".concat(this.rec().toString());if(this.isInfinite())return"Infinity";for(var r="",a=this.array.length-1;a>=0;a--){var t=this.array[a],n="10{".concat(t.arrow===1/0?"!":t.arrow).concat(t.expans>1||t.megota>1?",".concat(t.expans===1/0?"!":t.expans):"").concat(t.megota>1?",".concat(t.megota):"","}");n=1==t.arrow&&1==t.expans&&1==t.megota&&t.repeat<5?"e".repeat(t.repeat):0==t.arrow&&1==t.expans&&1==t.megota?t.repeat.toString():t.repeat>1?"(".concat(n,")^").concat(t.repeat," "):"".concat(n," "),r+="".concat(n)}return r}},{key:"arr01",get:function(){for(var r=[0],e=0;e<this.array.length;e++)0==e?r[0]=this.array[e].repeat:(r[e]=[0,0,0,0],r[e][0]=this.array[e].arrow==1/0?"x":this.array[e].arrow,r[e][1]=this.array[e].repeat,r[e][2]=this.array[e].expans==1/0?"x":this.array[e].expans,r[e][3]=this.array[e].megota);return r}}],[{key:"add",value:function(r,a){return new e(r).add(a)}},{key:"sub",value:function(r,a){return new e(r).sub(a)}},{key:"mul",value:function(r,a){return new e(r).mul(a)}},{key:"div",value:function(r,a){return new e(r).div(a)}},{key:"pow",value:function(r,a){return new e(r).pow(a)}},{key:"root",value:function(r,a){return new e(r).root(a)}},{key:"sqrt",value:function(r){return new e(r).sqrt()}},{key:"cbrt",value:function(r){return new e(r).cbrt()}},{key:"log10",value:function(r){return new e(r).log10()}},{key:"log",value:function(r){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Math.E;return new e(r).log(a)}},{key:"exp",value:function(r){return new e(r).pow_base(Math.E)}},{key:"factorial",value:function(r){return new e(r).factorial()}},{key:"gamma",value:function(r){return new e(r).gamma()}},{key:"lambertw",value:function(r){var a=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new e(r).lambertw(a)}},{key:"isNaN",value:function(r){return new e(r).isNaN()}},{key:"fromNumber",value:function(r){var a=new e;r<0?a.sign=-1:0==r?a.sign=0:r>0&&(a.sign=1);var n=Math.abs(r);return n>=11102230246251568e-32&&n<1?(a.small=!0,a.array=[o(1/n,0)]):n<11102230246251568e-32?(a.small=!0,a.array=[o(-Math.log10(n),0),o(1,1)]):n<=t?a.array=[o(n,0)]:(a.setOperator(Math.log10(n),0),a.array=[o(Math.log10(n),0),o(1,1)]),a}},{key:"fromString",value:function(r){var a,s,u,h,g,y;if(!i.test(r))throw"[PowiainaNum 0.2 error]malformed input: "+r;var p=new e;if(!isNaN(Number(r))&&isFinite(Number(r)))return p.resetFromObject(e.fromNumber(Number(r))),p;var c=!1,f=!1;if("-"==r[0]||"+"==r[0]){var m=r.search(/[^-\+]/);c=(null!==(s=null===(a=r.substring(0,m).match(/-/g))||void 0===a?void 0:a.length)&&void 0!==s?s:0)%2==1,r=r.substring(m)}if("/"==r[0]){m=r.search(/[^\/]/);f=(null!==(h=null===(u=r.substring(0,m).match(/\//g))||void 0===u?void 0:u.length)&&void 0!==h?h:0)%2==1,r=r.substring(m)}if("NaN"==r)p.array=[o(NaN)];else if("Infinity"==r)p.array=[o(1/0)];else{var v,N,w,b;for(p.sign=1,p.array=[o(0)];r&&/^(\(?10[\^\{])/.test(r);){var d,I,O;if("("==r[0]&&(r=r.substring(1)),"^"==r[2])d=v=r.substring(2).search(/[^\^]/),N=v+2;else{v=r.indexOf("}");var E=r.substring(3,v).split(",");d=Number("!"==E[0]?1/0:E[0]),I=Number(null!==(g="!"==E[1]?1/0:E[1])&&void 0!==g?g:1),O=Number(null!==(y=E[2])&&void 0!==y?y:1),N=v+1}")"==(r=r.substring(N))[0]?(v=r.indexOf(" "),w=Number(r.substring(2,v)),r=r.substring(v+1)):w=1,1==d&&1==I&&1==O?p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat+=w:p.array.splice(1,0,o(w,1,I,O)):2==d&&1==I&&1==O?(v=p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat:0,(N=p.array[0].repeat)>=1e10&&++v,N>=10&&++v,p.array[0].repeat=v,p.array.length>=2&&1==p.array[1].arrow&&p.array.splice(1,1),b=p.getOperatorIndex(2),Number.isInteger(b)?p.array[b].repeat+=w:p.array.splice(Math.ceil(b),0,o(w,2,I,O))):isFinite(d)?(v=p.getOperator(d-1),(N=p.getOperator(d-2))>=10&&++v,b=p.getOperatorIndex(d),p.array.splice(1,Math.ceil(b)-1),p.array[0].repeat=v,Number.isInteger(b)?p.array[1].repeat+=w:p.array.splice(1,0,o(w,d,I,O))):p.array.splice(1,0,o(w,d,I,O))}v=r.split(/[Ee]/),N=[p.array[0].repeat,0],w=1;for(var M=v.length-1;M>=0;--M){N[0]<n&&0===N[1]?N[0]=Math.pow(10,w*N[0]):-1==w?(0===N[1]?N[0]=Math.pow(10,w*N[0]):1==N[1]&&N[0]<=Math.log10(Number.MAX_VALUE)?N[0]=Math.pow(10,w*Math.pow(10,N[0])):N[0]=0,N[1]=0):N[1]++;var k=v[M].indexOf("."),x=-1==k?v[M].length:k;0===N[1]?x>=17?(N[0]=Math.log10(N[0])+l(v[M].substring(0,x)),N[1]=1):v[M]&&(N[0]*=Number(v[M])):(b=x>=17?l(v[M].substring(0,x)):v[M]?Math.log10(Number(v[M])):0,1==N[1]?N[0]+=b:2==N[1]&&N[0]<n+Math.log10(b)&&(N[0]+=Math.log10(1+Math.pow(10,Math.log10(b)-N[0])))),N[0]<n&&N[1]?(N[0]=Math.pow(10,N[0]),N[1]--):N[0]>t&&(N[0]=Math.log10(N[0]),N[1]++)}p.array[0].repeat=N[0],N[1]&&(p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat+=N[1]:p.array.splice(1,0,o(N[1],1,1,1)))}return c&&(p.sign*=-1),f&&(p.small=!p.small),p.normalize(),p.normalize(),p}},{key:"fromObject",value:function(r){var a=new e;a.array=[];for(var t=0;t<r.array.length;t++)a.array[t]={arrow:r.array[t].arrow,expans:r.array[t].expans,megota:r.array[t].megota,repeat:r.array[t].repeat,valuereplaced:r.array[t].valuereplaced};return a.small=r.small,a.sign=r.sign,a.layer=r.layer,a}}])}();return p.ZERO=new p({array:[{arrow:0,expans:1,megota:1,repeat:1/0}],small:!0,layer:0,sign:0}),p.ONE=new p({array:[{arrow:0,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),p.MSI=new p(t),p.MSI_REC=((y=new p(t)).small=!0,y),p.E_MSI=new p({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),p.E_MSI_REC=new p({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:1}],small:!0,layer:0,sign:1}),p.TRITRI=new p({small:!1,layer:0,sign:1,array:[o(3638334640023.7783,0,1,1),o(7625587484984,1,1,1)]}),p.GRAHAMS_NUMBER=new p("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783"),p.POSITIVE_INFINITY=new p(1/0),p.NEGATIVE_INFINITY=new p(-1/0),p.NaN=new p({array:[{arrow:0,expans:1,megota:1,repeat:NaN}],small:!1,layer:0,sign:0}),p.maxOps=100,p}));
1
+ !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).PowiainaNum=e()}(this,(function(){"use strict";function r(r,a){for(var t=0;t<a.length;t++){var n=a[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,e(n.key),n)}}function e(r){var e=function(r,e){if("object"!=typeof r||!r)return r;var a=r[Symbol.toPrimitive];if(void 0!==a){var t=a.call(r,e||"default");if("object"!=typeof t)return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(r)}(r,"string");return"symbol"==typeof e?e:e+""}function a(r){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var t=9007199254740991,n=15.954589770191003,i=/^[-\+]*(Infinity|NaN|(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;function o(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;return{repeat:r,arrow:e,expans:a,megota:t,valuereplaced:e==1/0?0:a==1/0?1:-1}}function s(){for(var r=arguments.length,e=new Array(r),a=0;a<r;a++)e[a]=arguments[a];for(var t=0;t<Math.min(e[0].length,e[1].length);t++){var n=e[0][t],i=e[1][t];if(n<i)return-1;if(n>i)return 1}return 0}function l(r){return Math.log10(Number(r.substring(0,17)))+(r.length-17)}var u=.5671432904097838;function h(r){var e,a,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!Number.isFinite(r))return r;if(n){if(0===r)return r;if(1===r)return u;e=r<10?0:Math.log(r)-Math.log(Math.log(r))}else{if(0===r)return-1/0;e=r<=-.1?-2:Math.log(-r)-Math.log(-Math.log(-r))}for(var i=0;i<100;++i){if(a=(r*Math.exp(-e)+e*e)/(e+1),Math.abs(a-e)<t*Math.abs(a))return a;e=a}throw Error("Iteration failed to converge: ".concat(r.toString()))}function g(r){var e,a,t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(r.isInfinite())return r;if(o){if(r.eq(p.ZERO))return p.ZERO.clone();if(r.eq(p.ONE))return p.fromNumber(u);e=r.log()}else{if(r.eq(p.ZERO))return p.NEGATIVE_INFINITY.clone();e=r.neg().log()}for(var s=0;s<100;++s){if(a=e.neg().exp(),t=e.sub(r.mul(a)),(n=e.sub(t.div(e.add(1).sub(e.add(2).mul(t).div(e.mul(2).add(2)))))).sub(e).abs().lt(n.abs().mul(i)))return n;e=n}throw Error("Iteration failed to converge: ".concat(r.toString()))}var y,p=function(){function e(r){if(function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.array=[{arrow:0,expans:1,megota:1,repeat:NaN}],this.small=!1,this.sign=0,this.layer=0,void 0===r);else if("number"==typeof r){var t=e.fromNumber(r);this.resetFromObject(t)}else if("object"==a(r)){var n=e.fromObject(r);this.resetFromObject(n)}else if("string"==typeof r){var i=e.fromString(r);this.resetFromObject(i)}}return function(e,a,t){return a&&r(e.prototype,a),t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}(e,[{key:"add",value:function(r){var a,t,i,s,l,u,h=this.clone(),g=new e(r);if(h.eq(e.POSITIVE_INFINITY)&&g.eq(e.NEGATIVE_INFINITY)||h.eq(e.NEGATIVE_INFINITY)&&g.eq(e.POSITIVE_INFINITY))return e.NaN.clone();if(!h.isFinite())return h.clone();if(!g.isFinite())return g.clone();if(h.isZero())return g.clone();if(g.isZero())return h.clone();if(h.sign==-g.sign&&function(){var r=h.abs(),e=g.abs();return r.eq(e)}())return e.ZERO.clone();if(h.abs().lt(e.E_MSI_REC)||h.abs().gt(e.E_MSI)||g.abs().lt(e.E_MSI_REC)||g.abs().gt(e.E_MSI))return h.maxabs(g);if(-1==h.sign)return h.neg().add(g.neg()).neg();h.cmpabs(g)>0?(l=h,u=g):(u=h,l=g);var y=1;if(!(l.small||u.small||(null===(a=l.array[1])||void 0===a?void 0:a.repeat)||(null===(t=u.array[1])||void 0===t?void 0:t.repeat)||l.sign!=u.sign))return new e((l.array[0].repeat+u.array[0].repeat)*l.sign);var p=(l.small?-1:1)*((null===(i=l.array[1])||void 0===i?void 0:i.repeat)?l.array[0].repeat:Math.log10(l.array[0].repeat)),f=(u.small?-1:1)*((null===(s=u.array[1])||void 0===s?void 0:s.repeat)?u.array[0].repeat:Math.log10(u.array[0].repeat));if(p-f>n)return l;var c,m,v=-Math.floor(p),N=0;if((m=l.sign*Math.pow(10,p+v)+u.sign*Math.pow(10,f+v))>0&&(N=Math.log10(m)-v),m<0&&(N=Math.log10(-m)-v,y*=-1),0==m)throw Error("Encounter a calculate error");return(c=new e).sign=1,c.array=N>n||N<-n?[o(N,0),o(1,1)]:[o(Math.pow(10,N),0)],c.small=N<0,c.sign*=y,c}},{key:"sub",value:function(r){return this.add(new e(r).neg())}},{key:"mul",value:function(r){var a,t=this.clone(),n=new e(r);return t.eq(e.POSITIVE_INFINITY)&&n.eq(e.NEGATIVE_INFINITY)||n.eq(e.POSITIVE_INFINITY)&&t.eq(e.NEGATIVE_INFINITY)?e.NEGATIVE_INFINITY.clone():t.isInfinite()&&n.eq(e.ZERO)&&n.isInfinite()&&t.eq(e.ZERO)?e.NaN.clone():t.eq(e.NEGATIVE_INFINITY)&&n.eq(e.NEGATIVE_INFINITY)?e.POSITIVE_INFINITY.clone():t.isFinite()?n.isFinite()?t.isZero()||n.isZero()?e.ZERO.clone():((a=t.abs().log10().add(n.abs().log10()).pow10()).sign=t.sign*n.sign,a):n.clone():t.clone()}},{key:"div",value:function(r){var a=new e(r).rec();return this.mul(a)}},{key:"pow10",value:function(){var r,a,t=this.clone();return this.isFinite()?t.isneg()?(t.sign*=-1,t.pow10().rec()):t.lte(308.25471555991675)?e.fromNumber(Math.pow(10,t.toNumber())):t.small?t.lt(e.MSI_REC)?e.ONE:new e(Math.pow(10,Math.pow(t.array[0].repeat,-1))):(t.setOperator((null!==(a=null===(r=t.array[1])||void 0===r?void 0:r.repeat)&&void 0!==a?a:0)+1,1),t.normalize(),t):this.clone()}},{key:"pow",value:function(r){var a=new e(r);if(!a.isFinite())return a.clone();if(!this.isFinite())return this.clone();if(this.eq(10))return a.pow10();if(this.isneg()){if(!a.isInt())return e.NaN.clone();var t=this.abs().pow(a);return t.sign=function(){var r=a.mod(2).round();return r.eq(0)||r.eq(2)?1:-1}(),t}var n=this.toNumber(),i=a.toNumber(),o=Math.pow(n,i);return isFinite(o)?e.fromNumber(o):this.log10().mul(a).pow10()}},{key:"pow_base",value:function(r){return new e(r).pow(this)}},{key:"root",value:function(r){var a=new e(r);return this.pow(a.rec())}},{key:"sqrt",value:function(){return this.pow(.5)}},{key:"cbrt",value:function(){return this.root(3)}},{key:"abs",value:function(){var r=this.clone();return r.sign<0&&(r.sign*=-1),r}},{key:"log10",value:function(){var r,a;if(this.isneg())return e.NaN.clone();if(this.isZero())return e.NEGATIVE_INFINITY.clone();if(this.small){var t=this.clone();return t.small=!t.small,t.log10().neg()}if(null===(a=null===(r=this.array[1])||void 0===r?void 0:r.repeat)||void 0===a||a)return new e(Math.log10(this.array[0].repeat));var n=this.clone();return n.array[1].repeat=n.array[1].repeat-1,n.normalize(),n}},{key:"log",value:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.E,a=new e(r);return this.log10().div(a.log10())}},{key:"exp",value:function(){return this.pow_base(Math.E)}},{key:"mod",value:function(r){var a=new e(r),t=this.div(a);return t.sub(t.floor()).mul(a)}},{key:"factorial",value:function(){return this.abs().lt(t)?this.add(1).gamma():this.abs().lt(e.E_MSI)?e.exp(this.mul(this.log10().sub(1))):e.exp(this)}},{key:"gamma",value:function(){if(this.small)return this.rec();if(this.lte(t)){if(this.lt(24))return e.fromNumber(function(r){if(!isFinite(r))return r;if(r<-50)return r===Math.trunc(r)?Number.NEGATIVE_INFINITY:0;for(var e=1;r<10;)e*=r,++r;var a=.9189385332046727;a+=((r-=1)+.5)*Math.log(r),a-=r;var t=r*r,n=r;return a+=1/(12*n),a-=1/(360*(n*=t)),a+=1/(1260*(n*=t)),a-=1/(1680*(n*=t)),a+=1/(1188*(n*=t)),a-=691/(360360*(n*=t)),a+=7/(1092*(n*=t)),a-=3617/(122400*(n*=t)),Math.exp(a)/e}(this.sign*this.getOperator(0)));var r=this.getOperator(0)-1,a=.9189385332046727;a+=(r+.5)*Math.log(r);var n=r*r,i=r,o=12*i,s=1/o,l=(a-=r)+s;if(l===a)return e.exp(a);if((l=(a=l)-(s=1/(o=360*(i*=n))))===a)return e.exp(a);a=l;var u=1/(o=1260*(i*=n));return a+=u,a-=u=1/(o=1680*(i*=n)),e.exp(a)}return this.gt(t)?e.exp(this.mul(this.log().sub(1))):e.exp(this)}},{key:"lambertw",value:function(){var r=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.lt(-.3678794411710499)?e.NaN.clone():r?this.abs().lt("1e-300")?new e(this):this.small?e.fromNumber(h(this.toNumber())):0===this.layer?e.fromNumber(h(this.sign*this.getOperator(0))):this.lt("eee15")?g(this):this.log():1===this.sign?e.NaN.clone():0===this.layer?e.fromNumber(h(this.sign*this.array[0].repeat,1e-10,!1)):1==this.layer?g(this,1e-10,!1):this.neg().rec().lambertw().neg()}},{key:"max",value:function(r){var a=new e(r);return this.lt(a)?a.clone():this.clone()}},{key:"min",value:function(r){var a=new e(r);return this.gte(a)?a.clone():this.clone()}},{key:"maxabs",value:function(r){var a=new e(r).abs();return this.abs().lt(a)?a.clone():this.clone()}},{key:"minabs",value:function(r){var a=new e(r).abs();return this.abs().gt(a)?a.clone():this.clone()}},{key:"cmpabs",value:function(r){var a=new e(r).abs();return this.abs().cmp(a)}},{key:"neg",value:function(){var r=this.clone();return r.sign*=-1,r.normalize(),r}},{key:"rec",value:function(){var r=this.clone();return r.small=!r.small,r}},{key:"floor",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?e.ZERO.clone():e.ONE.neg().clone();var r=this.abs();return r.array[0].repeat=Math[1==this.sign?"floor":"ceil"](r.getOperator(0)),r}},{key:"ceil",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?e.ONE.clone():e.ZERO.clone();var r=this.abs();return r.array[0].repeat=Math[1==this.sign?"ceil":"floor"](r.getOperator(0)),r.sign=this.sign,r}},{key:"round",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?this.rec().lte(2)?e.ONE.clone():e.ZERO.clone():this.abs().rec().lte(2)?e.ZERO.clone():e.ONE.neg().clone();var r=this.abs();return r.array[0].repeat=Math.round(r.array[0].repeat),r.sign=this.sign,r}},{key:"compare",value:function(r){var a=new e(r);if(this.isNaN()||a.isNaN())return 2;if(this.sign<a.sign)return-1;if(this.sign>a.sign)return 1;var t=-1==this.sign&&-1==a.sign;if(this.small&&!a.small)return-1*(t?-1:1);if(a.small&&!this.small)return 1*(t?-1:1);var n=1;this.small&&a.small&&(n*=-1),t&&(n*=-1);for(var i=0,o=0;this.array.length-1-o>=0&&a.array.length-1-o>=0;o++){var l=this.array[this.array.length-1-o],u=a.array[a.array.length-1-o],h=s([l.megota,l.expans,l.arrow,l.repeat],[u.megota,u.expans,u.arrow,u.repeat]);if(1==h){i=1;break}if(-1==h){i=-1;break}}return i*n+1-1}},{key:"cmp",value:function(r){return this.compare(r)}},{key:"eq",value:function(r){return 0===this.cmp(r)}},{key:"neq",value:function(r){return 0!==this.cmp(r)}},{key:"lt",value:function(r){return-1===this.cmp(r)}},{key:"lte",value:function(r){return this.cmp(r)<=0}},{key:"gt",value:function(r){return 1==this.cmp(r)}},{key:"gte",value:function(r){var e=this.cmp(r);return 0==e||1==e}},{key:"isNaN",value:function(r){function e(){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(){return isNaN(this.getOperator(0))}))},{key:"isZero",value:function(){return Boolean(this.small&&!isFinite(this.getOperator(0)))}},{key:"isFinite",value:function(r){function e(){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(){return Boolean(this.small||isFinite(this.getOperator(0)))&&!this.isNaN()}))},{key:"isInfinite",value:function(){return Boolean(!this.small&&!isFinite(this.getOperator(0)))||this.isNaN()}},{key:"isInt",value:function(){return!!this.isZero()||(!(this.small||!Number.isInteger(this.getOperator(0)))||!!this.abs().gte(t/2))}},{key:"ispos",value:function(){return this.sign>0}},{key:"isneg",value:function(){return this.sign<0}},{key:"normalize",value:function(){for(var r=!0,a=this,i=0;i<this.array.length;i++)if(this.array[i].repeat==1/0)return this.array=[{arrow:0,expans:1,megota:1,repeat:1/0}],this.layer=0,this;for(var l=1;l<a.array.length;++l){var u=a.array[l];if(null!==u.arrow&&void 0!==u.arrow||(u.arrow=0),null!==u.expans&&void 0!==u.expans||(u.expans=1),null!==u.megota&&void 0!==u.megota||(u.megota=1),isNaN(u.arrow)||isNaN(u.repeat)||isNaN(u.expans)||isNaN(u.megota))return a.array=[o(NaN,0,1,1)],a;if(!isFinite(u.repeat)||!isFinite(u.megota))return a.array=[o(1/0,0,1,1)],a;Number.isInteger(u.arrow)||(u.arrow=Math.floor(u.arrow)),Number.isInteger(u.repeat)||(u.repeat=Math.floor(u.repeat)),Number.isInteger(u.expans)||(u.expans=Math.floor(u.expans)),Number.isInteger(u.megota)||(u.megota=Math.floor(u.megota))}do{for(r=!1,this.array.sort((function(r,e){return s([r.megota,r.expans,r.arrow],[e.megota,e.expans,e.arrow])})),l=1;l<a.array.length;++l)0===a.array[l].arrow||0!==a.array[l].repeat&&null!==a.array[l].repeat&&void 0!==a.array[l].repeat?0==a.array[l].arrow&&a.array[l].expans>=2&&(a.array[l].arrow=1/0,a.array[l].valuereplaced=0,a.array[l].expans=a.array[l].expans-1):(a.array.splice(l,1),--l);for(var h=1;h<this.array.length;h++)0==this.array[h].repeat&&(this.array.splice(h,1),h--);for(a.array.length||(a.small=!a.small,a.array=[o(1/0)]),a.array.length>e.maxOps&&a.array.splice(1,a.array.length-e.maxOps),this.getOperator(1)>=1&&this.getOperator(0)<n&&(this.setOperator(this.getOperator(1)-1,1),this.setOperator(Math.pow(10,this.getOperator(0)),0),r=!0),this.getOperator(0)>t&&(this.setOperator(this.getOperator(1)+1,1),this.setOperator(Math.log10(this.getOperator(0)),0),r=!0),1==this.array.length&&this.array[0].repeat<1&&(this.array[0].repeat=1/this.array[0].repeat,this.small=!this.small,r=!0);a.array.length>=2&&1==a.array[0].repeat&&a.array[1].repeat;)a.array[1].repeat>1?a.array[1].repeat--:a.array.splice(1,1),a.array[0].repeat=10,r=!0;for(a.array.length>=2&&a.array[0].repeat<t&&a.array[1].arrow>=2&&1==a.array[1].repeat&&(a.array.splice(1,1,o(a.array[0].repeat,a.array[1].arrow-1,a.array[1].expans,a.array[1].megota)),a.array[0].repeat=10,r=!0),l=1;l<a.array.length-1;++l)a.array[l].arrow==a.array[l+1].arrow&&a.array[l].expans==a.array[l+1].expans&&a.array[l].megota==a.array[l+1].megota&&(a.array[l].repeat+=a.array[l+1].repeat,a.array.splice(l+1,1),--l,r=!0)}while(r);return this}},{key:"getOperatorIndex",value:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if(1==this.array.length&&0==r)return 0;if(1==this.array.length&&1==r)return.5;if(2==this.array.length&&1==r)return 1;if(2==this.array.length&&0==r)return 0;for(var t=0;t<this.array.length;t++){var n=s([this.array[t].megota,this.array[t].expans,this.array[t].arrow],[a,e,r]);if(0==n)return t;if(1==n)return t-.5}return this.array.length-.5}},{key:"getOperator",value:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=this.getOperatorIndex(r,e,a);return this.array[t]?this.array[t].repeat:0}},{key:"setOperator",value:function(r,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=this.getOperatorIndex(e,a,t);return this.array[n]?(this.array[n].repeat=r,!1):(this.array.splice(Math.ceil(n),0,{arrow:e,expans:a,megota:t,valuereplaced:a===1/0?1:e==1/0?0:-1,repeat:r}),!0)}},{key:"clone",value:function(){var r=new e;return r.resetFromObject(this),r}},{key:"resetFromObject",value:function(r){this.array=[];for(var e=0;e<r.array.length;e++)this.array[e]={arrow:r.array[e].arrow,expans:r.array[e].expans,megota:r.array[e].megota,repeat:r.array[e].repeat,valuereplaced:r.array[e].valuereplaced};return this.small=r.small,this.sign=r.sign,this.layer=r.layer,this}},{key:"toNumber",value:function(){return-1==this.sign?-this.neg().toNumber():this.small?1/this.rec().toNumber():this.array.length>2?1/0:1==this.array.length?this.array[0].repeat:2==this.array.length&&1==this.array[1].arrow&&1==this.array[1].expans&&1==this.array[1].megota&&1==this.array[1].repeat?Math.pow(10,this.getOperator(0)):NaN}},{key:"toString",value:function(){if(this.isNaN())return"NaN";if(-1==this.sign)return"-".concat(this.neg().toString());if(this.small)return this.eq(e.ZERO)?"0":"/".concat(this.rec().toString());if(this.isInfinite())return"Infinity";for(var r="",a=this.array.length-1;a>=0;a--){var t=this.array[a],n="10{".concat(t.arrow===1/0?"!":t.arrow).concat(t.expans>1||t.megota>1?",".concat(t.expans===1/0?"!":t.expans):"").concat(t.megota>1?",".concat(t.megota):"","}");n=1==t.arrow&&1==t.expans&&1==t.megota&&t.repeat<5?"e".repeat(t.repeat):0==t.arrow&&1==t.expans&&1==t.megota?t.repeat.toString():t.repeat>1?"(".concat(n,")^").concat(t.repeat," "):"".concat(n," "),r+="".concat(n)}return r}},{key:"arr01",get:function(){for(var r=[0],e=0;e<this.array.length;e++)0==e?r[0]=this.array[e].repeat:(r[e]=[0,0,0,0],r[e][0]=this.array[e].arrow==1/0?"x":this.array[e].arrow,r[e][1]=this.array[e].repeat,r[e][2]=this.array[e].expans==1/0?"x":this.array[e].expans,r[e][3]=this.array[e].megota);return r}}],[{key:"add",value:function(r,a){return new e(r).add(a)}},{key:"sub",value:function(r,a){return new e(r).sub(a)}},{key:"mul",value:function(r,a){return new e(r).mul(a)}},{key:"div",value:function(r,a){return new e(r).div(a)}},{key:"pow",value:function(r,a){return new e(r).pow(a)}},{key:"root",value:function(r,a){return new e(r).root(a)}},{key:"sqrt",value:function(r){return new e(r).sqrt()}},{key:"cbrt",value:function(r){return new e(r).cbrt()}},{key:"log10",value:function(r){return new e(r).log10()}},{key:"log",value:function(r){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Math.E;return new e(r).log(a)}},{key:"exp",value:function(r){return new e(r).pow_base(Math.E)}},{key:"factorial",value:function(r){return new e(r).factorial()}},{key:"gamma",value:function(r){return new e(r).gamma()}},{key:"lambertw",value:function(r){var a=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new e(r).lambertw(a)}},{key:"isNaN",value:function(r){return new e(r).isNaN()}},{key:"fromNumber",value:function(r){var a=new e;r<0?a.sign=-1:0==r?a.sign=0:r>0&&(a.sign=1);var n=Math.abs(r);return n>=11102230246251568e-32&&n<1?(a.small=!0,a.array=[o(1/n,0)]):n<11102230246251568e-32?(a.small=!0,a.array=[o(-Math.log10(n),0),o(1,1)]):n<=t?a.array=[o(n,0)]:(a.setOperator(Math.log10(n),0),a.array=[o(Math.log10(n),0),o(1,1)]),a}},{key:"fromString",value:function(r){var a,s,u,h,g,y,p=new e;if(!isNaN(Number(r))&&isFinite(Number(r)))return p.resetFromObject(e.fromNumber(Number(r))),p;if(!i.test(r))throw"[PowiainaNum 0.2 error]malformed input: "+r;var f=!1,c=!1;if("-"==r[0]||"+"==r[0]){var m=r.search(/[^-\+]/);f=(null!==(s=null===(a=r.substring(0,m).match(/-/g))||void 0===a?void 0:a.length)&&void 0!==s?s:0)%2==1,r=r.substring(m)}if("/"==r[0]){m=r.search(/[^\/]/);c=(null!==(h=null===(u=r.substring(0,m).match(/\//g))||void 0===u?void 0:u.length)&&void 0!==h?h:0)%2==1,r=r.substring(m)}if("NaN"==r)p.array=[o(NaN)];else if("Infinity"==r)p.array=[o(1/0)];else{var v,N,w,b;for(p.sign=1,p.array=[o(0)];r&&/^(\(?10[\^\{])/.test(r);){var d,I,E;if("("==r[0]&&(r=r.substring(1)),"^"==r[2])d=v=r.substring(2).search(/[^\^]/),N=v+2;else{v=r.indexOf("}");var M=r.substring(3,v).split(",");d=Number("!"==M[0]?1/0:M[0]),I=Number(null!==(g="!"==M[1]?1/0:M[1])&&void 0!==g?g:1),E=Number(null!==(y=M[2])&&void 0!==y?y:1),N=v+1}")"==(r=r.substring(N))[0]?(v=r.indexOf(" "),w=Number(r.substring(2,v)),r=r.substring(v+1)):w=1,1==d&&1==I&&1==E?p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat+=w:p.array.splice(1,0,o(w,1,I,E)):2==d&&1==I&&1==E?(v=p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat:0,(N=p.array[0].repeat)>=1e10&&++v,N>=10&&++v,p.array[0].repeat=v,p.array.length>=2&&1==p.array[1].arrow&&p.array.splice(1,1),b=p.getOperatorIndex(2),Number.isInteger(b)?p.array[b].repeat+=w:p.array.splice(Math.ceil(b),0,o(w,2,I,E))):isFinite(d)?(v=p.getOperator(d-1),(N=p.getOperator(d-2))>=10&&++v,b=p.getOperatorIndex(d),p.array.splice(1,Math.ceil(b)-1),p.array[0].repeat=v,Number.isInteger(b)?p.array[1].repeat+=w:p.array.splice(1,0,o(w,d,I,E))):p.array.splice(1,0,o(w,d,I,E))}v=r.split(/[Ee]/),N=[p.array[0].repeat,0],w=1;for(var O=v.length-1;O>=0;--O){N[0]<n&&0===N[1]?N[0]=Math.pow(10,w*N[0]):-1==w?(0===N[1]?N[0]=Math.pow(10,w*N[0]):1==N[1]&&N[0]<=Math.log10(Number.MAX_VALUE)?N[0]=Math.pow(10,w*Math.pow(10,N[0])):N[0]=0,N[1]=0):N[1]++;var k=v[O].indexOf("."),x=-1==k?v[O].length:k;0===N[1]?x>=17?(N[0]=Math.log10(N[0])+l(v[O].substring(0,x)),N[1]=1):v[O]&&(N[0]*=Number(v[O])):(b=x>=17?l(v[O].substring(0,x)):v[O]?Math.log10(Number(v[O])):0,1==N[1]?N[0]+=b:2==N[1]&&N[0]<n+Math.log10(b)&&(N[0]+=Math.log10(1+Math.pow(10,Math.log10(b)-N[0])))),N[0]<n&&N[1]?(N[0]=Math.pow(10,N[0]),N[1]--):N[0]>t&&(N[0]=Math.log10(N[0]),N[1]++)}p.array[0].repeat=N[0],N[1]&&(p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat+=N[1]:p.array.splice(1,0,o(N[1],1,1,1)))}return f&&(p.sign*=-1),c&&(p.small=!p.small),p.normalize(),p.normalize(),p}},{key:"fromObject",value:function(r){var a=new e;a.array=[];for(var t=0;t<r.array.length;t++)a.array[t]={arrow:r.array[t].arrow,expans:r.array[t].expans,megota:r.array[t].megota,repeat:r.array[t].repeat,valuereplaced:r.array[t].valuereplaced};return a.small=r.small,a.sign=r.sign,a.layer=r.layer,a}}])}();return p.ZERO=new p({array:[{arrow:0,expans:1,megota:1,repeat:1/0}],small:!0,layer:0,sign:0}),p.ONE=new p({array:[{arrow:0,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),p.MSI=new p(t),p.MSI_REC=((y=new p(t)).small=!0,y),p.E_MSI=new p({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),p.E_MSI_REC=new p({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:1}],small:!0,layer:0,sign:1}),p.TETRATED_MSI=new p({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:t}],small:!1,layer:0,sign:1}),p.TRITRI=new p({small:!1,layer:0,sign:1,array:[o(3638334640023.7783,0,1,1),o(7625587484984,1,1,1)]}),p.GRAHAMS_NUMBER=new p("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783"),p.POSITIVE_INFINITY=new p(1/0),p.NEGATIVE_INFINITY=new p(-1/0),p.NaN=new p({array:[{arrow:0,expans:1,megota:1,repeat:NaN}],small:!1,layer:0,sign:0}),p.maxOps=100,p}));
package/dist/index.d.ts CHANGED
@@ -97,6 +97,8 @@ export default class PowiainaNum implements IPowiainaNum {
97
97
  isFinite(): boolean;
98
98
  isInfinite(): boolean;
99
99
  isInt(): boolean;
100
+ ispos(): boolean;
101
+ isneg(): boolean;
100
102
  static isNaN(x: PowiainaNumSource): boolean;
101
103
  /**
102
104
  * Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
@@ -137,6 +139,7 @@ export default class PowiainaNum implements IPowiainaNum {
137
139
  static readonly MSI_REC: PowiainaNum;
138
140
  static readonly E_MSI: PowiainaNum;
139
141
  static readonly E_MSI_REC: PowiainaNum;
142
+ static readonly TETRATED_MSI: PowiainaNum;
140
143
  static readonly TRITRI: PowiainaNum;
141
144
  static readonly GRAHAMS_NUMBER: PowiainaNum;
142
145
  static readonly POSITIVE_INFINITY: PowiainaNum;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powiaina_num.js",
3
- "version": "0.2.0-alpha.2.4",
3
+ "version": "0.2.0-alpha.2.6",
4
4
  "description": "A JavaScript library that handles arithmetic for numbers as large as {10,9e15,1,1,1,2}.",
5
5
  "type": "module",
6
6
  "main": "dist/PowiainaNum.js",