powiaina_num.js 0.2.0-alpha.2.6 → 0.2.0-alpha.2.8
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 +72 -71
- package/dist/PowiainaNum.cjs.js +260 -36
- package/dist/PowiainaNum.esm.js +260 -36
- package/dist/PowiainaNum.js +260 -36
- package/dist/PowiainaNum.min.js +1 -1
- package/dist/index.d.ts +21 -1
- package/package.json +47 -47
package/README.md
CHANGED
|
@@ -1,71 +1,72 @@
|
|
|
1
|
-
# PowiainaNum.js
|
|
2
|
-
|
|
3
|
-
A JavaScript library that handles arithmetic for numbers as large as {10,9e15,1,1,1,2}.
|
|
4
|
-
|
|
5
|
-
This reaches level f<sub>ω<sup>3</sup>+1</sub>.
|
|
6
|
-
|
|
7
|
-
Internally, it is represented as an sign,layer, small and array. Sign is 1 or -1. It's 10{oper.arrow, oper.expans, oper.megota}, If arrow count or expans count is Infinite, the count replaces from the next operators.
|
|
8
|
-
|
|
9
|
-
Some codes snippet from [ExpantaNum.js by Naruyoko](https://github.com/Naruyoko/ExpantaNum.js)
|
|
10
|
-
|
|
11
|
-
Functions are as follows `abs, neg, add, sub, mul, div, rec, pow, sqrt, cbrt, root, log10, log, cmp, isFinite, isInfinite, isNaN`(some missing items that have not been fully developed)
|
|
12
|
-
|
|
13
|
-
## Using
|
|
14
|
-
|
|
15
|
-
The library exports a class,
|
|
16
|
-
Create a PowiainaNum.js object like this:
|
|
17
|
-
|
|
18
|
-
```javascript
|
|
19
|
-
import PowiainaNum from "powiaina_num.js";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
a.
|
|
43
|
-
a.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
a.
|
|
51
|
-
a.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/*
|
|
62
|
-
/*
|
|
63
|
-
/*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
# PowiainaNum.js
|
|
2
|
+
|
|
3
|
+
A JavaScript library that handles arithmetic for numbers as large as {10,9e15,1,1,1,2}.
|
|
4
|
+
|
|
5
|
+
This reaches level f<sub>ω<sup>3</sup>+1</sub>.
|
|
6
|
+
|
|
7
|
+
Internally, it is represented as an sign,layer, small and array. Sign is 1 or -1. It's 10{oper.arrow, oper.expans, oper.megota}, If arrow count or expans count is Infinite, the count replaces from the next operators.
|
|
8
|
+
|
|
9
|
+
Some codes snippet from [ExpantaNum.js by Naruyoko](https://github.com/Naruyoko/ExpantaNum.js)
|
|
10
|
+
|
|
11
|
+
Functions are as follows `abs, neg, add, sub, mul, div, rec, pow, sqrt, cbrt, root, log10, log, cmp, isFinite, isInfinite, isNaN`(some missing items that have not been fully developed)
|
|
12
|
+
|
|
13
|
+
## Using
|
|
14
|
+
|
|
15
|
+
The library exports a class,
|
|
16
|
+
Create a PowiainaNum.js object like this:
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
import PowiainaNum from "powiaina_num.js"; // static import
|
|
20
|
+
const { default: PowiainaNum } = await import("powiaina_num.js") // dynamic import
|
|
21
|
+
|
|
22
|
+
let a = new PowiainaNum(); // create PN.js number with NaN
|
|
23
|
+
let b = new PowiainaNum(3); // create PN.js number with number 3
|
|
24
|
+
let c = new PowiainaNum("1e114514"); // create PN.js number with number 10^114514
|
|
25
|
+
|
|
26
|
+
let d = new PowiainaNum(c); // create PN.js number from a PN.js number
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Javascript operators will not work such as `+`, `-`, etc.
|
|
30
|
+
You should call the equivalent functions instead.
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
let a = new PowiainaNum(114514);
|
|
34
|
+
let b = new PowiainaNum(1919810);
|
|
35
|
+
|
|
36
|
+
// Calculate a+b:
|
|
37
|
+
let c = a.add(b); // 1919810+114514
|
|
38
|
+
|
|
39
|
+
// Calculate a-b:
|
|
40
|
+
let c = a.sub(b);
|
|
41
|
+
|
|
42
|
+
a.mul(b); // a*b
|
|
43
|
+
a.div(b); // a/b
|
|
44
|
+
a.pow(b); // a^b
|
|
45
|
+
|
|
46
|
+
a.log10(); // log10(a)
|
|
47
|
+
|
|
48
|
+
// comparing PN.js numbers
|
|
49
|
+
|
|
50
|
+
a.lt(b); // a is less than b
|
|
51
|
+
a.gt(b); // a is greater than b
|
|
52
|
+
a.eq(b); // a is equals to b
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Future ideas
|
|
56
|
+
|
|
57
|
+
Extend `Operator` to nearly infinite keys to reach level f<sub>ω<sup>ω</sup></sub>
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface Operator {
|
|
61
|
+
/*P3*/ arrow: number;
|
|
62
|
+
/*P4*/ expans: number;
|
|
63
|
+
/*P5*/ megota: number;
|
|
64
|
+
/*P6*/ powiaina: number;
|
|
65
|
+
P7: number;
|
|
66
|
+
.....
|
|
67
|
+
|
|
68
|
+
repeat: number;
|
|
69
|
+
|
|
70
|
+
valuereplaced?: -1 | 0 | 1 | 2 | ...
|
|
71
|
+
}
|
|
72
|
+
```
|
package/dist/PowiainaNum.cjs.js
CHANGED
|
@@ -43,6 +43,7 @@ var MSI = 9007199254740991;
|
|
|
43
43
|
var MSI_LOG10 = 15.954589770191003;
|
|
44
44
|
var MSI_REC = 1.1102230246251568e-16;
|
|
45
45
|
var LONG_STRING_MIN_LENGTH = 17;
|
|
46
|
+
var EXP_E_REC = 1.444667861009766;
|
|
46
47
|
var isPowiainaNum = /^[-\+]*(Infinity|NaN|(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;
|
|
47
48
|
function newOperator(r) {
|
|
48
49
|
var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -162,7 +163,7 @@ function d_lambertw(z) {
|
|
|
162
163
|
var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
163
164
|
var w;
|
|
164
165
|
var ew, wewz, wn;
|
|
165
|
-
if (z.
|
|
166
|
+
if (z.isInfiNaN()) return z;
|
|
166
167
|
if (principal) {
|
|
167
168
|
if (z.eq(PowiainaNum.ZERO)) {
|
|
168
169
|
return PowiainaNum.ZERO.clone();
|
|
@@ -276,7 +277,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
276
277
|
if (l > MSI_LOG10 || l < -MSI_LOG10) {
|
|
277
278
|
r.array = [newOperator(l, 0), newOperator(1, 1)];
|
|
278
279
|
} else {
|
|
279
|
-
r.array = [newOperator(Math.pow(10, l), 0)];
|
|
280
|
+
r.array = [newOperator(Math.pow(10, Math.abs(l)), 0)];
|
|
280
281
|
}
|
|
281
282
|
r.small = l < 0 ? true : false;
|
|
282
283
|
r.sign *= mult;
|
|
@@ -294,7 +295,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
294
295
|
var y = new PowiainaNum(other);
|
|
295
296
|
// inf * -inf = -inf
|
|
296
297
|
if (x.eq(PowiainaNum.POSITIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY) || y.eq(PowiainaNum.POSITIVE_INFINITY) && x.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.NEGATIVE_INFINITY.clone();
|
|
297
|
-
if (x.
|
|
298
|
+
if (x.isInfiNaN() && y.eq(PowiainaNum.ZERO) && y.isInfiNaN() && x.eq(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
|
|
298
299
|
if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
299
300
|
// inf & nan check
|
|
300
301
|
if (!x.isFinite()) return x.clone();
|
|
@@ -393,6 +394,127 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
393
394
|
value: function cbrt() {
|
|
394
395
|
return this.root(3);
|
|
395
396
|
}
|
|
397
|
+
}, {
|
|
398
|
+
key: "tetrate",
|
|
399
|
+
value:
|
|
400
|
+
// Code from ExpantaNum.js
|
|
401
|
+
function tetrate(other2) {
|
|
402
|
+
var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
403
|
+
var t = this.clone();
|
|
404
|
+
var other = new PowiainaNum(other2);
|
|
405
|
+
var payl = new PowiainaNum(payload);
|
|
406
|
+
if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
|
|
407
|
+
if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
|
|
408
|
+
var negln;
|
|
409
|
+
if (other.isInfi() && other.sign > 0) {
|
|
410
|
+
if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
411
|
+
negln = this.log().neg();
|
|
412
|
+
return negln.lambertw().div(negln);
|
|
413
|
+
}
|
|
414
|
+
if (other.lte(-2)) return PowiainaNum.NaN.clone();
|
|
415
|
+
if (t.isZero()) {
|
|
416
|
+
if (other.isZero()) return PowiainaNum.NaN.clone();
|
|
417
|
+
if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
|
|
418
|
+
return PowiainaNum.ONE.clone();
|
|
419
|
+
}
|
|
420
|
+
if (t.eq(PowiainaNum.ONE)) {
|
|
421
|
+
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
|
|
422
|
+
return PowiainaNum.ONE.clone();
|
|
423
|
+
}
|
|
424
|
+
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
|
|
425
|
+
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
426
|
+
if (other.eq(PowiainaNum.ONE)) return t;
|
|
427
|
+
if (other.eq(2)) return t.pow(t);
|
|
428
|
+
if (t.eq(2)) {
|
|
429
|
+
if (other.eq(3)) return PowiainaNum.fromNumber(16);
|
|
430
|
+
if (other.eq(4)) return PowiainaNum.fromNumber(65536);
|
|
431
|
+
}
|
|
432
|
+
var m = t.max(other);
|
|
433
|
+
if (m.gt(PowiainaNum.PENTATED_MSI)) return m;
|
|
434
|
+
if (m.gt(PowiainaNum.TETRATED_MSI) || other.gt(MSI)) {
|
|
435
|
+
if (this.lt(EXP_E_REC)) {
|
|
436
|
+
negln = t.ln().neg();
|
|
437
|
+
return negln.lambertw().div(negln);
|
|
438
|
+
}
|
|
439
|
+
var j = t.slog(10).add(other);
|
|
440
|
+
j.setOperator(j.getOperator(2) + 1, 2);
|
|
441
|
+
j.normalize();
|
|
442
|
+
return j;
|
|
443
|
+
}
|
|
444
|
+
var y = other.toNumber();
|
|
445
|
+
var f = Math.floor(y);
|
|
446
|
+
var r = t.pow(y - f);
|
|
447
|
+
var l = PowiainaNum.NaN;
|
|
448
|
+
var i = 0;
|
|
449
|
+
for (var w = PowiainaNum.E_MSI.clone(); f !== 0 && r.lt(w) && i < 100; ++i) {
|
|
450
|
+
if (f > 0) {
|
|
451
|
+
r = t.pow(r);
|
|
452
|
+
if (l.eq(r)) {
|
|
453
|
+
f = 0;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
l = r;
|
|
457
|
+
--f;
|
|
458
|
+
} else {
|
|
459
|
+
r = r.log(t);
|
|
460
|
+
if (l.eq(r)) {
|
|
461
|
+
f = 0;
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
l = r;
|
|
465
|
+
++f;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (i == 100 || this.lt(EXP_E_REC)) f = 0;
|
|
469
|
+
r.setOperator(r.getOperator(1) + f, 1);
|
|
470
|
+
r.normalize();
|
|
471
|
+
return r;
|
|
472
|
+
}
|
|
473
|
+
// Code from ExpantaNum.js
|
|
474
|
+
}, {
|
|
475
|
+
key: "slog",
|
|
476
|
+
value: function slog() {
|
|
477
|
+
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
478
|
+
var x = this.clone();
|
|
479
|
+
var b = new PowiainaNum(base);
|
|
480
|
+
if (x.isInfiNaN()) return x;
|
|
481
|
+
if (b.isNaN()) return b;
|
|
482
|
+
if (b.isInfi()) return PowiainaNum.ZERO.clone();
|
|
483
|
+
if (x.isZero()) return PowiainaNum.ONE.clone();
|
|
484
|
+
if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
485
|
+
if (x.eq(b)) return PowiainaNum.ONE.clone();
|
|
486
|
+
if (b.lt(EXP_E_REC)) {
|
|
487
|
+
var a = b.tetrate(Infinity);
|
|
488
|
+
if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
489
|
+
if (x.gt(a)) return PowiainaNum.NaN.clone();
|
|
490
|
+
}
|
|
491
|
+
if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
|
|
492
|
+
if (x.gt(b)) return x;
|
|
493
|
+
return PowiainaNum.ZERO.clone();
|
|
494
|
+
}
|
|
495
|
+
if (x.max(b).gt(PowiainaNum.TETRATED_MSI)) {
|
|
496
|
+
if (x.gt(b)) {
|
|
497
|
+
x.setOperator(x.getOperator(2) - 1, 2);
|
|
498
|
+
x.normalize();
|
|
499
|
+
return x.sub(x.getOperator(1));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (x.lt(PowiainaNum.ZERO.clone())) return b.pow(x).sub(2);
|
|
503
|
+
var r = 0;
|
|
504
|
+
var t = x.getOperator(1) - b.getOperator(1);
|
|
505
|
+
if (t > 3) {
|
|
506
|
+
var l = t - 3;
|
|
507
|
+
r += l;
|
|
508
|
+
x.setOperator(x.getOperator(1) - l, 1);
|
|
509
|
+
}
|
|
510
|
+
for (var i = 0; i < 100; ++i) {
|
|
511
|
+
if (x.lte(PowiainaNum.ONE)) return new PowiainaNum(r + x.toNumber());
|
|
512
|
+
++r;
|
|
513
|
+
x = PowiainaNum.log(x, base);
|
|
514
|
+
}
|
|
515
|
+
console.warn("Failed to converage");
|
|
516
|
+
return PowiainaNum.NaN.clone();
|
|
517
|
+
}
|
|
396
518
|
}, {
|
|
397
519
|
key: "abs",
|
|
398
520
|
value: function abs() {
|
|
@@ -403,7 +525,6 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
403
525
|
}, {
|
|
404
526
|
key: "log10",
|
|
405
527
|
value: function log10() {
|
|
406
|
-
var _a, _b;
|
|
407
528
|
if (this.isneg()) return PowiainaNum.NaN.clone();
|
|
408
529
|
if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
|
|
409
530
|
if (this.small) {
|
|
@@ -411,7 +532,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
411
532
|
_x.small = !_x.small;
|
|
412
533
|
return _x.log10().neg();
|
|
413
534
|
}
|
|
414
|
-
if (
|
|
535
|
+
if (this.array.length == 1) return new PowiainaNum(Math.log10(this.array[0].repeat));
|
|
415
536
|
var x = this.clone();
|
|
416
537
|
x.array[1].repeat = x.array[1].repeat - 1;
|
|
417
538
|
x.normalize();
|
|
@@ -425,6 +546,11 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
425
546
|
var other = new PowiainaNum(base);
|
|
426
547
|
return this.log10().div(other.log10());
|
|
427
548
|
}
|
|
549
|
+
}, {
|
|
550
|
+
key: "ln",
|
|
551
|
+
value: function ln() {
|
|
552
|
+
return this.log();
|
|
553
|
+
}
|
|
428
554
|
}, {
|
|
429
555
|
key: "exp",
|
|
430
556
|
value: function exp() {
|
|
@@ -631,6 +757,24 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
631
757
|
r.sign = this.sign;
|
|
632
758
|
return r;
|
|
633
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Work like `Math.trunc`,
|
|
762
|
+
*
|
|
763
|
+
* if `this > 0`, return `floor(this)`
|
|
764
|
+
*
|
|
765
|
+
* if `this < 0`, return `ceil(this)`
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
|
|
769
|
+
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
770
|
+
* @returns
|
|
771
|
+
*/
|
|
772
|
+
}, {
|
|
773
|
+
key: "trunc",
|
|
774
|
+
value: function trunc() {
|
|
775
|
+
var y = this.clone();
|
|
776
|
+
return y.gte(0) ? y.floor() : y.ceil();
|
|
777
|
+
}
|
|
634
778
|
/**
|
|
635
779
|
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
636
780
|
*/
|
|
@@ -731,9 +875,14 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
731
875
|
return Boolean(this.small || isFinite(this.getOperator(0))) && !this.isNaN();
|
|
732
876
|
})
|
|
733
877
|
}, {
|
|
734
|
-
key: "
|
|
735
|
-
value: function
|
|
736
|
-
return
|
|
878
|
+
key: "isInfi",
|
|
879
|
+
value: function isInfi() {
|
|
880
|
+
return this.rec().isZero();
|
|
881
|
+
}
|
|
882
|
+
}, {
|
|
883
|
+
key: "isInfiNaN",
|
|
884
|
+
value: function isInfiNaN() {
|
|
885
|
+
return this.isInfi() || this.isNaN();
|
|
737
886
|
}
|
|
738
887
|
}, {
|
|
739
888
|
key: "isInt",
|
|
@@ -765,6 +914,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
765
914
|
var renormalize = true;
|
|
766
915
|
var x = this;
|
|
767
916
|
for (var _i = 0; _i < this.array.length; _i++) {
|
|
917
|
+
// Check what is infinity
|
|
768
918
|
if (this.array[_i].repeat == Infinity) {
|
|
769
919
|
this.array = [{
|
|
770
920
|
arrow: 0,
|
|
@@ -800,36 +950,42 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
800
950
|
if (!Number.isInteger(e.expans)) e.expans = Math.floor(e.expans);
|
|
801
951
|
if (!Number.isInteger(e.megota)) e.megota = Math.floor(e.megota);
|
|
802
952
|
}
|
|
953
|
+
if (!x.array.length) {
|
|
954
|
+
x.small = !x.small;
|
|
955
|
+
x.array = [newOperator(Infinity)]; // if no array set zero
|
|
956
|
+
}
|
|
803
957
|
do {
|
|
804
958
|
renormalize = false;
|
|
959
|
+
// Sort arrays.
|
|
805
960
|
this.array.sort(function (a, b) {
|
|
806
961
|
return compareTuples([a.megota, a.expans, a.arrow], [b.megota, b.expans, b.arrow]);
|
|
807
962
|
});
|
|
963
|
+
for (i = 1; i < x.array.length - 1; ++i) {
|
|
964
|
+
if (x.array[i].arrow == x.array[i + 1].arrow && x.array[i].expans == x.array[i + 1].expans && x.array[i].megota == x.array[i + 1].megota) {
|
|
965
|
+
// same array's merge
|
|
966
|
+
x.array[i].repeat += x.array[i + 1].repeat;
|
|
967
|
+
x.array.splice(i + 1, 1);
|
|
968
|
+
--i;
|
|
969
|
+
renormalize = true;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
808
972
|
for (i = 1; i < x.array.length; ++i) {
|
|
809
|
-
//
|
|
973
|
+
// If there is a 0 repeat operator, remove it.
|
|
810
974
|
if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
|
|
811
975
|
x.array.splice(i, 1);
|
|
812
976
|
--i;
|
|
813
977
|
continue;
|
|
814
978
|
}
|
|
815
|
-
//
|
|
979
|
+
// If there is a operator which arrow 0 and brace count >=2
|
|
980
|
+
// replace it as arrow replacement operaotr
|
|
816
981
|
if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
|
|
817
982
|
x.array[i].arrow = Infinity;
|
|
818
983
|
x.array[i].valuereplaced = 0;
|
|
819
984
|
x.array[i].expans = x.array[i].expans - 1;
|
|
820
985
|
}
|
|
821
986
|
}
|
|
822
|
-
for (var _i2 = 1; _i2 < this.array.length; _i2++) {
|
|
823
|
-
if (this.array[_i2].repeat == 0) {
|
|
824
|
-
this.array.splice(_i2, 1);
|
|
825
|
-
_i2--;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
if (!x.array.length) {
|
|
829
|
-
x.small = !x.small;
|
|
830
|
-
x.array = [newOperator(Infinity)]; // if no array set zero
|
|
831
|
-
}
|
|
832
987
|
if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
|
|
988
|
+
// for any 10^a but a >log10(MSI), replace to regular 10^a
|
|
833
989
|
if (this.getOperator(1) >= 1 && this.getOperator(0) < MSI_LOG10) {
|
|
834
990
|
this.setOperator(this.getOperator(1) - 1, 1);
|
|
835
991
|
this.setOperator(Math.pow(10, this.getOperator(0)), 0);
|
|
@@ -840,13 +996,15 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
840
996
|
this.setOperator(Math.log10(this.getOperator(0)), 0);
|
|
841
997
|
renormalize = true;
|
|
842
998
|
}
|
|
999
|
+
// for a<1, turn into reciprocate
|
|
843
1000
|
if (this.array.length == 1 && this.array[0].repeat < 1) {
|
|
844
1001
|
this.array[0].repeat = 1 / this.array[0].repeat;
|
|
845
1002
|
this.small = !this.small;
|
|
846
1003
|
renormalize = true;
|
|
847
1004
|
}
|
|
848
1005
|
while (x.array.length >= 2 && x.array[0].repeat == 1 && x.array[1].repeat) {
|
|
849
|
-
//
|
|
1006
|
+
// for any 10{X}10{X} 1, turn into 10{x}10
|
|
1007
|
+
// [1, [R=sth, A=sth, E=sth, M=sth]]
|
|
850
1008
|
if (x.array[1].repeat > 1) {
|
|
851
1009
|
x.array[1].repeat--;
|
|
852
1010
|
} else {
|
|
@@ -856,19 +1014,18 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
856
1014
|
renormalize = true;
|
|
857
1015
|
}
|
|
858
1016
|
if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1) {
|
|
1017
|
+
// for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
|
|
859
1018
|
// [1e9, [R=1, A=2, sth, sth]]
|
|
860
1019
|
x.array.splice(1, 1, newOperator(x.array[0].repeat, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
|
|
861
1020
|
x.array[0].repeat = 10;
|
|
862
1021
|
renormalize = true;
|
|
863
1022
|
}
|
|
864
|
-
for (
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
renormalize = true;
|
|
871
|
-
}
|
|
1023
|
+
// for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
|
|
1024
|
+
if (x.array.length >= 2 && x.array[1].repeat > MSI) {
|
|
1025
|
+
x.array[1].arrow++;
|
|
1026
|
+
x.array[0].repeat = x.array[1].repeat;
|
|
1027
|
+
x.array[1].repeat = 1;
|
|
1028
|
+
renormalize = true;
|
|
872
1029
|
}
|
|
873
1030
|
} while (renormalize);
|
|
874
1031
|
return this;
|
|
@@ -976,7 +1133,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
976
1133
|
if (this.eq(PowiainaNum.ZERO)) return "0";
|
|
977
1134
|
return "/".concat(this.rec().toString());
|
|
978
1135
|
}
|
|
979
|
-
if (this.
|
|
1136
|
+
if (this.isInfi()) return "Infinity";
|
|
980
1137
|
// O^a (10{arrow,expans,megota})^repeation base
|
|
981
1138
|
var res = "";
|
|
982
1139
|
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
@@ -1059,6 +1216,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1059
1216
|
value: function cbrt(t) {
|
|
1060
1217
|
return new PowiainaNum(t).cbrt();
|
|
1061
1218
|
}
|
|
1219
|
+
}, {
|
|
1220
|
+
key: "tetrate",
|
|
1221
|
+
value: function tetrate(t, other2) {
|
|
1222
|
+
var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1223
|
+
return new PowiainaNum(t).tetrate(other2, payload);
|
|
1224
|
+
}
|
|
1062
1225
|
}, {
|
|
1063
1226
|
key: "log10",
|
|
1064
1227
|
value: function log10(t) {
|
|
@@ -1092,6 +1255,41 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1092
1255
|
var principal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1093
1256
|
return new PowiainaNum(x).lambertw(principal);
|
|
1094
1257
|
}
|
|
1258
|
+
}, {
|
|
1259
|
+
key: "tetrate_10",
|
|
1260
|
+
value: function tetrate_10(other2) {
|
|
1261
|
+
return PowiainaNum.fromNumber(10).tetrate(other2);
|
|
1262
|
+
/*
|
|
1263
|
+
const other = new PowiainaNum(other2);
|
|
1264
|
+
const height_int = other.trunc().toNumber();
|
|
1265
|
+
const height_frac = other.sub(height_int).toNumber();
|
|
1266
|
+
if (other.gt(PowiainaNum.PENTATED_MSI))
|
|
1267
|
+
return other.clone();
|
|
1268
|
+
else if (other.gt(PowiainaNum.MSI)) {
|
|
1269
|
+
other.setOperator(other.getOperator(2)+1, 2);
|
|
1270
|
+
} else if (other.lt(-2))
|
|
1271
|
+
return PowiainaNum.NaN.clone();
|
|
1272
|
+
else if (other.lt(-1)) {
|
|
1273
|
+
return other.add(2).log10();
|
|
1274
|
+
}
|
|
1275
|
+
else if (other.lt(0)) {
|
|
1276
|
+
return other.add(1);
|
|
1277
|
+
}else if (other.lt(1)) {
|
|
1278
|
+
return other.pow10() // 10^x
|
|
1279
|
+
}else if (height_int==1)
|
|
1280
|
+
return PowiainaNum.pow(10,PowiainaNum.pow(10,height_frac));
|
|
1281
|
+
else if (height_int==2)
|
|
1282
|
+
return PowiainaNum.pow(10,PowiainaNum.pow(10,PowiainaNum.pow(10,height_frac)));
|
|
1283
|
+
else {
|
|
1284
|
+
const remain = height_int-2;
|
|
1285
|
+
let a = PowiainaNum.pow(10,PowiainaNum.pow(10,PowiainaNum.pow(10,height_frac)));
|
|
1286
|
+
a.setOperator(a.getOperator(1)+remain, 1);
|
|
1287
|
+
return a;
|
|
1288
|
+
}
|
|
1289
|
+
// 1--2, 10-<1e10, 10^10^0->1
|
|
1290
|
+
// 2--3, 1e10-<e1e10, 10^10^10^0->1
|
|
1291
|
+
return PowiainaNum.NaN.clone();*/
|
|
1292
|
+
}
|
|
1095
1293
|
}, {
|
|
1096
1294
|
key: "isNaN",
|
|
1097
1295
|
value: function isNaN(x) {
|
|
@@ -1102,7 +1300,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1102
1300
|
value: function fromNumber(x) {
|
|
1103
1301
|
var obj = new PowiainaNum(); // NaN
|
|
1104
1302
|
if (x < 0) obj.sign = -1; // negative
|
|
1105
|
-
else if (x == 0)
|
|
1303
|
+
else if (x == 0) {
|
|
1304
|
+
obj.sign = 0;
|
|
1305
|
+
obj.small = true;
|
|
1306
|
+
obj.array = [newOperator(Infinity, 0)];
|
|
1307
|
+
return obj;
|
|
1308
|
+
} else if (x > 0) obj.sign = 1;
|
|
1106
1309
|
var y = Math.abs(x);
|
|
1107
1310
|
if (y >= MSI_REC && y < 1) {
|
|
1108
1311
|
obj.small = true;
|
|
@@ -1225,7 +1428,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1225
1428
|
a = input.split(/[Ee]/);
|
|
1226
1429
|
b = [x.array[0].repeat, 0];
|
|
1227
1430
|
c = 1;
|
|
1228
|
-
for (var
|
|
1431
|
+
for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
|
|
1229
1432
|
//The things that are already there
|
|
1230
1433
|
if (b[0] < MSI_LOG10 && b[1] === 0) {
|
|
1231
1434
|
b[0] = Math.pow(10, c * b[0]);
|
|
@@ -1242,12 +1445,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
1242
1445
|
b[1]++;
|
|
1243
1446
|
}
|
|
1244
1447
|
//Multiplying coefficient
|
|
1245
|
-
var decimalPointPos = a[
|
|
1246
|
-
var intPartLen = decimalPointPos == -1 ? a[
|
|
1448
|
+
var decimalPointPos = a[_i2].indexOf(".");
|
|
1449
|
+
var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
|
|
1247
1450
|
if (b[1] === 0) {
|
|
1248
|
-
if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(a[
|
|
1451
|
+
if (intPartLen >= LONG_STRING_MIN_LENGTH) b[0] = Math.log10(b[0]) + log10LongString(a[_i2].substring(0, intPartLen)), b[1] = 1;else if (a[_i2]) b[0] *= Number(a[_i2]);
|
|
1249
1452
|
} else {
|
|
1250
|
-
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[
|
|
1453
|
+
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
|
|
1251
1454
|
if (b[1] == 1) {
|
|
1252
1455
|
b[0] += d;
|
|
1253
1456
|
} else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
|
|
@@ -1371,6 +1574,27 @@ PowiainaNum.TETRATED_MSI = new PowiainaNum({
|
|
|
1371
1574
|
layer: 0,
|
|
1372
1575
|
sign: 1
|
|
1373
1576
|
});
|
|
1577
|
+
PowiainaNum.PENTATED_MSI = new PowiainaNum({
|
|
1578
|
+
array: [{
|
|
1579
|
+
arrow: 0,
|
|
1580
|
+
expans: 1,
|
|
1581
|
+
megota: 1,
|
|
1582
|
+
repeat: MSI
|
|
1583
|
+
}, {
|
|
1584
|
+
arrow: 1,
|
|
1585
|
+
expans: 1,
|
|
1586
|
+
megota: 1,
|
|
1587
|
+
repeat: MSI
|
|
1588
|
+
}, {
|
|
1589
|
+
arrow: 2,
|
|
1590
|
+
expans: 1,
|
|
1591
|
+
megota: 1,
|
|
1592
|
+
repeat: MSI
|
|
1593
|
+
}],
|
|
1594
|
+
small: false,
|
|
1595
|
+
layer: 0,
|
|
1596
|
+
sign: 1
|
|
1597
|
+
});
|
|
1374
1598
|
PowiainaNum.TRITRI = new PowiainaNum({
|
|
1375
1599
|
small: false,
|
|
1376
1600
|
layer: 0,
|