powiaina_num.js 0.2.25 → 0.2.26
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/dist/PowiainaNum.cjs.js +78 -74
- package/dist/PowiainaNum.esm.js +78 -74
- package/dist/PowiainaNum.js +78 -74
- package/dist/PowiainaNum.min.js +1 -1
- package/dist/index.d.ts +4 -1
- package/package.json +1 -1
package/dist/PowiainaNum.cjs.js
CHANGED
|
@@ -101,7 +101,6 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/* Author: VeryrrDefine 0.2.16*/
|
|
104
|
-
var _a;
|
|
105
104
|
//#endregion
|
|
106
105
|
//#region constants
|
|
107
106
|
var powiainaNumError = "[PowiainaNum 0.2 error]";
|
|
@@ -168,7 +167,7 @@ function parseLegacyPowiainaNumString(str) {
|
|
|
168
167
|
array: JSON.parse(match[3])
|
|
169
168
|
};
|
|
170
169
|
}
|
|
171
|
-
} catch (
|
|
170
|
+
} catch (_a) {
|
|
172
171
|
return null;
|
|
173
172
|
}
|
|
174
173
|
return null;
|
|
@@ -451,7 +450,6 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
451
450
|
*/
|
|
452
451
|
function PowiainaNum(arg1) {
|
|
453
452
|
_classCallCheck(this, PowiainaNum);
|
|
454
|
-
this[_a] = "PowiainaNum";
|
|
455
453
|
this.array = [{
|
|
456
454
|
arrow: 0,
|
|
457
455
|
expans: 1,
|
|
@@ -462,28 +460,36 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
462
460
|
this.sign = 0;
|
|
463
461
|
this.layer = 0;
|
|
464
462
|
if (PowiainaNum.blankArgumentConstructorReturnZero) {
|
|
465
|
-
this.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
463
|
+
this.array = [{
|
|
464
|
+
arrow: 0,
|
|
465
|
+
expans: 1,
|
|
466
|
+
megota: 1,
|
|
467
|
+
repeat: Infinity
|
|
468
|
+
}];
|
|
469
|
+
this.small = true;
|
|
470
|
+
}
|
|
471
|
+
if (arg1 !== undefined) {
|
|
472
|
+
try {
|
|
473
|
+
if (typeof arg1 == "undefined") {} else if (typeof arg1 == "number") {
|
|
474
|
+
var obj = PowiainaNum.fromNumber(arg1);
|
|
475
|
+
this.resetFromObject(obj);
|
|
476
|
+
} else if (_typeof(arg1) == "object") {
|
|
477
|
+
var _obj = PowiainaNum.fromObject(arg1);
|
|
478
|
+
this.resetFromObject(_obj);
|
|
479
|
+
} else if (typeof arg1 == "string") {
|
|
480
|
+
var _obj2 = PowiainaNum.fromString(arg1);
|
|
481
|
+
this.resetFromObject(_obj2);
|
|
482
|
+
} else if (typeof arg1 == "bigint") {
|
|
483
|
+
var _obj3 = PowiainaNum.fromBigInt(arg1);
|
|
484
|
+
this.resetFromObject(_obj3);
|
|
485
|
+
} else {
|
|
486
|
+
var isn = arg1;
|
|
487
|
+
}
|
|
488
|
+
} catch (e) {
|
|
489
|
+
console.error("Malformed input");
|
|
490
|
+
console.error(e);
|
|
491
|
+
if (PowiainaNum.throwErrorOnResultNaN && PowiainaNum.isNaN(this)) throw new Error("NaN");
|
|
482
492
|
}
|
|
483
|
-
} catch (e) {
|
|
484
|
-
console.error("Malformed input");
|
|
485
|
-
console.error(e);
|
|
486
|
-
if (PowiainaNum.throwErrorOnResultNaN && PowiainaNum.isNaN(this)) throw new Error("NaN");
|
|
487
493
|
}
|
|
488
494
|
}
|
|
489
495
|
//#region 4 Basic calculates.
|
|
@@ -494,7 +500,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
494
500
|
return _createClass(PowiainaNum, [{
|
|
495
501
|
key: "add",
|
|
496
502
|
value: function add(other) {
|
|
497
|
-
var _b, _c, _d
|
|
503
|
+
var _a, _b, _c, _d;
|
|
498
504
|
var x = this.clone().normalize();
|
|
499
505
|
var y = new PowiainaNum(other);
|
|
500
506
|
// inf + -inf = nan
|
|
@@ -543,12 +549,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
543
549
|
}
|
|
544
550
|
var signMult = 1;
|
|
545
551
|
/**Calculate numbers [1, 9e15] (useless) */
|
|
546
|
-
if (!a.small && !b.small && !((
|
|
552
|
+
if (!a.small && !b.small && !((_a = a.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) && !((_b = b.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) && a.sign == b.sign) {
|
|
547
553
|
return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
|
|
548
554
|
}
|
|
549
555
|
// Calculate a & b's 10-logarithm
|
|
550
|
-
var alog10 = (a.small ? -1 : 1) * (((
|
|
551
|
-
var blog10 = (b.small ? -1 : 1) * (((
|
|
556
|
+
var alog10 = (a.small ? -1 : 1) * (((_c = a.array[1]) === null || _c === void 0 ? void 0 : _c.repeat) ? a.array[0].repeat : Math.log10(a.array[0].repeat));
|
|
557
|
+
var blog10 = (b.small ? -1 : 1) * (((_d = b.array[1]) === null || _d === void 0 ? void 0 : _d.repeat) ? b.array[0].repeat : Math.log10(b.array[0].repeat));
|
|
552
558
|
if (alog10 - blog10 > MSI_LOG10) return a;
|
|
553
559
|
/**
|
|
554
560
|
* Offset, a number can make 10^ a+off calculatable not very small or big
|
|
@@ -664,7 +670,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
664
670
|
* @returns 10 to the power of `this`
|
|
665
671
|
*/
|
|
666
672
|
function pow10() {
|
|
667
|
-
var
|
|
673
|
+
var _a, _b;
|
|
668
674
|
var thisObject = this.clone();
|
|
669
675
|
// inf & nan check
|
|
670
676
|
if (!this.isFinite()) return this.clone();
|
|
@@ -686,7 +692,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
686
692
|
/** indistinguishable above 10^^9e15 */
|
|
687
693
|
if (thisObject.gt(PowiainaNum.TETRATED_MSI)) return thisObject;
|
|
688
694
|
/**otherwise add 10^ directly */
|
|
689
|
-
thisObject.setOperator(((
|
|
695
|
+
thisObject.setOperator(((_b = (_a = thisObject.array[1]) === null || _a === void 0 ? void 0 : _a.repeat) !== null && _b !== void 0 ? _b : 0) + 1, 1);
|
|
690
696
|
thisObject.normalize();
|
|
691
697
|
return thisObject;
|
|
692
698
|
}
|
|
@@ -854,9 +860,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
854
860
|
return this.rec();
|
|
855
861
|
} else if (this.lte(MSI)) {
|
|
856
862
|
if (this.lt(24)) {
|
|
857
|
-
return PowiainaNum.fromNumber(f_gamma(this.sign * this.
|
|
863
|
+
return PowiainaNum.fromNumber(f_gamma(this.sign * this.array[0].repeat));
|
|
858
864
|
}
|
|
859
|
-
var t = this.
|
|
865
|
+
var t = this.array[0].repeat - 1;
|
|
860
866
|
var l = 0.9189385332046727; //0.5*Math.log(2*Math.PI)
|
|
861
867
|
l = l + (t + 0.5) * Math.log(t);
|
|
862
868
|
l = l - t;
|
|
@@ -915,7 +921,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
915
921
|
if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
|
|
916
922
|
return PowiainaNum.fromNumber(f_lambertw(this.toNumber()));
|
|
917
923
|
} else if (this.lt(MSI)) {
|
|
918
|
-
return PowiainaNum.fromNumber(f_lambertw(this.sign * this.
|
|
924
|
+
return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat));
|
|
919
925
|
} else if (this.lt("eee15")) {
|
|
920
926
|
return d_lambertw(this);
|
|
921
927
|
} else {
|
|
@@ -2184,12 +2190,12 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2184
2190
|
//#endregion
|
|
2185
2191
|
//#region judge-numbers
|
|
2186
2192
|
function () {
|
|
2187
|
-
return isNaN(this.
|
|
2193
|
+
return isNaN(this.array[0].repeat);
|
|
2188
2194
|
})
|
|
2189
2195
|
}, {
|
|
2190
2196
|
key: "isZero",
|
|
2191
2197
|
value: function isZero() {
|
|
2192
|
-
return Boolean(this.small && !isFinite(this.
|
|
2198
|
+
return Boolean(this.small && !isFinite(this.array[0].repeat));
|
|
2193
2199
|
}
|
|
2194
2200
|
}, {
|
|
2195
2201
|
key: "isFinite",
|
|
@@ -2202,7 +2208,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2202
2208
|
};
|
|
2203
2209
|
return isFinite;
|
|
2204
2210
|
}(function () {
|
|
2205
|
-
return Boolean(this.small || isFinite(this.
|
|
2211
|
+
return Boolean(this.small || isFinite(this.array[0].repeat)) && !this.isNaN();
|
|
2206
2212
|
})
|
|
2207
2213
|
}, {
|
|
2208
2214
|
key: "isInfi",
|
|
@@ -2218,7 +2224,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2218
2224
|
key: "isInt",
|
|
2219
2225
|
value: function isInt() {
|
|
2220
2226
|
if (this.isZero()) return true;
|
|
2221
|
-
if (!this.small && Number.isInteger(this.
|
|
2227
|
+
if (!this.small && Number.isInteger(this.array[0].repeat)) return true;
|
|
2222
2228
|
if (this.abs().gte(MSI / 2)) return true;
|
|
2223
2229
|
return false;
|
|
2224
2230
|
}
|
|
@@ -2288,7 +2294,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2288
2294
|
if (this.sign == -1) return -this.neg().toNumber();
|
|
2289
2295
|
if (this.small) return 1 / this.rec().toNumber();
|
|
2290
2296
|
if (this.gte("e308.25471555991675")) return Infinity;
|
|
2291
|
-
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.
|
|
2297
|
+
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.array[0].repeat);
|
|
2292
2298
|
return NaN;
|
|
2293
2299
|
}
|
|
2294
2300
|
/**
|
|
@@ -2328,7 +2334,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2328
2334
|
value: function toString() {
|
|
2329
2335
|
try {
|
|
2330
2336
|
return this.toString_core();
|
|
2331
|
-
} catch (
|
|
2337
|
+
} catch (_a) {
|
|
2332
2338
|
console.error("Checked error when converting to string");
|
|
2333
2339
|
return "NaN";
|
|
2334
2340
|
}
|
|
@@ -2493,9 +2499,9 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2493
2499
|
renormalize = true;
|
|
2494
2500
|
}
|
|
2495
2501
|
// for any a but a > MSI, replace to 10^a.
|
|
2496
|
-
if (this.
|
|
2502
|
+
if (this.array[0].repeat > MSI && isFinite(this.array[0].repeat)) {
|
|
2497
2503
|
this.setOperator(this.getOperator(1) + 1, 1);
|
|
2498
|
-
this.setOperator(Math.log10(this.
|
|
2504
|
+
this.setOperator(Math.log10(this.array[0].repeat), 0);
|
|
2499
2505
|
renormalize = true;
|
|
2500
2506
|
}
|
|
2501
2507
|
// if an operator megota > MSI, layer++
|
|
@@ -2608,13 +2614,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2608
2614
|
}
|
|
2609
2615
|
this.array = [];
|
|
2610
2616
|
for (var i = 0; i < powlikeObject.array.length; i++) {
|
|
2611
|
-
this.array[i] = {
|
|
2612
|
-
arrow: powlikeObject.array[i].arrow,
|
|
2613
|
-
expans: powlikeObject.array[i].expans,
|
|
2614
|
-
megota: powlikeObject.array[i].megota,
|
|
2615
|
-
repeat: powlikeObject.array[i].repeat,
|
|
2616
|
-
valuereplaced: powlikeObject.array[i].valuereplaced
|
|
2617
|
-
};
|
|
2617
|
+
this.array[i] = Object.assign({}, powlikeObject.array[i]);
|
|
2618
2618
|
}
|
|
2619
2619
|
this.small = powlikeObject.small;
|
|
2620
2620
|
this.sign = powlikeObject.sign;
|
|
@@ -2870,7 +2870,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2870
2870
|
}, {
|
|
2871
2871
|
key: "omegacollect",
|
|
2872
2872
|
value: function omegacollect(operators) {
|
|
2873
|
-
var
|
|
2873
|
+
var _a;
|
|
2874
2874
|
// const result = {
|
|
2875
2875
|
// bottom: NaN,
|
|
2876
2876
|
// top: NaN,
|
|
@@ -2888,7 +2888,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
2888
2888
|
operators[0].repeat = Math.log10(base);
|
|
2889
2889
|
PowiainaNum.opSetOperator(operators, PowiainaNum.opGetOperator(operators, 1, 1, 1) + 1, 1, 1, 1);
|
|
2890
2890
|
} else {
|
|
2891
|
-
if (operators.length <= 2 && ((
|
|
2891
|
+
if (operators.length <= 2 && ((_a = operators[1]) === null || _a === void 0 ? void 0 : _a.repeat) == 1) {
|
|
2892
2892
|
return operators;
|
|
2893
2893
|
}
|
|
2894
2894
|
// Operator upgrade mode:
|
|
@@ -3056,8 +3056,8 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
3056
3056
|
var base = new PowiainaNum(base2);
|
|
3057
3057
|
var power = new PowiainaNum(power2);
|
|
3058
3058
|
function readArg(a) {
|
|
3059
|
-
var
|
|
3060
|
-
return new PowiainaNum((
|
|
3059
|
+
var _a;
|
|
3060
|
+
return new PowiainaNum((_a = [arrow2, expans2, megota2, powiaina2][a]) !== null && _a !== void 0 ? _a : 1);
|
|
3061
3061
|
}
|
|
3062
3062
|
if (base.eq(1)) return new PowiainaNum(1);
|
|
3063
3063
|
if (power.eq(1)) return new PowiainaNum(base);
|
|
@@ -3493,23 +3493,25 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
3493
3493
|
}, {
|
|
3494
3494
|
key: "fromString_core",
|
|
3495
3495
|
value: function fromString_core(input) {
|
|
3496
|
-
var _b, _c, _d, _e, _f
|
|
3496
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3497
3497
|
var x = new PowiainaNum(NaN);
|
|
3498
3498
|
// Judge the string was a number
|
|
3499
3499
|
if (input.startsWith("PN")) input = input.substring(2);
|
|
3500
3500
|
if (input == "NaN") return PowiainaNum.NaN.clone();
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3501
|
+
if (!PowiainaNum.vanilla) {
|
|
3502
|
+
input = input.replace(/J\^(\d+)/g, "(10{!})^$1");
|
|
3503
|
+
input = input.replace(/J/g, "10{!}");
|
|
3504
|
+
input = input.replace(/K\^(\d+)/g, "(10{1,2})^$1");
|
|
3505
|
+
input = input.replace(/K/g, "10{1,2}");
|
|
3506
|
+
input = input.replace(/L\^(\d+)/g, "(10{2,2})^$1");
|
|
3507
|
+
input = input.replace(/L/g, "10{2,2}");
|
|
3508
|
+
input = input.replace(/M\^(\d+)/g, "(10{!,2})^$1");
|
|
3509
|
+
input = input.replace(/M/g, "10{!,2}");
|
|
3510
|
+
input = input.replace(/N\^(\d+)/g, "(10{1,!})^$1");
|
|
3511
|
+
input = input.replace(/N/g, "10{1,!}");
|
|
3512
|
+
if (/^.*e-.*(e|\^).*/.test(input)) {
|
|
3513
|
+
input = "/10^" + input.substring(input.indexOf("e-"));
|
|
3514
|
+
}
|
|
3513
3515
|
}
|
|
3514
3516
|
if (!isNaN(Number(input))) {
|
|
3515
3517
|
var res = Number(input);
|
|
@@ -3566,8 +3568,8 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
3566
3568
|
x.normalize();
|
|
3567
3569
|
return x;
|
|
3568
3570
|
}
|
|
3569
|
-
input = replaceETo10(input);
|
|
3570
|
-
input = removeCommasOutsideBraces(input);
|
|
3571
|
+
if (!PowiainaNum.vanilla) input = replaceETo10(input);
|
|
3572
|
+
if (!PowiainaNum.vanilla) input = removeCommasOutsideBraces(input);
|
|
3571
3573
|
if (!isPowiainaNum.test(input)) {
|
|
3572
3574
|
throw powiainaNumError + "malformed input: " + input;
|
|
3573
3575
|
}
|
|
@@ -3576,13 +3578,13 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
3576
3578
|
if (input[0] == "-" || input[0] == "+") {
|
|
3577
3579
|
var numSigns = input.search(/[^-\+]/);
|
|
3578
3580
|
var signs = input.substring(0, numSigns);
|
|
3579
|
-
negateIt = ((
|
|
3581
|
+
negateIt = ((_b = (_a = signs.match(/-/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) % 2 == 1;
|
|
3580
3582
|
input = input.substring(numSigns);
|
|
3581
3583
|
}
|
|
3582
3584
|
if (input[0] == "/") {
|
|
3583
3585
|
var _numSigns = input.search(/[^\/]/);
|
|
3584
3586
|
var _signs = input.substring(0, _numSigns);
|
|
3585
|
-
recipIt = ((
|
|
3587
|
+
recipIt = ((_d = (_c = _signs.match(/\//g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) % 2 == 1;
|
|
3586
3588
|
input = input.substring(_numSigns);
|
|
3587
3589
|
}
|
|
3588
3590
|
if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
|
|
@@ -3627,8 +3629,8 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
3627
3629
|
// select contents between {...}
|
|
3628
3630
|
var tmp = input.substring(3, _a3).split(",");
|
|
3629
3631
|
arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
|
|
3630
|
-
expans = Number((
|
|
3631
|
-
megota = Number((
|
|
3632
|
+
expans = Number((_e = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _e !== void 0 ? _e : 1);
|
|
3633
|
+
megota = Number((_f = tmp[2]) !== null && _f !== void 0 ? _f : 1);
|
|
3632
3634
|
b = _a3 + 1;
|
|
3633
3635
|
// b points to after }.
|
|
3634
3636
|
}
|
|
@@ -3788,9 +3790,7 @@ var PowiainaNum = /*#__PURE__*/function () {
|
|
|
3788
3790
|
}
|
|
3789
3791
|
}
|
|
3790
3792
|
}]);
|
|
3791
|
-
}();
|
|
3792
|
-
_a = Symbol.toStringTag;
|
|
3793
|
-
//#endregion
|
|
3793
|
+
}(); //#endregion
|
|
3794
3794
|
//#region constants
|
|
3795
3795
|
/**
|
|
3796
3796
|
* Zero
|
|
@@ -4018,6 +4018,10 @@ PowiainaNum.blankArgumentConstructorReturnZero = false;
|
|
|
4018
4018
|
* If you set this config to true, when calucation returns NaN, the program will throw error.
|
|
4019
4019
|
*/
|
|
4020
4020
|
PowiainaNum.throwErrorOnResultNaN = false;
|
|
4021
|
+
/**
|
|
4022
|
+
* If you set this config to true, it will turn off replacement of string, e.g replace e^x to 10^^x
|
|
4023
|
+
*/
|
|
4024
|
+
PowiainaNum.vanilla = false;
|
|
4021
4025
|
|
|
4022
4026
|
exports.arraySortFunction = arraySortFunction;
|
|
4023
4027
|
exports["default"] = PowiainaNum;
|