powiaina_num.js 0.2.12 → 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 +1 -1
package/dist/PowiainaNum.esm.js
CHANGED
|
@@ -62,6 +62,8 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
62
62
|
|
|
63
63
|
/* Author: VeryrrDefine 0.2.0-beta.1.1*/
|
|
64
64
|
var _a;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region constants
|
|
65
67
|
var powiainaNumError = "[PowiainaNum 0.2 error]";
|
|
66
68
|
var MSI = 9007199254740991;
|
|
67
69
|
var MSI_LOG10 = 15.954589770191003;
|
|
@@ -69,6 +71,8 @@ var MSI_REC = 1.1102230246251568e-16;
|
|
|
69
71
|
var LONG_STRING_MIN_LENGTH = 17;
|
|
70
72
|
var EXP_E_REC = 1.444667861009766;
|
|
71
73
|
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+))$/;
|
|
74
|
+
var BE_REGEX = /^((\d+(\.\d*)?|\d*\.\d+)?([EeFf]([-\+]?)))*(0|\d+(\.\d*)?|\d*\.\d+)$/;
|
|
75
|
+
//#endregion
|
|
72
76
|
//#region some useful functions
|
|
73
77
|
function newOperator(r) {
|
|
74
78
|
var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -82,6 +86,29 @@ function newOperator(r) {
|
|
|
82
86
|
valuereplaced: a == Infinity ? 0 : e == Infinity ? 1 : -1
|
|
83
87
|
};
|
|
84
88
|
}
|
|
89
|
+
function removeCommasOutsideBraces(input) {
|
|
90
|
+
var result = "";
|
|
91
|
+
var inBraces = false;
|
|
92
|
+
for (var i = 0; i < input.length; i++) {
|
|
93
|
+
var _char = input[i];
|
|
94
|
+
if (_char === "{") {
|
|
95
|
+
inBraces = true;
|
|
96
|
+
result += _char;
|
|
97
|
+
} else if (_char === "}") {
|
|
98
|
+
inBraces = false;
|
|
99
|
+
result += _char;
|
|
100
|
+
} else if (_char === ",") {
|
|
101
|
+
// 只有在花括号内部才保留逗号
|
|
102
|
+
if (inBraces) {
|
|
103
|
+
result += _char;
|
|
104
|
+
}
|
|
105
|
+
// 如果在花括号外部,就不添加到结果中(相当于删除)
|
|
106
|
+
} else {
|
|
107
|
+
result += _char;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
85
112
|
// parse 0.1.x PowiainaNum.js string
|
|
86
113
|
function parseLegacyPowiainaNumString(str) {
|
|
87
114
|
var pattern = /l(\d+)\s+s(\d+)\s+a(\[.*\])/;
|
|
@@ -114,7 +141,7 @@ function compareTuples() {
|
|
|
114
141
|
function replaceETo10(str) {
|
|
115
142
|
// 使用正则表达式匹配 (e^数字) 的模式
|
|
116
143
|
// 正则解释:\(e\^(\d+)\) 匹配 (e^数字),其中 \d+ 匹配一个或多个数字
|
|
117
|
-
return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)
|
|
144
|
+
return str.replace(/\(e\^(\d+)\)/g, "(10^)^$1 ").replace(/(\d+)[Pp][Tt]/g, "(10^)^$1 ");
|
|
118
145
|
}
|
|
119
146
|
/**
|
|
120
147
|
* 把一个字符串很长的数进行以10为底的对数
|
|
@@ -168,8 +195,10 @@ var OMEGA = 0.56714329040978387299997; // W(1, 0)
|
|
|
168
195
|
// The evaluation can become inaccurate very close to the branch point
|
|
169
196
|
// Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
|
|
170
197
|
function f_lambertw(z) {
|
|
171
|
-
var
|
|
172
|
-
var
|
|
198
|
+
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
|
|
199
|
+
var pr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
200
|
+
var tol = t;
|
|
201
|
+
var principal = pr;
|
|
173
202
|
var w;
|
|
174
203
|
var wn;
|
|
175
204
|
if (!Number.isFinite(z)) {
|
|
@@ -332,16 +361,26 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
332
361
|
this.small = false;
|
|
333
362
|
this.sign = 0;
|
|
334
363
|
this.layer = 0;
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
364
|
+
if (PowiainaNum.blankArgumentConstructorReturnZero) {
|
|
365
|
+
this.resetFromObject(PowiainaNum.ZERO);
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
if (typeof arg1 == "undefined") {} else if (typeof arg1 == "number") {
|
|
369
|
+
var obj = PowiainaNum.fromNumber(arg1);
|
|
370
|
+
this.resetFromObject(obj);
|
|
371
|
+
} else if (_typeof(arg1) == "object") {
|
|
372
|
+
var _obj = PowiainaNum.fromObject(arg1);
|
|
373
|
+
this.resetFromObject(_obj);
|
|
374
|
+
} else if (typeof arg1 == "string") {
|
|
375
|
+
var _obj2 = PowiainaNum.fromString(arg1);
|
|
376
|
+
this.resetFromObject(_obj2);
|
|
377
|
+
} else {
|
|
378
|
+
var isn = arg1;
|
|
379
|
+
}
|
|
380
|
+
} catch (e) {
|
|
381
|
+
console.error("Malformed input");
|
|
382
|
+
console.error(e);
|
|
383
|
+
}
|
|
345
384
|
}
|
|
346
385
|
//#region 4 Basic calculates.
|
|
347
386
|
/**
|
|
@@ -352,7 +391,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
352
391
|
key: "add",
|
|
353
392
|
value: function add(other) {
|
|
354
393
|
var _b, _c, _d, _e;
|
|
355
|
-
var x = this.clone();
|
|
394
|
+
var x = this.clone().normalize();
|
|
356
395
|
var y = new PowiainaNum(other);
|
|
357
396
|
// inf + -inf = nan
|
|
358
397
|
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();
|
|
@@ -395,40 +434,56 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
395
434
|
if (isFinite(temp) && temp !== 0) {
|
|
396
435
|
return PowiainaNum.fromNumber(temp);
|
|
397
436
|
}
|
|
398
|
-
var
|
|
437
|
+
var signMult = 1;
|
|
438
|
+
/**Calculate numbers [1, 9e15] (useless) */
|
|
399
439
|
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) {
|
|
400
440
|
return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
|
|
401
441
|
}
|
|
442
|
+
// Calculate a & b's 10-logarithm
|
|
402
443
|
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));
|
|
403
444
|
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));
|
|
404
445
|
if (alog10 - blog10 > MSI_LOG10) return a;
|
|
446
|
+
/**
|
|
447
|
+
* Offset, a number can make 10^ a+off calculatable not very small or big
|
|
448
|
+
*/
|
|
405
449
|
var offset = -Math.floor(alog10); //a number can make a+off in [0,1)
|
|
406
|
-
var
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if (
|
|
419
|
-
|
|
450
|
+
var resultLogarithm = 0;
|
|
451
|
+
/** 10^(a+off) + 10^(b+off). */
|
|
452
|
+
var offsetedResult = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
|
|
453
|
+
if (offsetedResult > 0) resultLogarithm = Math.log10(offsetedResult) - offset;
|
|
454
|
+
if (offsetedResult < 0) {
|
|
455
|
+
resultLogarithm = Math.log10(-offsetedResult) - offset;
|
|
456
|
+
signMult *= -1;
|
|
457
|
+
}
|
|
458
|
+
if (offsetedResult == 0) return PowiainaNum.ZERO.clone();
|
|
459
|
+
var resultPN = PowiainaNum.NaN.clone();
|
|
460
|
+
resultPN.sign = 1;
|
|
461
|
+
/** abs(resultLogarithm) > 15.9, use 10^x form. */
|
|
462
|
+
if (resultLogarithm > MSI_LOG10 || resultLogarithm < -MSI_LOG10) {
|
|
463
|
+
resultPN.array = [newOperator(resultLogarithm, 0), newOperator(1, 1)];
|
|
464
|
+
/**otherwise, use 10** abs(resultLogarithm) */
|
|
420
465
|
} else {
|
|
421
|
-
|
|
466
|
+
resultPN.array = [newOperator(Math.pow(10, Math.abs(resultLogarithm)), 0)];
|
|
422
467
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return
|
|
468
|
+
resultPN.small = resultLogarithm < 0 ? true : false;
|
|
469
|
+
resultPN.sign *= signMult;
|
|
470
|
+
return resultPN;
|
|
471
|
+
}
|
|
472
|
+
}, {
|
|
473
|
+
key: "plus",
|
|
474
|
+
value: function plus(other) {
|
|
475
|
+
return this.add(other);
|
|
426
476
|
}
|
|
427
477
|
}, {
|
|
428
478
|
key: "sub",
|
|
429
479
|
value: function sub(a) {
|
|
430
480
|
return this.add(new PowiainaNum(a).neg());
|
|
431
481
|
}
|
|
482
|
+
}, {
|
|
483
|
+
key: "minus",
|
|
484
|
+
value: function minus(other) {
|
|
485
|
+
return this.sub(other);
|
|
486
|
+
}
|
|
432
487
|
}, {
|
|
433
488
|
key: "mul",
|
|
434
489
|
value: function mul(other) {
|
|
@@ -462,12 +517,22 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
462
517
|
r.sign = x.sign * y.sign;
|
|
463
518
|
return r;
|
|
464
519
|
}
|
|
520
|
+
}, {
|
|
521
|
+
key: "times",
|
|
522
|
+
value: function times(other) {
|
|
523
|
+
return this.mul(other);
|
|
524
|
+
}
|
|
465
525
|
}, {
|
|
466
526
|
key: "div",
|
|
467
527
|
value: function div(other) {
|
|
468
528
|
var x = new PowiainaNum(other).rec();
|
|
469
529
|
return this.mul(x);
|
|
470
530
|
}
|
|
531
|
+
}, {
|
|
532
|
+
key: "divide",
|
|
533
|
+
value: function divide(other) {
|
|
534
|
+
return this.div(other);
|
|
535
|
+
}
|
|
471
536
|
}, {
|
|
472
537
|
key: "mod",
|
|
473
538
|
value: function mod(x) {
|
|
@@ -475,34 +540,45 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
475
540
|
var division = this.div(other);
|
|
476
541
|
return division.sub(division.floor()).mul(other);
|
|
477
542
|
}
|
|
543
|
+
}, {
|
|
544
|
+
key: "modulus",
|
|
545
|
+
value: function modulus(x) {
|
|
546
|
+
return this.mod(x);
|
|
547
|
+
}
|
|
548
|
+
}, {
|
|
549
|
+
key: "pow10",
|
|
550
|
+
value:
|
|
478
551
|
//#endregion
|
|
479
552
|
//#region power
|
|
480
553
|
/**
|
|
481
554
|
* @returns 10 to the power of `this`
|
|
482
555
|
*/
|
|
483
|
-
|
|
484
|
-
key: "pow10",
|
|
485
|
-
value: function pow10() {
|
|
556
|
+
function pow10() {
|
|
486
557
|
var _b, _c;
|
|
487
|
-
var
|
|
558
|
+
var thisObject = this.clone();
|
|
488
559
|
// inf & nan check
|
|
489
560
|
if (!this.isFinite()) return this.clone();
|
|
490
|
-
|
|
561
|
+
/** when 10^(t), t<0, use 10^(-t) reciprocate. */
|
|
562
|
+
if (thisObject.isneg()) {
|
|
491
563
|
// 10^(-x) = 1/(10^x)
|
|
492
|
-
|
|
493
|
-
return
|
|
564
|
+
thisObject.sign *= -1;
|
|
565
|
+
return thisObject.pow10().rec();
|
|
494
566
|
}
|
|
495
|
-
if
|
|
496
|
-
|
|
567
|
+
/**if t lessthan log10 2^1024, use fromNumber. */
|
|
568
|
+
if (thisObject.lte(308.25471555991675)) {
|
|
569
|
+
return PowiainaNum.fromNumber(Math.pow(10, thisObject.toNumber()));
|
|
497
570
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
571
|
+
/**calculate directly */
|
|
572
|
+
if (thisObject.small) {
|
|
573
|
+
if (thisObject.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
|
|
574
|
+
return new PowiainaNum(Math.pow(10, Math.pow(thisObject.array[0].repeat, -1)));
|
|
501
575
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
576
|
+
/** indistinguishable above 10^^9e15 */
|
|
577
|
+
if (thisObject.gt(PowiainaNum.TETRATED_MSI)) return thisObject;
|
|
578
|
+
/**otherwise add 10^ directly */
|
|
579
|
+
thisObject.setOperator(((_c = (_b = thisObject.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
|
|
580
|
+
thisObject.normalize();
|
|
581
|
+
return thisObject;
|
|
506
582
|
}
|
|
507
583
|
}, {
|
|
508
584
|
key: "pow",
|
|
@@ -512,8 +588,16 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
512
588
|
if (!other.isFinite()) return other.clone();
|
|
513
589
|
if (!this.isFinite()) return this.clone();
|
|
514
590
|
if (this.eq(10)) return other.pow10();
|
|
591
|
+
if (other.isneg()) return this.pow(other.neg()).rec();
|
|
515
592
|
if (this.isneg()) {
|
|
516
|
-
if (!other.isInt())
|
|
593
|
+
if (!other.isInt()) {
|
|
594
|
+
if (other.small) {
|
|
595
|
+
if (other.rec().div(2).eq(1)) {
|
|
596
|
+
return this.neg().pow(other).neg();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return PowiainaNum.NaN.clone();
|
|
600
|
+
}
|
|
517
601
|
var r = this.abs().pow(other);
|
|
518
602
|
r.sign = function () {
|
|
519
603
|
var a = other.mod(2).round();
|
|
@@ -590,6 +674,16 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
590
674
|
var other = new PowiainaNum(base);
|
|
591
675
|
return this.log10().div(other.log10());
|
|
592
676
|
}
|
|
677
|
+
}, {
|
|
678
|
+
key: "log2",
|
|
679
|
+
value: function log2() {
|
|
680
|
+
return this.log(2);
|
|
681
|
+
}
|
|
682
|
+
}, {
|
|
683
|
+
key: "logBase",
|
|
684
|
+
value: function logBase(a) {
|
|
685
|
+
return this.log(a);
|
|
686
|
+
}
|
|
593
687
|
}, {
|
|
594
688
|
key: "ln",
|
|
595
689
|
value: function ln() {
|
|
@@ -697,7 +791,8 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
697
791
|
//Code from break_eternity.js
|
|
698
792
|
//Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
|
|
699
793
|
function lambertw() {
|
|
700
|
-
var
|
|
794
|
+
var princ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
795
|
+
var principal = princ;
|
|
701
796
|
if (this.lt(-0.3678794411710499)) {
|
|
702
797
|
return PowiainaNum.NaN.clone(); //complex
|
|
703
798
|
} else if (principal) {
|
|
@@ -712,12 +807,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
712
807
|
return this.log();
|
|
713
808
|
}
|
|
714
809
|
} else {
|
|
715
|
-
if (this.sign === 1) {
|
|
810
|
+
if (this.sign === -1) {
|
|
716
811
|
return PowiainaNum.NaN.clone(); //complex
|
|
717
812
|
}
|
|
718
|
-
if (this.
|
|
813
|
+
if (this.lt(9e15)) {
|
|
719
814
|
return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
|
|
720
|
-
} else if (this.
|
|
815
|
+
} else if (this.lt(PowiainaNum.E_MSI)) {
|
|
721
816
|
return d_lambertw(this, 1e-10, false);
|
|
722
817
|
} else {
|
|
723
818
|
return this.neg().rec().lambertw().neg();
|
|
@@ -738,7 +833,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
738
833
|
var payl = new PowiainaNum(payload);
|
|
739
834
|
if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
|
|
740
835
|
if (t.eq(1)) return PowiainaNum.ONE.clone();
|
|
741
|
-
if (payl.neq(PowiainaNum.ONE)
|
|
836
|
+
if (payl.neq(PowiainaNum.ONE) && t.gte(EXP_E_REC)) {
|
|
837
|
+
other = other.add(payl.slog(t));
|
|
838
|
+
}
|
|
742
839
|
var negln;
|
|
743
840
|
if (other.isInfi() && other.sign > 0) {
|
|
744
841
|
if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
@@ -1068,9 +1165,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1068
1165
|
// base^base^... = x? (? bases)
|
|
1069
1166
|
var r = 0;
|
|
1070
1167
|
// 计算x与base的差距
|
|
1071
|
-
var
|
|
1072
|
-
if (
|
|
1073
|
-
var l =
|
|
1168
|
+
var distanceLayerOf = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
|
|
1169
|
+
if (distanceLayerOf > 3) {
|
|
1170
|
+
var l = distanceLayerOf - 3;
|
|
1074
1171
|
r += l;
|
|
1075
1172
|
x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
|
|
1076
1173
|
}
|
|
@@ -1112,18 +1209,18 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1112
1209
|
}
|
|
1113
1210
|
}, {
|
|
1114
1211
|
key: "pentate",
|
|
1115
|
-
value: function pentate(other) {
|
|
1116
|
-
return this.arrow(3)(other);
|
|
1212
|
+
value: function pentate(other, payload) {
|
|
1213
|
+
return this.arrow(3)(other, payload);
|
|
1117
1214
|
}
|
|
1118
1215
|
}, {
|
|
1119
1216
|
key: "hexate",
|
|
1120
|
-
value: function hexate(other) {
|
|
1121
|
-
return this.arrow(4)(other);
|
|
1217
|
+
value: function hexate(other, payload) {
|
|
1218
|
+
return this.arrow(4)(other, payload);
|
|
1122
1219
|
}
|
|
1123
1220
|
}, {
|
|
1124
1221
|
key: "pent",
|
|
1125
|
-
value: function pent(other) {
|
|
1126
|
-
return this.arrow(3)(other);
|
|
1222
|
+
value: function pent(other, payload) {
|
|
1223
|
+
return this.arrow(3)(other, payload);
|
|
1127
1224
|
}
|
|
1128
1225
|
}, {
|
|
1129
1226
|
key: "penta_log",
|
|
@@ -1131,6 +1228,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1131
1228
|
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1132
1229
|
return this.anyarrow_log(3)(base);
|
|
1133
1230
|
}
|
|
1231
|
+
}, {
|
|
1232
|
+
key: "expansion",
|
|
1233
|
+
value:
|
|
1134
1234
|
/**
|
|
1135
1235
|
* Expansion, which is `this`{{1}}`other2`.
|
|
1136
1236
|
*
|
|
@@ -1138,9 +1238,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1138
1238
|
*
|
|
1139
1239
|
* @url https://googology.fandom.com/wiki/Expansion
|
|
1140
1240
|
*/
|
|
1141
|
-
|
|
1142
|
-
key: "expansion",
|
|
1143
|
-
value: function expansion(other2) {
|
|
1241
|
+
function expansion(other2) {
|
|
1144
1242
|
var other = new PowiainaNum(other2);
|
|
1145
1243
|
var t = this.clone();
|
|
1146
1244
|
if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
|
|
@@ -1388,6 +1486,11 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1388
1486
|
var other = new PowiainaNum(x).abs();
|
|
1389
1487
|
return this.abs().cmp(other);
|
|
1390
1488
|
}
|
|
1489
|
+
/**
|
|
1490
|
+
* -1: `this` is smaller
|
|
1491
|
+
* 0: equals
|
|
1492
|
+
* 1: `x` is bigger
|
|
1493
|
+
*/
|
|
1391
1494
|
}, {
|
|
1392
1495
|
key: "compare",
|
|
1393
1496
|
value: function compare(x) {
|
|
@@ -1406,6 +1509,14 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1406
1509
|
for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
|
|
1407
1510
|
var op1 = this.array[this.array.length - 1 - i];
|
|
1408
1511
|
var op2 = other.array[other.array.length - 1 - i];
|
|
1512
|
+
if (op1.repeat === Infinity) {
|
|
1513
|
+
result = 1;
|
|
1514
|
+
break;
|
|
1515
|
+
}
|
|
1516
|
+
if (op2.repeat === Infinity) {
|
|
1517
|
+
result = -1;
|
|
1518
|
+
break;
|
|
1519
|
+
}
|
|
1409
1520
|
var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
|
|
1410
1521
|
if (cmp == 1) {
|
|
1411
1522
|
result = 1;
|
|
@@ -1453,6 +1564,16 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1453
1564
|
var t = this.cmp(other);
|
|
1454
1565
|
return t == 0 || t == 1;
|
|
1455
1566
|
}
|
|
1567
|
+
}, {
|
|
1568
|
+
key: "equals",
|
|
1569
|
+
value: function equals(other) {
|
|
1570
|
+
return this.eq(other);
|
|
1571
|
+
}
|
|
1572
|
+
}, {
|
|
1573
|
+
key: "notEquals",
|
|
1574
|
+
value: function notEquals(other) {
|
|
1575
|
+
return this.neq(other);
|
|
1576
|
+
}
|
|
1456
1577
|
}, {
|
|
1457
1578
|
key: "eq_tolerance",
|
|
1458
1579
|
value: function eq_tolerance(value) {
|
|
@@ -1462,6 +1583,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1462
1583
|
}
|
|
1463
1584
|
//#endregion
|
|
1464
1585
|
//#region geometry
|
|
1586
|
+
/**this function is indistinguishable above 4503599627370496*/
|
|
1465
1587
|
}, {
|
|
1466
1588
|
key: "sin",
|
|
1467
1589
|
value: function sin() {
|
|
@@ -1514,6 +1636,16 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1514
1636
|
a.small = !a.small;
|
|
1515
1637
|
return a;
|
|
1516
1638
|
}
|
|
1639
|
+
}, {
|
|
1640
|
+
key: "recip",
|
|
1641
|
+
value: function recip() {
|
|
1642
|
+
return this.rec();
|
|
1643
|
+
}
|
|
1644
|
+
}, {
|
|
1645
|
+
key: "reciprocate",
|
|
1646
|
+
value: function reciprocate() {
|
|
1647
|
+
return this.rec();
|
|
1648
|
+
}
|
|
1517
1649
|
}, {
|
|
1518
1650
|
key: "floor",
|
|
1519
1651
|
value: function floor() {
|
|
@@ -1554,6 +1686,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1554
1686
|
r.sign = this.sign;
|
|
1555
1687
|
return r;
|
|
1556
1688
|
}
|
|
1689
|
+
}, {
|
|
1690
|
+
key: "trunc",
|
|
1691
|
+
value:
|
|
1557
1692
|
/**
|
|
1558
1693
|
* Work like `Math.trunc`,
|
|
1559
1694
|
*
|
|
@@ -1566,15 +1701,10 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1566
1701
|
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
1567
1702
|
* @returns
|
|
1568
1703
|
*/
|
|
1569
|
-
|
|
1570
|
-
key: "trunc",
|
|
1571
|
-
value: function trunc() {
|
|
1704
|
+
function trunc() {
|
|
1572
1705
|
var y = this.clone();
|
|
1573
1706
|
return y.gte(0) ? y.floor() : y.ceil();
|
|
1574
1707
|
}
|
|
1575
|
-
/**
|
|
1576
|
-
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
1577
|
-
*/
|
|
1578
1708
|
}, {
|
|
1579
1709
|
key: "isNaN",
|
|
1580
1710
|
value: function (_isNaN) {
|
|
@@ -1637,10 +1767,164 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1637
1767
|
value: function isneg() {
|
|
1638
1768
|
return this.sign < 0;
|
|
1639
1769
|
}
|
|
1770
|
+
}, {
|
|
1771
|
+
key: "getOperatorIndex",
|
|
1772
|
+
value:
|
|
1773
|
+
//#endregion
|
|
1774
|
+
//#region operators
|
|
1775
|
+
/**
|
|
1776
|
+
* @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.
|
|
1777
|
+
*/
|
|
1778
|
+
function getOperatorIndex(arrow) {
|
|
1779
|
+
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1780
|
+
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1781
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1782
|
+
var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
|
|
1783
|
+
if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
|
|
1784
|
+
if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
|
|
1785
|
+
}
|
|
1786
|
+
return this.array.length - 0.5;
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* @returns number repeats of operators with given arguments.
|
|
1790
|
+
*/
|
|
1791
|
+
}, {
|
|
1792
|
+
key: "getOperator",
|
|
1793
|
+
value: function getOperator(arrow) {
|
|
1794
|
+
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1795
|
+
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1796
|
+
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1797
|
+
if (!this.array[index]) return 0;
|
|
1798
|
+
return this.array[index].repeat;
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* Modify the repeat of operator
|
|
1802
|
+
* @param number val the repeat of operator will modify to array.
|
|
1803
|
+
* @returns bool Is the operators array changed?
|
|
1804
|
+
*/
|
|
1805
|
+
}, {
|
|
1806
|
+
key: "setOperator",
|
|
1807
|
+
value: function setOperator(val, arrow) {
|
|
1808
|
+
var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1809
|
+
var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
1810
|
+
// if (arrow!=0&&val==0) return false;
|
|
1811
|
+
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1812
|
+
if (!this.array[index]) {
|
|
1813
|
+
this.array.splice(Math.ceil(index), 0, {
|
|
1814
|
+
arrow: arrow,
|
|
1815
|
+
expans: expans,
|
|
1816
|
+
megota: megota,
|
|
1817
|
+
valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
|
|
1818
|
+
repeat: val
|
|
1819
|
+
});
|
|
1820
|
+
return true;
|
|
1821
|
+
}
|
|
1822
|
+
this.array[index].repeat = val;
|
|
1823
|
+
// this.normalize()
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
//#endregion
|
|
1827
|
+
//#region converters
|
|
1828
|
+
/**
|
|
1829
|
+
* Convert `this` to Javascript `number`
|
|
1830
|
+
*
|
|
1831
|
+
* returns `Infinity` when the number is greater than `Number.MAX_VALUE`
|
|
1832
|
+
*/
|
|
1833
|
+
}, {
|
|
1834
|
+
key: "toNumber",
|
|
1835
|
+
value: function toNumber() {
|
|
1836
|
+
if (this.sign == -1) return -this.neg().toNumber();
|
|
1837
|
+
if (this.small) return 1 / this.rec().toNumber();
|
|
1838
|
+
if (this.array.length > 2) return Infinity;
|
|
1839
|
+
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));
|
|
1840
|
+
return NaN;
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Convert `this` to a string
|
|
1844
|
+
*/
|
|
1845
|
+
}, {
|
|
1846
|
+
key: "toString_core",
|
|
1847
|
+
value: function toString_core() {
|
|
1848
|
+
if (this.isNaN()) return "NaN";
|
|
1849
|
+
if (this.sign == -1) return "-".concat(this.neg().toString());
|
|
1850
|
+
if (this.small) {
|
|
1851
|
+
if (this.isZero()) return "0";
|
|
1852
|
+
return "/".concat(this.rec().toString());
|
|
1853
|
+
}
|
|
1854
|
+
if (this.isInfi()) return "Infinity";
|
|
1855
|
+
// P^a (10{arrow,expans,megota})^repeation base
|
|
1856
|
+
var res = "";
|
|
1857
|
+
if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
|
|
1858
|
+
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
1859
|
+
var oper = this.array[i];
|
|
1860
|
+
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) : "", "}");
|
|
1861
|
+
if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
|
|
1862
|
+
calc = "e".repeat(oper.repeat);
|
|
1863
|
+
} else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
|
|
1864
|
+
calc = oper.repeat.toString();
|
|
1865
|
+
} else if (oper.repeat > 1) {
|
|
1866
|
+
calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
|
|
1867
|
+
} else {
|
|
1868
|
+
calc = "".concat(calc);
|
|
1869
|
+
}
|
|
1870
|
+
res += "".concat(calc);
|
|
1871
|
+
}
|
|
1872
|
+
return res;
|
|
1873
|
+
}
|
|
1874
|
+
}, {
|
|
1875
|
+
key: "toString",
|
|
1876
|
+
value: function toString() {
|
|
1877
|
+
try {
|
|
1878
|
+
return this.toString_core();
|
|
1879
|
+
} catch (_b) {
|
|
1880
|
+
console.error("Checked error when converting to string");
|
|
1881
|
+
return "NaN";
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}, {
|
|
1885
|
+
key: "toJSON",
|
|
1886
|
+
value:
|
|
1887
|
+
/**
|
|
1888
|
+
* Convert `this` to a JSON object
|
|
1889
|
+
* @returns a JSON object
|
|
1890
|
+
*/
|
|
1891
|
+
function toJSON() {
|
|
1892
|
+
return "PN" + this.toString();
|
|
1893
|
+
}
|
|
1894
|
+
}, {
|
|
1895
|
+
key: "arr01",
|
|
1896
|
+
get:
|
|
1897
|
+
/**
|
|
1898
|
+
* A property array value for version 0.1.x PowiainaNum.
|
|
1899
|
+
*/
|
|
1900
|
+
function get() {
|
|
1901
|
+
var res = [0];
|
|
1902
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1903
|
+
if (i == 0) res[0] = this.array[i].repeat;else {
|
|
1904
|
+
// @ts-ignore
|
|
1905
|
+
res[i] = [0, 0, 0, 0];
|
|
1906
|
+
// @ts-ignore
|
|
1907
|
+
res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
|
|
1908
|
+
// @ts-ignore
|
|
1909
|
+
res[i][1] = this.array[i].repeat;
|
|
1910
|
+
// @ts-ignore
|
|
1911
|
+
res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
|
|
1912
|
+
// @ts-ignore
|
|
1913
|
+
res[i][3] = this.array[i].megota;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return res;
|
|
1917
|
+
}
|
|
1918
|
+
//#endregion
|
|
1919
|
+
//#region useless functions
|
|
1920
|
+
/**
|
|
1921
|
+
* This function is for NaNe308, if you want to calculate G(x), use this function directly.
|
|
1922
|
+
*/
|
|
1640
1923
|
}, {
|
|
1641
1924
|
key: "normalize",
|
|
1642
1925
|
value:
|
|
1643
1926
|
//#endregion
|
|
1927
|
+
//#region other functions
|
|
1644
1928
|
/**
|
|
1645
1929
|
* Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
|
|
1646
1930
|
* @returns normalized number
|
|
@@ -1649,9 +1933,14 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1649
1933
|
//TODO: normalize
|
|
1650
1934
|
var renormalize = true;
|
|
1651
1935
|
var x = this;
|
|
1652
|
-
|
|
1936
|
+
if (this.array === undefined) {
|
|
1937
|
+
x.array = [newOperator(NaN, 0, 1, 1)];
|
|
1938
|
+
}
|
|
1939
|
+
if (this.sign === undefined) this.sign = 0;
|
|
1940
|
+
if (this.layer === undefined) this.layer = 0;
|
|
1941
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1653
1942
|
// Check what is infinity
|
|
1654
|
-
if (this.array[
|
|
1943
|
+
if (this.array[i].repeat == Infinity) {
|
|
1655
1944
|
this.array = [{
|
|
1656
1945
|
arrow: 0,
|
|
1657
1946
|
expans: 1,
|
|
@@ -1662,8 +1951,8 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1662
1951
|
return this;
|
|
1663
1952
|
}
|
|
1664
1953
|
}
|
|
1665
|
-
for (var
|
|
1666
|
-
var e = x.array[
|
|
1954
|
+
for (var _i = 1; _i < x.array.length; ++_i) {
|
|
1955
|
+
var e = x.array[_i];
|
|
1667
1956
|
if (e.arrow === null || e.arrow === undefined) {
|
|
1668
1957
|
e.arrow = 0;
|
|
1669
1958
|
}
|
|
@@ -1694,28 +1983,28 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1694
1983
|
renormalize = false;
|
|
1695
1984
|
// Sort arrays.
|
|
1696
1985
|
this.array.sort(arraySortFunction);
|
|
1697
|
-
for (
|
|
1698
|
-
if (x.array[
|
|
1986
|
+
for (var _i2 = 1; _i2 < x.array.length - 1; ++_i2) {
|
|
1987
|
+
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) {
|
|
1699
1988
|
// same array's merge
|
|
1700
|
-
x.array[
|
|
1701
|
-
x.array.splice(
|
|
1702
|
-
--
|
|
1989
|
+
x.array[_i2].repeat += x.array[_i2 + 1].repeat;
|
|
1990
|
+
x.array.splice(_i2 + 1, 1);
|
|
1991
|
+
--_i2;
|
|
1703
1992
|
renormalize = true;
|
|
1704
1993
|
}
|
|
1705
1994
|
}
|
|
1706
|
-
for (
|
|
1995
|
+
for (var _i3 = 1; _i3 < x.array.length; ++_i3) {
|
|
1707
1996
|
// If there is a 0 repeat operator, remove it.
|
|
1708
|
-
if (x.array[
|
|
1709
|
-
x.array.splice(
|
|
1710
|
-
--
|
|
1997
|
+
if (x.array[_i3].arrow !== 0 && (x.array[_i3].repeat === 0 || x.array[_i3].repeat === null || x.array[_i3].repeat === undefined)) {
|
|
1998
|
+
x.array.splice(_i3, 1);
|
|
1999
|
+
--_i3;
|
|
1711
2000
|
continue;
|
|
1712
2001
|
}
|
|
1713
2002
|
// If there is a operator which arrow 0 and brace count >=2
|
|
1714
2003
|
// replace it as arrow replacement operaotr
|
|
1715
|
-
if (x.array[
|
|
1716
|
-
x.array[
|
|
1717
|
-
x.array[
|
|
1718
|
-
x.array[
|
|
2004
|
+
if (x.array[_i3].arrow == 0 && x.array[_i3].expans >= 2) {
|
|
2005
|
+
x.array[_i3].arrow = Infinity;
|
|
2006
|
+
x.array[_i3].valuereplaced = 0;
|
|
2007
|
+
x.array[_i3].expans = x.array[_i3].expans - 1;
|
|
1719
2008
|
}
|
|
1720
2009
|
}
|
|
1721
2010
|
if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
|
|
@@ -1745,6 +2034,11 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1745
2034
|
this.small = !this.small;
|
|
1746
2035
|
renormalize = true;
|
|
1747
2036
|
}
|
|
2037
|
+
// for a = 1, small should false.
|
|
2038
|
+
if (this.array.length == 1 && this.array[0].repeat == 1 && this.small) {
|
|
2039
|
+
this.small = false;
|
|
2040
|
+
renormalize = true;
|
|
2041
|
+
}
|
|
1748
2042
|
// for any 10{X>9e15}10, replace into 10{!}X;
|
|
1749
2043
|
if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
|
|
1750
2044
|
this.array[0].repeat = this.array[1].arrow;
|
|
@@ -1800,61 +2094,6 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1800
2094
|
} while (renormalize);
|
|
1801
2095
|
return this;
|
|
1802
2096
|
}
|
|
1803
|
-
//#region operators
|
|
1804
|
-
/**
|
|
1805
|
-
* @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.
|
|
1806
|
-
*/
|
|
1807
|
-
}, {
|
|
1808
|
-
key: "getOperatorIndex",
|
|
1809
|
-
value: function getOperatorIndex(arrow) {
|
|
1810
|
-
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1811
|
-
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1812
|
-
for (var i = 0; i < this.array.length; i++) {
|
|
1813
|
-
var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
|
|
1814
|
-
if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
|
|
1815
|
-
if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
|
|
1816
|
-
}
|
|
1817
|
-
return this.array.length - 0.5;
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* @returns number repeats of operators with given arguments.
|
|
1821
|
-
*/
|
|
1822
|
-
}, {
|
|
1823
|
-
key: "getOperator",
|
|
1824
|
-
value: function getOperator(arrow) {
|
|
1825
|
-
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1826
|
-
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1827
|
-
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1828
|
-
if (!this.array[index]) return 0;
|
|
1829
|
-
return this.array[index].repeat;
|
|
1830
|
-
}
|
|
1831
|
-
/**
|
|
1832
|
-
* Modify the repeat of operator
|
|
1833
|
-
* @param number val the repeat of operator will modify to array.
|
|
1834
|
-
* @returns bool Is the operators array changed?
|
|
1835
|
-
*/
|
|
1836
|
-
}, {
|
|
1837
|
-
key: "setOperator",
|
|
1838
|
-
value: function setOperator(val, arrow) {
|
|
1839
|
-
var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1840
|
-
var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
1841
|
-
// if (arrow!=0&&val==0) return false;
|
|
1842
|
-
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1843
|
-
if (!this.array[index]) {
|
|
1844
|
-
this.array.splice(Math.ceil(index), 0, {
|
|
1845
|
-
arrow: arrow,
|
|
1846
|
-
expans: expans,
|
|
1847
|
-
megota: megota,
|
|
1848
|
-
valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
|
|
1849
|
-
repeat: val
|
|
1850
|
-
});
|
|
1851
|
-
return true;
|
|
1852
|
-
}
|
|
1853
|
-
this.array[index].repeat = val;
|
|
1854
|
-
// this.normalize()
|
|
1855
|
-
return false;
|
|
1856
|
-
}
|
|
1857
|
-
//#endregion
|
|
1858
2097
|
/**
|
|
1859
2098
|
* @returns a PowiainaNum object which deep copied from `this` object.
|
|
1860
2099
|
*/
|
|
@@ -1873,6 +2112,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1873
2112
|
}, {
|
|
1874
2113
|
key: "resetFromObject",
|
|
1875
2114
|
value: function resetFromObject(powlikeObject) {
|
|
2115
|
+
if (!powlikeObject.array) {
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
1876
2118
|
this.array = [];
|
|
1877
2119
|
for (var i = 0; i < powlikeObject.array.length; i++) {
|
|
1878
2120
|
this.array[i] = {
|
|
@@ -1888,107 +2130,56 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1888
2130
|
this.layer = powlikeObject.layer;
|
|
1889
2131
|
return this;
|
|
1890
2132
|
}
|
|
1891
|
-
//#region converters
|
|
1892
|
-
/**
|
|
1893
|
-
* Convert `this` to Javascript `number`
|
|
1894
|
-
*
|
|
1895
|
-
* returns `Infinity` when the number is greater than `Number.MAX_VALUE`
|
|
1896
|
-
*/
|
|
1897
|
-
}, {
|
|
1898
|
-
key: "toNumber",
|
|
1899
|
-
value: function toNumber() {
|
|
1900
|
-
if (this.sign == -1) return -this.neg().toNumber();
|
|
1901
|
-
if (this.small) return 1 / this.rec().toNumber();
|
|
1902
|
-
if (this.array.length > 2) return Infinity;
|
|
1903
|
-
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));
|
|
1904
|
-
return NaN;
|
|
1905
|
-
}
|
|
1906
|
-
/**
|
|
1907
|
-
* Convert `this` to a string
|
|
1908
|
-
*/
|
|
1909
|
-
}, {
|
|
1910
|
-
key: "toString",
|
|
1911
|
-
value: function toString() {
|
|
1912
|
-
if (this.isNaN()) return "NaN";
|
|
1913
|
-
if (this.sign == -1) return "-".concat(this.neg().toString());
|
|
1914
|
-
if (this.small) {
|
|
1915
|
-
if (this.isZero()) return "0";
|
|
1916
|
-
return "/".concat(this.rec().toString());
|
|
1917
|
-
}
|
|
1918
|
-
if (this.isInfi()) return "Infinity";
|
|
1919
|
-
// P^a (10{arrow,expans,megota})^repeation base
|
|
1920
|
-
var res = "";
|
|
1921
|
-
if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
|
|
1922
|
-
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
1923
|
-
var oper = this.array[i];
|
|
1924
|
-
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) : "", "}");
|
|
1925
|
-
if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
|
|
1926
|
-
calc = "e".repeat(oper.repeat);
|
|
1927
|
-
} else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
|
|
1928
|
-
calc = oper.repeat.toString();
|
|
1929
|
-
} else if (oper.repeat > 1) {
|
|
1930
|
-
calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
|
|
1931
|
-
} else {
|
|
1932
|
-
calc = "".concat(calc);
|
|
1933
|
-
}
|
|
1934
|
-
res += "".concat(calc);
|
|
1935
|
-
}
|
|
1936
|
-
return res;
|
|
1937
|
-
}
|
|
1938
|
-
}, {
|
|
1939
|
-
key: "toJSON",
|
|
1940
|
-
value:
|
|
1941
|
-
/**
|
|
1942
|
-
* Convert `this` to a JSON object
|
|
1943
|
-
* @returns a JSON object
|
|
1944
|
-
*/
|
|
1945
|
-
function toJSON() {
|
|
1946
|
-
return "PN" + this.toString();
|
|
1947
|
-
}
|
|
1948
|
-
}, {
|
|
1949
|
-
key: "arr01",
|
|
1950
|
-
get:
|
|
1951
|
-
/**
|
|
1952
|
-
* A property array value for version 0.1.x PowiainaNum.
|
|
1953
|
-
*/
|
|
1954
|
-
function get() {
|
|
1955
|
-
var res = [0];
|
|
1956
|
-
for (var i = 0; i < this.array.length; i++) {
|
|
1957
|
-
if (i == 0) res[0] = this.array[i].repeat;else {
|
|
1958
|
-
// @ts-ignore
|
|
1959
|
-
res[i] = [0, 0, 0, 0];
|
|
1960
|
-
// @ts-ignore
|
|
1961
|
-
res[i][0] = this.array[i].arrow == Infinity ? "x" : this.array[i].arrow;
|
|
1962
|
-
// @ts-ignore
|
|
1963
|
-
res[i][1] = this.array[i].repeat;
|
|
1964
|
-
// @ts-ignore
|
|
1965
|
-
res[i][2] = this.array[i].expans == Infinity ? "x" : this.array[i].expans;
|
|
1966
|
-
// @ts-ignore
|
|
1967
|
-
res[i][3] = this.array[i].megota;
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
return res;
|
|
1971
|
-
}
|
|
1972
2133
|
}], [{
|
|
1973
2134
|
key: "add",
|
|
1974
2135
|
value: function add(t, other) {
|
|
1975
2136
|
return new PowiainaNum(t).add(other);
|
|
1976
2137
|
}
|
|
2138
|
+
}, {
|
|
2139
|
+
key: "plus",
|
|
2140
|
+
value: function plus(t, other) {
|
|
2141
|
+
return new PowiainaNum(t).add(other);
|
|
2142
|
+
}
|
|
1977
2143
|
}, {
|
|
1978
2144
|
key: "sub",
|
|
1979
2145
|
value: function sub(t, other) {
|
|
1980
2146
|
return new PowiainaNum(t).sub(other);
|
|
1981
2147
|
}
|
|
2148
|
+
}, {
|
|
2149
|
+
key: "minus",
|
|
2150
|
+
value: function minus(t, other) {
|
|
2151
|
+
return new PowiainaNum(t).sub(other);
|
|
2152
|
+
}
|
|
1982
2153
|
}, {
|
|
1983
2154
|
key: "mul",
|
|
1984
2155
|
value: function mul(t, other) {
|
|
1985
2156
|
return new PowiainaNum(t).mul(other);
|
|
1986
2157
|
}
|
|
2158
|
+
}, {
|
|
2159
|
+
key: "times",
|
|
2160
|
+
value: function times(t, other) {
|
|
2161
|
+
return new PowiainaNum(t).mul(other);
|
|
2162
|
+
}
|
|
1987
2163
|
}, {
|
|
1988
2164
|
key: "div",
|
|
1989
2165
|
value: function div(t, other) {
|
|
1990
2166
|
return new PowiainaNum(t).div(other);
|
|
1991
2167
|
}
|
|
2168
|
+
}, {
|
|
2169
|
+
key: "divide",
|
|
2170
|
+
value: function divide(t, other) {
|
|
2171
|
+
return new PowiainaNum(t).div(other);
|
|
2172
|
+
}
|
|
2173
|
+
}, {
|
|
2174
|
+
key: "mod",
|
|
2175
|
+
value: function mod(x, y) {
|
|
2176
|
+
return new PowiainaNum(x).mod(y);
|
|
2177
|
+
}
|
|
2178
|
+
}, {
|
|
2179
|
+
key: "modulus",
|
|
2180
|
+
value: function modulus(x, y) {
|
|
2181
|
+
return new PowiainaNum(x).mod(y);
|
|
2182
|
+
}
|
|
1992
2183
|
}, {
|
|
1993
2184
|
key: "pow",
|
|
1994
2185
|
value: function pow(t, other) {
|
|
@@ -2020,6 +2211,17 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2020
2211
|
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
|
|
2021
2212
|
return new PowiainaNum(t).log(base);
|
|
2022
2213
|
}
|
|
2214
|
+
}, {
|
|
2215
|
+
key: "log2",
|
|
2216
|
+
value: function log2(t) {
|
|
2217
|
+
return new PowiainaNum(t).log2();
|
|
2218
|
+
}
|
|
2219
|
+
}, {
|
|
2220
|
+
key: "logBase",
|
|
2221
|
+
value: function logBase(t) {
|
|
2222
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
|
|
2223
|
+
return new PowiainaNum(t).log(base);
|
|
2224
|
+
}
|
|
2023
2225
|
}, {
|
|
2024
2226
|
key: "pLog10",
|
|
2025
2227
|
value: function pLog10(t) {
|
|
@@ -2171,6 +2373,27 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2171
2373
|
};
|
|
2172
2374
|
}
|
|
2173
2375
|
}
|
|
2376
|
+
}, {
|
|
2377
|
+
key: "pentate",
|
|
2378
|
+
value: function pentate(x, other, payload) {
|
|
2379
|
+
return new PowiainaNum(x).arrow(3)(other, payload);
|
|
2380
|
+
}
|
|
2381
|
+
}, {
|
|
2382
|
+
key: "hexate",
|
|
2383
|
+
value: function hexate(x, other, payload) {
|
|
2384
|
+
return new PowiainaNum(x).arrow(4)(other, payload);
|
|
2385
|
+
}
|
|
2386
|
+
}, {
|
|
2387
|
+
key: "pent",
|
|
2388
|
+
value: function pent(x, other, payload) {
|
|
2389
|
+
return new PowiainaNum(x).arrow(3)(other, payload);
|
|
2390
|
+
}
|
|
2391
|
+
}, {
|
|
2392
|
+
key: "penta_log",
|
|
2393
|
+
value: function penta_log(x) {
|
|
2394
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
2395
|
+
return new PowiainaNum(x).anyarrow_log(3)(base);
|
|
2396
|
+
}
|
|
2174
2397
|
}, {
|
|
2175
2398
|
key: "expansion",
|
|
2176
2399
|
value: function expansion(t, other) {
|
|
@@ -2269,9 +2492,6 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2269
2492
|
if (a == 0 && e == 1 && m > 1) {
|
|
2270
2493
|
return [1, 1 / 0, m - 1];
|
|
2271
2494
|
}
|
|
2272
|
-
if (e == 0 && m > 1) {
|
|
2273
|
-
return [1, 1 / 0, m - 1];
|
|
2274
|
-
}
|
|
2275
2495
|
return [a, e, m];
|
|
2276
2496
|
}
|
|
2277
2497
|
if (megota.gt(MSI)) {
|
|
@@ -2285,8 +2505,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2285
2505
|
return x.toString();
|
|
2286
2506
|
}
|
|
2287
2507
|
function getMSIForm(arrow, expans, megota) {
|
|
2288
|
-
|
|
2289
|
-
return "10{".concat(infToBang(conv[0]), ",").concat(infToBang(conv[1]), ",").concat(conv[2], "}").concat(MSI);
|
|
2508
|
+
return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
|
|
2290
2509
|
}
|
|
2291
2510
|
var t = base.clone();
|
|
2292
2511
|
var arrows = new PowiainaNum(readArg(0));
|
|
@@ -2294,14 +2513,6 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2294
2513
|
var _r, _r2;
|
|
2295
2514
|
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2296
2515
|
console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
|
|
2297
|
-
if (depth >= 200) {
|
|
2298
|
-
return new PowiainaNum({
|
|
2299
|
-
layer: 0,
|
|
2300
|
-
array: [newOperator(10), newOperator(1, new PowiainaNum(arrow2).clampMax(MSI).toNumber(), new PowiainaNum(expans2).clampMax(MSI).toNumber(), new PowiainaNum(megota2).clampMax(MSI).toNumber())],
|
|
2301
|
-
sign: 1,
|
|
2302
|
-
small: false
|
|
2303
|
-
}).normalize();
|
|
2304
|
-
}
|
|
2305
2516
|
var other = new PowiainaNum(other2);
|
|
2306
2517
|
var r;
|
|
2307
2518
|
if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
|
|
@@ -2319,7 +2530,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2319
2530
|
}
|
|
2320
2531
|
if (expans.eq(0)) {
|
|
2321
2532
|
return PowiainaNum.BEAF(t, t, t, power, megota.sub(1), powiaina2, depth + 1);
|
|
2322
|
-
// {this, this, power,
|
|
2533
|
+
// {this, this, this, power, megota-1}
|
|
2323
2534
|
}
|
|
2324
2535
|
if (megota.eq(0)) {
|
|
2325
2536
|
return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
|
|
@@ -2438,6 +2649,84 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2438
2649
|
value: function clampMax() {
|
|
2439
2650
|
return PowiainaNum.min.apply(PowiainaNum, arguments);
|
|
2440
2651
|
}
|
|
2652
|
+
}, {
|
|
2653
|
+
key: "eq",
|
|
2654
|
+
value: function eq(a, o) {
|
|
2655
|
+
return new PowiainaNum(a).eq(o);
|
|
2656
|
+
}
|
|
2657
|
+
}, {
|
|
2658
|
+
key: "equals",
|
|
2659
|
+
value: function equals(a, o) {
|
|
2660
|
+
return new PowiainaNum(a).eq(o);
|
|
2661
|
+
}
|
|
2662
|
+
}, {
|
|
2663
|
+
key: "neq",
|
|
2664
|
+
value: function neq(a, o) {
|
|
2665
|
+
return new PowiainaNum(a).neq(o);
|
|
2666
|
+
}
|
|
2667
|
+
}, {
|
|
2668
|
+
key: "notEquals",
|
|
2669
|
+
value: function notEquals(a, o) {
|
|
2670
|
+
return new PowiainaNum(a).notEquals(o);
|
|
2671
|
+
}
|
|
2672
|
+
}, {
|
|
2673
|
+
key: "lt",
|
|
2674
|
+
value: function lt(a, o) {
|
|
2675
|
+
return new PowiainaNum(a).lt(o);
|
|
2676
|
+
}
|
|
2677
|
+
}, {
|
|
2678
|
+
key: "gt",
|
|
2679
|
+
value: function gt(a, o) {
|
|
2680
|
+
return new PowiainaNum(a).gt(o);
|
|
2681
|
+
}
|
|
2682
|
+
}, {
|
|
2683
|
+
key: "lte",
|
|
2684
|
+
value: function lte(a, o) {
|
|
2685
|
+
return new PowiainaNum(a).lte(o);
|
|
2686
|
+
}
|
|
2687
|
+
}, {
|
|
2688
|
+
key: "gte",
|
|
2689
|
+
value: function gte(a, o) {
|
|
2690
|
+
return new PowiainaNum(a).gte(o);
|
|
2691
|
+
}
|
|
2692
|
+
}, {
|
|
2693
|
+
key: "rec",
|
|
2694
|
+
value: function rec(t) {
|
|
2695
|
+
return new PowiainaNum(t).rec();
|
|
2696
|
+
}
|
|
2697
|
+
}, {
|
|
2698
|
+
key: "recip",
|
|
2699
|
+
value: function recip(t) {
|
|
2700
|
+
return new PowiainaNum(t).rec();
|
|
2701
|
+
}
|
|
2702
|
+
}, {
|
|
2703
|
+
key: "reciprocate",
|
|
2704
|
+
value: function reciprocate(t) {
|
|
2705
|
+
return new PowiainaNum(t).rec();
|
|
2706
|
+
}
|
|
2707
|
+
}, {
|
|
2708
|
+
key: "floor",
|
|
2709
|
+
value: function floor(x) {
|
|
2710
|
+
return new PowiainaNum(x).floor();
|
|
2711
|
+
}
|
|
2712
|
+
}, {
|
|
2713
|
+
key: "ceil",
|
|
2714
|
+
value: function ceil(x) {
|
|
2715
|
+
return new PowiainaNum(x).ceil();
|
|
2716
|
+
}
|
|
2717
|
+
}, {
|
|
2718
|
+
key: "round",
|
|
2719
|
+
value: function round(x) {
|
|
2720
|
+
return new PowiainaNum(x).round();
|
|
2721
|
+
}
|
|
2722
|
+
}, {
|
|
2723
|
+
key: "trunc",
|
|
2724
|
+
value: function trunc(x) {
|
|
2725
|
+
return new PowiainaNum(x).trunc();
|
|
2726
|
+
}
|
|
2727
|
+
/**
|
|
2728
|
+
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
2729
|
+
*/
|
|
2441
2730
|
}, {
|
|
2442
2731
|
key: "sign",
|
|
2443
2732
|
value: function sign(a) {
|
|
@@ -2452,6 +2741,17 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2452
2741
|
key: "fromNumber",
|
|
2453
2742
|
value: function fromNumber(x) {
|
|
2454
2743
|
var obj = new PowiainaNum(); // NaN
|
|
2744
|
+
obj.resetFromObject({
|
|
2745
|
+
array: [{
|
|
2746
|
+
arrow: 0,
|
|
2747
|
+
expans: 1,
|
|
2748
|
+
megota: 1,
|
|
2749
|
+
repeat: NaN
|
|
2750
|
+
}],
|
|
2751
|
+
small: false,
|
|
2752
|
+
layer: 0,
|
|
2753
|
+
sign: 0
|
|
2754
|
+
});
|
|
2455
2755
|
if (x < 0) obj.sign = -1; // negative
|
|
2456
2756
|
else if (x == 0) {
|
|
2457
2757
|
obj.sign = 0;
|
|
@@ -2479,10 +2779,26 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2479
2779
|
}, {
|
|
2480
2780
|
key: "fromString",
|
|
2481
2781
|
value: function fromString(input) {
|
|
2782
|
+
if (PowiainaNum.usingBreakEternityLikeFromString && BE_REGEX.test(input)) {
|
|
2783
|
+
/*
|
|
2784
|
+
* 0i00000000a7 says that eee-3000 will wrongly parse to 1. So i added this
|
|
2785
|
+
*/
|
|
2786
|
+
var a = input.match(/(e+-)(\d+(.\d+)?)/);
|
|
2787
|
+
if (a) {
|
|
2788
|
+
var e_s = a[1].length;
|
|
2789
|
+
input = "e-" + "e".repeat(e_s - 1) + a[2];
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
return this.fromString_core(input);
|
|
2793
|
+
}
|
|
2794
|
+
}, {
|
|
2795
|
+
key: "fromString_core",
|
|
2796
|
+
value: function fromString_core(input) {
|
|
2482
2797
|
var _b, _c, _d, _e, _f, _g;
|
|
2483
|
-
var x = new PowiainaNum();
|
|
2798
|
+
var x = new PowiainaNum(NaN);
|
|
2484
2799
|
// Judge the string was a number
|
|
2485
2800
|
if (input.startsWith("PN")) input = input.substring(2);
|
|
2801
|
+
if (input == "NaN") return PowiainaNum.NaN.clone();
|
|
2486
2802
|
input = input.replace(/J\^(\d+)/g, "(10{!})^$1");
|
|
2487
2803
|
input = input.replace(/J/g, "10{!}");
|
|
2488
2804
|
input = input.replace(/K\^(\d+)/g, "(10{1,2})^$1");
|
|
@@ -2493,17 +2809,20 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2493
2809
|
input = input.replace(/M/g, "10{!,2}");
|
|
2494
2810
|
input = input.replace(/N\^(\d+)/g, "(10{1,!})^$1");
|
|
2495
2811
|
input = input.replace(/N/g, "10{1,!}");
|
|
2812
|
+
if (/^.*e-.*(e|\^).*/.test(input)) {
|
|
2813
|
+
input = "/10^" + input.substring(input.indexOf("e-"));
|
|
2814
|
+
}
|
|
2496
2815
|
if (!isNaN(Number(input))) {
|
|
2497
2816
|
var res = Number(input);
|
|
2498
|
-
var
|
|
2817
|
+
var a = false;
|
|
2499
2818
|
if (res == 0) {
|
|
2500
2819
|
if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
|
|
2501
|
-
|
|
2820
|
+
a = true;
|
|
2502
2821
|
}
|
|
2503
2822
|
} else {
|
|
2504
|
-
|
|
2823
|
+
a = true;
|
|
2505
2824
|
}
|
|
2506
|
-
if (!
|
|
2825
|
+
if (!a) {
|
|
2507
2826
|
var m = input.search(/e/);
|
|
2508
2827
|
var exponent = input.substring((m == -1 ? input.length : m) + 1);
|
|
2509
2828
|
var mantissa = input.substring(0, m == -1 ? undefined : m);
|
|
@@ -2513,11 +2832,11 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2513
2832
|
// Is regular number gte 1:
|
|
2514
2833
|
if (Number(mantissa) >= 1) {
|
|
2515
2834
|
// check The mantissa is very long?
|
|
2516
|
-
var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
|
|
2517
|
-
var log10int = Math.floor(log10mant);
|
|
2518
|
-
var log10float = log10mant - log10int;
|
|
2835
|
+
var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa)); // sample 10
|
|
2836
|
+
var log10int = Math.floor(log10mant); // sample 1
|
|
2837
|
+
var log10float = log10mant - log10int; // sample 0;
|
|
2519
2838
|
mantissaME[0] = Math.pow(10, log10float);
|
|
2520
|
-
mantissaME[1] +=
|
|
2839
|
+
mantissaME[1] += log10int;
|
|
2521
2840
|
} else {
|
|
2522
2841
|
// If not , count how many zeros until reached non-zero numbers
|
|
2523
2842
|
var zeros = countLeadingZerosAfterDecimal(mantissa);
|
|
@@ -2532,7 +2851,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2532
2851
|
// /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
|
|
2533
2852
|
return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
|
|
2534
2853
|
}
|
|
2535
|
-
if (isFinite(res) &&
|
|
2854
|
+
if (isFinite(res) && a) {
|
|
2536
2855
|
x = PowiainaNum.fromNumber(Number(input));
|
|
2537
2856
|
return x;
|
|
2538
2857
|
}
|
|
@@ -2549,6 +2868,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2549
2868
|
return x;
|
|
2550
2869
|
}
|
|
2551
2870
|
input = replaceETo10(input);
|
|
2871
|
+
input = removeCommasOutsideBraces(input);
|
|
2552
2872
|
if (!isPowiainaNum.test(input)) {
|
|
2553
2873
|
throw powiainaNumError + "malformed input: " + input;
|
|
2554
2874
|
}
|
|
@@ -2561,28 +2881,31 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2561
2881
|
input = input.substring(numSigns);
|
|
2562
2882
|
}
|
|
2563
2883
|
if (input[0] == "/") {
|
|
2564
|
-
var
|
|
2565
|
-
var
|
|
2566
|
-
recipIt = ((_e = (_d =
|
|
2567
|
-
input = input.substring(
|
|
2884
|
+
var _numSigns = input.search(/[^\/]/);
|
|
2885
|
+
var _signs = input.substring(0, _numSigns);
|
|
2886
|
+
recipIt = ((_e = (_d = _signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
|
|
2887
|
+
input = input.substring(_numSigns);
|
|
2568
2888
|
}
|
|
2569
2889
|
if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
|
|
2570
2890
|
x.sign = 1;
|
|
2571
2891
|
x.array = [newOperator(0)];
|
|
2572
|
-
var
|
|
2892
|
+
var _a3, b, c, d;
|
|
2573
2893
|
if (input[0] == "P") {
|
|
2574
2894
|
if (input[1] == "^") {
|
|
2575
|
-
|
|
2576
|
-
x.layer = Number(input.substring(2,
|
|
2577
|
-
input = input.substring(
|
|
2895
|
+
_a3 = input.substring(2).search(/[^0-9]/) + 2;
|
|
2896
|
+
x.layer = Number(input.substring(2, _a3));
|
|
2897
|
+
input = input.substring(_a3 + 1);
|
|
2578
2898
|
} else {
|
|
2579
|
-
|
|
2580
|
-
x.layer =
|
|
2581
|
-
input = input.substring(
|
|
2899
|
+
_a3 = input.search(/[^P]/);
|
|
2900
|
+
x.layer = _a3;
|
|
2901
|
+
input = input.substring(_a3);
|
|
2582
2902
|
}
|
|
2583
2903
|
}
|
|
2584
2904
|
while (input) {
|
|
2585
2905
|
if (/^(\(?10[\^\{])/.test(input)) {
|
|
2906
|
+
var arrows = void 0,
|
|
2907
|
+
expans = void 0,
|
|
2908
|
+
megota = void 0;
|
|
2586
2909
|
/*
|
|
2587
2910
|
10^ - 匹配
|
|
2588
2911
|
10{ - 匹配
|
|
@@ -2593,30 +2916,29 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2593
2916
|
*/
|
|
2594
2917
|
if (input[0] == "(") input = input.substring(1);
|
|
2595
2918
|
//cutted, 10^.... or 10{....
|
|
2596
|
-
var arrows, expans, megota;
|
|
2597
2919
|
if (input[2] == "^") {
|
|
2598
|
-
|
|
2920
|
+
_a3 = input.substring(2).search(/[^\^]/);
|
|
2599
2921
|
//cut input to ^^...^^, and search how numbers
|
|
2600
|
-
arrows =
|
|
2922
|
+
arrows = _a3;
|
|
2601
2923
|
// 10^^^
|
|
2602
|
-
b =
|
|
2924
|
+
b = _a3 + 2; // b points to after ^'s.
|
|
2603
2925
|
} else {
|
|
2604
2926
|
// 10{...}
|
|
2605
|
-
|
|
2927
|
+
_a3 = input.indexOf("}");
|
|
2606
2928
|
// select contents between {...}
|
|
2607
|
-
var tmp = input.substring(3,
|
|
2929
|
+
var tmp = input.substring(3, _a3).split(",");
|
|
2608
2930
|
arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
|
|
2609
2931
|
expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
|
|
2610
2932
|
megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
|
|
2611
|
-
b =
|
|
2933
|
+
b = _a3 + 1;
|
|
2612
2934
|
// b points to after }.
|
|
2613
2935
|
}
|
|
2614
2936
|
input = input.substring(b);
|
|
2615
2937
|
if (input[0] == ")") {
|
|
2616
2938
|
// )^....<Space>
|
|
2617
|
-
|
|
2618
|
-
c = Number(input.substring(2,
|
|
2619
|
-
input = input.substring(
|
|
2939
|
+
_a3 = input.indexOf(" ");
|
|
2940
|
+
c = Number(input.substring(2, _a3)); // Select contents between )^....<Space>
|
|
2941
|
+
input = input.substring(_a3 + 1); // c points to after <Space>
|
|
2620
2942
|
} else {
|
|
2621
2943
|
c = 1; // There is only spaces, count as <ONE>
|
|
2622
2944
|
}
|
|
@@ -2627,21 +2949,21 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2627
2949
|
x.array.splice(1, 0, newOperator(c, 1, expans, megota));
|
|
2628
2950
|
}
|
|
2629
2951
|
} else if (arrows == 2 && expans == 1 && megota == 1) {
|
|
2630
|
-
|
|
2952
|
+
_a3 = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
|
|
2631
2953
|
b = x.array[0].repeat;
|
|
2632
|
-
if (b >= 1e10) ++
|
|
2633
|
-
if (b >= 10) ++
|
|
2634
|
-
x.array[0].repeat =
|
|
2954
|
+
if (b >= 1e10) ++_a3;
|
|
2955
|
+
if (b >= 10) ++_a3;
|
|
2956
|
+
x.array[0].repeat = _a3;
|
|
2635
2957
|
if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
|
|
2636
2958
|
d = x.getOperatorIndex(2);
|
|
2637
2959
|
if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
|
|
2638
2960
|
} else if (isFinite(arrows)) {
|
|
2639
|
-
|
|
2961
|
+
_a3 = x.getOperator(arrows - 1);
|
|
2640
2962
|
b = x.getOperator(arrows - 2);
|
|
2641
|
-
if (b >= 10) ++
|
|
2963
|
+
if (b >= 10) ++_a3;
|
|
2642
2964
|
d = x.getOperatorIndex(arrows);
|
|
2643
2965
|
x.array.splice(1, Math.ceil(d) - 1);
|
|
2644
|
-
x.array[0].repeat =
|
|
2966
|
+
x.array[0].repeat = _a3;
|
|
2645
2967
|
if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
2646
2968
|
} else {
|
|
2647
2969
|
x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
@@ -2650,10 +2972,10 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2650
2972
|
break;
|
|
2651
2973
|
}
|
|
2652
2974
|
}
|
|
2653
|
-
|
|
2975
|
+
_a3 = input.split(/[Ee]/);
|
|
2654
2976
|
b = [x.array[0].repeat, 0];
|
|
2655
2977
|
c = 1;
|
|
2656
|
-
for (var
|
|
2978
|
+
for (var i = _a3.length - 1; i >= 0; --i) {
|
|
2657
2979
|
//The things that are already there
|
|
2658
2980
|
if (b[0] < MSI_LOG10 && b[1] === 0) {
|
|
2659
2981
|
b[0] = Math.pow(10, c * b[0]);
|
|
@@ -2670,12 +2992,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2670
2992
|
b[1]++;
|
|
2671
2993
|
}
|
|
2672
2994
|
//Multiplying coefficient
|
|
2673
|
-
var decimalPointPos =
|
|
2674
|
-
var intPartLen = decimalPointPos == -1 ?
|
|
2995
|
+
var decimalPointPos = _a3[i].indexOf(".");
|
|
2996
|
+
var intPartLen = decimalPointPos == -1 ? _a3[i].length : decimalPointPos;
|
|
2675
2997
|
if (b[1] === 0) {
|
|
2676
|
-
if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(
|
|
2998
|
+
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]);
|
|
2677
2999
|
} else {
|
|
2678
|
-
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(
|
|
3000
|
+
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(_a3[i].substring(0, intPartLen)) : _a3[i] ? Math.log10(Number(_a3[i])) : 0;
|
|
2679
3001
|
if (b[1] == 1) {
|
|
2680
3002
|
b[0] += d;
|
|
2681
3003
|
} else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
|
|
@@ -2706,6 +3028,17 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2706
3028
|
key: "fromObject",
|
|
2707
3029
|
value: function fromObject(powlikeObject) {
|
|
2708
3030
|
var obj = new PowiainaNum();
|
|
3031
|
+
obj.resetFromObject({
|
|
3032
|
+
array: [{
|
|
3033
|
+
arrow: 0,
|
|
3034
|
+
expans: 1,
|
|
3035
|
+
megota: 1,
|
|
3036
|
+
repeat: NaN
|
|
3037
|
+
}],
|
|
3038
|
+
small: false,
|
|
3039
|
+
layer: 0,
|
|
3040
|
+
sign: 0
|
|
3041
|
+
});
|
|
2709
3042
|
obj.array = [];
|
|
2710
3043
|
if (isExpantaNumArray(powlikeObject)) {
|
|
2711
3044
|
for (var i = 0; i < powlikeObject.length; i++) {
|
|
@@ -2723,8 +3056,8 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2723
3056
|
} else if (isPowiainaNum01XArray(powlikeObject)) {
|
|
2724
3057
|
var arrayobj = powlikeObject;
|
|
2725
3058
|
obj.array[0] = newOperator(arrayobj[0]);
|
|
2726
|
-
for (var
|
|
2727
|
-
var b = arrayobj[
|
|
3059
|
+
for (var _i4 = 1; _i4 < arrayobj.length; _i4++) {
|
|
3060
|
+
var b = arrayobj[_i4];
|
|
2728
3061
|
obj.array[1] = newOperator(b[1], replaceXToInfinity(b[0]), replaceXToInfinity(b[2]), b[3]);
|
|
2729
3062
|
}
|
|
2730
3063
|
obj.small = false;
|
|
@@ -2732,21 +3065,21 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2732
3065
|
obj.layer = 0;
|
|
2733
3066
|
return obj;
|
|
2734
3067
|
} else {
|
|
2735
|
-
|
|
2736
|
-
obj.array[_i4] = {
|
|
2737
|
-
arrow: powlikeObject.array[_i4].arrow,
|
|
2738
|
-
expans: powlikeObject.array[_i4].expans,
|
|
2739
|
-
megota: powlikeObject.array[_i4].megota,
|
|
2740
|
-
repeat: powlikeObject.array[_i4].repeat,
|
|
2741
|
-
valuereplaced: powlikeObject.array[_i4].valuereplaced
|
|
2742
|
-
};
|
|
2743
|
-
}
|
|
2744
|
-
obj.small = powlikeObject.small;
|
|
2745
|
-
obj.sign = powlikeObject.sign;
|
|
2746
|
-
obj.layer = powlikeObject.layer;
|
|
3068
|
+
obj.resetFromObject(powlikeObject);
|
|
2747
3069
|
return obj;
|
|
2748
3070
|
}
|
|
2749
3071
|
}
|
|
3072
|
+
}, {
|
|
3073
|
+
key: "grahalFunction",
|
|
3074
|
+
value: function grahalFunction(layers2) {
|
|
3075
|
+
var layers = new PowiainaNum(layers2);
|
|
3076
|
+
if (!layers.isInt() || layers.lt(0) || layers.isNaN()) return PowiainaNum.NaN.clone();
|
|
3077
|
+
if (layers.eq(1)) return new PowiainaNum("10^^^(10^)^7625597484984 3638334640023.7783");else if (layers.lte(MSI)) {
|
|
3078
|
+
return new PowiainaNum("(10{!})^".concat(layers.toNumber(), " 10^^^(10^)^7625597484984 3638334640023.7783"));
|
|
3079
|
+
} else {
|
|
3080
|
+
return PowiainaNum.BEAF(3, layers, 1, 2);
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
2750
3083
|
}]);
|
|
2751
3084
|
}();
|
|
2752
3085
|
_a = Symbol.toStringTag;
|
|
@@ -2963,5 +3296,14 @@ PowiainaNum.maxOps = 100;
|
|
|
2963
3296
|
PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
|
|
2964
3297
|
//#endregion
|
|
2965
3298
|
PowiainaNum.arrowFuncMap = new Map();
|
|
3299
|
+
//#region configurations
|
|
3300
|
+
/**
|
|
3301
|
+
* 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.
|
|
3302
|
+
*/
|
|
3303
|
+
PowiainaNum.usingBreakEternityLikeFromString = false;
|
|
3304
|
+
/**
|
|
3305
|
+
* If you set this config to true, the `constructor` method will return Zero instead of NaN when call new PowiainaNum() with no arguments.
|
|
3306
|
+
*/
|
|
3307
|
+
PowiainaNum.blankArgumentConstructorReturnZero = false;
|
|
2966
3308
|
|
|
2967
3309
|
export { arraySortFunction, PowiainaNum as default, mergeSameArrays };
|