powiaina_num.js 0.2.0-alpha.2.7 → 0.2.0-alpha.2.9
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.
- package/README.md +2 -1
- package/dist/PowiainaNum.cjs.js +216 -47
- package/dist/PowiainaNum.esm.js +216 -47
- package/dist/PowiainaNum.js +216 -47
- package/dist/PowiainaNum.min.js +1 -1
- package/dist/index.d.ts +18 -1
- package/package.json +1 -1
package/dist/PowiainaNum.js
CHANGED
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
var MSI_LOG10 = 15.954589770191003;
|
|
48
48
|
var MSI_REC = 1.1102230246251568e-16;
|
|
49
49
|
var LONG_STRING_MIN_LENGTH = 17;
|
|
50
|
-
var
|
|
50
|
+
var EXP_E_REC = 1.444667861009766;
|
|
51
|
+
var isPowiainaNum = /^\/*[-\+]*(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+))$/;
|
|
51
52
|
function newOperator(r) {
|
|
52
53
|
var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
53
54
|
var e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
@@ -166,7 +167,7 @@
|
|
|
166
167
|
var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
167
168
|
var w;
|
|
168
169
|
var ew, wewz, wn;
|
|
169
|
-
if (z.
|
|
170
|
+
if (z.isInfiNaN()) return z;
|
|
170
171
|
if (principal) {
|
|
171
172
|
if (z.eq(PowiainaNum.ZERO)) {
|
|
172
173
|
return PowiainaNum.ZERO.clone();
|
|
@@ -298,7 +299,7 @@
|
|
|
298
299
|
var y = new PowiainaNum(other);
|
|
299
300
|
// inf * -inf = -inf
|
|
300
301
|
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();
|
|
301
|
-
if (x.
|
|
302
|
+
if (x.isInfiNaN() && y.eq(PowiainaNum.ZERO) && y.isInfiNaN() && x.eq(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
|
|
302
303
|
if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
303
304
|
// inf & nan check
|
|
304
305
|
if (!x.isFinite()) return x.clone();
|
|
@@ -397,6 +398,127 @@
|
|
|
397
398
|
value: function cbrt() {
|
|
398
399
|
return this.root(3);
|
|
399
400
|
}
|
|
401
|
+
}, {
|
|
402
|
+
key: "tetrate",
|
|
403
|
+
value:
|
|
404
|
+
// Code from ExpantaNum.js
|
|
405
|
+
function tetrate(other2) {
|
|
406
|
+
var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
407
|
+
var t = this.clone();
|
|
408
|
+
var other = new PowiainaNum(other2);
|
|
409
|
+
var payl = new PowiainaNum(payload);
|
|
410
|
+
if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
|
|
411
|
+
if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
|
|
412
|
+
var negln;
|
|
413
|
+
if (other.isInfi() && other.sign > 0) {
|
|
414
|
+
if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
415
|
+
negln = this.log().neg();
|
|
416
|
+
return negln.lambertw().div(negln);
|
|
417
|
+
}
|
|
418
|
+
if (other.lte(-2)) return PowiainaNum.NaN.clone();
|
|
419
|
+
if (t.isZero()) {
|
|
420
|
+
if (other.isZero()) return PowiainaNum.NaN.clone();
|
|
421
|
+
if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
|
|
422
|
+
return PowiainaNum.ONE.clone();
|
|
423
|
+
}
|
|
424
|
+
if (t.eq(PowiainaNum.ONE)) {
|
|
425
|
+
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
|
|
426
|
+
return PowiainaNum.ONE.clone();
|
|
427
|
+
}
|
|
428
|
+
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
|
|
429
|
+
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
430
|
+
if (other.eq(PowiainaNum.ONE)) return t;
|
|
431
|
+
if (other.eq(2)) return t.pow(t);
|
|
432
|
+
if (t.eq(2)) {
|
|
433
|
+
if (other.eq(3)) return PowiainaNum.fromNumber(16);
|
|
434
|
+
if (other.eq(4)) return PowiainaNum.fromNumber(65536);
|
|
435
|
+
}
|
|
436
|
+
var m = t.max(other);
|
|
437
|
+
if (m.gt(PowiainaNum.PENTATED_MSI)) return m;
|
|
438
|
+
if (m.gt(PowiainaNum.TETRATED_MSI) || other.gt(MSI)) {
|
|
439
|
+
if (this.lt(EXP_E_REC)) {
|
|
440
|
+
negln = t.ln().neg();
|
|
441
|
+
return negln.lambertw().div(negln);
|
|
442
|
+
}
|
|
443
|
+
var j = t.slog(10).add(other);
|
|
444
|
+
j.setOperator(j.getOperator(2) + 1, 2);
|
|
445
|
+
j.normalize();
|
|
446
|
+
return j;
|
|
447
|
+
}
|
|
448
|
+
var y = other.toNumber();
|
|
449
|
+
var f = Math.floor(y);
|
|
450
|
+
var r = t.pow(y - f);
|
|
451
|
+
var l = PowiainaNum.NaN;
|
|
452
|
+
var i = 0;
|
|
453
|
+
for (var w = PowiainaNum.E_MSI.clone(); f !== 0 && r.lt(w) && i < 100; ++i) {
|
|
454
|
+
if (f > 0) {
|
|
455
|
+
r = t.pow(r);
|
|
456
|
+
if (l.eq(r)) {
|
|
457
|
+
f = 0;
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
l = r;
|
|
461
|
+
--f;
|
|
462
|
+
} else {
|
|
463
|
+
r = r.log(t);
|
|
464
|
+
if (l.eq(r)) {
|
|
465
|
+
f = 0;
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
l = r;
|
|
469
|
+
++f;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (i == 100 || this.lt(EXP_E_REC)) f = 0;
|
|
473
|
+
r.setOperator(r.getOperator(1) + f, 1);
|
|
474
|
+
r.normalize();
|
|
475
|
+
return r;
|
|
476
|
+
}
|
|
477
|
+
// Code from ExpantaNum.js
|
|
478
|
+
}, {
|
|
479
|
+
key: "slog",
|
|
480
|
+
value: function slog() {
|
|
481
|
+
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
482
|
+
var x = this.clone();
|
|
483
|
+
var b = new PowiainaNum(base);
|
|
484
|
+
if (x.isInfiNaN()) return x;
|
|
485
|
+
if (b.isNaN()) return b;
|
|
486
|
+
if (b.isInfi()) return PowiainaNum.ZERO.clone();
|
|
487
|
+
if (x.isZero()) return PowiainaNum.ONE.clone();
|
|
488
|
+
if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
489
|
+
if (x.eq(b)) return PowiainaNum.ONE.clone();
|
|
490
|
+
if (b.lt(EXP_E_REC)) {
|
|
491
|
+
var a = b.tetrate(Infinity);
|
|
492
|
+
if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
493
|
+
if (x.gt(a)) return PowiainaNum.NaN.clone();
|
|
494
|
+
}
|
|
495
|
+
if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
|
|
496
|
+
if (x.gt(b)) return x;
|
|
497
|
+
return PowiainaNum.ZERO.clone();
|
|
498
|
+
}
|
|
499
|
+
if (x.max(b).gt(PowiainaNum.TETRATED_MSI)) {
|
|
500
|
+
if (x.gt(b)) {
|
|
501
|
+
x.setOperator(x.getOperator(2) - 1, 2);
|
|
502
|
+
x.normalize();
|
|
503
|
+
return x.sub(x.getOperator(1));
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (x.lt(PowiainaNum.ZERO.clone())) return b.pow(x).sub(2);
|
|
507
|
+
var r = 0;
|
|
508
|
+
var t = x.getOperator(1) - b.getOperator(1);
|
|
509
|
+
if (t > 3) {
|
|
510
|
+
var l = t - 3;
|
|
511
|
+
r += l;
|
|
512
|
+
x.setOperator(x.getOperator(1) - l, 1);
|
|
513
|
+
}
|
|
514
|
+
for (var i = 0; i < 100; ++i) {
|
|
515
|
+
if (x.lte(PowiainaNum.ONE)) return new PowiainaNum(r + x.toNumber());
|
|
516
|
+
++r;
|
|
517
|
+
x = PowiainaNum.log(x, base);
|
|
518
|
+
}
|
|
519
|
+
console.warn("Failed to converage");
|
|
520
|
+
return PowiainaNum.NaN.clone();
|
|
521
|
+
}
|
|
400
522
|
}, {
|
|
401
523
|
key: "abs",
|
|
402
524
|
value: function abs() {
|
|
@@ -428,6 +550,11 @@
|
|
|
428
550
|
var other = new PowiainaNum(base);
|
|
429
551
|
return this.log10().div(other.log10());
|
|
430
552
|
}
|
|
553
|
+
}, {
|
|
554
|
+
key: "ln",
|
|
555
|
+
value: function ln() {
|
|
556
|
+
return this.log();
|
|
557
|
+
}
|
|
431
558
|
}, {
|
|
432
559
|
key: "exp",
|
|
433
560
|
value: function exp() {
|
|
@@ -634,6 +761,18 @@
|
|
|
634
761
|
r.sign = this.sign;
|
|
635
762
|
return r;
|
|
636
763
|
}
|
|
764
|
+
/**
|
|
765
|
+
* Work like `Math.trunc`,
|
|
766
|
+
*
|
|
767
|
+
* if `this > 0`, return `floor(this)`
|
|
768
|
+
*
|
|
769
|
+
* if `this < 0`, return `ceil(this)`
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
|
|
773
|
+
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
774
|
+
* @returns
|
|
775
|
+
*/
|
|
637
776
|
}, {
|
|
638
777
|
key: "trunc",
|
|
639
778
|
value: function trunc() {
|
|
@@ -740,9 +879,14 @@
|
|
|
740
879
|
return Boolean(this.small || isFinite(this.getOperator(0))) && !this.isNaN();
|
|
741
880
|
})
|
|
742
881
|
}, {
|
|
743
|
-
key: "
|
|
744
|
-
value: function
|
|
745
|
-
return
|
|
882
|
+
key: "isInfi",
|
|
883
|
+
value: function isInfi() {
|
|
884
|
+
return this.rec().isZero();
|
|
885
|
+
}
|
|
886
|
+
}, {
|
|
887
|
+
key: "isInfiNaN",
|
|
888
|
+
value: function isInfiNaN() {
|
|
889
|
+
return this.isInfi() || this.isNaN();
|
|
746
890
|
}
|
|
747
891
|
}, {
|
|
748
892
|
key: "isInt",
|
|
@@ -774,6 +918,7 @@
|
|
|
774
918
|
var renormalize = true;
|
|
775
919
|
var x = this;
|
|
776
920
|
for (var _i = 0; _i < this.array.length; _i++) {
|
|
921
|
+
// Check what is infinity
|
|
777
922
|
if (this.array[_i].repeat == Infinity) {
|
|
778
923
|
this.array = [{
|
|
779
924
|
arrow: 0,
|
|
@@ -809,36 +954,42 @@
|
|
|
809
954
|
if (!Number.isInteger(e.expans)) e.expans = Math.floor(e.expans);
|
|
810
955
|
if (!Number.isInteger(e.megota)) e.megota = Math.floor(e.megota);
|
|
811
956
|
}
|
|
957
|
+
if (!x.array.length) {
|
|
958
|
+
x.small = !x.small;
|
|
959
|
+
x.array = [newOperator(Infinity)]; // if no array set zero
|
|
960
|
+
}
|
|
812
961
|
do {
|
|
813
962
|
renormalize = false;
|
|
963
|
+
// Sort arrays.
|
|
814
964
|
this.array.sort(function (a, b) {
|
|
815
965
|
return compareTuples([a.megota, a.expans, a.arrow], [b.megota, b.expans, b.arrow]);
|
|
816
966
|
});
|
|
967
|
+
for (i = 1; i < x.array.length - 1; ++i) {
|
|
968
|
+
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) {
|
|
969
|
+
// same array's merge
|
|
970
|
+
x.array[i].repeat += x.array[i + 1].repeat;
|
|
971
|
+
x.array.splice(i + 1, 1);
|
|
972
|
+
--i;
|
|
973
|
+
renormalize = true;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
817
976
|
for (i = 1; i < x.array.length; ++i) {
|
|
818
|
-
//
|
|
977
|
+
// If there is a 0 repeat operator, remove it.
|
|
819
978
|
if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
|
|
820
979
|
x.array.splice(i, 1);
|
|
821
980
|
--i;
|
|
822
981
|
continue;
|
|
823
982
|
}
|
|
824
|
-
//
|
|
983
|
+
// If there is a operator which arrow 0 and brace count >=2
|
|
984
|
+
// replace it as arrow replacement operaotr
|
|
825
985
|
if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
|
|
826
986
|
x.array[i].arrow = Infinity;
|
|
827
987
|
x.array[i].valuereplaced = 0;
|
|
828
988
|
x.array[i].expans = x.array[i].expans - 1;
|
|
829
989
|
}
|
|
830
990
|
}
|
|
831
|
-
for (var _i2 = 1; _i2 < this.array.length; _i2++) {
|
|
832
|
-
if (this.array[_i2].repeat == 0) {
|
|
833
|
-
this.array.splice(_i2, 1);
|
|
834
|
-
_i2--;
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
if (!x.array.length) {
|
|
838
|
-
x.small = !x.small;
|
|
839
|
-
x.array = [newOperator(Infinity)]; // if no array set zero
|
|
840
|
-
}
|
|
841
991
|
if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
|
|
992
|
+
// for any 10^a but a >log10(MSI), replace to regular 10^a
|
|
842
993
|
if (this.getOperator(1) >= 1 && this.getOperator(0) < MSI_LOG10) {
|
|
843
994
|
this.setOperator(this.getOperator(1) - 1, 1);
|
|
844
995
|
this.setOperator(Math.pow(10, this.getOperator(0)), 0);
|
|
@@ -849,13 +1000,15 @@
|
|
|
849
1000
|
this.setOperator(Math.log10(this.getOperator(0)), 0);
|
|
850
1001
|
renormalize = true;
|
|
851
1002
|
}
|
|
1003
|
+
// for a<1, turn into reciprocate
|
|
852
1004
|
if (this.array.length == 1 && this.array[0].repeat < 1) {
|
|
853
1005
|
this.array[0].repeat = 1 / this.array[0].repeat;
|
|
854
1006
|
this.small = !this.small;
|
|
855
1007
|
renormalize = true;
|
|
856
1008
|
}
|
|
857
1009
|
while (x.array.length >= 2 && x.array[0].repeat == 1 && x.array[1].repeat) {
|
|
858
|
-
//
|
|
1010
|
+
// for any 10{X}10{X} 1, turn into 10{x}10
|
|
1011
|
+
// [1, [R=sth, A=sth, E=sth, M=sth]]
|
|
859
1012
|
if (x.array[1].repeat > 1) {
|
|
860
1013
|
x.array[1].repeat--;
|
|
861
1014
|
} else {
|
|
@@ -865,19 +1018,18 @@
|
|
|
865
1018
|
renormalize = true;
|
|
866
1019
|
}
|
|
867
1020
|
if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1) {
|
|
1021
|
+
// for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
|
|
868
1022
|
// [1e9, [R=1, A=2, sth, sth]]
|
|
869
1023
|
x.array.splice(1, 1, newOperator(x.array[0].repeat, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
|
|
870
1024
|
x.array[0].repeat = 10;
|
|
871
1025
|
renormalize = true;
|
|
872
1026
|
}
|
|
873
|
-
for (
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
renormalize = true;
|
|
880
|
-
}
|
|
1027
|
+
// for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
|
|
1028
|
+
if (x.array.length >= 2 && x.array[1].repeat > MSI) {
|
|
1029
|
+
x.array[1].arrow++;
|
|
1030
|
+
x.array[0].repeat = x.array[1].repeat;
|
|
1031
|
+
x.array[1].repeat = 1;
|
|
1032
|
+
renormalize = true;
|
|
881
1033
|
}
|
|
882
1034
|
} while (renormalize);
|
|
883
1035
|
return this;
|
|
@@ -985,7 +1137,7 @@
|
|
|
985
1137
|
if (this.eq(PowiainaNum.ZERO)) return "0";
|
|
986
1138
|
return "/".concat(this.rec().toString());
|
|
987
1139
|
}
|
|
988
|
-
if (this.
|
|
1140
|
+
if (this.isInfi()) return "Infinity";
|
|
989
1141
|
// O^a (10{arrow,expans,megota})^repeation base
|
|
990
1142
|
var res = "";
|
|
991
1143
|
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
@@ -1068,6 +1220,12 @@
|
|
|
1068
1220
|
value: function cbrt(t) {
|
|
1069
1221
|
return new PowiainaNum(t).cbrt();
|
|
1070
1222
|
}
|
|
1223
|
+
}, {
|
|
1224
|
+
key: "tetrate",
|
|
1225
|
+
value: function tetrate(t, other2) {
|
|
1226
|
+
var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1227
|
+
return new PowiainaNum(t).tetrate(other2, payload);
|
|
1228
|
+
}
|
|
1071
1229
|
}, {
|
|
1072
1230
|
key: "log10",
|
|
1073
1231
|
value: function log10(t) {
|
|
@@ -1104,26 +1262,37 @@
|
|
|
1104
1262
|
}, {
|
|
1105
1263
|
key: "tetrate_10",
|
|
1106
1264
|
value: function tetrate_10(other2) {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1265
|
+
return PowiainaNum.fromNumber(10).tetrate(other2);
|
|
1266
|
+
/*
|
|
1267
|
+
const other = new PowiainaNum(other2);
|
|
1268
|
+
const height_int = other.trunc().toNumber();
|
|
1269
|
+
const height_frac = other.sub(height_int).toNumber();
|
|
1270
|
+
if (other.gt(PowiainaNum.PENTATED_MSI))
|
|
1271
|
+
return other.clone();
|
|
1272
|
+
else if (other.gt(PowiainaNum.MSI)) {
|
|
1273
|
+
other.setOperator(other.getOperator(2)+1, 2);
|
|
1274
|
+
} else if (other.lt(-2))
|
|
1275
|
+
return PowiainaNum.NaN.clone();
|
|
1276
|
+
else if (other.lt(-1)) {
|
|
1113
1277
|
return other.add(2).log10();
|
|
1114
|
-
}
|
|
1278
|
+
}
|
|
1279
|
+
else if (other.lt(0)) {
|
|
1115
1280
|
return other.add(1);
|
|
1116
|
-
}
|
|
1117
|
-
return other.pow10()
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1281
|
+
}else if (other.lt(1)) {
|
|
1282
|
+
return other.pow10() // 10^x
|
|
1283
|
+
}else if (height_int==1)
|
|
1284
|
+
return PowiainaNum.pow(10,PowiainaNum.pow(10,height_frac));
|
|
1285
|
+
else if (height_int==2)
|
|
1286
|
+
return PowiainaNum.pow(10,PowiainaNum.pow(10,PowiainaNum.pow(10,height_frac)));
|
|
1287
|
+
else {
|
|
1288
|
+
const remain = height_int-2;
|
|
1289
|
+
let a = PowiainaNum.pow(10,PowiainaNum.pow(10,PowiainaNum.pow(10,height_frac)));
|
|
1290
|
+
a.setOperator(a.getOperator(1)+remain, 1);
|
|
1122
1291
|
return a;
|
|
1123
1292
|
}
|
|
1124
1293
|
// 1--2, 10-<1e10, 10^10^0->1
|
|
1125
1294
|
// 2--3, 1e10-<e1e10, 10^10^10^0->1
|
|
1126
|
-
return PowiainaNum.NaN.clone()
|
|
1295
|
+
return PowiainaNum.NaN.clone();*/
|
|
1127
1296
|
}
|
|
1128
1297
|
}, {
|
|
1129
1298
|
key: "isNaN",
|
|
@@ -1263,7 +1432,7 @@
|
|
|
1263
1432
|
a = input.split(/[Ee]/);
|
|
1264
1433
|
b = [x.array[0].repeat, 0];
|
|
1265
1434
|
c = 1;
|
|
1266
|
-
for (var
|
|
1435
|
+
for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
|
|
1267
1436
|
//The things that are already there
|
|
1268
1437
|
if (b[0] < MSI_LOG10 && b[1] === 0) {
|
|
1269
1438
|
b[0] = Math.pow(10, c * b[0]);
|
|
@@ -1280,12 +1449,12 @@
|
|
|
1280
1449
|
b[1]++;
|
|
1281
1450
|
}
|
|
1282
1451
|
//Multiplying coefficient
|
|
1283
|
-
var decimalPointPos = a[
|
|
1284
|
-
var intPartLen = decimalPointPos == -1 ? a[
|
|
1452
|
+
var decimalPointPos = a[_i2].indexOf(".");
|
|
1453
|
+
var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
|
|
1285
1454
|
if (b[1] === 0) {
|
|
1286
|
-
if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(a[
|
|
1455
|
+
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]);
|
|
1287
1456
|
} else {
|
|
1288
|
-
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[
|
|
1457
|
+
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
|
|
1289
1458
|
if (b[1] == 1) {
|
|
1290
1459
|
b[0] += d;
|
|
1291
1460
|
} else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
|
package/dist/PowiainaNum.min.js
CHANGED
|
@@ -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)),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),w=0;if((m=l.sign*Math.pow(10,p+v)+u.sign*Math.pow(10,f+v))>0&&(w=Math.log10(m)-v),m<0&&(w=Math.log10(-m)-v,y*=-1),0==m)throw Error("Encounter a calculate error");return(c=new e).sign=1,c.array=w>n||w<-n?[o(w,0),o(1,1)]:[o(Math.pow(10,Math.abs(w)),0)],c.small=w<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(){if(this.isneg())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(1==this.array.length)return new e(Math.log10(this.array[0].repeat));var a=this.clone();return a.array[1].repeat=a.array[1].repeat-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.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:"trunc",value:function(){var r=this.clone();return r.gte(0)?r.floor():r.ceil()}},{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:"tetrate_10",value:function(r){var a=new e(r),t=a.trunc().toNumber(),n=a.sub(t).toNumber();if(a.gt(e.PENTATED_MSI))return a.clone();if(!a.gt(e.MSI)){if(a.lt(-2))return e.NaN.clone();if(a.lt(-1))return a.add(2).log10();if(a.lt(0))return a.add(1);if(a.lt(1))return a.pow10();if(1==t)return e.pow(10,e.pow(10,n));if(2==t)return e.pow(10,e.pow(10,e.pow(10,n)));var i=t-2,o=e.pow(10,e.pow(10,e.pow(10,n)));return o.setOperator(o.getOperator(1)+i,1),o}return a.setOperator(a.getOperator(2)+1,2),e.NaN.clone()}},{key:"isNaN",value:function(r){return new e(r).isNaN()}},{key:"fromNumber",value:function(r){var a=new e;if(r<0)a.sign=-1;else{if(0==r)return a.sign=0,a.small=!0,a.array=[o(1/0,0)],a;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,w,N,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(/[^\^]/),w=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),w=v+1}")"==(r=r.substring(w))[0]?(v=r.indexOf(" "),N=Number(r.substring(2,v)),r=r.substring(v+1)):N=1,1==d&&1==I&&1==E?p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat+=N:p.array.splice(1,0,o(N,1,I,E)):2==d&&1==I&&1==E?(v=p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat:0,(w=p.array[0].repeat)>=1e10&&++v,w>=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+=N:p.array.splice(Math.ceil(b),0,o(N,2,I,E))):isFinite(d)?(v=p.getOperator(d-1),(w=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+=N:p.array.splice(1,0,o(N,d,I,E))):p.array.splice(1,0,o(N,d,I,E))}v=r.split(/[Ee]/),w=[p.array[0].repeat,0],N=1;for(var O=v.length-1;O>=0;--O){w[0]<n&&0===w[1]?w[0]=Math.pow(10,N*w[0]):-1==N?(0===w[1]?w[0]=Math.pow(10,N*w[0]):1==w[1]&&w[0]<=Math.log10(Number.MAX_VALUE)?w[0]=Math.pow(10,N*Math.pow(10,w[0])):w[0]=0,w[1]=0):w[1]++;var x=v[O].indexOf("."),k=-1==x?v[O].length:x;0===w[1]?k>=17?(w[0]=Math.log10(w[0])+l(v[O].substring(0,k)),w[1]=1):v[O]&&(w[0]*=Number(v[O])):(b=k>=17?l(v[O].substring(0,k)):v[O]?Math.log10(Number(v[O])):0,1==w[1]?w[0]+=b:2==w[1]&&w[0]<n+Math.log10(b)&&(w[0]+=Math.log10(1+Math.pow(10,Math.log10(b)-w[0])))),w[0]<n&&w[1]?(w[0]=Math.pow(10,w[0]),w[1]--):w[0]>t&&(w[0]=Math.log10(w[0]),w[1]++)}p.array[0].repeat=w[0],w[1]&&(p.array.length>=2&&1==p.array[1].arrow?p.array[1].repeat+=w[1]:p.array.splice(1,0,o(w[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.PENTATED_MSI=new p({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:t},{arrow:2,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}));
|
|
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=1.444667861009766,o=/^\/*[-\+]*(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 s(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 l(){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 u(r){return Math.log10(Number(r.substring(0,17)))+(r.length-17)}var h=.5671432904097838;function g(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 h;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 f(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.isInfiNaN())return r;if(o){if(r.eq(c.ZERO))return c.ZERO.clone();if(r.eq(c.ONE))return c.fromNumber(h);e=r.log()}else{if(r.eq(c.ZERO))return c.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,c=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,o,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 f=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 y=(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===(o=u.array[1])||void 0===o?void 0:o.repeat)?u.array[0].repeat:Math.log10(u.array[0].repeat));if(y-c>n)return l;var p,m,v=-Math.floor(y),N=0;if((m=l.sign*Math.pow(10,y+v)+u.sign*Math.pow(10,c+v))>0&&(N=Math.log10(m)-v),m<0&&(N=Math.log10(-m)-v,f*=-1),0==m)throw Error("Encounter a calculate error");return(p=new e).sign=1,p.array=N>n||N<-n?[s(N,0),s(1,1)]:[s(Math.pow(10,Math.abs(N)),0)],p.small=N<0,p.sign*=f,p}},{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.isInfiNaN()&&n.eq(e.ZERO)&&n.isInfiNaN()&&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:"tetrate",value:function(r){var a,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,o=this.clone(),s=new e(r),l=new e(n);if(o.isNaN()||s.isNaN()||l.isNaN())return e.NaN.clone();if(l.neq(e.ONE)&&(s=s.add(l.slog(o))),s.isInfi()&&s.sign>0)return o.gte(i)?e.POSITIVE_INFINITY.clone():(a=this.log().neg()).lambertw().div(a);if(s.lte(-2))return e.NaN.clone();if(o.isZero())return s.isZero()?e.NaN.clone():s.gte(t/2)||s.toNumber()%2==0?e.ZERO.clone():e.ONE.clone();if(o.eq(e.ONE))return s.eq(e.ONE.neg())?e.NaN.clone():e.ONE.clone();if(s.eq(e.ONE.neg()))return e.ZERO.clone();if(s.eq(e.ZERO))return e.ONE.clone();if(s.eq(e.ONE))return o;if(s.eq(2))return o.pow(o);if(o.eq(2)){if(s.eq(3))return e.fromNumber(16);if(s.eq(4))return e.fromNumber(65536)}var u=o.max(s);if(u.gt(e.PENTATED_MSI))return u;if(u.gt(e.TETRATED_MSI)||s.gt(t)){if(this.lt(i))return(a=o.ln().neg()).lambertw().div(a);var h=o.slog(10).add(s);return h.setOperator(h.getOperator(2)+1,2),h.normalize(),h}for(var g=s.toNumber(),f=Math.floor(g),y=o.pow(g-f),c=e.NaN,p=0,m=e.E_MSI.clone();0!==f&&y.lt(m)&&p<100;++p)if(f>0){if(y=o.pow(y),c.eq(y)){f=0;break}c=y,--f}else{if(y=y.log(o),c.eq(y)){f=0;break}c=y,++f}return(100==p||this.lt(i))&&(f=0),y.setOperator(y.getOperator(1)+f,1),y.normalize(),y}},{key:"slog",value:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,a=this.clone(),t=new e(r);if(a.isInfiNaN())return a;if(t.isNaN())return t;if(t.isInfi())return e.ZERO.clone();if(a.isZero())return e.ONE.clone();if(a.eq(e.ONE))return e.ZERO.clone();if(a.eq(t))return e.ONE.clone();if(t.lt(i)){var n=t.tetrate(1/0);if(a.eq(n))return e.POSITIVE_INFINITY.clone();if(a.gt(n))return e.NaN.clone()}if(a.max(t).gt(e.PENTATED_MSI))return a.gt(t)?a:e.ZERO.clone();if(a.max(t).gt(e.TETRATED_MSI)&&a.gt(t))return a.setOperator(a.getOperator(2)-1,2),a.normalize(),a.sub(a.getOperator(1));if(a.lt(e.ZERO.clone()))return t.pow(a).sub(2);var o=0,s=a.getOperator(1)-t.getOperator(1);if(s>3){var l=s-3;o+=l,a.setOperator(a.getOperator(1)-l,1)}for(var u=0;u<100;++u){if(a.lte(e.ONE))return new e(o+a.toNumber());++o,a=e.log(a,r)}return console.warn("Failed to converage"),e.NaN.clone()}},{key:"abs",value:function(){var r=this.clone();return r.sign<0&&(r.sign*=-1),r}},{key:"log10",value:function(){if(this.isneg())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(1==this.array.length)return new e(Math.log10(this.array[0].repeat));var a=this.clone();return a.array[1].repeat=a.array[1].repeat-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:"ln",value:function(){return this.log()}},{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(g(this.toNumber())):0===this.layer?e.fromNumber(g(this.sign*this.getOperator(0))):this.lt("eee15")?f(this):this.log():1===this.sign?e.NaN.clone():0===this.layer?e.fromNumber(g(this.sign*this.array[0].repeat,1e-10,!1)):1==this.layer?f(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:"trunc",value:function(){var r=this.clone();return r.gte(0)?r.floor():r.ceil()}},{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 s=this.array[this.array.length-1-o],u=a.array[a.array.length-1-o],h=l([s.megota,s.expans,s.arrow,s.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:"isInfi",value:function(){return this.rec().isZero()}},{key:"isInfiNaN",value:function(){return this.isInfi()||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 o=1;o<a.array.length;++o){var u=a.array[o];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=[s(NaN,0,1,1)],a;if(!isFinite(u.repeat)||!isFinite(u.megota))return a.array=[s(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))}a.array.length||(a.small=!a.small,a.array=[s(1/0)]);do{for(r=!1,this.array.sort((function(r,e){return l([r.megota,r.expans,r.arrow],[e.megota,e.expans,e.arrow])})),o=1;o<a.array.length-1;++o)a.array[o].arrow==a.array[o+1].arrow&&a.array[o].expans==a.array[o+1].expans&&a.array[o].megota==a.array[o+1].megota&&(a.array[o].repeat+=a.array[o+1].repeat,a.array.splice(o+1,1),--o,r=!0);for(o=1;o<a.array.length;++o)0===a.array[o].arrow||0!==a.array[o].repeat&&null!==a.array[o].repeat&&void 0!==a.array[o].repeat?0==a.array[o].arrow&&a.array[o].expans>=2&&(a.array[o].arrow=1/0,a.array[o].valuereplaced=0,a.array[o].expans=a.array[o].expans-1):(a.array.splice(o,1),--o);for(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;a.array.length>=2&&a.array[0].repeat<t&&a.array[1].arrow>=2&&1==a.array[1].repeat&&(a.array.splice(1,1,s(a.array[0].repeat,a.array[1].arrow-1,a.array[1].expans,a.array[1].megota)),a.array[0].repeat=10,r=!0),a.array.length>=2&&a.array[1].repeat>t&&(a.array[1].arrow++,a.array[0].repeat=a.array[1].repeat,a.array[1].repeat=1,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=l([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.isInfi())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:"tetrate",value:function(r,a){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return new e(r).tetrate(a,t)}},{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:"tetrate_10",value:function(r){return e.fromNumber(10).tetrate(r)}},{key:"isNaN",value:function(r){return new e(r).isNaN()}},{key:"fromNumber",value:function(r){var a=new e;if(r<0)a.sign=-1;else{if(0==r)return a.sign=0,a.small=!0,a.array=[s(1/0,0)],a;r>0&&(a.sign=1)}var n=Math.abs(r);return n>=11102230246251568e-32&&n<1?(a.small=!0,a.array=[s(1/n,0)]):n<11102230246251568e-32?(a.small=!0,a.array=[s(-Math.log10(n),0),s(1,1)]):n<=t?a.array=[s(n,0)]:(a.setOperator(Math.log10(n),0),a.array=[s(Math.log10(n),0),s(1,1)]),a}},{key:"fromString",value:function(r){var a,i,l,h,g,f,y=new e;if(!isNaN(Number(r))&&isFinite(Number(r)))return y.resetFromObject(e.fromNumber(Number(r))),y;if(!o.test(r))throw"[PowiainaNum 0.2 error]malformed input: "+r;var c=!1,p=!1;if("-"==r[0]||"+"==r[0]){var m=r.search(/[^-\+]/);c=(null!==(i=null===(a=r.substring(0,m).match(/-/g))||void 0===a?void 0:a.length)&&void 0!==i?i:0)%2==1,r=r.substring(m)}if("/"==r[0]){m=r.search(/[^\/]/);p=(null!==(h=null===(l=r.substring(0,m).match(/\//g))||void 0===l?void 0:l.length)&&void 0!==h?h:0)%2==1,r=r.substring(m)}if("NaN"==r)y.array=[s(NaN)];else if("Infinity"==r)y.array=[s(1/0)];else{var v,N,w,b;for(y.sign=1,y.array=[s(0)];r&&/^(\(?10[\^\{])/.test(r);){var I,d,E;if("("==r[0]&&(r=r.substring(1)),"^"==r[2])I=v=r.substring(2).search(/[^\^]/),N=v+2;else{v=r.indexOf("}");var O=r.substring(3,v).split(",");I=Number("!"==O[0]?1/0:O[0]),d=Number(null!==(g="!"==O[1]?1/0:O[1])&&void 0!==g?g:1),E=Number(null!==(f=O[2])&&void 0!==f?f: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==I&&1==d&&1==E?y.array.length>=2&&1==y.array[1].arrow?y.array[1].repeat+=w:y.array.splice(1,0,s(w,1,d,E)):2==I&&1==d&&1==E?(v=y.array.length>=2&&1==y.array[1].arrow?y.array[1].repeat:0,(N=y.array[0].repeat)>=1e10&&++v,N>=10&&++v,y.array[0].repeat=v,y.array.length>=2&&1==y.array[1].arrow&&y.array.splice(1,1),b=y.getOperatorIndex(2),Number.isInteger(b)?y.array[b].repeat+=w:y.array.splice(Math.ceil(b),0,s(w,2,d,E))):isFinite(I)?(v=y.getOperator(I-1),(N=y.getOperator(I-2))>=10&&++v,b=y.getOperatorIndex(I),y.array.splice(1,Math.ceil(b)-1),y.array[0].repeat=v,Number.isInteger(b)?y.array[1].repeat+=w:y.array.splice(1,0,s(w,I,d,E))):y.array.splice(1,0,s(w,I,d,E))}v=r.split(/[Ee]/),N=[y.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])+u(v[M].substring(0,x)),N[1]=1):v[M]&&(N[0]*=Number(v[M])):(b=x>=17?u(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]++)}y.array[0].repeat=N[0],N[1]&&(y.array.length>=2&&1==y.array[1].arrow?y.array[1].repeat+=N[1]:y.array.splice(1,0,s(N[1],1,1,1)))}return c&&(y.sign*=-1),p&&(y.small=!y.small),y.normalize(),y.normalize(),y}},{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 c.ZERO=new c({array:[{arrow:0,expans:1,megota:1,repeat:1/0}],small:!0,layer:0,sign:0}),c.ONE=new c({array:[{arrow:0,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),c.MSI=new c(t),c.MSI_REC=((y=new c(t)).small=!0,y),c.E_MSI=new c({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),c.E_MSI_REC=new c({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:1}],small:!0,layer:0,sign:1}),c.TETRATED_MSI=new c({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:t}],small:!1,layer:0,sign:1}),c.PENTATED_MSI=new c({array:[{arrow:0,expans:1,megota:1,repeat:t},{arrow:1,expans:1,megota:1,repeat:t},{arrow:2,expans:1,megota:1,repeat:t}],small:!1,layer:0,sign:1}),c.TRITRI=new c({small:!1,layer:0,sign:1,array:[s(3638334640023.7783,0,1,1),s(7625587484984,1,1,1)]}),c.GRAHAMS_NUMBER=new c("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783"),c.POSITIVE_INFINITY=new c(1/0),c.NEGATIVE_INFINITY=new c(-1/0),c.NaN=new c({array:[{arrow:0,expans:1,megota:1,repeat:NaN}],small:!1,layer:0,sign:0}),c.maxOps=100,c}));
|
package/dist/index.d.ts
CHANGED
|
@@ -40,11 +40,15 @@ export default class PowiainaNum implements IPowiainaNum {
|
|
|
40
40
|
static sqrt(t: PowiainaNumSource): PowiainaNum;
|
|
41
41
|
cbrt(): PowiainaNum;
|
|
42
42
|
static cbrt(t: PowiainaNumSource): PowiainaNum;
|
|
43
|
+
tetrate(other2: PowiainaNumSource, payload?: PowiainaNumSource): PowiainaNum;
|
|
44
|
+
slog(base?: PowiainaNumSource): PowiainaNum;
|
|
45
|
+
static tetrate(t: PowiainaNumSource, other2: PowiainaNumSource, payload?: PowiainaNumSource): PowiainaNum;
|
|
43
46
|
abs(): PowiainaNum;
|
|
44
47
|
log10(): PowiainaNum;
|
|
45
48
|
static log10(t: PowiainaNumSource): PowiainaNum;
|
|
46
49
|
log(base?: PowiainaNumSource): PowiainaNum;
|
|
47
50
|
static log(t: PowiainaNumSource, base?: PowiainaNumSource): PowiainaNum;
|
|
51
|
+
ln(): PowiainaNum;
|
|
48
52
|
static exp(x: PowiainaNumSource): PowiainaNum;
|
|
49
53
|
exp(): PowiainaNum;
|
|
50
54
|
mod(x: PowiainaNumSource): PowiainaNum;
|
|
@@ -82,6 +86,18 @@ export default class PowiainaNum implements IPowiainaNum {
|
|
|
82
86
|
floor(): PowiainaNum;
|
|
83
87
|
ceil(): PowiainaNum;
|
|
84
88
|
round(): PowiainaNum;
|
|
89
|
+
/**
|
|
90
|
+
* Work like `Math.trunc`,
|
|
91
|
+
*
|
|
92
|
+
* if `this > 0`, return `floor(this)`
|
|
93
|
+
*
|
|
94
|
+
* if `this < 0`, return `ceil(this)`
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
|
|
98
|
+
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
85
101
|
trunc(): PowiainaNum;
|
|
86
102
|
/**
|
|
87
103
|
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
@@ -97,7 +113,8 @@ export default class PowiainaNum implements IPowiainaNum {
|
|
|
97
113
|
isNaN(): boolean;
|
|
98
114
|
isZero(): boolean;
|
|
99
115
|
isFinite(): boolean;
|
|
100
|
-
|
|
116
|
+
isInfi(): boolean;
|
|
117
|
+
isInfiNaN(): boolean;
|
|
101
118
|
isInt(): boolean;
|
|
102
119
|
ispos(): boolean;
|
|
103
120
|
isneg(): boolean;
|
package/package.json
CHANGED