powiaina_num.js 0.2.11 → 0.2.13
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 +1 -1
- package/dist/PowiainaNum.cjs.js +640 -298
- package/dist/PowiainaNum.esm.js +640 -298
- package/dist/PowiainaNum.js +640 -298
- package/dist/PowiainaNum.min.js +1 -1
- package/dist/index.d.ts +76 -18
- package/package.json +2 -2
- package/LICENSE +0 -21
package/dist/PowiainaNum.js
CHANGED
|
@@ -68,6 +68,8 @@
|
|
|
68
68
|
|
|
69
69
|
/* Author: VeryrrDefine 0.2.0-beta.1.1*/
|
|
70
70
|
var _a;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region constants
|
|
71
73
|
var powiainaNumError = "[PowiainaNum 0.2 error]";
|
|
72
74
|
var MSI = 9007199254740991;
|
|
73
75
|
var MSI_LOG10 = 15.954589770191003;
|
|
@@ -75,6 +77,8 @@
|
|
|
75
77
|
var LONG_STRING_MIN_LENGTH = 17;
|
|
76
78
|
var EXP_E_REC = 1.444667861009766;
|
|
77
79
|
var isPowiainaNum = /^(PN)?[\/\-\+]*(Infinity|NaN|(P+|P\^\d+ )?(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d*\x20*)*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;
|
|
80
|
+
var BE_REGEX = /^((\d+(\.\d*)?|\d*\.\d+)?([EeFf]([-\+]?)))*(0|\d+(\.\d*)?|\d*\.\d+)$/;
|
|
81
|
+
//#endregion
|
|
78
82
|
//#region some useful functions
|
|
79
83
|
function newOperator(r) {
|
|
80
84
|
var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -88,6 +92,29 @@
|
|
|
88
92
|
valuereplaced: a == Infinity ? 0 : e == Infinity ? 1 : -1
|
|
89
93
|
};
|
|
90
94
|
}
|
|
95
|
+
function removeCommasOutsideBraces(input) {
|
|
96
|
+
var result = "";
|
|
97
|
+
var inBraces = false;
|
|
98
|
+
for (var i = 0; i < input.length; i++) {
|
|
99
|
+
var _char = input[i];
|
|
100
|
+
if (_char === "{") {
|
|
101
|
+
inBraces = true;
|
|
102
|
+
result += _char;
|
|
103
|
+
} else if (_char === "}") {
|
|
104
|
+
inBraces = false;
|
|
105
|
+
result += _char;
|
|
106
|
+
} else if (_char === ",") {
|
|
107
|
+
// 只有在花括号内部才保留逗号
|
|
108
|
+
if (inBraces) {
|
|
109
|
+
result += _char;
|
|
110
|
+
}
|
|
111
|
+
// 如果在花括号外部,就不添加到结果中(相当于删除)
|
|
112
|
+
} else {
|
|
113
|
+
result += _char;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
91
118
|
// parse 0.1.x PowiainaNum.js string
|
|
92
119
|
function parseLegacyPowiainaNumString(str) {
|
|
93
120
|
var pattern = /l(\d+)\s+s(\d+)\s+a(\[.*\])/;
|
|
@@ -120,7 +147,7 @@
|
|
|
120
147
|
function replaceETo10(str) {
|
|
121
148
|
// 使用正则表达式匹配 (e^数字) 的模式
|
|
122
149
|
// 正则解释:\(e\^(\d+)\) 匹配 (e^数字),其中 \d+ 匹配一个或多个数字
|
|
123
|
-
return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)
|
|
150
|
+
return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)[Pp][Tt]/g, "(10^)^$1 ");
|
|
124
151
|
}
|
|
125
152
|
/**
|
|
126
153
|
* 把一个字符串很长的数进行以10为底的对数
|
|
@@ -174,8 +201,10 @@
|
|
|
174
201
|
// The evaluation can become inaccurate very close to the branch point
|
|
175
202
|
// Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
|
|
176
203
|
function f_lambertw(z) {
|
|
177
|
-
var
|
|
178
|
-
var
|
|
204
|
+
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
|
|
205
|
+
var pr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
206
|
+
var tol = t;
|
|
207
|
+
var principal = pr;
|
|
179
208
|
var w;
|
|
180
209
|
var wn;
|
|
181
210
|
if (!Number.isFinite(z)) {
|
|
@@ -338,16 +367,26 @@
|
|
|
338
367
|
this.small = false;
|
|
339
368
|
this.sign = 0;
|
|
340
369
|
this.layer = 0;
|
|
341
|
-
if (
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
370
|
+
if (PowiainaNum.blankArgumentConstructorReturnZero) {
|
|
371
|
+
this.resetFromObject(PowiainaNum.ZERO);
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
if (typeof arg1 == "undefined") {} else if (typeof arg1 == "number") {
|
|
375
|
+
var obj = PowiainaNum.fromNumber(arg1);
|
|
376
|
+
this.resetFromObject(obj);
|
|
377
|
+
} else if (_typeof(arg1) == "object") {
|
|
378
|
+
var _obj = PowiainaNum.fromObject(arg1);
|
|
379
|
+
this.resetFromObject(_obj);
|
|
380
|
+
} else if (typeof arg1 == "string") {
|
|
381
|
+
var _obj2 = PowiainaNum.fromString(arg1);
|
|
382
|
+
this.resetFromObject(_obj2);
|
|
383
|
+
} else {
|
|
384
|
+
var isn = arg1;
|
|
385
|
+
}
|
|
386
|
+
} catch (e) {
|
|
387
|
+
console.error("Malformed input");
|
|
388
|
+
console.error(e);
|
|
389
|
+
}
|
|
351
390
|
}
|
|
352
391
|
//#region 4 Basic calculates.
|
|
353
392
|
/**
|
|
@@ -358,7 +397,7 @@
|
|
|
358
397
|
key: "add",
|
|
359
398
|
value: function add(other) {
|
|
360
399
|
var _b, _c, _d, _e;
|
|
361
|
-
var x = this.clone();
|
|
400
|
+
var x = this.clone().normalize();
|
|
362
401
|
var y = new PowiainaNum(other);
|
|
363
402
|
// inf + -inf = nan
|
|
364
403
|
if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.POSITIVE_INFINITY)) return PowiainaNum.NaN.clone();
|
|
@@ -401,40 +440,56 @@
|
|
|
401
440
|
if (isFinite(temp) && temp !== 0) {
|
|
402
441
|
return PowiainaNum.fromNumber(temp);
|
|
403
442
|
}
|
|
404
|
-
var
|
|
443
|
+
var signMult = 1;
|
|
444
|
+
/**Calculate numbers [1, 9e15] (useless) */
|
|
405
445
|
if (!a.small && !b.small && !((_b = a.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) && !((_c = b.array[1]) === null || _c === void 0 ? void 0 : _c.repeat) && a.sign == b.sign) {
|
|
406
446
|
return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
|
|
407
447
|
}
|
|
448
|
+
// Calculate a & b's 10-logarithm
|
|
408
449
|
var alog10 = (a.small ? -1 : 1) * (((_d = a.array[1]) === null || _d === void 0 ? void 0 : _d.repeat) ? a.array[0].repeat : Math.log10(a.array[0].repeat));
|
|
409
450
|
var blog10 = (b.small ? -1 : 1) * (((_e = b.array[1]) === null || _e === void 0 ? void 0 : _e.repeat) ? b.array[0].repeat : Math.log10(b.array[0].repeat));
|
|
410
451
|
if (alog10 - blog10 > MSI_LOG10) return a;
|
|
452
|
+
/**
|
|
453
|
+
* Offset, a number can make 10^ a+off calculatable not very small or big
|
|
454
|
+
*/
|
|
411
455
|
var offset = -Math.floor(alog10); //a number can make a+off in [0,1)
|
|
412
|
-
var
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (
|
|
425
|
-
|
|
456
|
+
var resultLogarithm = 0;
|
|
457
|
+
/** 10^(a+off) + 10^(b+off). */
|
|
458
|
+
var offsetedResult = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
|
|
459
|
+
if (offsetedResult > 0) resultLogarithm = Math.log10(offsetedResult) - offset;
|
|
460
|
+
if (offsetedResult < 0) {
|
|
461
|
+
resultLogarithm = Math.log10(-offsetedResult) - offset;
|
|
462
|
+
signMult *= -1;
|
|
463
|
+
}
|
|
464
|
+
if (offsetedResult == 0) return PowiainaNum.ZERO.clone();
|
|
465
|
+
var resultPN = PowiainaNum.NaN.clone();
|
|
466
|
+
resultPN.sign = 1;
|
|
467
|
+
/** abs(resultLogarithm) > 15.9, use 10^x form. */
|
|
468
|
+
if (resultLogarithm > MSI_LOG10 || resultLogarithm < -MSI_LOG10) {
|
|
469
|
+
resultPN.array = [newOperator(resultLogarithm, 0), newOperator(1, 1)];
|
|
470
|
+
/**otherwise, use 10** abs(resultLogarithm) */
|
|
426
471
|
} else {
|
|
427
|
-
|
|
472
|
+
resultPN.array = [newOperator(Math.pow(10, Math.abs(resultLogarithm)), 0)];
|
|
428
473
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return
|
|
474
|
+
resultPN.small = resultLogarithm < 0 ? true : false;
|
|
475
|
+
resultPN.sign *= signMult;
|
|
476
|
+
return resultPN;
|
|
477
|
+
}
|
|
478
|
+
}, {
|
|
479
|
+
key: "plus",
|
|
480
|
+
value: function plus(other) {
|
|
481
|
+
return this.add(other);
|
|
432
482
|
}
|
|
433
483
|
}, {
|
|
434
484
|
key: "sub",
|
|
435
485
|
value: function sub(a) {
|
|
436
486
|
return this.add(new PowiainaNum(a).neg());
|
|
437
487
|
}
|
|
488
|
+
}, {
|
|
489
|
+
key: "minus",
|
|
490
|
+
value: function minus(other) {
|
|
491
|
+
return this.sub(other);
|
|
492
|
+
}
|
|
438
493
|
}, {
|
|
439
494
|
key: "mul",
|
|
440
495
|
value: function mul(other) {
|
|
@@ -468,12 +523,22 @@
|
|
|
468
523
|
r.sign = x.sign * y.sign;
|
|
469
524
|
return r;
|
|
470
525
|
}
|
|
526
|
+
}, {
|
|
527
|
+
key: "times",
|
|
528
|
+
value: function times(other) {
|
|
529
|
+
return this.mul(other);
|
|
530
|
+
}
|
|
471
531
|
}, {
|
|
472
532
|
key: "div",
|
|
473
533
|
value: function div(other) {
|
|
474
534
|
var x = new PowiainaNum(other).rec();
|
|
475
535
|
return this.mul(x);
|
|
476
536
|
}
|
|
537
|
+
}, {
|
|
538
|
+
key: "divide",
|
|
539
|
+
value: function divide(other) {
|
|
540
|
+
return this.div(other);
|
|
541
|
+
}
|
|
477
542
|
}, {
|
|
478
543
|
key: "mod",
|
|
479
544
|
value: function mod(x) {
|
|
@@ -481,34 +546,45 @@
|
|
|
481
546
|
var division = this.div(other);
|
|
482
547
|
return division.sub(division.floor()).mul(other);
|
|
483
548
|
}
|
|
549
|
+
}, {
|
|
550
|
+
key: "modulus",
|
|
551
|
+
value: function modulus(x) {
|
|
552
|
+
return this.mod(x);
|
|
553
|
+
}
|
|
554
|
+
}, {
|
|
555
|
+
key: "pow10",
|
|
556
|
+
value:
|
|
484
557
|
//#endregion
|
|
485
558
|
//#region power
|
|
486
559
|
/**
|
|
487
560
|
* @returns 10 to the power of `this`
|
|
488
561
|
*/
|
|
489
|
-
|
|
490
|
-
key: "pow10",
|
|
491
|
-
value: function pow10() {
|
|
562
|
+
function pow10() {
|
|
492
563
|
var _b, _c;
|
|
493
|
-
var
|
|
564
|
+
var thisObject = this.clone();
|
|
494
565
|
// inf & nan check
|
|
495
566
|
if (!this.isFinite()) return this.clone();
|
|
496
|
-
|
|
567
|
+
/** when 10^(t), t<0, use 10^(-t) reciprocate. */
|
|
568
|
+
if (thisObject.isneg()) {
|
|
497
569
|
// 10^(-x) = 1/(10^x)
|
|
498
|
-
|
|
499
|
-
return
|
|
570
|
+
thisObject.sign *= -1;
|
|
571
|
+
return thisObject.pow10().rec();
|
|
500
572
|
}
|
|
501
|
-
if
|
|
502
|
-
|
|
573
|
+
/**if t lessthan log10 2^1024, use fromNumber. */
|
|
574
|
+
if (thisObject.lte(308.25471555991675)) {
|
|
575
|
+
return PowiainaNum.fromNumber(Math.pow(10, thisObject.toNumber()));
|
|
503
576
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
577
|
+
/**calculate directly */
|
|
578
|
+
if (thisObject.small) {
|
|
579
|
+
if (thisObject.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
|
|
580
|
+
return new PowiainaNum(Math.pow(10, Math.pow(thisObject.array[0].repeat, -1)));
|
|
507
581
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
582
|
+
/** indistinguishable above 10^^9e15 */
|
|
583
|
+
if (thisObject.gt(PowiainaNum.TETRATED_MSI)) return thisObject;
|
|
584
|
+
/**otherwise add 10^ directly */
|
|
585
|
+
thisObject.setOperator(((_c = (_b = thisObject.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
|
|
586
|
+
thisObject.normalize();
|
|
587
|
+
return thisObject;
|
|
512
588
|
}
|
|
513
589
|
}, {
|
|
514
590
|
key: "pow",
|
|
@@ -518,8 +594,16 @@
|
|
|
518
594
|
if (!other.isFinite()) return other.clone();
|
|
519
595
|
if (!this.isFinite()) return this.clone();
|
|
520
596
|
if (this.eq(10)) return other.pow10();
|
|
597
|
+
if (other.isneg()) return this.pow(other.neg()).rec();
|
|
521
598
|
if (this.isneg()) {
|
|
522
|
-
if (!other.isInt())
|
|
599
|
+
if (!other.isInt()) {
|
|
600
|
+
if (other.small) {
|
|
601
|
+
if (other.rec().div(2).eq(1)) {
|
|
602
|
+
return this.neg().pow(other).neg();
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return PowiainaNum.NaN.clone();
|
|
606
|
+
}
|
|
523
607
|
var r = this.abs().pow(other);
|
|
524
608
|
r.sign = function () {
|
|
525
609
|
var a = other.mod(2).round();
|
|
@@ -596,6 +680,16 @@
|
|
|
596
680
|
var other = new PowiainaNum(base);
|
|
597
681
|
return this.log10().div(other.log10());
|
|
598
682
|
}
|
|
683
|
+
}, {
|
|
684
|
+
key: "log2",
|
|
685
|
+
value: function log2() {
|
|
686
|
+
return this.log(2);
|
|
687
|
+
}
|
|
688
|
+
}, {
|
|
689
|
+
key: "logBase",
|
|
690
|
+
value: function logBase(a) {
|
|
691
|
+
return this.log(a);
|
|
692
|
+
}
|
|
599
693
|
}, {
|
|
600
694
|
key: "ln",
|
|
601
695
|
value: function ln() {
|
|
@@ -703,7 +797,8 @@
|
|
|
703
797
|
//Code from break_eternity.js
|
|
704
798
|
//Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
|
|
705
799
|
function lambertw() {
|
|
706
|
-
var
|
|
800
|
+
var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
801
|
+
var principal = princ;
|
|
707
802
|
if (this.lt(-0.3678794411710499)) {
|
|
708
803
|
return PowiainaNum.NaN.clone(); //complex
|
|
709
804
|
} else if (principal) {
|
|
@@ -718,12 +813,12 @@
|
|
|
718
813
|
return this.log();
|
|
719
814
|
}
|
|
720
815
|
} else {
|
|
721
|
-
if (this.sign === 1) {
|
|
816
|
+
if (this.sign === -1) {
|
|
722
817
|
return PowiainaNum.NaN.clone(); //complex
|
|
723
818
|
}
|
|
724
|
-
if (this.
|
|
819
|
+
if (this.lt(9e15)) {
|
|
725
820
|
return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
|
|
726
|
-
} else if (this.
|
|
821
|
+
} else if (this.lt(PowiainaNum.E_MSI)) {
|
|
727
822
|
return d_lambertw(this, 1e-10, false);
|
|
728
823
|
} else {
|
|
729
824
|
return this.neg().rec().lambertw().neg();
|
|
@@ -744,7 +839,9 @@
|
|
|
744
839
|
var payl = new PowiainaNum(payload);
|
|
745
840
|
if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
|
|
746
841
|
if (t.eq(1)) return PowiainaNum.ONE.clone();
|
|
747
|
-
if (payl.neq(PowiainaNum.ONE)
|
|
842
|
+
if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
|
|
843
|
+
other = other.add(payl.slog(t));
|
|
844
|
+
}
|
|
748
845
|
var negln;
|
|
749
846
|
if (other.isInfi() && other.sign > 0) {
|
|
750
847
|
if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
@@ -1074,9 +1171,9 @@
|
|
|
1074
1171
|
// base^base^... = x? (? bases)
|
|
1075
1172
|
var r = 0;
|
|
1076
1173
|
// 计算x与base的差距
|
|
1077
|
-
var
|
|
1078
|
-
if (
|
|
1079
|
-
var l =
|
|
1174
|
+
var distanceLayerOf = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
|
|
1175
|
+
if (distanceLayerOf > 3) {
|
|
1176
|
+
var l = distanceLayerOf - 3;
|
|
1080
1177
|
r += l;
|
|
1081
1178
|
x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
|
|
1082
1179
|
}
|
|
@@ -1118,18 +1215,18 @@
|
|
|
1118
1215
|
}
|
|
1119
1216
|
}, {
|
|
1120
1217
|
key: "pentate",
|
|
1121
|
-
value: function pentate(other) {
|
|
1122
|
-
return this.arrow(3)(other);
|
|
1218
|
+
value: function pentate(other, payload) {
|
|
1219
|
+
return this.arrow(3)(other, payload);
|
|
1123
1220
|
}
|
|
1124
1221
|
}, {
|
|
1125
1222
|
key: "hexate",
|
|
1126
|
-
value: function hexate(other) {
|
|
1127
|
-
return this.arrow(4)(other);
|
|
1223
|
+
value: function hexate(other, payload) {
|
|
1224
|
+
return this.arrow(4)(other, payload);
|
|
1128
1225
|
}
|
|
1129
1226
|
}, {
|
|
1130
1227
|
key: "pent",
|
|
1131
|
-
value: function pent(other) {
|
|
1132
|
-
return this.arrow(3)(other);
|
|
1228
|
+
value: function pent(other, payload) {
|
|
1229
|
+
return this.arrow(3)(other, payload);
|
|
1133
1230
|
}
|
|
1134
1231
|
}, {
|
|
1135
1232
|
key: "penta_log",
|
|
@@ -1137,6 +1234,9 @@
|
|
|
1137
1234
|
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1138
1235
|
return this.anyarrow_log(3)(base);
|
|
1139
1236
|
}
|
|
1237
|
+
}, {
|
|
1238
|
+
key: "expansion",
|
|
1239
|
+
value:
|
|
1140
1240
|
/**
|
|
1141
1241
|
* Expansion, which is `this`{{1}}`other2`.
|
|
1142
1242
|
*
|
|
@@ -1144,9 +1244,7 @@
|
|
|
1144
1244
|
*
|
|
1145
1245
|
* @url https://googology.fandom.com/wiki/Expansion
|
|
1146
1246
|
*/
|
|
1147
|
-
|
|
1148
|
-
key: "expansion",
|
|
1149
|
-
value: function expansion(other2) {
|
|
1247
|
+
function expansion(other2) {
|
|
1150
1248
|
var other = new PowiainaNum(other2);
|
|
1151
1249
|
var t = this.clone();
|
|
1152
1250
|
if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
|
|
@@ -1394,6 +1492,11 @@
|
|
|
1394
1492
|
var other = new PowiainaNum(x).abs();
|
|
1395
1493
|
return this.abs().cmp(other);
|
|
1396
1494
|
}
|
|
1495
|
+
/**
|
|
1496
|
+
* -1: `this` is smaller
|
|
1497
|
+
* 0: equals
|
|
1498
|
+
* 1: `x` is bigger
|
|
1499
|
+
*/
|
|
1397
1500
|
}, {
|
|
1398
1501
|
key: "compare",
|
|
1399
1502
|
value: function compare(x) {
|
|
@@ -1412,6 +1515,14 @@
|
|
|
1412
1515
|
for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
|
|
1413
1516
|
var op1 = this.array[this.array.length - 1 - i];
|
|
1414
1517
|
var op2 = other.array[other.array.length - 1 - i];
|
|
1518
|
+
if (op1.repeat === Infinity) {
|
|
1519
|
+
result = 1;
|
|
1520
|
+
break;
|
|
1521
|
+
}
|
|
1522
|
+
if (op2.repeat === Infinity) {
|
|
1523
|
+
result = -1;
|
|
1524
|
+
break;
|
|
1525
|
+
}
|
|
1415
1526
|
var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
|
|
1416
1527
|
if (cmp == 1) {
|
|
1417
1528
|
result = 1;
|
|
@@ -1459,6 +1570,16 @@
|
|
|
1459
1570
|
var t = this.cmp(other);
|
|
1460
1571
|
return t == 0 || t == 1;
|
|
1461
1572
|
}
|
|
1573
|
+
}, {
|
|
1574
|
+
key: "equals",
|
|
1575
|
+
value: function equals(other) {
|
|
1576
|
+
return this.eq(other);
|
|
1577
|
+
}
|
|
1578
|
+
}, {
|
|
1579
|
+
key: "notEquals",
|
|
1580
|
+
value: function notEquals(other) {
|
|
1581
|
+
return this.neq(other);
|
|
1582
|
+
}
|
|
1462
1583
|
}, {
|
|
1463
1584
|
key: "eq_tolerance",
|
|
1464
1585
|
value: function eq_tolerance(value) {
|
|
@@ -1468,6 +1589,7 @@
|
|
|
1468
1589
|
}
|
|
1469
1590
|
//#endregion
|
|
1470
1591
|
//#region geometry
|
|
1592
|
+
/**this function is indistinguishable above 4503599627370496*/
|
|
1471
1593
|
}, {
|
|
1472
1594
|
key: "sin",
|
|
1473
1595
|
value: function sin() {
|
|
@@ -1520,6 +1642,16 @@
|
|
|
1520
1642
|
a.small = !a.small;
|
|
1521
1643
|
return a;
|
|
1522
1644
|
}
|
|
1645
|
+
}, {
|
|
1646
|
+
key: "recip",
|
|
1647
|
+
value: function recip() {
|
|
1648
|
+
return this.rec();
|
|
1649
|
+
}
|
|
1650
|
+
}, {
|
|
1651
|
+
key: "reciprocate",
|
|
1652
|
+
value: function reciprocate() {
|
|
1653
|
+
return this.rec();
|
|
1654
|
+
}
|
|
1523
1655
|
}, {
|
|
1524
1656
|
key: "floor",
|
|
1525
1657
|
value: function floor() {
|
|
@@ -1560,6 +1692,9 @@
|
|
|
1560
1692
|
r.sign = this.sign;
|
|
1561
1693
|
return r;
|
|
1562
1694
|
}
|
|
1695
|
+
}, {
|
|
1696
|
+
key: "trunc",
|
|
1697
|
+
value:
|
|
1563
1698
|
/**
|
|
1564
1699
|
* Work like `Math.trunc`,
|
|
1565
1700
|
*
|
|
@@ -1572,15 +1707,10 @@
|
|
|
1572
1707
|
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
1573
1708
|
* @returns
|
|
1574
1709
|
*/
|
|
1575
|
-
|
|
1576
|
-
key: "trunc",
|
|
1577
|
-
value: function trunc() {
|
|
1710
|
+
function trunc() {
|
|
1578
1711
|
var y = this.clone();
|
|
1579
1712
|
return y.gte(0) ? y.floor() : y.ceil();
|
|
1580
1713
|
}
|
|
1581
|
-
/**
|
|
1582
|
-
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
1583
|
-
*/
|
|
1584
1714
|
}, {
|
|
1585
1715
|
key: "isNaN",
|
|
1586
1716
|
value: function (_isNaN) {
|
|
@@ -1643,10 +1773,164 @@
|
|
|
1643
1773
|
value: function isneg() {
|
|
1644
1774
|
return this.sign < 0;
|
|
1645
1775
|
}
|
|
1776
|
+
}, {
|
|
1777
|
+
key: "getOperatorIndex",
|
|
1778
|
+
value:
|
|
1779
|
+
//#endregion
|
|
1780
|
+
//#region operators
|
|
1781
|
+
/**
|
|
1782
|
+
* @returns number will return the index of the operator in array. return as x.5 if it's between the xth and x+1th operators.
|
|
1783
|
+
*/
|
|
1784
|
+
function getOperatorIndex(arrow) {
|
|
1785
|
+
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1786
|
+
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1787
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1788
|
+
var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
|
|
1789
|
+
if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
|
|
1790
|
+
if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
|
|
1791
|
+
}
|
|
1792
|
+
return this.array.length - 0.5;
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* @returns number repeats of operators with given arguments.
|
|
1796
|
+
*/
|
|
1797
|
+
}, {
|
|
1798
|
+
key: "getOperator",
|
|
1799
|
+
value: function getOperator(arrow) {
|
|
1800
|
+
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1801
|
+
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1802
|
+
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1803
|
+
if (!this.array[index]) return 0;
|
|
1804
|
+
return this.array[index].repeat;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Modify the repeat of operator
|
|
1808
|
+
* @param number val the repeat of operator will modify to array.
|
|
1809
|
+
* @returns bool Is the operators array changed?
|
|
1810
|
+
*/
|
|
1811
|
+
}, {
|
|
1812
|
+
key: "setOperator",
|
|
1813
|
+
value: function setOperator(val, arrow) {
|
|
1814
|
+
var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1815
|
+
var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
1816
|
+
// if (arrow!=0&&val==0) return false;
|
|
1817
|
+
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1818
|
+
if (!this.array[index]) {
|
|
1819
|
+
this.array.splice(Math.ceil(index), 0, {
|
|
1820
|
+
arrow: arrow,
|
|
1821
|
+
expans: expans,
|
|
1822
|
+
megota: megota,
|
|
1823
|
+
valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
|
|
1824
|
+
repeat: val
|
|
1825
|
+
});
|
|
1826
|
+
return true;
|
|
1827
|
+
}
|
|
1828
|
+
this.array[index].repeat = val;
|
|
1829
|
+
// this.normalize()
|
|
1830
|
+
return false;
|
|
1831
|
+
}
|
|
1832
|
+
//#endregion
|
|
1833
|
+
//#region converters
|
|
1834
|
+
/**
|
|
1835
|
+
* Convert `this` to Javascript `number`
|
|
1836
|
+
*
|
|
1837
|
+
* returns `Infinity` when the number is greater than `Number.MAX_VALUE`
|
|
1838
|
+
*/
|
|
1839
|
+
}, {
|
|
1840
|
+
key: "toNumber",
|
|
1841
|
+
value: function toNumber() {
|
|
1842
|
+
if (this.sign == -1) return -this.neg().toNumber();
|
|
1843
|
+
if (this.small) return 1 / this.rec().toNumber();
|
|
1844
|
+
if (this.array.length > 2) return Infinity;
|
|
1845
|
+
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));
|
|
1846
|
+
return NaN;
|
|
1847
|
+
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Convert `this` to a string
|
|
1850
|
+
*/
|
|
1851
|
+
}, {
|
|
1852
|
+
key: "toString_core",
|
|
1853
|
+
value: function toString_core() {
|
|
1854
|
+
if (this.isNaN()) return "NaN";
|
|
1855
|
+
if (this.sign == -1) return "-".concat(this.neg().toString());
|
|
1856
|
+
if (this.small) {
|
|
1857
|
+
if (this.isZero()) return "0";
|
|
1858
|
+
return "/".concat(this.rec().toString());
|
|
1859
|
+
}
|
|
1860
|
+
if (this.isInfi()) return "Infinity";
|
|
1861
|
+
// P^a (10{arrow,expans,megota})^repeation base
|
|
1862
|
+
var res = "";
|
|
1863
|
+
if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
|
|
1864
|
+
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
1865
|
+
var oper = this.array[i];
|
|
1866
|
+
var calc = "10{".concat(oper.arrow === Infinity ? "!" : oper.arrow).concat(oper.expans > 1 || oper.megota > 1 ? ",".concat(oper.expans === Infinity ? "!" : oper.expans) : "").concat(oper.megota > 1 ? ",".concat(oper.megota) : "", "}");
|
|
1867
|
+
if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
|
|
1868
|
+
calc = "e".repeat(oper.repeat);
|
|
1869
|
+
} else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
|
|
1870
|
+
calc = oper.repeat.toString();
|
|
1871
|
+
} else if (oper.repeat > 1) {
|
|
1872
|
+
calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
|
|
1873
|
+
} else {
|
|
1874
|
+
calc = "".concat(calc);
|
|
1875
|
+
}
|
|
1876
|
+
res += "".concat(calc);
|
|
1877
|
+
}
|
|
1878
|
+
return res;
|
|
1879
|
+
}
|
|
1880
|
+
}, {
|
|
1881
|
+
key: "toString",
|
|
1882
|
+
value: function toString() {
|
|
1883
|
+
try {
|
|
1884
|
+
return this.toString_core();
|
|
1885
|
+
} catch (_b) {
|
|
1886
|
+
console.error("Checked error when converting to string");
|
|
1887
|
+
return "NaN";
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
}, {
|
|
1891
|
+
key: "toJSON",
|
|
1892
|
+
value:
|
|
1893
|
+
/**
|
|
1894
|
+
* Convert `this` to a JSON object
|
|
1895
|
+
* @returns a JSON object
|
|
1896
|
+
*/
|
|
1897
|
+
function toJSON() {
|
|
1898
|
+
return "PN" + this.toString();
|
|
1899
|
+
}
|
|
1900
|
+
}, {
|
|
1901
|
+
key: "arr01",
|
|
1902
|
+
get:
|
|
1903
|
+
/**
|
|
1904
|
+
* A property array value for version 0.1.x PowiainaNum.
|
|
1905
|
+
*/
|
|
1906
|
+
function get() {
|
|
1907
|
+
var res = [0];
|
|
1908
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1909
|
+
if (i == 0) res[0] = this.array[i].repeat;else {
|
|
1910
|
+
// @ts-ignore
|
|
1911
|
+
res[i] = [0, 0, 0, 0];
|
|
1912
|
+
// @ts-ignore
|
|
1913
|
+
res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
|
|
1914
|
+
// @ts-ignore
|
|
1915
|
+
res[i][1] = this.array[i].repeat;
|
|
1916
|
+
// @ts-ignore
|
|
1917
|
+
res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
|
|
1918
|
+
// @ts-ignore
|
|
1919
|
+
res[i][3] = this.array[i].megota;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
return res;
|
|
1923
|
+
}
|
|
1924
|
+
//#endregion
|
|
1925
|
+
//#region useless functions
|
|
1926
|
+
/**
|
|
1927
|
+
* This function is for NaNe308, if you want to calculate G(x), use this function directly.
|
|
1928
|
+
*/
|
|
1646
1929
|
}, {
|
|
1647
1930
|
key: "normalize",
|
|
1648
1931
|
value:
|
|
1649
1932
|
//#endregion
|
|
1933
|
+
//#region other functions
|
|
1650
1934
|
/**
|
|
1651
1935
|
* Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
|
|
1652
1936
|
* @returns normalized number
|
|
@@ -1655,9 +1939,14 @@
|
|
|
1655
1939
|
//TODO: normalize
|
|
1656
1940
|
var renormalize = true;
|
|
1657
1941
|
var x = this;
|
|
1658
|
-
|
|
1942
|
+
if (this.array === undefined) {
|
|
1943
|
+
x.array = [newOperator(NaN, 0, 1, 1)];
|
|
1944
|
+
}
|
|
1945
|
+
if (this.sign === undefined) this.sign = 0;
|
|
1946
|
+
if (this.layer === undefined) this.layer = 0;
|
|
1947
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1659
1948
|
// Check what is infinity
|
|
1660
|
-
if (this.array[
|
|
1949
|
+
if (this.array[i].repeat == Infinity) {
|
|
1661
1950
|
this.array = [{
|
|
1662
1951
|
arrow: 0,
|
|
1663
1952
|
expans: 1,
|
|
@@ -1668,8 +1957,8 @@
|
|
|
1668
1957
|
return this;
|
|
1669
1958
|
}
|
|
1670
1959
|
}
|
|
1671
|
-
for (var
|
|
1672
|
-
var e = x.array[
|
|
1960
|
+
for (var _i = 1; _i < x.array.length; ++_i) {
|
|
1961
|
+
var e = x.array[_i];
|
|
1673
1962
|
if (e.arrow === null || e.arrow === undefined) {
|
|
1674
1963
|
e.arrow = 0;
|
|
1675
1964
|
}
|
|
@@ -1700,28 +1989,28 @@
|
|
|
1700
1989
|
renormalize = false;
|
|
1701
1990
|
// Sort arrays.
|
|
1702
1991
|
this.array.sort(arraySortFunction);
|
|
1703
|
-
for (
|
|
1704
|
-
if (x.array[
|
|
1992
|
+
for (var _i2 = 1; _i2 < x.array.length - 1; ++_i2) {
|
|
1993
|
+
if (x.array[_i2].arrow == x.array[_i2 + 1].arrow && x.array[_i2].expans == x.array[_i2 + 1].expans && x.array[_i2].megota == x.array[_i2 + 1].megota) {
|
|
1705
1994
|
// same array's merge
|
|
1706
|
-
x.array[
|
|
1707
|
-
x.array.splice(
|
|
1708
|
-
--
|
|
1995
|
+
x.array[_i2].repeat += x.array[_i2 + 1].repeat;
|
|
1996
|
+
x.array.splice(_i2 + 1, 1);
|
|
1997
|
+
--_i2;
|
|
1709
1998
|
renormalize = true;
|
|
1710
1999
|
}
|
|
1711
2000
|
}
|
|
1712
|
-
for (
|
|
2001
|
+
for (var _i3 = 1; _i3 < x.array.length; ++_i3) {
|
|
1713
2002
|
// If there is a 0 repeat operator, remove it.
|
|
1714
|
-
if (x.array[
|
|
1715
|
-
x.array.splice(
|
|
1716
|
-
--
|
|
2003
|
+
if (x.array[_i3].arrow !== 0 && (x.array[_i3].repeat === 0 || x.array[_i3].repeat === null || x.array[_i3].repeat === undefined)) {
|
|
2004
|
+
x.array.splice(_i3, 1);
|
|
2005
|
+
--_i3;
|
|
1717
2006
|
continue;
|
|
1718
2007
|
}
|
|
1719
2008
|
// If there is a operator which arrow 0 and brace count >=2
|
|
1720
2009
|
// replace it as arrow replacement operaotr
|
|
1721
|
-
if (x.array[
|
|
1722
|
-
x.array[
|
|
1723
|
-
x.array[
|
|
1724
|
-
x.array[
|
|
2010
|
+
if (x.array[_i3].arrow == 0 && x.array[_i3].expans >= 2) {
|
|
2011
|
+
x.array[_i3].arrow = Infinity;
|
|
2012
|
+
x.array[_i3].valuereplaced = 0;
|
|
2013
|
+
x.array[_i3].expans = x.array[_i3].expans - 1;
|
|
1725
2014
|
}
|
|
1726
2015
|
}
|
|
1727
2016
|
if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
|
|
@@ -1751,6 +2040,11 @@
|
|
|
1751
2040
|
this.small = !this.small;
|
|
1752
2041
|
renormalize = true;
|
|
1753
2042
|
}
|
|
2043
|
+
// for a = 1, small should false.
|
|
2044
|
+
if (this.array.length == 1 && this.array[0].repeat == 1 && this.small) {
|
|
2045
|
+
this.small = false;
|
|
2046
|
+
renormalize = true;
|
|
2047
|
+
}
|
|
1754
2048
|
// for any 10{X>9e15}10, replace into 10{!}X;
|
|
1755
2049
|
if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
|
|
1756
2050
|
this.array[0].repeat = this.array[1].arrow;
|
|
@@ -1806,61 +2100,6 @@
|
|
|
1806
2100
|
} while (renormalize);
|
|
1807
2101
|
return this;
|
|
1808
2102
|
}
|
|
1809
|
-
//#region operators
|
|
1810
|
-
/**
|
|
1811
|
-
* @returns number will return the index of the operator in array. return as x.5 if it's between the xth and x+1th operators.
|
|
1812
|
-
*/
|
|
1813
|
-
}, {
|
|
1814
|
-
key: "getOperatorIndex",
|
|
1815
|
-
value: function getOperatorIndex(arrow) {
|
|
1816
|
-
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1817
|
-
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1818
|
-
for (var i = 0; i < this.array.length; i++) {
|
|
1819
|
-
var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
|
|
1820
|
-
if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
|
|
1821
|
-
if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
|
|
1822
|
-
}
|
|
1823
|
-
return this.array.length - 0.5;
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* @returns number repeats of operators with given arguments.
|
|
1827
|
-
*/
|
|
1828
|
-
}, {
|
|
1829
|
-
key: "getOperator",
|
|
1830
|
-
value: function getOperator(arrow) {
|
|
1831
|
-
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1832
|
-
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1833
|
-
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1834
|
-
if (!this.array[index]) return 0;
|
|
1835
|
-
return this.array[index].repeat;
|
|
1836
|
-
}
|
|
1837
|
-
/**
|
|
1838
|
-
* Modify the repeat of operator
|
|
1839
|
-
* @param number val the repeat of operator will modify to array.
|
|
1840
|
-
* @returns bool Is the operators array changed?
|
|
1841
|
-
*/
|
|
1842
|
-
}, {
|
|
1843
|
-
key: "setOperator",
|
|
1844
|
-
value: function setOperator(val, arrow) {
|
|
1845
|
-
var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1846
|
-
var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
1847
|
-
// if (arrow!=0&&val==0) return false;
|
|
1848
|
-
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1849
|
-
if (!this.array[index]) {
|
|
1850
|
-
this.array.splice(Math.ceil(index), 0, {
|
|
1851
|
-
arrow: arrow,
|
|
1852
|
-
expans: expans,
|
|
1853
|
-
megota: megota,
|
|
1854
|
-
valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
|
|
1855
|
-
repeat: val
|
|
1856
|
-
});
|
|
1857
|
-
return true;
|
|
1858
|
-
}
|
|
1859
|
-
this.array[index].repeat = val;
|
|
1860
|
-
// this.normalize()
|
|
1861
|
-
return false;
|
|
1862
|
-
}
|
|
1863
|
-
//#endregion
|
|
1864
2103
|
/**
|
|
1865
2104
|
* @returns a PowiainaNum object which deep copied from `this` object.
|
|
1866
2105
|
*/
|
|
@@ -1879,6 +2118,9 @@
|
|
|
1879
2118
|
}, {
|
|
1880
2119
|
key: "resetFromObject",
|
|
1881
2120
|
value: function resetFromObject(powlikeObject) {
|
|
2121
|
+
if (!powlikeObject.array) {
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
1882
2124
|
this.array = [];
|
|
1883
2125
|
for (var i = 0; i < powlikeObject.array.length; i++) {
|
|
1884
2126
|
this.array[i] = {
|
|
@@ -1894,107 +2136,56 @@
|
|
|
1894
2136
|
this.layer = powlikeObject.layer;
|
|
1895
2137
|
return this;
|
|
1896
2138
|
}
|
|
1897
|
-
//#region converters
|
|
1898
|
-
/**
|
|
1899
|
-
* Convert `this` to Javascript `number`
|
|
1900
|
-
*
|
|
1901
|
-
* returns `Infinity` when the number is greater than `Number.MAX_VALUE`
|
|
1902
|
-
*/
|
|
1903
|
-
}, {
|
|
1904
|
-
key: "toNumber",
|
|
1905
|
-
value: function toNumber() {
|
|
1906
|
-
if (this.sign == -1) return -this.neg().toNumber();
|
|
1907
|
-
if (this.small) return 1 / this.rec().toNumber();
|
|
1908
|
-
if (this.array.length > 2) return Infinity;
|
|
1909
|
-
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));
|
|
1910
|
-
return NaN;
|
|
1911
|
-
}
|
|
1912
|
-
/**
|
|
1913
|
-
* Convert `this` to a string
|
|
1914
|
-
*/
|
|
1915
|
-
}, {
|
|
1916
|
-
key: "toString",
|
|
1917
|
-
value: function toString() {
|
|
1918
|
-
if (this.isNaN()) return "NaN";
|
|
1919
|
-
if (this.sign == -1) return "-".concat(this.neg().toString());
|
|
1920
|
-
if (this.small) {
|
|
1921
|
-
if (this.isZero()) return "0";
|
|
1922
|
-
return "/".concat(this.rec().toString());
|
|
1923
|
-
}
|
|
1924
|
-
if (this.isInfi()) return "Infinity";
|
|
1925
|
-
// P^a (10{arrow,expans,megota})^repeation base
|
|
1926
|
-
var res = "";
|
|
1927
|
-
if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
|
|
1928
|
-
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
1929
|
-
var oper = this.array[i];
|
|
1930
|
-
var calc = "10{".concat(oper.arrow === Infinity ? "!" : oper.arrow).concat(oper.expans > 1 || oper.megota > 1 ? ",".concat(oper.expans === Infinity ? "!" : oper.expans) : "").concat(oper.megota > 1 ? ",".concat(oper.megota) : "", "}");
|
|
1931
|
-
if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
|
|
1932
|
-
calc = "e".repeat(oper.repeat);
|
|
1933
|
-
} else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
|
|
1934
|
-
calc = oper.repeat.toString();
|
|
1935
|
-
} else if (oper.repeat > 1) {
|
|
1936
|
-
calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
|
|
1937
|
-
} else {
|
|
1938
|
-
calc = "".concat(calc);
|
|
1939
|
-
}
|
|
1940
|
-
res += "".concat(calc);
|
|
1941
|
-
}
|
|
1942
|
-
return res;
|
|
1943
|
-
}
|
|
1944
|
-
}, {
|
|
1945
|
-
key: "toJSON",
|
|
1946
|
-
value:
|
|
1947
|
-
/**
|
|
1948
|
-
* Convert `this` to a JSON object
|
|
1949
|
-
* @returns a JSON object
|
|
1950
|
-
*/
|
|
1951
|
-
function toJSON() {
|
|
1952
|
-
return "PN" + this.toString();
|
|
1953
|
-
}
|
|
1954
|
-
}, {
|
|
1955
|
-
key: "arr01",
|
|
1956
|
-
get:
|
|
1957
|
-
/**
|
|
1958
|
-
* A property array value for version 0.1.x PowiainaNum.
|
|
1959
|
-
*/
|
|
1960
|
-
function get() {
|
|
1961
|
-
var res = [0];
|
|
1962
|
-
for (var i = 0; i < this.array.length; i++) {
|
|
1963
|
-
if (i == 0) res[0] = this.array[i].repeat;else {
|
|
1964
|
-
// @ts-ignore
|
|
1965
|
-
res[i] = [0, 0, 0, 0];
|
|
1966
|
-
// @ts-ignore
|
|
1967
|
-
res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
|
|
1968
|
-
// @ts-ignore
|
|
1969
|
-
res[i][1] = this.array[i].repeat;
|
|
1970
|
-
// @ts-ignore
|
|
1971
|
-
res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
|
|
1972
|
-
// @ts-ignore
|
|
1973
|
-
res[i][3] = this.array[i].megota;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
return res;
|
|
1977
|
-
}
|
|
1978
2139
|
}], [{
|
|
1979
2140
|
key: "add",
|
|
1980
2141
|
value: function add(t, other) {
|
|
1981
2142
|
return new PowiainaNum(t).add(other);
|
|
1982
2143
|
}
|
|
2144
|
+
}, {
|
|
2145
|
+
key: "plus",
|
|
2146
|
+
value: function plus(t, other) {
|
|
2147
|
+
return new PowiainaNum(t).add(other);
|
|
2148
|
+
}
|
|
1983
2149
|
}, {
|
|
1984
2150
|
key: "sub",
|
|
1985
2151
|
value: function sub(t, other) {
|
|
1986
2152
|
return new PowiainaNum(t).sub(other);
|
|
1987
2153
|
}
|
|
2154
|
+
}, {
|
|
2155
|
+
key: "minus",
|
|
2156
|
+
value: function minus(t, other) {
|
|
2157
|
+
return new PowiainaNum(t).sub(other);
|
|
2158
|
+
}
|
|
1988
2159
|
}, {
|
|
1989
2160
|
key: "mul",
|
|
1990
2161
|
value: function mul(t, other) {
|
|
1991
2162
|
return new PowiainaNum(t).mul(other);
|
|
1992
2163
|
}
|
|
2164
|
+
}, {
|
|
2165
|
+
key: "times",
|
|
2166
|
+
value: function times(t, other) {
|
|
2167
|
+
return new PowiainaNum(t).mul(other);
|
|
2168
|
+
}
|
|
1993
2169
|
}, {
|
|
1994
2170
|
key: "div",
|
|
1995
2171
|
value: function div(t, other) {
|
|
1996
2172
|
return new PowiainaNum(t).div(other);
|
|
1997
2173
|
}
|
|
2174
|
+
}, {
|
|
2175
|
+
key: "divide",
|
|
2176
|
+
value: function divide(t, other) {
|
|
2177
|
+
return new PowiainaNum(t).div(other);
|
|
2178
|
+
}
|
|
2179
|
+
}, {
|
|
2180
|
+
key: "mod",
|
|
2181
|
+
value: function mod(x, y) {
|
|
2182
|
+
return new PowiainaNum(x).mod(y);
|
|
2183
|
+
}
|
|
2184
|
+
}, {
|
|
2185
|
+
key: "modulus",
|
|
2186
|
+
value: function modulus(x, y) {
|
|
2187
|
+
return new PowiainaNum(x).mod(y);
|
|
2188
|
+
}
|
|
1998
2189
|
}, {
|
|
1999
2190
|
key: "pow",
|
|
2000
2191
|
value: function pow(t, other) {
|
|
@@ -2026,6 +2217,17 @@
|
|
|
2026
2217
|
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
|
|
2027
2218
|
return new PowiainaNum(t).log(base);
|
|
2028
2219
|
}
|
|
2220
|
+
}, {
|
|
2221
|
+
key: "log2",
|
|
2222
|
+
value: function log2(t) {
|
|
2223
|
+
return new PowiainaNum(t).log2();
|
|
2224
|
+
}
|
|
2225
|
+
}, {
|
|
2226
|
+
key: "logBase",
|
|
2227
|
+
value: function logBase(t) {
|
|
2228
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
|
|
2229
|
+
return new PowiainaNum(t).log(base);
|
|
2230
|
+
}
|
|
2029
2231
|
}, {
|
|
2030
2232
|
key: "pLog10",
|
|
2031
2233
|
value: function pLog10(t) {
|
|
@@ -2177,6 +2379,27 @@
|
|
|
2177
2379
|
};
|
|
2178
2380
|
}
|
|
2179
2381
|
}
|
|
2382
|
+
}, {
|
|
2383
|
+
key: "pentate",
|
|
2384
|
+
value: function pentate(x, other, payload) {
|
|
2385
|
+
return new PowiainaNum(x).arrow(3)(other, payload);
|
|
2386
|
+
}
|
|
2387
|
+
}, {
|
|
2388
|
+
key: "hexate",
|
|
2389
|
+
value: function hexate(x, other, payload) {
|
|
2390
|
+
return new PowiainaNum(x).arrow(4)(other, payload);
|
|
2391
|
+
}
|
|
2392
|
+
}, {
|
|
2393
|
+
key: "pent",
|
|
2394
|
+
value: function pent(x, other, payload) {
|
|
2395
|
+
return new PowiainaNum(x).arrow(3)(other, payload);
|
|
2396
|
+
}
|
|
2397
|
+
}, {
|
|
2398
|
+
key: "penta_log",
|
|
2399
|
+
value: function penta_log(x) {
|
|
2400
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
2401
|
+
return new PowiainaNum(x).anyarrow_log(3)(base);
|
|
2402
|
+
}
|
|
2180
2403
|
}, {
|
|
2181
2404
|
key: "expansion",
|
|
2182
2405
|
value: function expansion(t, other) {
|
|
@@ -2275,9 +2498,6 @@
|
|
|
2275
2498
|
if (a == 0 && e == 1 && m > 1) {
|
|
2276
2499
|
return [1, 1 / 0, m - 1];
|
|
2277
2500
|
}
|
|
2278
|
-
if (e == 0 && m > 1) {
|
|
2279
|
-
return [1, 1 / 0, m - 1];
|
|
2280
|
-
}
|
|
2281
2501
|
return [a, e, m];
|
|
2282
2502
|
}
|
|
2283
2503
|
if (megota.gt(MSI)) {
|
|
@@ -2291,8 +2511,7 @@
|
|
|
2291
2511
|
return x.toString();
|
|
2292
2512
|
}
|
|
2293
2513
|
function getMSIForm(arrow, expans, megota) {
|
|
2294
|
-
|
|
2295
|
-
return "10{".concat(infToBang(conv[0]), ",").concat(infToBang(conv[1]), ",").concat(conv[2], "}").concat(MSI);
|
|
2514
|
+
return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
|
|
2296
2515
|
}
|
|
2297
2516
|
var t = base.clone();
|
|
2298
2517
|
var arrows = new PowiainaNum(readArg(0));
|
|
@@ -2300,14 +2519,6 @@
|
|
|
2300
2519
|
var _r, _r2;
|
|
2301
2520
|
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2302
2521
|
console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
|
|
2303
|
-
if (depth >= 200) {
|
|
2304
|
-
return new PowiainaNum({
|
|
2305
|
-
layer: 0,
|
|
2306
|
-
array: [newOperator(10), newOperator(1, new PowiainaNum(arrow2).clampMax(MSI).toNumber(), new PowiainaNum(expans2).clampMax(MSI).toNumber(), new PowiainaNum(megota2).clampMax(MSI).toNumber())],
|
|
2307
|
-
sign: 1,
|
|
2308
|
-
small: false
|
|
2309
|
-
}).normalize();
|
|
2310
|
-
}
|
|
2311
2522
|
var other = new PowiainaNum(other2);
|
|
2312
2523
|
var r;
|
|
2313
2524
|
if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
|
|
@@ -2325,7 +2536,7 @@
|
|
|
2325
2536
|
}
|
|
2326
2537
|
if (expans.eq(0)) {
|
|
2327
2538
|
return PowiainaNum.BEAF(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
|
|
2328
|
-
// {this, this, power,
|
|
2539
|
+
// {this, this, this, power, megota-1}
|
|
2329
2540
|
}
|
|
2330
2541
|
if (megota.eq(0)) {
|
|
2331
2542
|
return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
|
|
@@ -2444,6 +2655,84 @@
|
|
|
2444
2655
|
value: function clampMax() {
|
|
2445
2656
|
return PowiainaNum.min.apply(PowiainaNum, arguments);
|
|
2446
2657
|
}
|
|
2658
|
+
}, {
|
|
2659
|
+
key: "eq",
|
|
2660
|
+
value: function eq(a, o) {
|
|
2661
|
+
return new PowiainaNum(a).eq(o);
|
|
2662
|
+
}
|
|
2663
|
+
}, {
|
|
2664
|
+
key: "equals",
|
|
2665
|
+
value: function equals(a, o) {
|
|
2666
|
+
return new PowiainaNum(a).eq(o);
|
|
2667
|
+
}
|
|
2668
|
+
}, {
|
|
2669
|
+
key: "neq",
|
|
2670
|
+
value: function neq(a, o) {
|
|
2671
|
+
return new PowiainaNum(a).neq(o);
|
|
2672
|
+
}
|
|
2673
|
+
}, {
|
|
2674
|
+
key: "notEquals",
|
|
2675
|
+
value: function notEquals(a, o) {
|
|
2676
|
+
return new PowiainaNum(a).notEquals(o);
|
|
2677
|
+
}
|
|
2678
|
+
}, {
|
|
2679
|
+
key: "lt",
|
|
2680
|
+
value: function lt(a, o) {
|
|
2681
|
+
return new PowiainaNum(a).lt(o);
|
|
2682
|
+
}
|
|
2683
|
+
}, {
|
|
2684
|
+
key: "gt",
|
|
2685
|
+
value: function gt(a, o) {
|
|
2686
|
+
return new PowiainaNum(a).gt(o);
|
|
2687
|
+
}
|
|
2688
|
+
}, {
|
|
2689
|
+
key: "lte",
|
|
2690
|
+
value: function lte(a, o) {
|
|
2691
|
+
return new PowiainaNum(a).lte(o);
|
|
2692
|
+
}
|
|
2693
|
+
}, {
|
|
2694
|
+
key: "gte",
|
|
2695
|
+
value: function gte(a, o) {
|
|
2696
|
+
return new PowiainaNum(a).gte(o);
|
|
2697
|
+
}
|
|
2698
|
+
}, {
|
|
2699
|
+
key: "rec",
|
|
2700
|
+
value: function rec(t) {
|
|
2701
|
+
return new PowiainaNum(t).rec();
|
|
2702
|
+
}
|
|
2703
|
+
}, {
|
|
2704
|
+
key: "recip",
|
|
2705
|
+
value: function recip(t) {
|
|
2706
|
+
return new PowiainaNum(t).rec();
|
|
2707
|
+
}
|
|
2708
|
+
}, {
|
|
2709
|
+
key: "reciprocate",
|
|
2710
|
+
value: function reciprocate(t) {
|
|
2711
|
+
return new PowiainaNum(t).rec();
|
|
2712
|
+
}
|
|
2713
|
+
}, {
|
|
2714
|
+
key: "floor",
|
|
2715
|
+
value: function floor(x) {
|
|
2716
|
+
return new PowiainaNum(x).floor();
|
|
2717
|
+
}
|
|
2718
|
+
}, {
|
|
2719
|
+
key: "ceil",
|
|
2720
|
+
value: function ceil(x) {
|
|
2721
|
+
return new PowiainaNum(x).ceil();
|
|
2722
|
+
}
|
|
2723
|
+
}, {
|
|
2724
|
+
key: "round",
|
|
2725
|
+
value: function round(x) {
|
|
2726
|
+
return new PowiainaNum(x).round();
|
|
2727
|
+
}
|
|
2728
|
+
}, {
|
|
2729
|
+
key: "trunc",
|
|
2730
|
+
value: function trunc(x) {
|
|
2731
|
+
return new PowiainaNum(x).trunc();
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
2735
|
+
*/
|
|
2447
2736
|
}, {
|
|
2448
2737
|
key: "sign",
|
|
2449
2738
|
value: function sign(a) {
|
|
@@ -2458,6 +2747,17 @@
|
|
|
2458
2747
|
key: "fromNumber",
|
|
2459
2748
|
value: function fromNumber(x) {
|
|
2460
2749
|
var obj = new PowiainaNum(); // NaN
|
|
2750
|
+
obj.resetFromObject({
|
|
2751
|
+
array: [{
|
|
2752
|
+
arrow: 0,
|
|
2753
|
+
expans: 1,
|
|
2754
|
+
megota: 1,
|
|
2755
|
+
repeat: NaN
|
|
2756
|
+
}],
|
|
2757
|
+
small: false,
|
|
2758
|
+
layer: 0,
|
|
2759
|
+
sign: 0
|
|
2760
|
+
});
|
|
2461
2761
|
if (x < 0) obj.sign = -1; // negative
|
|
2462
2762
|
else if (x == 0) {
|
|
2463
2763
|
obj.sign = 0;
|
|
@@ -2485,10 +2785,26 @@
|
|
|
2485
2785
|
}, {
|
|
2486
2786
|
key: "fromString",
|
|
2487
2787
|
value: function fromString(input) {
|
|
2788
|
+
if (PowiainaNum.usingBreakEternityLikeFromString && BE_REGEX.test(input)) {
|
|
2789
|
+
/*
|
|
2790
|
+
* 0i00000000a7 says that eee-3000 will wrongly parse to 1. So i added this
|
|
2791
|
+
*/
|
|
2792
|
+
var a = input.match(/(e+-)(\d+(.\d+)?)/);
|
|
2793
|
+
if (a) {
|
|
2794
|
+
var e_s = a[1].length;
|
|
2795
|
+
input = "e-" + "e".repeat(e_s - 1) + a[2];
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
return this.fromString_core(input);
|
|
2799
|
+
}
|
|
2800
|
+
}, {
|
|
2801
|
+
key: "fromString_core",
|
|
2802
|
+
value: function fromString_core(input) {
|
|
2488
2803
|
var _b, _c, _d, _e, _f, _g;
|
|
2489
|
-
var x = new PowiainaNum();
|
|
2804
|
+
var x = new PowiainaNum(NaN);
|
|
2490
2805
|
// Judge the string was a number
|
|
2491
2806
|
if (input.startsWith("PN")) input = input.substring(2);
|
|
2807
|
+
if (input == "NaN") return PowiainaNum.NaN.clone();
|
|
2492
2808
|
input = input.replace(/J\^(\d+)/g, "(10{!})^$1");
|
|
2493
2809
|
input = input.replace(/J/g, "10{!}");
|
|
2494
2810
|
input = input.replace(/K\^(\d+)/g, "(10{1,2})^$1");
|
|
@@ -2499,17 +2815,20 @@
|
|
|
2499
2815
|
input = input.replace(/M/g, "10{!,2}");
|
|
2500
2816
|
input = input.replace(/N\^(\d+)/g, "(10{1,!})^$1");
|
|
2501
2817
|
input = input.replace(/N/g, "10{1,!}");
|
|
2818
|
+
if (/^.*e-.*(e|\^).*/.test(input)) {
|
|
2819
|
+
input = "/10^" + input.substring(input.indexOf("e-"));
|
|
2820
|
+
}
|
|
2502
2821
|
if (!isNaN(Number(input))) {
|
|
2503
2822
|
var res = Number(input);
|
|
2504
|
-
var
|
|
2823
|
+
var a = false;
|
|
2505
2824
|
if (res == 0) {
|
|
2506
2825
|
if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
|
|
2507
|
-
|
|
2826
|
+
a = true;
|
|
2508
2827
|
}
|
|
2509
2828
|
} else {
|
|
2510
|
-
|
|
2829
|
+
a = true;
|
|
2511
2830
|
}
|
|
2512
|
-
if (!
|
|
2831
|
+
if (!a) {
|
|
2513
2832
|
var m = input.search(/e/);
|
|
2514
2833
|
var exponent = input.substring((m == -1 ? input.length : m) + 1);
|
|
2515
2834
|
var mantissa = input.substring(0, m == -1 ? undefined : m);
|
|
@@ -2519,11 +2838,11 @@
|
|
|
2519
2838
|
// Is regular number gte 1:
|
|
2520
2839
|
if (Number(mantissa) >= 1) {
|
|
2521
2840
|
// check The mantissa is very long?
|
|
2522
|
-
var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
|
|
2523
|
-
var log10int = Math.floor(log10mant);
|
|
2524
|
-
var log10float = log10mant - log10int;
|
|
2841
|
+
var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa)); // sample 10
|
|
2842
|
+
var log10int = Math.floor(log10mant); // sample 1
|
|
2843
|
+
var log10float = log10mant - log10int; // sample 0;
|
|
2525
2844
|
mantissaME[0] = Math.pow(10, log10float);
|
|
2526
|
-
mantissaME[1] +=
|
|
2845
|
+
mantissaME[1] += log10int;
|
|
2527
2846
|
} else {
|
|
2528
2847
|
// If not , count how many zeros until reached non-zero numbers
|
|
2529
2848
|
var zeros = countLeadingZerosAfterDecimal(mantissa);
|
|
@@ -2538,7 +2857,7 @@
|
|
|
2538
2857
|
// /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
|
|
2539
2858
|
return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
|
|
2540
2859
|
}
|
|
2541
|
-
if (isFinite(res) &&
|
|
2860
|
+
if (isFinite(res) && a) {
|
|
2542
2861
|
x = PowiainaNum.fromNumber(Number(input));
|
|
2543
2862
|
return x;
|
|
2544
2863
|
}
|
|
@@ -2555,6 +2874,7 @@
|
|
|
2555
2874
|
return x;
|
|
2556
2875
|
}
|
|
2557
2876
|
input = replaceETo10(input);
|
|
2877
|
+
input = removeCommasOutsideBraces(input);
|
|
2558
2878
|
if (!isPowiainaNum.test(input)) {
|
|
2559
2879
|
throw powiainaNumError + "malformed input: " + input;
|
|
2560
2880
|
}
|
|
@@ -2567,28 +2887,31 @@
|
|
|
2567
2887
|
input = input.substring(numSigns);
|
|
2568
2888
|
}
|
|
2569
2889
|
if (input[0] == "/") {
|
|
2570
|
-
var
|
|
2571
|
-
var
|
|
2572
|
-
recipIt = ((_e = (_d =
|
|
2573
|
-
input = input.substring(
|
|
2890
|
+
var _numSigns = input.search(/[^\/]/);
|
|
2891
|
+
var _signs = input.substring(0, _numSigns);
|
|
2892
|
+
recipIt = ((_e = (_d = _signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
|
|
2893
|
+
input = input.substring(_numSigns);
|
|
2574
2894
|
}
|
|
2575
2895
|
if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
|
|
2576
2896
|
x.sign = 1;
|
|
2577
2897
|
x.array = [newOperator(0)];
|
|
2578
|
-
var
|
|
2898
|
+
var _a3, b, c, d;
|
|
2579
2899
|
if (input[0] == "P") {
|
|
2580
2900
|
if (input[1] == "^") {
|
|
2581
|
-
|
|
2582
|
-
x.layer = Number(input.substring(2,
|
|
2583
|
-
input = input.substring(
|
|
2901
|
+
_a3 = input.substring(2).search(/[^0-9]/) + 2;
|
|
2902
|
+
x.layer = Number(input.substring(2, _a3));
|
|
2903
|
+
input = input.substring(_a3 + 1);
|
|
2584
2904
|
} else {
|
|
2585
|
-
|
|
2586
|
-
x.layer =
|
|
2587
|
-
input = input.substring(
|
|
2905
|
+
_a3 = input.search(/[^P]/);
|
|
2906
|
+
x.layer = _a3;
|
|
2907
|
+
input = input.substring(_a3);
|
|
2588
2908
|
}
|
|
2589
2909
|
}
|
|
2590
2910
|
while (input) {
|
|
2591
2911
|
if (/^(\(?10[\^\{])/.test(input)) {
|
|
2912
|
+
var arrows = void 0,
|
|
2913
|
+
expans = void 0,
|
|
2914
|
+
megota = void 0;
|
|
2592
2915
|
/*
|
|
2593
2916
|
10^ - 匹配
|
|
2594
2917
|
10{ - 匹配
|
|
@@ -2599,30 +2922,29 @@
|
|
|
2599
2922
|
*/
|
|
2600
2923
|
if (input[0] == "(") input = input.substring(1);
|
|
2601
2924
|
//cutted, 10^.... or 10{....
|
|
2602
|
-
var arrows, expans, megota;
|
|
2603
2925
|
if (input[2] == "^") {
|
|
2604
|
-
|
|
2926
|
+
_a3 = input.substring(2).search(/[^\^]/);
|
|
2605
2927
|
//cut input to ^^...^^, and search how numbers
|
|
2606
|
-
arrows =
|
|
2928
|
+
arrows = _a3;
|
|
2607
2929
|
// 10^^^
|
|
2608
|
-
b =
|
|
2930
|
+
b = _a3 + 2; // b points to after ^'s.
|
|
2609
2931
|
} else {
|
|
2610
2932
|
// 10{...}
|
|
2611
|
-
|
|
2933
|
+
_a3 = input.indexOf("}");
|
|
2612
2934
|
// select contents between {...}
|
|
2613
|
-
var tmp = input.substring(3,
|
|
2935
|
+
var tmp = input.substring(3, _a3).split(",");
|
|
2614
2936
|
arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
|
|
2615
2937
|
expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
|
|
2616
2938
|
megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
|
|
2617
|
-
b =
|
|
2939
|
+
b = _a3 + 1;
|
|
2618
2940
|
// b points to after }.
|
|
2619
2941
|
}
|
|
2620
2942
|
input = input.substring(b);
|
|
2621
2943
|
if (input[0] == ")") {
|
|
2622
2944
|
// )^....<Space>
|
|
2623
|
-
|
|
2624
|
-
c = Number(input.substring(2,
|
|
2625
|
-
input = input.substring(
|
|
2945
|
+
_a3 = input.indexOf(" ");
|
|
2946
|
+
c = Number(input.substring(2, _a3)); // Select contents between )^....<Space>
|
|
2947
|
+
input = input.substring(_a3 + 1); // c points to after <Space>
|
|
2626
2948
|
} else {
|
|
2627
2949
|
c = 1; // There is only spaces, count as <ONE>
|
|
2628
2950
|
}
|
|
@@ -2633,21 +2955,21 @@
|
|
|
2633
2955
|
x.array.splice(1, 0, newOperator(c, 1, expans, megota));
|
|
2634
2956
|
}
|
|
2635
2957
|
} else if (arrows == 2 && expans == 1 && megota == 1) {
|
|
2636
|
-
|
|
2958
|
+
_a3 = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
|
|
2637
2959
|
b = x.array[0].repeat;
|
|
2638
|
-
if (b >= 1e10) ++
|
|
2639
|
-
if (b >= 10) ++
|
|
2640
|
-
x.array[0].repeat =
|
|
2960
|
+
if (b >= 1e10) ++_a3;
|
|
2961
|
+
if (b >= 10) ++_a3;
|
|
2962
|
+
x.array[0].repeat = _a3;
|
|
2641
2963
|
if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
|
|
2642
2964
|
d = x.getOperatorIndex(2);
|
|
2643
2965
|
if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
|
|
2644
2966
|
} else if (isFinite(arrows)) {
|
|
2645
|
-
|
|
2967
|
+
_a3 = x.getOperator(arrows - 1);
|
|
2646
2968
|
b = x.getOperator(arrows - 2);
|
|
2647
|
-
if (b >= 10) ++
|
|
2969
|
+
if (b >= 10) ++_a3;
|
|
2648
2970
|
d = x.getOperatorIndex(arrows);
|
|
2649
2971
|
x.array.splice(1, Math.ceil(d) - 1);
|
|
2650
|
-
x.array[0].repeat =
|
|
2972
|
+
x.array[0].repeat = _a3;
|
|
2651
2973
|
if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
2652
2974
|
} else {
|
|
2653
2975
|
x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
@@ -2656,10 +2978,10 @@
|
|
|
2656
2978
|
break;
|
|
2657
2979
|
}
|
|
2658
2980
|
}
|
|
2659
|
-
|
|
2981
|
+
_a3 = input.split(/[Ee]/);
|
|
2660
2982
|
b = [x.array[0].repeat, 0];
|
|
2661
2983
|
c = 1;
|
|
2662
|
-
for (var
|
|
2984
|
+
for (var i = _a3.length - 1; i >= 0; --i) {
|
|
2663
2985
|
//The things that are already there
|
|
2664
2986
|
if (b[0] < MSI_LOG10 && b[1] === 0) {
|
|
2665
2987
|
b[0] = Math.pow(10, c * b[0]);
|
|
@@ -2676,12 +2998,12 @@
|
|
|
2676
2998
|
b[1]++;
|
|
2677
2999
|
}
|
|
2678
3000
|
//Multiplying coefficient
|
|
2679
|
-
var decimalPointPos =
|
|
2680
|
-
var intPartLen = decimalPointPos == -1 ?
|
|
3001
|
+
var decimalPointPos = _a3[i].indexOf(".");
|
|
3002
|
+
var intPartLen = decimalPointPos == -1 ? _a3[i].length : decimalPointPos;
|
|
2681
3003
|
if (b[1] === 0) {
|
|
2682
|
-
if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(
|
|
3004
|
+
if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(_a3[i].substring(0, intPartLen)), b[1] = 1;else if (_a3[i]) b[0] *= Number(_a3[i]);
|
|
2683
3005
|
} else {
|
|
2684
|
-
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(
|
|
3006
|
+
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(_a3[i].substring(0, intPartLen)) : _a3[i] ? Math.log10(Number(_a3[i])) : 0;
|
|
2685
3007
|
if (b[1] == 1) {
|
|
2686
3008
|
b[0] += d;
|
|
2687
3009
|
} else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
|
|
@@ -2712,6 +3034,17 @@
|
|
|
2712
3034
|
key: "fromObject",
|
|
2713
3035
|
value: function fromObject(powlikeObject) {
|
|
2714
3036
|
var obj = new PowiainaNum();
|
|
3037
|
+
obj.resetFromObject({
|
|
3038
|
+
array: [{
|
|
3039
|
+
arrow: 0,
|
|
3040
|
+
expans: 1,
|
|
3041
|
+
megota: 1,
|
|
3042
|
+
repeat: NaN
|
|
3043
|
+
}],
|
|
3044
|
+
small: false,
|
|
3045
|
+
layer: 0,
|
|
3046
|
+
sign: 0
|
|
3047
|
+
});
|
|
2715
3048
|
obj.array = [];
|
|
2716
3049
|
if (isExpantaNumArray(powlikeObject)) {
|
|
2717
3050
|
for (var i = 0; i < powlikeObject.length; i++) {
|
|
@@ -2729,8 +3062,8 @@
|
|
|
2729
3062
|
} else if (isPowiainaNum01XArray(powlikeObject)) {
|
|
2730
3063
|
var arrayobj = powlikeObject;
|
|
2731
3064
|
obj.array[0] = newOperator(arrayobj[0]);
|
|
2732
|
-
for (var
|
|
2733
|
-
var b = arrayobj[
|
|
3065
|
+
for (var _i4 = 1; _i4 < arrayobj.length; _i4++) {
|
|
3066
|
+
var b = arrayobj[_i4];
|
|
2734
3067
|
obj.array[1] = newOperator(b[1], replaceXToInfinity(b[0]), replaceXToInfinity(b[2]), b[3]);
|
|
2735
3068
|
}
|
|
2736
3069
|
obj.small = false;
|
|
@@ -2738,21 +3071,21 @@
|
|
|
2738
3071
|
obj.layer = 0;
|
|
2739
3072
|
return obj;
|
|
2740
3073
|
} else {
|
|
2741
|
-
|
|
2742
|
-
obj.array[_i4] = {
|
|
2743
|
-
arrow: powlikeObject.array[_i4].arrow,
|
|
2744
|
-
expans: powlikeObject.array[_i4].expans,
|
|
2745
|
-
megota: powlikeObject.array[_i4].megota,
|
|
2746
|
-
repeat: powlikeObject.array[_i4].repeat,
|
|
2747
|
-
valuereplaced: powlikeObject.array[_i4].valuereplaced
|
|
2748
|
-
};
|
|
2749
|
-
}
|
|
2750
|
-
obj.small = powlikeObject.small;
|
|
2751
|
-
obj.sign = powlikeObject.sign;
|
|
2752
|
-
obj.layer = powlikeObject.layer;
|
|
3074
|
+
obj.resetFromObject(powlikeObject);
|
|
2753
3075
|
return obj;
|
|
2754
3076
|
}
|
|
2755
3077
|
}
|
|
3078
|
+
}, {
|
|
3079
|
+
key: "grahalFunction",
|
|
3080
|
+
value: function grahalFunction(layers2) {
|
|
3081
|
+
var layers = new PowiainaNum(layers2);
|
|
3082
|
+
if (!layers.isInt() || layers.lt(0) || layers.isNaN()) return PowiainaNum.NaN.clone();
|
|
3083
|
+
if (layers.eq(1)) return new PowiainaNum("10^^^(10^)^7625597484984 3638334640023.7783");else if (layers.lte(MSI)) {
|
|
3084
|
+
return new PowiainaNum("(10{!})^".concat(layers.toNumber(), " 10^^^(10^)^7625597484984 3638334640023.7783"));
|
|
3085
|
+
} else {
|
|
3086
|
+
return PowiainaNum.BEAF(3, layers, 1, 2);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
2756
3089
|
}]);
|
|
2757
3090
|
}();
|
|
2758
3091
|
_a = Symbol.toStringTag;
|
|
@@ -2969,6 +3302,15 @@
|
|
|
2969
3302
|
PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
|
|
2970
3303
|
//#endregion
|
|
2971
3304
|
PowiainaNum.arrowFuncMap = new Map();
|
|
3305
|
+
//#region configurations
|
|
3306
|
+
/**
|
|
3307
|
+
* If you set this config to true, the `fromString` method will try to parse the string to `PowiainaNum` class with `break_eternity.js` similar `fromString` method, if cannot parse correctly, the program will use `PowiainaNum.js` `fromString` method.
|
|
3308
|
+
*/
|
|
3309
|
+
PowiainaNum.usingBreakEternityLikeFromString = false;
|
|
3310
|
+
/**
|
|
3311
|
+
* If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
|
|
3312
|
+
*/
|
|
3313
|
+
PowiainaNum.blankArgumentConstructorReturnZero = false;
|
|
2972
3314
|
|
|
2973
3315
|
exports.arraySortFunction = arraySortFunction;
|
|
2974
3316
|
exports["default"] = PowiainaNum;
|