powiaina_num.js 0.2.0 → 0.2.1
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 +2347 -2116
- package/dist/PowiainaNum.esm.js +2347 -2116
- package/dist/PowiainaNum.js +2347 -2144
- package/dist/PowiainaNum.min.js +1 -1
- package/package.json +1 -1
package/dist/PowiainaNum.esm.js
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _arrayLikeToArray(r, a) {
|
|
2
|
+
(null == a || a > r.length) && (a = r.length);
|
|
3
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
4
|
+
return n;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithoutHoles(r) {
|
|
7
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
8
|
+
}
|
|
9
|
+
function _classCallCheck(a, n) {
|
|
10
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(e, r) {
|
|
13
|
+
for (var t = 0; t < r.length; t++) {
|
|
14
|
+
var o = r[t];
|
|
15
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function _createClass(e, r, t) {
|
|
19
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
20
|
+
writable: !1
|
|
21
|
+
}), e;
|
|
22
|
+
}
|
|
23
|
+
function _iterableToArray(r) {
|
|
24
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
25
|
+
}
|
|
26
|
+
function _nonIterableSpread() {
|
|
27
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
28
|
+
}
|
|
29
|
+
function _toConsumableArray(r) {
|
|
30
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
31
|
+
}
|
|
32
|
+
function _toPrimitive(t, r) {
|
|
33
|
+
if ("object" != typeof t || !t) return t;
|
|
34
|
+
var e = t[Symbol.toPrimitive];
|
|
35
|
+
if (void 0 !== e) {
|
|
36
|
+
var i = e.call(t, r || "default");
|
|
37
|
+
if ("object" != typeof i) return i;
|
|
38
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
39
|
+
}
|
|
40
|
+
return ("string" === r ? String : Number)(t);
|
|
41
|
+
}
|
|
42
|
+
function _toPropertyKey(t) {
|
|
43
|
+
var i = _toPrimitive(t, "string");
|
|
44
|
+
return "symbol" == typeof i ? i : i + "";
|
|
45
|
+
}
|
|
3
46
|
function _typeof(o) {
|
|
4
47
|
"@babel/helpers - typeof";
|
|
5
48
|
|
|
@@ -9,7 +52,16 @@ function _typeof(o) {
|
|
|
9
52
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
10
53
|
}, _typeof(o);
|
|
11
54
|
}
|
|
55
|
+
function _unsupportedIterableToArray(r, a) {
|
|
56
|
+
if (r) {
|
|
57
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
58
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
59
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
12
62
|
|
|
63
|
+
/* Author: VeryrrDefine 0.2.0-beta.1.1*/
|
|
64
|
+
var _a;
|
|
13
65
|
var powiainaNumError = "[PowiainaNum 0.2 error]";
|
|
14
66
|
var MSI = 9007199254740991;
|
|
15
67
|
var MSI_LOG10 = 15.954589770191003;
|
|
@@ -18,16 +70,10 @@ var LONG_STRING_MIN_LENGTH = 17;
|
|
|
18
70
|
var EXP_E_REC = 1.444667861009766;
|
|
19
71
|
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+))$/;
|
|
20
72
|
//#region some useful functions
|
|
21
|
-
function newOperator(r
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (e === void 0) {
|
|
26
|
-
e = 1;
|
|
27
|
-
}
|
|
28
|
-
if (m === void 0) {
|
|
29
|
-
m = 1;
|
|
30
|
-
}
|
|
73
|
+
function newOperator(r) {
|
|
74
|
+
var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
75
|
+
var e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
76
|
+
var m = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
31
77
|
return {
|
|
32
78
|
repeat: r,
|
|
33
79
|
arrow: a,
|
|
@@ -37,9 +83,8 @@ function newOperator(r, a, e, m) {
|
|
|
37
83
|
};
|
|
38
84
|
}
|
|
39
85
|
function compareTuples() {
|
|
40
|
-
var tuples =
|
|
41
|
-
|
|
42
|
-
tuples[_i] = arguments[_i];
|
|
86
|
+
for (var _len = arguments.length, tuples = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
87
|
+
tuples[_key] = arguments[_key];
|
|
43
88
|
}
|
|
44
89
|
for (var i = 0; i < Math.min(tuples[0].length, tuples[1].length); i++) {
|
|
45
90
|
var a = tuples[0][i];
|
|
@@ -105,13 +150,7 @@ var OMEGA = 0.56714329040978387299997; // W(1, 0)
|
|
|
105
150
|
//from https://math.stackexchange.com/a/465183
|
|
106
151
|
// The evaluation can become inaccurate very close to the branch point
|
|
107
152
|
// Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
|
|
108
|
-
function f_lambertw(z
|
|
109
|
-
if (t === void 0) {
|
|
110
|
-
t = 1e-10;
|
|
111
|
-
}
|
|
112
|
-
if (pr === void 0) {
|
|
113
|
-
pr = true;
|
|
114
|
-
}
|
|
153
|
+
function f_lambertw(z) {
|
|
115
154
|
var tol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-10;
|
|
116
155
|
var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
117
156
|
var w;
|
|
@@ -180,13 +219,9 @@ function countLeadingZerosAfterDecimal(numStr) {
|
|
|
180
219
|
// at ``-1/e``. In some corner cases, `lambertw` might currently
|
|
181
220
|
// fail to converge, or can end up on the wrong branch.
|
|
182
221
|
// Evaluates W(x, 0) if principal is true, W(x, -1) if principal is false
|
|
183
|
-
function d_lambertw(z
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
if (principal === void 0) {
|
|
188
|
-
principal = true;
|
|
189
|
-
}
|
|
222
|
+
function d_lambertw(z) {
|
|
223
|
+
var tol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e10;
|
|
224
|
+
var principal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
190
225
|
z = new PowiainaNum(z);
|
|
191
226
|
var w;
|
|
192
227
|
if (!z.isFinite()) return z;
|
|
@@ -227,12 +262,13 @@ function mergeSameArrays(x) {
|
|
|
227
262
|
}
|
|
228
263
|
}
|
|
229
264
|
//#endregion
|
|
230
|
-
var PowiainaNum =
|
|
265
|
+
var PowiainaNum = /*#__PURE__*/function () {
|
|
231
266
|
/**
|
|
232
267
|
* Constructor of PowiainaNum class,
|
|
233
268
|
* If no arguments, return `PowiainaNum.NaN`.
|
|
234
269
|
*/
|
|
235
270
|
function PowiainaNum(arg1) {
|
|
271
|
+
_classCallCheck(this, PowiainaNum);
|
|
236
272
|
this[_a] = "PowiainaNum";
|
|
237
273
|
this.array = [{
|
|
238
274
|
arrow: 0,
|
|
@@ -247,11 +283,11 @@ var PowiainaNum = /** @class */function () {
|
|
|
247
283
|
var obj = PowiainaNum.fromNumber(arg1);
|
|
248
284
|
this.resetFromObject(obj);
|
|
249
285
|
} else if (_typeof(arg1) == "object") {
|
|
250
|
-
var
|
|
251
|
-
this.resetFromObject(
|
|
286
|
+
var _obj = PowiainaNum.fromObject(arg1);
|
|
287
|
+
this.resetFromObject(_obj);
|
|
252
288
|
} else if (typeof arg1 == "string") {
|
|
253
|
-
var
|
|
254
|
-
this.resetFromObject(
|
|
289
|
+
var _obj2 = PowiainaNum.fromString(arg1);
|
|
290
|
+
this.resetFromObject(_obj2);
|
|
255
291
|
} else ;
|
|
256
292
|
}
|
|
257
293
|
//#region 4 Basic calculates.
|
|
@@ -259,1981 +295,1507 @@ var PowiainaNum = /** @class */function () {
|
|
|
259
295
|
* Addition
|
|
260
296
|
* @returns the sum of `this` and `other`
|
|
261
297
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
a =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
l = Math.log10(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
r.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
PowiainaNum.add = function (t, other) {
|
|
334
|
-
return new PowiainaNum(t).add(other);
|
|
335
|
-
};
|
|
336
|
-
PowiainaNum.prototype.sub = function (a) {
|
|
337
|
-
return this.add(new PowiainaNum(a).neg());
|
|
338
|
-
};
|
|
339
|
-
PowiainaNum.sub = function (t, other) {
|
|
340
|
-
return new PowiainaNum(t).sub(other);
|
|
341
|
-
};
|
|
342
|
-
PowiainaNum.prototype.mul = function (other) {
|
|
343
|
-
var x = this.clone();
|
|
344
|
-
var y = new PowiainaNum(other);
|
|
345
|
-
// inf * -inf = -inf
|
|
346
|
-
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();
|
|
347
|
-
if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
|
|
348
|
-
if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
349
|
-
// inf & nan check
|
|
350
|
-
if (!x.isFinite()) return x.clone();
|
|
351
|
-
if (!y.isFinite()) return y.clone();
|
|
352
|
-
if (x.isZero() || y.isZero()) return PowiainaNum.ZERO.clone();
|
|
353
|
-
// x* x^-1 = 0
|
|
354
|
-
/* if (x.small==1-y.small&&(function(){
|
|
355
|
-
let a = x.abs();
|
|
356
|
-
let b = y.abs();
|
|
357
|
-
return a.eq(b)
|
|
358
|
-
})()) return (function () {
|
|
359
|
-
let a = new PowiainaNum(1);
|
|
360
|
-
a.sign = x.sign*y.sign as -1|0| 1;
|
|
361
|
-
return a;
|
|
362
|
-
})(); */
|
|
363
|
-
// calculate use number directly using number
|
|
364
|
-
var t = x.toNumber() * y.toNumber();
|
|
365
|
-
if (isFinite(t) && t !== 0) {
|
|
366
|
-
return PowiainaNum.fromNumber(t);
|
|
367
|
-
}
|
|
368
|
-
var r;
|
|
369
|
-
r = x.abs().log10().add(y.abs().log10()).pow10();
|
|
370
|
-
r.sign = x.sign * y.sign;
|
|
371
|
-
return r;
|
|
372
|
-
};
|
|
373
|
-
PowiainaNum.mul = function (t, other) {
|
|
374
|
-
return new PowiainaNum(t).mul(other);
|
|
375
|
-
};
|
|
376
|
-
PowiainaNum.prototype.div = function (other) {
|
|
377
|
-
var x = new PowiainaNum(other).rec();
|
|
378
|
-
return this.mul(x);
|
|
379
|
-
};
|
|
380
|
-
PowiainaNum.div = function (t, other) {
|
|
381
|
-
return new PowiainaNum(t).div(other);
|
|
382
|
-
};
|
|
383
|
-
PowiainaNum.prototype.mod = function (x) {
|
|
384
|
-
var other = new PowiainaNum(x);
|
|
385
|
-
var division = this.div(other);
|
|
386
|
-
return division.sub(division.floor()).mul(other);
|
|
387
|
-
};
|
|
388
|
-
//#endregion
|
|
389
|
-
//#region power
|
|
390
|
-
/**
|
|
391
|
-
* @returns 10 to the power of `this`
|
|
392
|
-
*/
|
|
393
|
-
PowiainaNum.prototype.pow10 = function () {
|
|
394
|
-
var _b, _c;
|
|
395
|
-
var r = this.clone();
|
|
396
|
-
// inf & nan check
|
|
397
|
-
if (!this.isFinite()) return this.clone();
|
|
398
|
-
if (r.isneg()) {
|
|
399
|
-
// 10^(-x) = 1/(10^x)
|
|
400
|
-
r.sign *= -1;
|
|
401
|
-
return r.pow10().rec();
|
|
402
|
-
}
|
|
403
|
-
if (r.lte(308.25471555991675)) {
|
|
404
|
-
return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
|
|
405
|
-
}
|
|
406
|
-
if (r.small) {
|
|
407
|
-
if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
|
|
408
|
-
return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
|
|
409
|
-
}
|
|
410
|
-
if (r.gt(PowiainaNum.TETRATED_MSI)) return r;
|
|
411
|
-
r.setOperator(((_c = (_b = r.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
|
|
412
|
-
r.normalize();
|
|
413
|
-
return r;
|
|
414
|
-
};
|
|
415
|
-
PowiainaNum.prototype.pow = function (x) {
|
|
416
|
-
var other = new PowiainaNum(x);
|
|
417
|
-
if (this.eq(1)) return PowiainaNum.ONE.clone();
|
|
418
|
-
if (!other.isFinite()) return other.clone();
|
|
419
|
-
if (!this.isFinite()) return this.clone();
|
|
420
|
-
if (this.eq(10)) return other.pow10();
|
|
421
|
-
if (this.isneg()) {
|
|
422
|
-
if (!other.isInt()) return PowiainaNum.NaN.clone();
|
|
423
|
-
var r = this.abs().pow(other);
|
|
424
|
-
r.sign = function () {
|
|
425
|
-
var a = other.mod(2).round();
|
|
426
|
-
if (a.eq(0) || a.eq(2)) return 1;
|
|
427
|
-
return -1;
|
|
428
|
-
}();
|
|
298
|
+
return _createClass(PowiainaNum, [{
|
|
299
|
+
key: "add",
|
|
300
|
+
value: function add(other) {
|
|
301
|
+
var _b, _c, _d, _e;
|
|
302
|
+
var x = this.clone();
|
|
303
|
+
var y = new PowiainaNum(other);
|
|
304
|
+
// inf + -inf = nan
|
|
305
|
+
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();
|
|
306
|
+
// inf & nan check
|
|
307
|
+
if (!x.isFinite()) return x.clone();
|
|
308
|
+
if (!y.isFinite()) return y.clone();
|
|
309
|
+
// if x or y = 0, return other.
|
|
310
|
+
if (x.isZero()) return y.clone();
|
|
311
|
+
if (y.isZero()) return x.clone();
|
|
312
|
+
// x+ -x = 0
|
|
313
|
+
if (x.sign == -y.sign && function () {
|
|
314
|
+
var a = x.abs();
|
|
315
|
+
var b = y.abs();
|
|
316
|
+
return a.eq(b);
|
|
317
|
+
}()) return PowiainaNum.ZERO.clone();
|
|
318
|
+
// Run pure number calculates in there
|
|
319
|
+
if (x.abs().lt(MSI) && y.abs().lt(MSI)) {
|
|
320
|
+
return PowiainaNum.fromNumber(x.toNumber() + y.toNumber());
|
|
321
|
+
}
|
|
322
|
+
// calculate anything > e9e15 or <e-9e15, take absval bigger.
|
|
323
|
+
if (x.abs().lt(PowiainaNum.E_MSI_REC) || x.abs().gt(PowiainaNum.E_MSI) || y.abs().lt(PowiainaNum.E_MSI_REC) || y.abs().gt(PowiainaNum.E_MSI)) {
|
|
324
|
+
return x.maxabs(y);
|
|
325
|
+
}
|
|
326
|
+
if (x.sign == -1) {
|
|
327
|
+
return x.neg().add(y.neg()).neg();
|
|
328
|
+
}
|
|
329
|
+
// if ((x.sign==1&&y.sign==-1&&x.lt(y.abs())) ) return y.neg().add(x.neg()).neg();
|
|
330
|
+
var a, b; //a=bigger, b=smaller
|
|
331
|
+
if (x.cmpabs(y) > 0) {
|
|
332
|
+
a = x;
|
|
333
|
+
b = y;
|
|
334
|
+
} else {
|
|
335
|
+
b = x;
|
|
336
|
+
a = y;
|
|
337
|
+
}
|
|
338
|
+
var temp = a.toNumber() + b.toNumber();
|
|
339
|
+
if (isFinite(temp) && temp !== 0) {
|
|
340
|
+
return PowiainaNum.fromNumber(temp);
|
|
341
|
+
}
|
|
342
|
+
var mult = 1;
|
|
343
|
+
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) {
|
|
344
|
+
return new PowiainaNum((a.array[0].repeat + b.array[0].repeat) * a.sign);
|
|
345
|
+
}
|
|
346
|
+
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));
|
|
347
|
+
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));
|
|
348
|
+
if (alog10 - blog10 > MSI_LOG10) return a;
|
|
349
|
+
var offset = -Math.floor(alog10); //a number can make a+off in [0,1)
|
|
350
|
+
var r,
|
|
351
|
+
l = 0,
|
|
352
|
+
t;
|
|
353
|
+
t = a.sign * Math.pow(10, alog10 + offset) + b.sign * Math.pow(10, blog10 + offset);
|
|
354
|
+
if (t > 0) l = Math.log10(t) - offset;
|
|
355
|
+
if (t < 0) {
|
|
356
|
+
l = Math.log10(-t) - offset;
|
|
357
|
+
mult *= -1;
|
|
358
|
+
}
|
|
359
|
+
if (t == 0) throw Error("Encounter a calculate error");
|
|
360
|
+
r = new PowiainaNum();
|
|
361
|
+
r.sign = 1;
|
|
362
|
+
if (l > MSI_LOG10 || l < -MSI_LOG10) {
|
|
363
|
+
r.array = [newOperator(l, 0), newOperator(1, 1)];
|
|
364
|
+
} else {
|
|
365
|
+
r.array = [newOperator(Math.pow(10, Math.abs(l)), 0)];
|
|
366
|
+
}
|
|
367
|
+
r.small = l < 0 ? true : false;
|
|
368
|
+
r.sign *= mult;
|
|
429
369
|
return r;
|
|
430
370
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
//
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
};
|
|
469
|
-
PowiainaNum.sqrt = function (t) {
|
|
470
|
-
return new PowiainaNum(t).sqrt();
|
|
471
|
-
};
|
|
472
|
-
PowiainaNum.prototype.cbrt = function () {
|
|
473
|
-
return this.abs().root(3).mul(this.sign);
|
|
474
|
-
};
|
|
475
|
-
PowiainaNum.cbrt = function (t) {
|
|
476
|
-
return new PowiainaNum(t).cbrt();
|
|
477
|
-
};
|
|
478
|
-
PowiainaNum.prototype.log10 = function () {
|
|
479
|
-
if (this.isneg()) return PowiainaNum.NaN.clone();
|
|
480
|
-
if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
|
|
481
|
-
if (this.small) {
|
|
482
|
-
var x_1 = this.clone();
|
|
483
|
-
x_1.small = !x_1.small;
|
|
484
|
-
return x_1.log10().neg();
|
|
485
|
-
}
|
|
486
|
-
if (this.array.length == 1) return new PowiainaNum(Math.log10(this.array[0].repeat));
|
|
487
|
-
if (this.gte(PowiainaNum.TETRATED_MSI)) return this.clone();
|
|
488
|
-
var x = this.clone();
|
|
489
|
-
x.array[1].repeat = x.array[1].repeat - 1;
|
|
490
|
-
x.normalize();
|
|
491
|
-
return x;
|
|
492
|
-
};
|
|
493
|
-
PowiainaNum.log10 = function (t) {
|
|
494
|
-
return new PowiainaNum(t).log10();
|
|
495
|
-
};
|
|
496
|
-
PowiainaNum.prototype.log = function (base) {
|
|
497
|
-
if (base === void 0) {
|
|
498
|
-
base = Math.E;
|
|
499
|
-
}
|
|
500
|
-
// log_a b = log_x b / log_x a;
|
|
501
|
-
var other = new PowiainaNum(base);
|
|
502
|
-
return this.log10().div(other.log10());
|
|
503
|
-
};
|
|
504
|
-
PowiainaNum.log = function (t, base) {
|
|
505
|
-
if (base === void 0) {
|
|
506
|
-
base = Math.E;
|
|
371
|
+
}, {
|
|
372
|
+
key: "sub",
|
|
373
|
+
value: function sub(a) {
|
|
374
|
+
return this.add(new PowiainaNum(a).neg());
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "mul",
|
|
378
|
+
value: function mul(other) {
|
|
379
|
+
var x = this.clone();
|
|
380
|
+
var y = new PowiainaNum(other);
|
|
381
|
+
// inf * -inf = -inf
|
|
382
|
+
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();
|
|
383
|
+
if (x.isInfiNaN() && y.isZero() || y.isInfiNaN() && x.isZero()) return PowiainaNum.NaN.clone();
|
|
384
|
+
if (x.eq(PowiainaNum.NEGATIVE_INFINITY) && y.eq(PowiainaNum.NEGATIVE_INFINITY)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
385
|
+
// inf & nan check
|
|
386
|
+
if (!x.isFinite()) return x.clone();
|
|
387
|
+
if (!y.isFinite()) return y.clone();
|
|
388
|
+
if (x.isZero() || y.isZero()) return PowiainaNum.ZERO.clone();
|
|
389
|
+
// x* x^-1 = 0
|
|
390
|
+
/* if (x.small==1-y.small&&(function(){
|
|
391
|
+
let a = x.abs();
|
|
392
|
+
let b = y.abs();
|
|
393
|
+
return a.eq(b)
|
|
394
|
+
})()) return (function () {
|
|
395
|
+
let a = new PowiainaNum(1);
|
|
396
|
+
a.sign = x.sign*y.sign as -1|0| 1;
|
|
397
|
+
return a;
|
|
398
|
+
})(); */
|
|
399
|
+
// calculate use number directly using number
|
|
400
|
+
var t = x.toNumber() * y.toNumber();
|
|
401
|
+
if (isFinite(t) && t !== 0) {
|
|
402
|
+
return PowiainaNum.fromNumber(t);
|
|
403
|
+
}
|
|
404
|
+
var r;
|
|
405
|
+
r = x.abs().log10().add(y.abs().log10()).pow10();
|
|
406
|
+
r.sign = x.sign * y.sign;
|
|
407
|
+
return r;
|
|
507
408
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
409
|
+
}, {
|
|
410
|
+
key: "div",
|
|
411
|
+
value: function div(other) {
|
|
412
|
+
var x = new PowiainaNum(other).rec();
|
|
413
|
+
return this.mul(x);
|
|
414
|
+
}
|
|
415
|
+
}, {
|
|
416
|
+
key: "mod",
|
|
417
|
+
value: function mod(x) {
|
|
418
|
+
var other = new PowiainaNum(x);
|
|
419
|
+
var division = this.div(other);
|
|
420
|
+
return division.sub(division.floor()).mul(other);
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region power
|
|
424
|
+
/**
|
|
425
|
+
* @returns 10 to the power of `this`
|
|
426
|
+
*/
|
|
427
|
+
}, {
|
|
428
|
+
key: "pow10",
|
|
429
|
+
value: function pow10() {
|
|
430
|
+
var _b, _c;
|
|
431
|
+
var r = this.clone();
|
|
432
|
+
// inf & nan check
|
|
433
|
+
if (!this.isFinite()) return this.clone();
|
|
434
|
+
if (r.isneg()) {
|
|
435
|
+
// 10^(-x) = 1/(10^x)
|
|
436
|
+
r.sign *= -1;
|
|
437
|
+
return r.pow10().rec();
|
|
438
|
+
}
|
|
439
|
+
if (r.lte(308.25471555991675)) {
|
|
440
|
+
return PowiainaNum.fromNumber(Math.pow(10, r.toNumber()));
|
|
441
|
+
}
|
|
442
|
+
if (r.small) {
|
|
443
|
+
if (r.lt(PowiainaNum.MSI_REC)) return PowiainaNum.ONE;
|
|
444
|
+
return new PowiainaNum(Math.pow(10, Math.pow(r.array[0].repeat, -1)));
|
|
445
|
+
}
|
|
446
|
+
if (r.gt(PowiainaNum.TETRATED_MSI)) return r;
|
|
447
|
+
r.setOperator(((_c = (_b = r.array[1]) === null || _b === void 0 ? void 0 : _b.repeat) !== null && _c !== void 0 ? _c : 0) + 1, 1);
|
|
448
|
+
r.normalize();
|
|
449
|
+
return r;
|
|
547
450
|
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
return
|
|
565
|
-
}
|
|
566
|
-
var t = this.getOperator(0) - 1;
|
|
567
|
-
var l = 0.9189385332046727; //0.5*Math.log(2*Math.PI)
|
|
568
|
-
l = l + (t + 0.5) * Math.log(t);
|
|
569
|
-
l = l - t;
|
|
570
|
-
var n2 = t * t;
|
|
571
|
-
var np = t;
|
|
572
|
-
var lm = 12 * np;
|
|
573
|
-
var adj = 1 / lm;
|
|
574
|
-
var l2 = l + adj;
|
|
575
|
-
if (l2 === l) {
|
|
576
|
-
return PowiainaNum.exp(l);
|
|
451
|
+
}, {
|
|
452
|
+
key: "pow",
|
|
453
|
+
value: function pow(x) {
|
|
454
|
+
var other = new PowiainaNum(x);
|
|
455
|
+
if (this.eq(1)) return PowiainaNum.ONE.clone();
|
|
456
|
+
if (!other.isFinite()) return other.clone();
|
|
457
|
+
if (!this.isFinite()) return this.clone();
|
|
458
|
+
if (this.eq(10)) return other.pow10();
|
|
459
|
+
if (this.isneg()) {
|
|
460
|
+
if (!other.isInt()) return PowiainaNum.NaN.clone();
|
|
461
|
+
var r = this.abs().pow(other);
|
|
462
|
+
r.sign = function () {
|
|
463
|
+
var a = other.mod(2).round();
|
|
464
|
+
if (a.eq(0) || a.eq(2)) return 1;
|
|
465
|
+
return -1;
|
|
466
|
+
}();
|
|
467
|
+
return r;
|
|
577
468
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
469
|
+
var a = this.toNumber();
|
|
470
|
+
var b = other.toNumber();
|
|
471
|
+
var t = Math.pow(a, b);
|
|
472
|
+
if (isFinite(t) && t !== 0) {
|
|
473
|
+
// optimize?
|
|
474
|
+
return PowiainaNum.fromNumber(t);
|
|
475
|
+
}
|
|
476
|
+
if (this.isZero() && other.isZero()) {
|
|
477
|
+
return PowiainaNum.ONE.clone();
|
|
478
|
+
}
|
|
479
|
+
if (this.isZero()) return PowiainaNum.ZERO.clone();
|
|
480
|
+
if (other.isZero()) return PowiainaNum.ONE.clone();
|
|
481
|
+
// if this<0, check other' rec is oddd
|
|
482
|
+
if (this.gt(0)) {
|
|
483
|
+
// log10(a^b) = b log10(a)
|
|
484
|
+
return this.log10().mul(other).pow10();
|
|
485
|
+
} else if (other.rec().mod(2).eq(1)) {
|
|
486
|
+
return this.neg().log10().mul(other).pow10().neg();
|
|
585
487
|
}
|
|
586
|
-
|
|
587
|
-
np = np * n2;
|
|
588
|
-
lm = 1260 * np;
|
|
589
|
-
var lt = 1 / lm;
|
|
590
|
-
l = l + lt;
|
|
591
|
-
np = np * n2;
|
|
592
|
-
lm = 1680 * np;
|
|
593
|
-
lt = 1 / lm;
|
|
594
|
-
l = l - lt;
|
|
595
|
-
return PowiainaNum.exp(l);
|
|
596
|
-
} else if (this.gt(MSI)) {
|
|
597
|
-
return PowiainaNum.exp(this.mul(this.log().sub(1)));
|
|
598
|
-
} else {
|
|
599
|
-
return PowiainaNum.exp(this);
|
|
488
|
+
return PowiainaNum.NaN.clone();
|
|
600
489
|
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
return
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
490
|
+
}, {
|
|
491
|
+
key: "pow_base",
|
|
492
|
+
value: function pow_base(x) {
|
|
493
|
+
var a = new PowiainaNum(x);
|
|
494
|
+
return a.pow(this);
|
|
495
|
+
}
|
|
496
|
+
}, {
|
|
497
|
+
key: "root",
|
|
498
|
+
value: function root(x) {
|
|
499
|
+
var other = new PowiainaNum(x);
|
|
500
|
+
return this.pow(other.rec());
|
|
501
|
+
}
|
|
502
|
+
}, {
|
|
503
|
+
key: "sqrt",
|
|
504
|
+
value: function sqrt() {
|
|
505
|
+
return this.pow(0.5);
|
|
506
|
+
}
|
|
507
|
+
}, {
|
|
508
|
+
key: "cbrt",
|
|
509
|
+
value: function cbrt() {
|
|
510
|
+
return this.abs().root(3).mul(this.sign);
|
|
511
|
+
}
|
|
512
|
+
}, {
|
|
513
|
+
key: "log10",
|
|
514
|
+
value: function log10() {
|
|
515
|
+
if (this.isneg()) return PowiainaNum.NaN.clone();
|
|
516
|
+
if (this.isZero()) return PowiainaNum.NEGATIVE_INFINITY.clone();
|
|
517
|
+
if (this.small) {
|
|
518
|
+
var _x = this.clone();
|
|
519
|
+
_x.small = !_x.small;
|
|
520
|
+
return _x.log10().neg();
|
|
521
|
+
}
|
|
522
|
+
if (this.array.length == 1) return new PowiainaNum(Math.log10(this.array[0].repeat));
|
|
523
|
+
if (this.gte(PowiainaNum.TETRATED_MSI)) return this.clone();
|
|
524
|
+
var x = this.clone();
|
|
525
|
+
x.array[1].repeat = x.array[1].repeat - 1;
|
|
526
|
+
x.normalize();
|
|
527
|
+
return x;
|
|
528
|
+
}
|
|
529
|
+
}, {
|
|
530
|
+
key: "log",
|
|
531
|
+
value: function log() {
|
|
532
|
+
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Math.E;
|
|
533
|
+
// log_a b = log_x b / log_x a;
|
|
534
|
+
var other = new PowiainaNum(base);
|
|
535
|
+
return this.log10().div(other.log10());
|
|
536
|
+
}
|
|
537
|
+
}, {
|
|
538
|
+
key: "ln",
|
|
539
|
+
value: function ln() {
|
|
540
|
+
return this.log();
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* positive-Log10, Returns the base-10 logarithm of nonnegative Decimals, but returns 0 for negative Decimals.
|
|
544
|
+
*/
|
|
545
|
+
}, {
|
|
546
|
+
key: "pLog10",
|
|
547
|
+
value: function pLog10() {
|
|
548
|
+
if (this.isneg()) return PowiainaNum.ZERO;
|
|
549
|
+
return this.log10();
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* positive-Log10
|
|
553
|
+
*/
|
|
554
|
+
}, {
|
|
555
|
+
key: "exp",
|
|
556
|
+
value: function exp() {
|
|
557
|
+
return this.pow_base(Math.E);
|
|
558
|
+
}
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region some math functions
|
|
561
|
+
/**
|
|
562
|
+
* For positive integers, X factorial (written as X!) equals X * (X - 1) * (X - 2) *... * 3 * 2 * 1. 0! equals 1.
|
|
563
|
+
* This can be extended to real numbers (except for negative integers) via the gamma function, which is what this function does.
|
|
564
|
+
*/
|
|
565
|
+
//[Code from break_eternity.js]
|
|
566
|
+
}, {
|
|
567
|
+
key: "factorial",
|
|
568
|
+
value: function factorial() {
|
|
569
|
+
if (this.abs().lt(MSI)) {
|
|
570
|
+
return this.add(1).gamma();
|
|
571
|
+
} else if (this.abs().lt(PowiainaNum.E_MSI)) {
|
|
572
|
+
return PowiainaNum.exp(this.mul(this.log10().sub(1)));
|
|
629
573
|
} else {
|
|
630
|
-
|
|
631
|
-
return this.log();
|
|
632
|
-
}
|
|
633
|
-
} else {
|
|
634
|
-
if (this.sign === 1) {
|
|
635
|
-
return PowiainaNum.NaN.clone(); //complex
|
|
574
|
+
return PowiainaNum.exp(this);
|
|
636
575
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
576
|
+
}
|
|
577
|
+
}, {
|
|
578
|
+
key: "gamma",
|
|
579
|
+
value:
|
|
580
|
+
/**
|
|
581
|
+
* The gamma function extends the idea of factorials to non-whole numbers using some calculus.
|
|
582
|
+
* Gamma(x) is defined as the integral of t^(x-1) * e^-t dt from t = 0 to t = infinity,
|
|
583
|
+
* and gamma(x) = (x - 1)! for nonnegative integer x, so the factorial for non-whole numbers is defined using the gamma function.
|
|
584
|
+
*/
|
|
585
|
+
//[Code from break_eternity.js]
|
|
586
|
+
//from HyperCalc source code
|
|
587
|
+
function gamma() {
|
|
588
|
+
if (this.small) {
|
|
589
|
+
return this.rec();
|
|
590
|
+
} else if (this.lte(MSI)) {
|
|
591
|
+
if (this.lt(24)) {
|
|
592
|
+
return PowiainaNum.fromNumber(f_gamma(this.sign * this.getOperator(0)));
|
|
593
|
+
}
|
|
594
|
+
var t = this.getOperator(0) - 1;
|
|
595
|
+
var l = 0.9189385332046727; //0.5*Math.log(2*Math.PI)
|
|
596
|
+
l = l + (t + 0.5) * Math.log(t);
|
|
597
|
+
l = l - t;
|
|
598
|
+
var n2 = t * t;
|
|
599
|
+
var np = t;
|
|
600
|
+
var lm = 12 * np;
|
|
601
|
+
var adj = 1 / lm;
|
|
602
|
+
var l2 = l + adj;
|
|
603
|
+
if (l2 === l) {
|
|
604
|
+
return PowiainaNum.exp(l);
|
|
605
|
+
}
|
|
606
|
+
l = l2;
|
|
607
|
+
np = np * n2;
|
|
608
|
+
lm = 360 * np;
|
|
609
|
+
adj = 1 / lm;
|
|
610
|
+
l2 = l - adj;
|
|
611
|
+
if (l2 === l) {
|
|
612
|
+
return PowiainaNum.exp(l);
|
|
613
|
+
}
|
|
614
|
+
l = l2;
|
|
615
|
+
np = np * n2;
|
|
616
|
+
lm = 1260 * np;
|
|
617
|
+
var lt = 1 / lm;
|
|
618
|
+
l = l + lt;
|
|
619
|
+
np = np * n2;
|
|
620
|
+
lm = 1680 * np;
|
|
621
|
+
lt = 1 / lm;
|
|
622
|
+
l = l - lt;
|
|
623
|
+
return PowiainaNum.exp(l);
|
|
624
|
+
} else if (this.gt(MSI)) {
|
|
625
|
+
return PowiainaNum.exp(this.mul(this.log().sub(1)));
|
|
641
626
|
} else {
|
|
642
|
-
return
|
|
627
|
+
return PowiainaNum.exp(this);
|
|
643
628
|
}
|
|
644
629
|
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
if (other.lte(-2)) return PowiainaNum.NaN.clone();
|
|
673
|
-
if (t.isZero()) {
|
|
674
|
-
if (other.isZero()) return PowiainaNum.NaN.clone();
|
|
675
|
-
if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
|
|
676
|
-
return PowiainaNum.ONE.clone();
|
|
677
|
-
}
|
|
678
|
-
if (t.eq(PowiainaNum.ONE)) {
|
|
679
|
-
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
|
|
680
|
-
return PowiainaNum.ONE.clone();
|
|
681
|
-
}
|
|
682
|
-
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
|
|
683
|
-
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
684
|
-
if (other.eq(PowiainaNum.ONE)) return t;
|
|
685
|
-
if (other.eq(2)) return t.pow(t);
|
|
686
|
-
if (t.eq(2)) {
|
|
687
|
-
if (other.eq(3)) return PowiainaNum.fromNumber(16);
|
|
688
|
-
if (other.eq(4)) return PowiainaNum.fromNumber(65536);
|
|
689
|
-
}
|
|
690
|
-
var m = t.max(other);
|
|
691
|
-
if (m.gt(PowiainaNum.PENTATED_MSI)) return m;
|
|
692
|
-
if (m.gt(PowiainaNum.TETRATED_MSI) || other.gt(MSI)) {
|
|
693
|
-
if (this.lt(EXP_E_REC)) {
|
|
694
|
-
negln = t.ln().neg();
|
|
695
|
-
return negln.lambertw().div(negln);
|
|
696
|
-
}
|
|
697
|
-
var j = t.slog(10).add(other);
|
|
698
|
-
j.setOperator(j.getOperator(2) + 1, 2);
|
|
699
|
-
j.normalize();
|
|
700
|
-
return j;
|
|
701
|
-
}
|
|
702
|
-
var y = other.toNumber();
|
|
703
|
-
var f = Math.floor(y);
|
|
704
|
-
var r = t.pow(y - f);
|
|
705
|
-
var l = PowiainaNum.NaN;
|
|
706
|
-
var i = 0;
|
|
707
|
-
for (var w = PowiainaNum.E_MSI.clone(); f !== 0 && r.lt(w) && i < 100; ++i) {
|
|
708
|
-
if (f > 0) {
|
|
709
|
-
r = t.pow(r);
|
|
710
|
-
if (l.eq(r)) {
|
|
711
|
-
f = 0;
|
|
712
|
-
break;
|
|
630
|
+
}, {
|
|
631
|
+
key: "lambertw",
|
|
632
|
+
value:
|
|
633
|
+
/**
|
|
634
|
+
* The Lambert W function, also called the omega function or product logarithm, is the solution W(x) === x*e^x.
|
|
635
|
+
* https://en.wikipedia.org/wiki/Lambert_W_function
|
|
636
|
+
*
|
|
637
|
+
* This is a multi-valued function in the complex plane, but only two branches matter for real numbers: the "principal branch" W0, and the "non-principal branch" W_-1.
|
|
638
|
+
* W_0 works for any number >= -1/e, but W_-1 only works for nonpositive numbers >= -1/e.
|
|
639
|
+
* The "principal" parameter, which is true by default, decides which branch we're looking for: W_0 is used if principal is true, W_-1 is used if principal is false.
|
|
640
|
+
*/
|
|
641
|
+
//Code from break_eternity.js
|
|
642
|
+
//Some special values, for testing: https://en.wikipedia.org/wiki/Lambert_W_function#Special_values
|
|
643
|
+
function lambertw() {
|
|
644
|
+
var principal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
645
|
+
if (this.lt(-0.3678794411710499)) {
|
|
646
|
+
return PowiainaNum.NaN.clone(); //complex
|
|
647
|
+
} else if (principal) {
|
|
648
|
+
if (this.abs().lt("1e-300")) return new PowiainaNum(this);else if (this.small) {
|
|
649
|
+
return PowiainaNum.fromNumber(f_lambertw(this.toNumber()));
|
|
650
|
+
} else if (this.lt(MSI)) {
|
|
651
|
+
return PowiainaNum.fromNumber(f_lambertw(this.sign * this.getOperator(0)));
|
|
652
|
+
} else if (this.lt("eee15")) {
|
|
653
|
+
return d_lambertw(this);
|
|
654
|
+
} else {
|
|
655
|
+
// Numbers this large would sometimes fail to converge using d_lambertw, and at this size this.ln() is close enough
|
|
656
|
+
return this.log();
|
|
713
657
|
}
|
|
714
|
-
l = r;
|
|
715
|
-
--f;
|
|
716
658
|
} else {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
659
|
+
if (this.sign === 1) {
|
|
660
|
+
return PowiainaNum.NaN.clone(); //complex
|
|
661
|
+
}
|
|
662
|
+
if (this.layer === 0) {
|
|
663
|
+
return PowiainaNum.fromNumber(f_lambertw(this.sign * this.array[0].repeat, 1e-10, false));
|
|
664
|
+
} else if (this.layer == 1) {
|
|
665
|
+
return d_lambertw(this, 1e-10, false);
|
|
666
|
+
} else {
|
|
667
|
+
return this.neg().rec().lambertw().neg();
|
|
721
668
|
}
|
|
722
|
-
l = r;
|
|
723
|
-
++f;
|
|
724
669
|
}
|
|
725
670
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
747
|
-
if (x.gt(a)) return PowiainaNum.NaN.clone();
|
|
748
|
-
}
|
|
749
|
-
if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
|
|
750
|
-
if (x.gt(b)) return x;
|
|
751
|
-
return PowiainaNum.ZERO.clone();
|
|
752
|
-
}
|
|
753
|
-
if (x.max(b).gt(PowiainaNum.TETRATED_MSI)) {
|
|
754
|
-
if (x.gt(b)) {
|
|
755
|
-
x.setOperator(x.getOperator(2) - 1, 2);
|
|
756
|
-
x.normalize();
|
|
757
|
-
return x.sub(x.getOperator(1));
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
if (x.lt(PowiainaNum.ZERO.clone())) return b.pow(x).sub(2);
|
|
761
|
-
// base^base^... = x? (? bases)
|
|
762
|
-
var r = 0;
|
|
763
|
-
// 计算x与base的差距
|
|
764
|
-
var t = x.getOperator(1) - b.getOperator(1);
|
|
765
|
-
if (t > 3) {
|
|
766
|
-
var l = t - 3;
|
|
767
|
-
r += l;
|
|
768
|
-
x.setOperator(x.getOperator(1) - l, 1);
|
|
769
|
-
}
|
|
770
|
-
// 假设b=3, x=1e19
|
|
771
|
-
for (var i = 0; i < 100; ++i) {
|
|
772
|
-
if (x.lt(PowiainaNum.ZERO)) {
|
|
773
|
-
x = PowiainaNum.pow(base, x);
|
|
774
|
-
--r;
|
|
775
|
-
} else if (x.lte(1)) {
|
|
776
|
-
// 第五次,进入此处
|
|
777
|
-
// 结果=4+0.08795395574340908-1=3.087953...
|
|
778
|
-
// 验算3**3**3**(3**.08795395574340908)=10000000000000720000,符合预期
|
|
779
|
-
return new PowiainaNum(r + x.toNumber() - 1);
|
|
780
|
-
} else {
|
|
781
|
-
// 第1-4次迭代,进入此处
|
|
782
|
-
++r;
|
|
783
|
-
x = PowiainaNum.log(x, base);
|
|
784
|
-
// 第一次:r = 1, x = log_3(1e19) ~ 39.822162211498316
|
|
785
|
-
// 第二次:r = 2, x = log_3(39.822...) ~ 3.353706885314807
|
|
786
|
-
// 第三次:r = 3, x = log_3(3.3537...) ~ 1.1014497830508163
|
|
787
|
-
// 第四次:r = 4, x = log_3(1.1014...) ~ 0.08795395574340908
|
|
671
|
+
}, {
|
|
672
|
+
key: "tetrate",
|
|
673
|
+
value:
|
|
674
|
+
//#endregion
|
|
675
|
+
//#region higher calculates
|
|
676
|
+
//#region Tetration
|
|
677
|
+
// Code from ExpantaNum.js
|
|
678
|
+
function tetrate(other2) {
|
|
679
|
+
var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
680
|
+
var t = this.clone();
|
|
681
|
+
var other = new PowiainaNum(other2);
|
|
682
|
+
var payl = new PowiainaNum(payload);
|
|
683
|
+
if (t.isNaN() || other.isNaN() || payl.isNaN()) return PowiainaNum.NaN.clone();
|
|
684
|
+
if (t.eq(1)) return PowiainaNum.ONE.clone();
|
|
685
|
+
if (payl.neq(PowiainaNum.ONE)) other = other.add(payl.slog(t));
|
|
686
|
+
var negln;
|
|
687
|
+
if (other.isInfi() && other.sign > 0) {
|
|
688
|
+
if (t.gte(EXP_E_REC)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
689
|
+
negln = this.log().neg();
|
|
690
|
+
return negln.lambertw().div(negln);
|
|
788
691
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
if (payload === void 0) {
|
|
795
|
-
payload = 1;
|
|
796
|
-
}
|
|
797
|
-
return new PowiainaNum(t).tetrate(other2, payload);
|
|
798
|
-
};
|
|
799
|
-
PowiainaNum.prototype.ssqrt = function () {
|
|
800
|
-
var x = this.clone();
|
|
801
|
-
if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
|
|
802
|
-
if (!x.isFinite()) return x;
|
|
803
|
-
if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
|
|
804
|
-
if (x.gt(PowiainaNum.EE_MSI)) {
|
|
805
|
-
x.setOperator(x.getOperator(1) - 1, 1);
|
|
806
|
-
return x;
|
|
807
|
-
}
|
|
808
|
-
// use lambertw
|
|
809
|
-
var l = x.ln();
|
|
810
|
-
return l.div(l.lambertw());
|
|
811
|
-
};
|
|
812
|
-
PowiainaNum.tetrate_10 = function (other2) {
|
|
813
|
-
return PowiainaNum.fromNumber(10).tetrate(other2);
|
|
814
|
-
};
|
|
815
|
-
/**
|
|
816
|
-
* iterated-log
|
|
817
|
-
*
|
|
818
|
-
* @example new P("10^10^3").iteratedlog(2,10) == 3
|
|
819
|
-
*/
|
|
820
|
-
PowiainaNum.prototype.iteratedlog = function (other2, base2) {
|
|
821
|
-
if (other2 === void 0) {
|
|
822
|
-
other2 = 1;
|
|
823
|
-
}
|
|
824
|
-
if (base2 === void 0) {
|
|
825
|
-
base2 = 10;
|
|
826
|
-
}
|
|
827
|
-
var t = this.clone();
|
|
828
|
-
var base = new PowiainaNum(base2);
|
|
829
|
-
var other = new PowiainaNum(other2);
|
|
830
|
-
if (other.isZero()) return t;
|
|
831
|
-
if (other.eq(PowiainaNum.ONE)) return t.log(base);
|
|
832
|
-
return base.tetrate(t.slog(base).sub(other));
|
|
833
|
-
};
|
|
834
|
-
//#endregion
|
|
835
|
-
/**
|
|
836
|
-
* Arrow operation, return a function
|
|
837
|
-
* The function has a parameter `other`
|
|
838
|
-
* call this function returns a powiainanum `this`{`arrow2`}`other`
|
|
839
|
-
* @param arrows2 arrow count
|
|
840
|
-
* @returns A function
|
|
841
|
-
*/
|
|
842
|
-
PowiainaNum.prototype.arrow = function (arrows2) {
|
|
843
|
-
var t = this.clone();
|
|
844
|
-
var arrows = new PowiainaNum(arrows2);
|
|
845
|
-
if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
|
|
846
|
-
console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
|
|
847
|
-
return function () {
|
|
848
|
-
return PowiainaNum.NaN.clone();
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
if (arrows.eq(0)) return function (other) {
|
|
852
|
-
return t.mul(other);
|
|
853
|
-
};
|
|
854
|
-
if (arrows.eq(1)) return function (other) {
|
|
855
|
-
return t.pow(other);
|
|
856
|
-
};
|
|
857
|
-
if (arrows.eq(2)) return function (other) {
|
|
858
|
-
return t.tetrate(other);
|
|
859
|
-
};
|
|
860
|
-
return function (other2, payload2, depth) {
|
|
861
|
-
if (depth === void 0) {
|
|
862
|
-
depth = 0;
|
|
692
|
+
if (other.lte(-2)) return PowiainaNum.NaN.clone();
|
|
693
|
+
if (t.isZero()) {
|
|
694
|
+
if (other.isZero()) return PowiainaNum.NaN.clone();
|
|
695
|
+
if (other.gte(MSI / 2) || other.toNumber() % 2 == 0) return PowiainaNum.ZERO.clone();
|
|
696
|
+
return PowiainaNum.ONE.clone();
|
|
863
697
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
if (
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
r = arrows.clone();
|
|
883
|
-
r.setOperator(r.getOperator(Infinity) + 1, Infinity);
|
|
884
|
-
return r;
|
|
698
|
+
if (t.eq(PowiainaNum.ONE)) {
|
|
699
|
+
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.NaN.clone();
|
|
700
|
+
return PowiainaNum.ONE.clone();
|
|
701
|
+
}
|
|
702
|
+
if (other.eq(PowiainaNum.ONE.neg())) return PowiainaNum.ZERO.clone();
|
|
703
|
+
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
704
|
+
if (other.eq(PowiainaNum.ONE)) return t;
|
|
705
|
+
if (other.eq(2)) return t.pow(t);
|
|
706
|
+
if (t.eq(2)) {
|
|
707
|
+
if (other.eq(3)) return PowiainaNum.fromNumber(16);
|
|
708
|
+
if (other.eq(4)) return PowiainaNum.fromNumber(65536);
|
|
709
|
+
}
|
|
710
|
+
var m = t.max(other);
|
|
711
|
+
if (m.gt(PowiainaNum.PENTATED_MSI)) return m;
|
|
712
|
+
if (m.gt(PowiainaNum.TETRATED_MSI) || other.gt(MSI)) {
|
|
713
|
+
if (this.lt(EXP_E_REC)) {
|
|
714
|
+
negln = t.ln().neg();
|
|
715
|
+
return negln.lambertw().div(negln);
|
|
885
716
|
}
|
|
886
|
-
var
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
717
|
+
var j = t.slog(10).add(other);
|
|
718
|
+
j.setOperator(j.getOperator(2) + 1, 2);
|
|
719
|
+
j.normalize();
|
|
720
|
+
return j;
|
|
721
|
+
}
|
|
722
|
+
var y = other.toNumber();
|
|
723
|
+
var f = Math.floor(y);
|
|
724
|
+
var r = t.pow(y - f);
|
|
725
|
+
var l = PowiainaNum.NaN;
|
|
726
|
+
var i = 0;
|
|
727
|
+
for (var w = PowiainaNum.E_MSI.clone(); f !== 0 && r.lt(w) && i < 100; ++i) {
|
|
728
|
+
if (f > 0) {
|
|
729
|
+
r = t.pow(r);
|
|
730
|
+
if (l.eq(r)) {
|
|
731
|
+
f = 0;
|
|
732
|
+
break;
|
|
900
733
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
small: false,
|
|
909
|
-
sign: 1,
|
|
910
|
-
layer: 0,
|
|
911
|
-
array: [newOperator(10, 0), newOperator(1, arrowsNum)]
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
var y = other.toNumber();
|
|
915
|
-
var f = Math.floor(y);
|
|
916
|
-
var arrows_m1 = arrows.sub(PowiainaNum.ONE);
|
|
917
|
-
r = t.arrow(arrows_m1)(y - f, payload, depth + 1);
|
|
918
|
-
var i = 0;
|
|
919
|
-
for (var m = PowiainaNum.arrowMSI(arrowsNum - 1); f !== 0 && r.lt(m) && i < 100; i++) {
|
|
920
|
-
if (f > 0) {
|
|
921
|
-
r = t.arrow(arrows_m1)(r, payload, depth + 1);
|
|
922
|
-
--f;
|
|
734
|
+
l = r;
|
|
735
|
+
--f;
|
|
736
|
+
} else {
|
|
737
|
+
r = r.log(t);
|
|
738
|
+
if (l.eq(r)) {
|
|
739
|
+
f = 0;
|
|
740
|
+
break;
|
|
923
741
|
}
|
|
742
|
+
l = r;
|
|
743
|
+
++f;
|
|
924
744
|
}
|
|
925
|
-
if (i == 100) f = 0;
|
|
926
|
-
r.setOperator(r.getOperator(arrowsNum - 1) + f, arrowsNum - 1);
|
|
927
|
-
r.normalize();
|
|
928
|
-
return r;
|
|
929
|
-
}();
|
|
930
|
-
if (depth < PowiainaNum.maxOps + 10) {
|
|
931
|
-
PowiainaNum.arrowFuncMap.set("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth), res.clone());
|
|
932
|
-
}
|
|
933
|
-
return res;
|
|
934
|
-
};
|
|
935
|
-
};
|
|
936
|
-
/**
|
|
937
|
-
* return `base`{`arrow2`}`x` = `this` which `x` is.
|
|
938
|
-
*
|
|
939
|
-
* @param arrow2
|
|
940
|
-
* @returns
|
|
941
|
-
*/
|
|
942
|
-
PowiainaNum.prototype.anyarrow_log = function (arrow2) {
|
|
943
|
-
var x = this.clone();
|
|
944
|
-
var arrow = new PowiainaNum(arrow2);
|
|
945
|
-
var arrowsNum = arrow.toNumber();
|
|
946
|
-
if (arrow.gt(MSI)) {
|
|
947
|
-
throw new Error(powiainaNumError + "Not implemented");
|
|
948
|
-
}
|
|
949
|
-
if (!arrow.isInt() || arrow.lt(0)) return function () {
|
|
950
|
-
return PowiainaNum.NaN.clone();
|
|
951
|
-
};
|
|
952
|
-
if (arrow.eq(0)) return function (base) {
|
|
953
|
-
return x.div(base);
|
|
954
|
-
};
|
|
955
|
-
if (arrow.eq(1)) return function (base) {
|
|
956
|
-
return x.log(base);
|
|
957
|
-
};
|
|
958
|
-
if (arrow.eq(2)) return function (base) {
|
|
959
|
-
return x.slog(base);
|
|
960
|
-
};
|
|
961
|
-
if (x.isInfiNaN()) return function () {
|
|
962
|
-
return x;
|
|
963
|
-
};
|
|
964
|
-
return function (base, depth) {
|
|
965
|
-
if (depth === void 0) {
|
|
966
|
-
depth = 0;
|
|
967
745
|
}
|
|
746
|
+
if (i == 100 || this.lt(EXP_E_REC)) f = 0;
|
|
747
|
+
r.setOperator(r.getOperator(1) + f, 1);
|
|
748
|
+
r.normalize();
|
|
749
|
+
return r;
|
|
750
|
+
}
|
|
751
|
+
// Code from ExpantaNum.js
|
|
752
|
+
}, {
|
|
753
|
+
key: "slog",
|
|
754
|
+
value: function slog() {
|
|
755
|
+
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
756
|
+
var x = this.clone();
|
|
968
757
|
var b = new PowiainaNum(base);
|
|
758
|
+
if (x.isInfiNaN()) return x;
|
|
969
759
|
if (b.isNaN()) return b;
|
|
970
760
|
if (b.isInfi()) return PowiainaNum.ZERO.clone();
|
|
971
761
|
if (x.isZero()) return PowiainaNum.ONE.clone();
|
|
972
762
|
if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
973
763
|
if (x.eq(b)) return PowiainaNum.ONE.clone();
|
|
974
|
-
if (
|
|
764
|
+
if (b.lt(EXP_E_REC)) {
|
|
765
|
+
var a = b.tetrate(Infinity);
|
|
766
|
+
if (x.eq(a)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
767
|
+
if (x.gt(a)) return PowiainaNum.NaN.clone();
|
|
768
|
+
}
|
|
769
|
+
if (x.max(b).gt(PowiainaNum.PENTATED_MSI)) {
|
|
975
770
|
if (x.gt(b)) return x;
|
|
976
771
|
return PowiainaNum.ZERO.clone();
|
|
977
772
|
}
|
|
978
|
-
if (x.max(b).gt(PowiainaNum.
|
|
773
|
+
if (x.max(b).gt(PowiainaNum.TETRATED_MSI)) {
|
|
979
774
|
if (x.gt(b)) {
|
|
980
|
-
x.setOperator(x.getOperator(
|
|
775
|
+
x.setOperator(x.getOperator(2) - 1, 2);
|
|
981
776
|
x.normalize();
|
|
982
|
-
return x.sub(x.getOperator(
|
|
777
|
+
return x.sub(x.getOperator(1));
|
|
983
778
|
}
|
|
984
779
|
}
|
|
985
|
-
if (x.lt(PowiainaNum.ZERO.clone())) return
|
|
780
|
+
if (x.lt(PowiainaNum.ZERO.clone())) return b.pow(x).sub(2);
|
|
986
781
|
// base^base^... = x? (? bases)
|
|
987
782
|
var r = 0;
|
|
988
783
|
// 计算x与base的差距
|
|
989
|
-
var t = x.getOperator(
|
|
784
|
+
var t = x.getOperator(1) - b.getOperator(1);
|
|
990
785
|
if (t > 3) {
|
|
991
786
|
var l = t - 3;
|
|
992
787
|
r += l;
|
|
993
|
-
x.setOperator(x.getOperator(
|
|
788
|
+
x.setOperator(x.getOperator(1) - l, 1);
|
|
994
789
|
}
|
|
995
790
|
// 假设b=3, x=1e19
|
|
996
791
|
for (var i = 0; i < 100; ++i) {
|
|
997
792
|
if (x.lt(PowiainaNum.ZERO)) {
|
|
998
|
-
x =
|
|
793
|
+
x = PowiainaNum.pow(base, x);
|
|
999
794
|
--r;
|
|
1000
795
|
} else if (x.lte(1)) {
|
|
796
|
+
// 第五次,进入此处
|
|
797
|
+
// 结果=4+0.08795395574340908-1=3.087953...
|
|
798
|
+
// 验算3**3**3**(3**.08795395574340908)=10000000000000720000,符合预期
|
|
1001
799
|
return new PowiainaNum(r + x.toNumber() - 1);
|
|
1002
800
|
} else {
|
|
1003
801
|
// 第1-4次迭代,进入此处
|
|
1004
802
|
++r;
|
|
1005
|
-
x =
|
|
803
|
+
x = PowiainaNum.log(x, base);
|
|
804
|
+
// 第一次:r = 1, x = log_3(1e19) ~ 39.822162211498316
|
|
805
|
+
// 第二次:r = 2, x = log_3(39.822...) ~ 3.353706885314807
|
|
806
|
+
// 第三次:r = 3, x = log_3(3.3537...) ~ 1.1014497830508163
|
|
807
|
+
// 第四次:r = 4, x = log_3(1.1014...) ~ 0.08795395574340908
|
|
1006
808
|
}
|
|
1007
809
|
}
|
|
1008
810
|
if (x.gt(10)) return new PowiainaNum(r);
|
|
1009
811
|
return PowiainaNum.NaN.clone();
|
|
1010
|
-
};
|
|
1011
|
-
};
|
|
1012
|
-
/**
|
|
1013
|
-
* Arrow height inverse (ExpantaNum.js), an alias of `anyarrow_log`
|
|
1014
|
-
* @param arrows
|
|
1015
|
-
* @returns
|
|
1016
|
-
*/
|
|
1017
|
-
PowiainaNum.prototype.arrow_height_inverse = function (arrows) {
|
|
1018
|
-
return this.anyarrow_log(arrows);
|
|
1019
|
-
};
|
|
1020
|
-
PowiainaNum.arrowMSI = function (arrowsNum) {
|
|
1021
|
-
return new PowiainaNum("10{".concat(arrowsNum, "}").concat(MSI));
|
|
1022
|
-
};
|
|
1023
|
-
PowiainaNum.prototype.chain = function (other, arrows) {
|
|
1024
|
-
return this.arrow(arrows)(other);
|
|
1025
|
-
};
|
|
1026
|
-
PowiainaNum.hyper = function (arr) {
|
|
1027
|
-
var z = new PowiainaNum(arr);
|
|
1028
|
-
if (z.eq(0)) return function (x, y) {
|
|
1029
|
-
return new PowiainaNum(y).eq(0) ? new PowiainaNum(x) : new PowiainaNum(x).add(1);
|
|
1030
|
-
};
|
|
1031
|
-
if (z.eq(1)) return PowiainaNum.add;else if (z.eq(2)) return PowiainaNum.mul;else if (z.eq(3)) return PowiainaNum.pow;else {
|
|
1032
|
-
return function (x, y) {
|
|
1033
|
-
return new PowiainaNum(x).arrow(z.sub(2))(y);
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
};
|
|
1037
|
-
PowiainaNum.prototype.pentate = function (other) {
|
|
1038
|
-
return this.arrow(3)(other);
|
|
1039
|
-
};
|
|
1040
|
-
PowiainaNum.prototype.hexate = function (other) {
|
|
1041
|
-
return this.arrow(4)(other);
|
|
1042
|
-
};
|
|
1043
|
-
PowiainaNum.prototype.penta_log = function (base) {
|
|
1044
|
-
if (base === void 0) {
|
|
1045
|
-
base = 10;
|
|
1046
812
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
var other = new PowiainaNum(other2);
|
|
1058
|
-
var t = this.clone();
|
|
1059
|
-
if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
|
|
1060
|
-
if (other.eq(PowiainaNum.ONE)) return this.clone();
|
|
1061
|
-
if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
|
|
1062
|
-
if (!this.isInt()) return PowiainaNum.NaN.clone();
|
|
1063
|
-
if (this.eq(2)) return new PowiainaNum(4);
|
|
1064
|
-
if (other.eq(0)) return PowiainaNum.ONE.clone();
|
|
1065
|
-
var r;
|
|
1066
|
-
// I don't know is this added partrs work correctly...
|
|
1067
|
-
if (t.gt("10{1,2}".concat(MSI)) || other.gt(MSI)) {
|
|
1068
|
-
if (t.gt("10{1,2}".concat(MSI))) {
|
|
1069
|
-
r = t.clone();
|
|
1070
|
-
r.setOperator(r.getOperator(1, 2) - 1, 1, 2);
|
|
1071
|
-
r.normalize();
|
|
1072
|
-
} else if (t.gt("10{".concat(MSI, "}10"))) {
|
|
1073
|
-
r = new PowiainaNum(t.getOperator(Infinity));
|
|
1074
|
-
} else {
|
|
1075
|
-
r = PowiainaNum.ZERO;
|
|
1076
|
-
}
|
|
1077
|
-
var j = r.add(other);
|
|
1078
|
-
j.setOperator(j.getOperator(1, 2) + 1, 1, 2);
|
|
1079
|
-
j.normalize();
|
|
1080
|
-
return j;
|
|
1081
|
-
}
|
|
1082
|
-
var f = other.toNumber() - 1;
|
|
1083
|
-
r = t.clone();
|
|
1084
|
-
var i;
|
|
1085
|
-
for (i = 0; f !== 0 && r.lt(MSI) && i < 100; ++i) {
|
|
1086
|
-
if (f > 0) {
|
|
1087
|
-
r = t.arrow(r)(t);
|
|
1088
|
-
--f;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
if (i == 100) f = 0;
|
|
1092
|
-
r.setOperator(r.getOperator(Infinity) + f, Infinity);
|
|
1093
|
-
r.normalize();
|
|
1094
|
-
return r;
|
|
1095
|
-
};
|
|
1096
|
-
PowiainaNum.prototype.expansionArrow = function (arrow2) {
|
|
1097
|
-
var arrow = new PowiainaNum(arrow2);
|
|
1098
|
-
var t = this.clone();
|
|
1099
|
-
if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
|
|
1100
|
-
return PowiainaNum.NaN.clone();
|
|
1101
|
-
};
|
|
1102
|
-
if (arrow.eq(0)) return function (other) {
|
|
1103
|
-
return t.arrow(other)(t);
|
|
1104
|
-
};
|
|
1105
|
-
if (arrow.eq(1)) return function (other) {
|
|
1106
|
-
return t.expansion(other);
|
|
1107
|
-
};
|
|
1108
|
-
var arrows = arrow;
|
|
1109
|
-
return function (other2, depth) {
|
|
1110
|
-
if (depth === void 0) {
|
|
1111
|
-
depth = 0;
|
|
813
|
+
}, {
|
|
814
|
+
key: "ssqrt",
|
|
815
|
+
value: function ssqrt() {
|
|
816
|
+
var x = this.clone();
|
|
817
|
+
if (x.lt(1 / EXP_E_REC)) return PowiainaNum.NaN.clone();
|
|
818
|
+
if (!x.isFinite()) return x;
|
|
819
|
+
if (x.gt(PowiainaNum.TETRATED_MSI)) return x;
|
|
820
|
+
if (x.gt(PowiainaNum.EE_MSI)) {
|
|
821
|
+
x.setOperator(x.getOperator(1) - 1, 1);
|
|
822
|
+
return x;
|
|
1112
823
|
}
|
|
824
|
+
// use lambertw
|
|
825
|
+
var l = x.ln();
|
|
826
|
+
return l.div(l.lambertw());
|
|
827
|
+
}
|
|
828
|
+
}, {
|
|
829
|
+
key: "iteratedlog",
|
|
830
|
+
value:
|
|
831
|
+
/**
|
|
832
|
+
* iterated-log
|
|
833
|
+
*
|
|
834
|
+
* @example new P("10^10^3").iteratedlog(2,10) == 3
|
|
835
|
+
*/
|
|
836
|
+
function iteratedlog() {
|
|
837
|
+
var other2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
838
|
+
var base2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
839
|
+
var t = this.clone();
|
|
840
|
+
var base = new PowiainaNum(base2);
|
|
1113
841
|
var other = new PowiainaNum(other2);
|
|
1114
|
-
|
|
1115
|
-
if (
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
842
|
+
if (other.isZero()) return t;
|
|
843
|
+
if (other.eq(PowiainaNum.ONE)) return t.log(base);
|
|
844
|
+
return base.tetrate(t.slog(base).sub(other));
|
|
845
|
+
}
|
|
846
|
+
//#endregion
|
|
847
|
+
/**
|
|
848
|
+
* Arrow operation, return a function
|
|
849
|
+
* The function has a parameter `other`
|
|
850
|
+
* call this function returns a powiainanum `this`{`arrow2`}`other`
|
|
851
|
+
* @param arrows2 arrow count
|
|
852
|
+
* @returns A function
|
|
853
|
+
*/
|
|
854
|
+
}, {
|
|
855
|
+
key: "arrow",
|
|
856
|
+
value: function arrow(arrows2) {
|
|
857
|
+
var t = this.clone();
|
|
858
|
+
var arrows = new PowiainaNum(arrows2);
|
|
859
|
+
if (!arrows.isInt() || arrows.lt(PowiainaNum.ZERO)) {
|
|
860
|
+
console.warn("The arrow is <0 or not a integer, the returned function will return NaN.");
|
|
861
|
+
return function () {
|
|
862
|
+
return PowiainaNum.NaN.clone();
|
|
863
|
+
};
|
|
1129
864
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
if (
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
865
|
+
if (arrows.eq(0)) return function (other) {
|
|
866
|
+
return t.mul(other);
|
|
867
|
+
};
|
|
868
|
+
if (arrows.eq(1)) return function (other) {
|
|
869
|
+
return t.pow(other);
|
|
870
|
+
};
|
|
871
|
+
if (arrows.eq(2)) return function (other) {
|
|
872
|
+
return t.tetrate(other);
|
|
873
|
+
};
|
|
874
|
+
return function (other2, payload2) {
|
|
875
|
+
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
876
|
+
var other = new PowiainaNum(other2);
|
|
877
|
+
var payload = new PowiainaNum(payload2);
|
|
878
|
+
var ctt = PowiainaNum.arrowFuncMap.get("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth));
|
|
879
|
+
if (ctt) return ctt.clone();
|
|
880
|
+
var res = function () {
|
|
881
|
+
var r;
|
|
882
|
+
if (t.isNaN() || other.isNaN() || payload.isNaN()) return PowiainaNum.NaN.clone();
|
|
883
|
+
if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
|
|
884
|
+
if (t.eq(PowiainaNum.ZERO)) {
|
|
885
|
+
if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
886
|
+
return PowiainaNum.NaN.clone();
|
|
887
|
+
}
|
|
888
|
+
if (payload.neq(PowiainaNum.ONE)) other = other.add(payload.anyarrow_log(arrows)(t));
|
|
889
|
+
if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
|
|
890
|
+
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
891
|
+
if (other.eq(PowiainaNum.ONE)) return t.clone();
|
|
892
|
+
// arrow > 9e15, that using 10{x}, x=arrow;
|
|
893
|
+
if (arrows.gt(PowiainaNum.MSI)) {
|
|
894
|
+
r = arrows.clone();
|
|
895
|
+
r.setOperator(r.getOperator(Infinity) + 1, Infinity);
|
|
896
|
+
return r;
|
|
897
|
+
}
|
|
898
|
+
var arrowsNum = arrows.toNumber();
|
|
899
|
+
// arrow < 9e15
|
|
900
|
+
// 10{x}2 = 10{x-1}10
|
|
901
|
+
if (other.eq(2)) return t.arrow(arrowsNum - 1)(t, payload, depth + 1);
|
|
902
|
+
if (t.max(other).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) return t.max(other);
|
|
903
|
+
if (t.gt(PowiainaNum.arrowMSI(arrowsNum)) || other.gt(MSI)) {
|
|
904
|
+
if (t.gt(PowiainaNum.arrowMSI(arrowsNum))) {
|
|
905
|
+
r = t.clone();
|
|
906
|
+
r.setOperator(r.getOperator(arrowsNum) - 1, arrowsNum);
|
|
907
|
+
r.normalize();
|
|
908
|
+
} else if (t.gt(PowiainaNum.arrowMSI(arrowsNum - 1))) {
|
|
909
|
+
r = new PowiainaNum(t.getOperator(arrowsNum - 1));
|
|
910
|
+
} else {
|
|
911
|
+
r = PowiainaNum.ZERO;
|
|
912
|
+
}
|
|
913
|
+
var j = r.add(other);
|
|
914
|
+
j.setOperator(j.getOperator(arrowsNum) + 1, arrowsNum);
|
|
915
|
+
j.normalize();
|
|
916
|
+
return j;
|
|
917
|
+
}
|
|
918
|
+
if (depth >= PowiainaNum.maxOps + 10) {
|
|
919
|
+
return new PowiainaNum({
|
|
920
|
+
small: false,
|
|
921
|
+
sign: 1,
|
|
922
|
+
layer: 0,
|
|
923
|
+
array: [newOperator(10, 0), newOperator(1, arrowsNum)]
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
var y = other.toNumber();
|
|
927
|
+
var f = Math.floor(y);
|
|
928
|
+
var arrows_m1 = arrows.sub(PowiainaNum.ONE);
|
|
929
|
+
r = t.arrow(arrows_m1)(y - f, payload, depth + 1);
|
|
930
|
+
var i = 0;
|
|
931
|
+
for (var m = PowiainaNum.arrowMSI(arrowsNum - 1); f !== 0 && r.lt(m) && i < 100; i++) {
|
|
932
|
+
if (f > 0) {
|
|
933
|
+
r = t.arrow(arrows_m1)(r, payload, depth + 1);
|
|
934
|
+
--f;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
if (i == 100) f = 0;
|
|
938
|
+
r.setOperator(r.getOperator(arrowsNum - 1) + f, arrowsNum - 1);
|
|
1139
939
|
r.normalize();
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
940
|
+
return r;
|
|
941
|
+
}();
|
|
942
|
+
if (depth < PowiainaNum.maxOps + 10) {
|
|
943
|
+
PowiainaNum.arrowFuncMap.set("".concat(t.toString(), " ").concat(arrows.toString(), " ").concat(other.toString(), " ").concat(depth), res.clone());
|
|
1144
944
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
j.normalize();
|
|
1148
|
-
return j;
|
|
1149
|
-
}
|
|
1150
|
-
if (depth >= PowiainaNum.maxOps + 10) {
|
|
1151
|
-
return new PowiainaNum({
|
|
1152
|
-
small: false,
|
|
1153
|
-
sign: 1,
|
|
1154
|
-
layer: 0,
|
|
1155
|
-
array: [newOperator(10, 0), newOperator(1, arrowsNum, 2)]
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
var y = other.toNumber();
|
|
1159
|
-
var f = Math.floor(y);
|
|
1160
|
-
var arrows_m1 = arrows.sub(PowiainaNum.ONE);
|
|
1161
|
-
r = t.expansionArrow(arrows_m1)(y - f, depth + 1);
|
|
1162
|
-
var i = 0;
|
|
1163
|
-
for (var m = new PowiainaNum("10{".concat(arrowsNum - 1, ",2}").concat(MSI)); f !== 0 && r.lt(m) && i < 100; i++) {
|
|
1164
|
-
if (f > 0) {
|
|
1165
|
-
r = t.expansionArrow(arrows_m1)(r, depth + 1);
|
|
1166
|
-
--f;
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
if (i == 100) f = 0;
|
|
1170
|
-
r.setOperator(r.getOperator(arrowsNum - 1, 2) + f, arrowsNum - 1, 2);
|
|
1171
|
-
r.normalize();
|
|
1172
|
-
return r;
|
|
1173
|
-
};
|
|
1174
|
-
};
|
|
1175
|
-
PowiainaNum.expansion = function (t, other) {
|
|
1176
|
-
return new PowiainaNum(t).expansion(other);
|
|
1177
|
-
};
|
|
1178
|
-
PowiainaNum.prototype.multiExpansion = function (other) {
|
|
1179
|
-
return this.expansionArrow(2)(other);
|
|
1180
|
-
};
|
|
1181
|
-
PowiainaNum.multiExpansion = function (t, other) {
|
|
1182
|
-
return new PowiainaNum(t).multiExpansion(other);
|
|
1183
|
-
};
|
|
1184
|
-
PowiainaNum.prototype.powerExpansion = function (other) {
|
|
1185
|
-
return this.expansionArrow(3)(other);
|
|
1186
|
-
};
|
|
1187
|
-
PowiainaNum.powerExpansion = function (t, other) {
|
|
1188
|
-
return new PowiainaNum(t).powerExpansion(other);
|
|
1189
|
-
};
|
|
1190
|
-
PowiainaNum.prototype.explosion = function (other) {
|
|
1191
|
-
return PowiainaNum.BEAF(this, other, 1, 3);
|
|
1192
|
-
};
|
|
1193
|
-
PowiainaNum.prototype.megotion = function (other) {
|
|
1194
|
-
return PowiainaNum.BEAF(this, other, 1, 1, 2);
|
|
1195
|
-
};
|
|
1196
|
-
PowiainaNum.prototype.powiaination = function (other) {
|
|
1197
|
-
return PowiainaNum.BEAF(this, other, 1, 1, 1, 2);
|
|
1198
|
-
};
|
|
1199
|
-
PowiainaNum.BEAF = function (base2, power2, arrow2, expans2, megota2, powiaina2, depth) {
|
|
1200
|
-
if (arrow2 === void 0) {
|
|
1201
|
-
arrow2 = 1;
|
|
1202
|
-
}
|
|
1203
|
-
if (expans2 === void 0) {
|
|
1204
|
-
expans2 = 1;
|
|
1205
|
-
}
|
|
1206
|
-
if (megota2 === void 0) {
|
|
1207
|
-
megota2 = 1;
|
|
1208
|
-
}
|
|
1209
|
-
if (powiaina2 === void 0) {
|
|
1210
|
-
powiaina2 = 1;
|
|
1211
|
-
}
|
|
1212
|
-
if (depth === void 0) {
|
|
1213
|
-
depth = 0;
|
|
1214
|
-
}
|
|
1215
|
-
// console.warn(
|
|
1216
|
-
// "This function is unstable when calculating numbers greater than *megotion*",
|
|
1217
|
-
// );
|
|
1218
|
-
var base = new PowiainaNum(base2);
|
|
1219
|
-
var power = new PowiainaNum(power2);
|
|
1220
|
-
function readArg(a) {
|
|
1221
|
-
var _b;
|
|
1222
|
-
return new PowiainaNum((_b = [arrow2, expans2, megota2, powiaina2][a]) !== null && _b !== void 0 ? _b : 1);
|
|
1223
|
-
}
|
|
1224
|
-
if (base.eq(1)) return new PowiainaNum(1);
|
|
1225
|
-
if (power.eq(1)) return new PowiainaNum(base);
|
|
1226
|
-
if (power.isZero()) return new PowiainaNum(1);
|
|
1227
|
-
if (base.lt(0)) return PowiainaNum.NaN.clone();
|
|
1228
|
-
// // check infinite
|
|
1229
|
-
// let sufpowiaina = args.slice(4);
|
|
1230
|
-
// if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
|
|
1231
|
-
// return PowiainaNum.POSITIVE_INFINITY;
|
|
1232
|
-
// }
|
|
1233
|
-
if (new PowiainaNum(powiaina2).gte(3)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
1234
|
-
if (readArg(0).eq(1) && readArg(1).eq(1) && readArg(2).eq(1)) {
|
|
1235
|
-
return base.pow(power);
|
|
1236
|
-
}
|
|
1237
|
-
if (readArg(0).eq(2) && readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
|
|
1238
|
-
return base.tetrate(power);
|
|
1239
|
-
}
|
|
1240
|
-
if (readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
|
|
1241
|
-
return base.arrow(readArg(0))(power);
|
|
1242
|
-
}
|
|
1243
|
-
if (readArg(1).eq(2) && readArg(2).eq(1) && readArg(3).eq(1)) {
|
|
1244
|
-
return base.expansionArrow(readArg(0))(power);
|
|
1245
|
-
}
|
|
1246
|
-
var arrow = readArg(0).toNumber();
|
|
1247
|
-
var expans = readArg(1);
|
|
1248
|
-
var megota = readArg(2);
|
|
1249
|
-
var powiaina = readArg(3);
|
|
1250
|
-
if (powiaina.eq(2)) {
|
|
1251
|
-
if (arrow != 1) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
1252
|
-
if (expans.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
1253
|
-
if (megota.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
1254
|
-
if (power.gte(MSI)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
1255
|
-
var r = new PowiainaNum(10);
|
|
1256
|
-
r.layer = power.toNumber();
|
|
1257
|
-
r.normalize();
|
|
1258
|
-
return r;
|
|
1259
|
-
}
|
|
1260
|
-
function convertOperator(arrows, expans, megota) {
|
|
1261
|
-
var a = arrows;
|
|
1262
|
-
var e = expans;
|
|
1263
|
-
var m = megota;
|
|
1264
|
-
if (a == 0 && e > 1) {
|
|
1265
|
-
return [1 / 0, e - 1, m];
|
|
1266
|
-
}
|
|
1267
|
-
if (a == 0 && e == 1 && m > 1) {
|
|
1268
|
-
return [1, 1 / 0, m - 1];
|
|
1269
|
-
}
|
|
1270
|
-
return [a, e, m];
|
|
1271
|
-
}
|
|
1272
|
-
if (megota.gt(MSI)) {
|
|
1273
|
-
var temp = new PowiainaNum(megota);
|
|
1274
|
-
temp.layer++;
|
|
1275
|
-
temp.normalize();
|
|
1276
|
-
return temp;
|
|
945
|
+
return res;
|
|
946
|
+
};
|
|
1277
947
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
948
|
+
/**
|
|
949
|
+
* return `base`{`arrow2`}`x` = `this` which `x` is.
|
|
950
|
+
*
|
|
951
|
+
* @param arrow2
|
|
952
|
+
* @returns
|
|
953
|
+
*/
|
|
954
|
+
}, {
|
|
955
|
+
key: "anyarrow_log",
|
|
956
|
+
value: function anyarrow_log(arrow2) {
|
|
957
|
+
var x = this.clone();
|
|
958
|
+
var arrow = new PowiainaNum(arrow2);
|
|
959
|
+
var arrowsNum = arrow.toNumber();
|
|
960
|
+
if (arrow.gt(MSI)) {
|
|
961
|
+
throw new Error(powiainaNumError + "Not implemented");
|
|
962
|
+
}
|
|
963
|
+
if (!arrow.isInt() || arrow.lt(0)) return function () {
|
|
964
|
+
return PowiainaNum.NaN.clone();
|
|
965
|
+
};
|
|
966
|
+
if (arrow.eq(0)) return function (base) {
|
|
967
|
+
return x.div(base);
|
|
968
|
+
};
|
|
969
|
+
if (arrow.eq(1)) return function (base) {
|
|
970
|
+
return x.log(base);
|
|
971
|
+
};
|
|
972
|
+
if (arrow.eq(2)) return function (base) {
|
|
973
|
+
return x.slog(base);
|
|
974
|
+
};
|
|
975
|
+
if (x.isInfiNaN()) return function () {
|
|
976
|
+
return x;
|
|
977
|
+
};
|
|
978
|
+
return function (base) {
|
|
979
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
980
|
+
var b = new PowiainaNum(base);
|
|
981
|
+
if (b.isNaN()) return b;
|
|
982
|
+
if (b.isInfi()) return PowiainaNum.ZERO.clone();
|
|
983
|
+
if (x.isZero()) return PowiainaNum.ONE.clone();
|
|
984
|
+
if (x.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
985
|
+
if (x.eq(b)) return PowiainaNum.ONE.clone();
|
|
986
|
+
if (x.max(b).gt(PowiainaNum.arrowMSI(arrowsNum + 1))) {
|
|
987
|
+
if (x.gt(b)) return x;
|
|
988
|
+
return PowiainaNum.ZERO.clone();
|
|
989
|
+
}
|
|
990
|
+
if (x.max(b).gt(PowiainaNum.arrowMSI(arrowsNum))) {
|
|
991
|
+
if (x.gt(b)) {
|
|
992
|
+
x.setOperator(x.getOperator(arrowsNum) - 1, arrowsNum);
|
|
993
|
+
x.normalize();
|
|
994
|
+
return x.sub(x.getOperator(arrowsNum - 1));
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (x.lt(PowiainaNum.ZERO.clone())) return PowiainaNum.NaN.clone();
|
|
998
|
+
// base^base^... = x? (? bases)
|
|
999
|
+
var r = 0;
|
|
1000
|
+
// 计算x与base的差距
|
|
1001
|
+
var t = x.getOperator(arrowsNum) - b.getOperator(arrowsNum);
|
|
1002
|
+
if (t > 3) {
|
|
1003
|
+
var l = t - 3;
|
|
1004
|
+
r += l;
|
|
1005
|
+
x.setOperator(x.getOperator(arrowsNum) - l, arrowsNum);
|
|
1006
|
+
}
|
|
1007
|
+
// 假设b=3, x=1e19
|
|
1008
|
+
for (var i = 0; i < 100; ++i) {
|
|
1009
|
+
if (x.lt(PowiainaNum.ZERO)) {
|
|
1010
|
+
x = x.arrow(arrowsNum - 1)(base);
|
|
1011
|
+
--r;
|
|
1012
|
+
} else if (x.lte(1)) {
|
|
1013
|
+
return new PowiainaNum(r + x.toNumber() - 1);
|
|
1014
|
+
} else {
|
|
1015
|
+
// 第1-4次迭代,进入此处
|
|
1016
|
+
++r;
|
|
1017
|
+
x = x.anyarrow_log(arrowsNum - 1)(base, depth + 1);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
if (x.gt(10)) return new PowiainaNum(r);
|
|
1021
|
+
return PowiainaNum.NaN.clone();
|
|
1022
|
+
};
|
|
1281
1023
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* Arrow height inverse (ExpantaNum.js), an alias of `anyarrow_log`
|
|
1026
|
+
* @param arrows
|
|
1027
|
+
* @returns
|
|
1028
|
+
*/
|
|
1029
|
+
}, {
|
|
1030
|
+
key: "arrow_height_inverse",
|
|
1031
|
+
value: function arrow_height_inverse(arrows) {
|
|
1032
|
+
return this.anyarrow_log(arrows);
|
|
1033
|
+
}
|
|
1034
|
+
}, {
|
|
1035
|
+
key: "chain",
|
|
1036
|
+
value: function chain(other, arrows) {
|
|
1037
|
+
return this.arrow(arrows)(other);
|
|
1038
|
+
}
|
|
1039
|
+
}, {
|
|
1040
|
+
key: "pentate",
|
|
1041
|
+
value: function pentate(other) {
|
|
1042
|
+
return this.arrow(3)(other);
|
|
1043
|
+
}
|
|
1044
|
+
}, {
|
|
1045
|
+
key: "hexate",
|
|
1046
|
+
value: function hexate(other) {
|
|
1047
|
+
return this.arrow(4)(other);
|
|
1048
|
+
}
|
|
1049
|
+
}, {
|
|
1050
|
+
key: "penta_log",
|
|
1051
|
+
value: function penta_log() {
|
|
1052
|
+
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1053
|
+
return this.anyarrow_log(3)(base);
|
|
1284
1054
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1055
|
+
/**
|
|
1056
|
+
* Expansion, which is `this`{{1}}`other2`.
|
|
1057
|
+
*
|
|
1058
|
+
* Expansion refers to the binary function a{{1}}b = a{a{...a{b}a...}a}a where there are b a's from the center out. It is {a,b,1,2} in BEAF and a{X+1}b in X-Sequence Hyper-Exponential Notation. The notation a{c}b means {a,b,c}, which is a "c + 2"-ated to b, using the bracket operator.
|
|
1059
|
+
*
|
|
1060
|
+
* @url https://googology.fandom.com/wiki/Expansion
|
|
1061
|
+
*/
|
|
1062
|
+
}, {
|
|
1063
|
+
key: "expansion",
|
|
1064
|
+
value: function expansion(other2) {
|
|
1292
1065
|
var other = new PowiainaNum(other2);
|
|
1066
|
+
var t = this.clone();
|
|
1067
|
+
if (other.lt(PowiainaNum.ZERO) || !other.isInt()) return PowiainaNum.NaN.clone();
|
|
1068
|
+
if (other.eq(PowiainaNum.ONE)) return this.clone();
|
|
1069
|
+
if (this.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
|
|
1070
|
+
if (!this.isInt()) return PowiainaNum.NaN.clone();
|
|
1071
|
+
if (this.eq(2)) return new PowiainaNum(4);
|
|
1072
|
+
if (other.eq(0)) return PowiainaNum.ONE.clone();
|
|
1293
1073
|
var r;
|
|
1294
|
-
|
|
1295
|
-
if (
|
|
1296
|
-
|
|
1297
|
-
if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
1298
|
-
return PowiainaNum.NaN.clone();
|
|
1299
|
-
}
|
|
1300
|
-
if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
|
|
1301
|
-
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
1302
|
-
if (other.eq(PowiainaNum.ONE)) return t.clone();
|
|
1303
|
-
if (arrows.eq(0)) {
|
|
1304
|
-
return PowiainaNum.BEAF(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
|
|
1305
|
-
// {this, this, power, expans-1, megota}
|
|
1306
|
-
}
|
|
1307
|
-
if (megota.eq(0)) {
|
|
1308
|
-
return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
|
|
1309
|
-
}
|
|
1310
|
-
// expans > 9e15, that using 10{?, x}, x=expans;
|
|
1311
|
-
if (expans.gt(MSI)) {
|
|
1312
|
-
r = new PowiainaNum(expans);
|
|
1313
|
-
r.setOperator(r.getOperator(1, Infinity, megota.toNumber()) + 1, 1, Infinity, megota.toNumber());
|
|
1314
|
-
return r;
|
|
1315
|
-
}
|
|
1316
|
-
// arrow > 9e15, that using 10{x,2}, x=arrow;
|
|
1317
|
-
if (arrows.gt(PowiainaNum.MSI)) {
|
|
1318
|
-
r = arrows.clone();
|
|
1319
|
-
r.setOperator(r.getOperator(Infinity, expans.toNumber(), megota.toNumber()) + 1, Infinity, expans.toNumber(), megota.toNumber());
|
|
1320
|
-
return r;
|
|
1321
|
-
}
|
|
1322
|
-
var arrowsNum = arrows.toNumber();
|
|
1323
|
-
// arrow < 9e15
|
|
1324
|
-
// 10{x}2 = 10{x-1}10
|
|
1325
|
-
if (other.eq(2)) return PowiainaNum.BEAF(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
|
|
1326
|
-
if (t.max(other).gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber()))) return t.max(other);
|
|
1327
|
-
if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
|
|
1328
|
-
if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
|
|
1074
|
+
// I don't know is this added partrs work correctly...
|
|
1075
|
+
if (t.gt("10{1,2}".concat(MSI)) || other.gt(MSI)) {
|
|
1076
|
+
if (t.gt("10{1,2}".concat(MSI))) {
|
|
1329
1077
|
r = t.clone();
|
|
1330
|
-
r.setOperator(r.getOperator(
|
|
1078
|
+
r.setOperator(r.getOperator(1, 2) - 1, 1, 2);
|
|
1331
1079
|
r.normalize();
|
|
1332
|
-
} else if (t.gt(
|
|
1333
|
-
r = new PowiainaNum(t.getOperator
|
|
1080
|
+
} else if (t.gt("10{".concat(MSI, "}10"))) {
|
|
1081
|
+
r = new PowiainaNum(t.getOperator(Infinity));
|
|
1334
1082
|
} else {
|
|
1335
1083
|
r = PowiainaNum.ZERO;
|
|
1336
1084
|
}
|
|
1337
1085
|
var j = r.add(other);
|
|
1338
|
-
j.setOperator(j.getOperator(
|
|
1086
|
+
j.setOperator(j.getOperator(1, 2) + 1, 1, 2);
|
|
1339
1087
|
j.normalize();
|
|
1340
1088
|
return j;
|
|
1341
1089
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
layer: 0,
|
|
1347
|
-
array: [newOperator(10, 0), newOperator(1, arrowsNum, expans.toNumber(), megota.toNumber())]
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
var y = other.toNumber();
|
|
1351
|
-
var f = Math.floor(y);
|
|
1352
|
-
var arrows_m1 = arrows.sub(PowiainaNum.ONE);
|
|
1353
|
-
r = PowiainaNum.BEAF(t, y - f, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
|
|
1354
|
-
var i = 0;
|
|
1355
|
-
for (var m = new PowiainaNum(getMSIForm.apply(void 0, convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))); f !== 0 && r.lt(m) && i < 100; i++) {
|
|
1090
|
+
var f = other.toNumber() - 1;
|
|
1091
|
+
r = t.clone();
|
|
1092
|
+
var i;
|
|
1093
|
+
for (i = 0; f !== 0 && r.lt(MSI) && i < 100; ++i) {
|
|
1356
1094
|
if (f > 0) {
|
|
1357
|
-
r =
|
|
1095
|
+
r = t.arrow(r)(t);
|
|
1358
1096
|
--f;
|
|
1359
1097
|
}
|
|
1360
1098
|
}
|
|
1361
1099
|
if (i == 100) f = 0;
|
|
1362
|
-
r.setOperator
|
|
1100
|
+
r.setOperator(r.getOperator(Infinity) + f, Infinity);
|
|
1363
1101
|
r.normalize();
|
|
1364
1102
|
return r;
|
|
1365
|
-
}(power, depth);
|
|
1366
|
-
console.log("".concat("-".repeat(depth), " = ").concat(result));
|
|
1367
|
-
return result;
|
|
1368
|
-
};
|
|
1369
|
-
//#endregion
|
|
1370
|
-
//#region comparsion
|
|
1371
|
-
PowiainaNum.prototype.abs = function () {
|
|
1372
|
-
var obj = this.clone();
|
|
1373
|
-
if (obj.sign < 0) obj.sign *= -1;
|
|
1374
|
-
return obj;
|
|
1375
|
-
};
|
|
1376
|
-
PowiainaNum.abs = function (x) {
|
|
1377
|
-
return new PowiainaNum(x).abs();
|
|
1378
|
-
};
|
|
1379
|
-
/**
|
|
1380
|
-
* Select the largest number of arguments.
|
|
1381
|
-
*/
|
|
1382
|
-
PowiainaNum.max = function () {
|
|
1383
|
-
var args = [];
|
|
1384
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1385
|
-
args[_i] = arguments[_i];
|
|
1386
1103
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1104
|
+
}, {
|
|
1105
|
+
key: "expansionArrow",
|
|
1106
|
+
value: function expansionArrow(arrow2) {
|
|
1107
|
+
var arrow = new PowiainaNum(arrow2);
|
|
1108
|
+
var t = this.clone();
|
|
1109
|
+
if (arrow.lt(0) || !arrow.isInt() || arrow.isNaN() || this.isNaN()) return function () {
|
|
1110
|
+
return PowiainaNum.NaN.clone();
|
|
1111
|
+
};
|
|
1112
|
+
if (arrow.eq(0)) return function (other) {
|
|
1113
|
+
return t.arrow(other)(t);
|
|
1114
|
+
};
|
|
1115
|
+
if (arrow.eq(1)) return function (other) {
|
|
1116
|
+
return t.expansion(other);
|
|
1117
|
+
};
|
|
1118
|
+
var arrows = arrow;
|
|
1119
|
+
return function (other2) {
|
|
1120
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1121
|
+
var other = new PowiainaNum(other2);
|
|
1122
|
+
var r;
|
|
1123
|
+
if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
|
|
1124
|
+
if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
|
|
1125
|
+
if (t.eq(PowiainaNum.ZERO)) {
|
|
1126
|
+
if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
1127
|
+
return PowiainaNum.NaN.clone();
|
|
1128
|
+
}
|
|
1129
|
+
if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
|
|
1130
|
+
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
1131
|
+
if (other.eq(PowiainaNum.ONE)) return t.clone();
|
|
1132
|
+
// arrow > 9e15, that using 10{x,2}, x=arrow;
|
|
1133
|
+
if (arrows.gt(PowiainaNum.MSI)) {
|
|
1134
|
+
r = arrows.clone();
|
|
1135
|
+
r.setOperator(r.getOperator(Infinity, 2) + 1, Infinity, 2);
|
|
1136
|
+
return r;
|
|
1137
|
+
}
|
|
1138
|
+
var arrowsNum = arrows.toNumber();
|
|
1139
|
+
// arrow < 9e15
|
|
1140
|
+
// 10{x}2 = 10{x-1}10
|
|
1141
|
+
if (other.eq(2)) return t.expansionArrow(arrowsNum - 1)(t, depth + 1);
|
|
1142
|
+
if (t.max(other).gt("10{".concat(arrowsNum + 1, ",2}").concat(MSI))) return t.max(other);
|
|
1143
|
+
if (t.gt("10{".concat(arrowsNum, ",2}").concat(MSI)) || other.gt(MSI)) {
|
|
1144
|
+
if (t.gt("10{".concat(arrowsNum, ",2}").concat(MSI))) {
|
|
1145
|
+
r = t.clone();
|
|
1146
|
+
r.setOperator(r.getOperator(arrowsNum, 2) - 1, arrowsNum, 2);
|
|
1147
|
+
r.normalize();
|
|
1148
|
+
} else if (t.gt("10{".concat(arrowsNum - 1, ",2}").concat(MSI))) {
|
|
1149
|
+
r = new PowiainaNum(t.getOperator(arrowsNum - 1, 2));
|
|
1150
|
+
} else {
|
|
1151
|
+
r = PowiainaNum.ZERO;
|
|
1152
|
+
}
|
|
1153
|
+
var j = r.add(other);
|
|
1154
|
+
j.setOperator(j.getOperator(arrowsNum, 2) + 1, arrowsNum, 2);
|
|
1155
|
+
j.normalize();
|
|
1156
|
+
return j;
|
|
1157
|
+
}
|
|
1158
|
+
if (depth >= PowiainaNum.maxOps + 10) {
|
|
1159
|
+
return new PowiainaNum({
|
|
1160
|
+
small: false,
|
|
1161
|
+
sign: 1,
|
|
1162
|
+
layer: 0,
|
|
1163
|
+
array: [newOperator(10, 0), newOperator(1, arrowsNum, 2)]
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
var y = other.toNumber();
|
|
1167
|
+
var f = Math.floor(y);
|
|
1168
|
+
var arrows_m1 = arrows.sub(PowiainaNum.ONE);
|
|
1169
|
+
r = t.expansionArrow(arrows_m1)(y - f, depth + 1);
|
|
1170
|
+
var i = 0;
|
|
1171
|
+
for (var m = new PowiainaNum("10{".concat(arrowsNum - 1, ",2}").concat(MSI)); f !== 0 && r.lt(m) && i < 100; i++) {
|
|
1172
|
+
if (f > 0) {
|
|
1173
|
+
r = t.expansionArrow(arrows_m1)(r, depth + 1);
|
|
1174
|
+
--f;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
if (i == 100) f = 0;
|
|
1178
|
+
r.setOperator(r.getOperator(arrowsNum - 1, 2) + f, arrowsNum - 1, 2);
|
|
1179
|
+
r.normalize();
|
|
1180
|
+
return r;
|
|
1181
|
+
};
|
|
1392
1182
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1183
|
+
}, {
|
|
1184
|
+
key: "multiExpansion",
|
|
1185
|
+
value: function multiExpansion(other) {
|
|
1186
|
+
return this.expansionArrow(2)(other);
|
|
1187
|
+
}
|
|
1188
|
+
}, {
|
|
1189
|
+
key: "powerExpansion",
|
|
1190
|
+
value: function powerExpansion(other) {
|
|
1191
|
+
return this.expansionArrow(3)(other);
|
|
1192
|
+
}
|
|
1193
|
+
}, {
|
|
1194
|
+
key: "explosion",
|
|
1195
|
+
value: function explosion(other) {
|
|
1196
|
+
return PowiainaNum.BEAF(this, other, 1, 3);
|
|
1197
|
+
}
|
|
1198
|
+
}, {
|
|
1199
|
+
key: "megotion",
|
|
1200
|
+
value: function megotion(other) {
|
|
1201
|
+
return PowiainaNum.BEAF(this, other, 1, 1, 2);
|
|
1202
|
+
}
|
|
1203
|
+
}, {
|
|
1204
|
+
key: "powiaination",
|
|
1205
|
+
value: function powiaination(other) {
|
|
1206
|
+
return PowiainaNum.BEAF(this, other, 1, 1, 1, 2);
|
|
1207
|
+
}
|
|
1208
|
+
}, {
|
|
1209
|
+
key: "abs",
|
|
1210
|
+
value:
|
|
1211
|
+
//#endregion
|
|
1212
|
+
//#region comparsion
|
|
1213
|
+
function abs() {
|
|
1214
|
+
var obj = this.clone();
|
|
1215
|
+
if (obj.sign < 0) obj.sign *= -1;
|
|
1216
|
+
return obj;
|
|
1402
1217
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1218
|
+
}, {
|
|
1219
|
+
key: "clampMin",
|
|
1220
|
+
value:
|
|
1221
|
+
/**
|
|
1222
|
+
* Restrict a number be not lower than a number
|
|
1223
|
+
*
|
|
1224
|
+
* It's also an alias of `PowiainaNum.max`.
|
|
1225
|
+
* @returns restricted number
|
|
1226
|
+
*/
|
|
1227
|
+
function clampMin() {
|
|
1228
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1229
|
+
args[_key2] = arguments[_key2];
|
|
1407
1230
|
}
|
|
1231
|
+
return PowiainaNum.max.apply(PowiainaNum, [this].concat(args));
|
|
1408
1232
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
*/
|
|
1430
|
-
PowiainaNum.prototype.clampMin = function () {
|
|
1431
|
-
var args = [];
|
|
1432
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1433
|
-
args[_i] = arguments[_i];
|
|
1434
|
-
}
|
|
1435
|
-
return PowiainaNum.max.apply(PowiainaNum, __spreadArray([this], args, false));
|
|
1436
|
-
};
|
|
1437
|
-
/**
|
|
1438
|
-
* Restrict a number be not higher than a number
|
|
1439
|
-
*
|
|
1440
|
-
* It's also an alias of `PowiainaNum.min`.
|
|
1441
|
-
* @returns restricted number
|
|
1442
|
-
*/
|
|
1443
|
-
PowiainaNum.clampMax = function () {
|
|
1444
|
-
var args = [];
|
|
1445
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1446
|
-
args[_i] = arguments[_i];
|
|
1447
|
-
}
|
|
1448
|
-
return PowiainaNum.min.apply(PowiainaNum, args);
|
|
1449
|
-
};
|
|
1450
|
-
/**
|
|
1451
|
-
* Restrict a number be not higher than a number
|
|
1452
|
-
*
|
|
1453
|
-
* It's also an alias of `PowiainaNum.min`.
|
|
1454
|
-
* @returns restricted number
|
|
1455
|
-
*/
|
|
1456
|
-
PowiainaNum.prototype.clampMax = function () {
|
|
1457
|
-
var args = [];
|
|
1458
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1459
|
-
args[_i] = arguments[_i];
|
|
1460
|
-
}
|
|
1461
|
-
return PowiainaNum.min.apply(PowiainaNum, __spreadArray([this], args, false));
|
|
1462
|
-
};
|
|
1463
|
-
/**
|
|
1464
|
-
* A combination of minimum and maximum: the value returned by clamp is normally 'this', but it won't go below 'min' and it won't go above 'max'.
|
|
1465
|
-
* Therefore, if 'this' < 'min', then 'min' is returned, and if 'this' > 'max', then 'max' is returned.
|
|
1466
|
-
*/
|
|
1467
|
-
PowiainaNum.prototype.clamp = function (min, max) {
|
|
1468
|
-
return this.max(min).min(max);
|
|
1469
|
-
};
|
|
1470
|
-
PowiainaNum.prototype.max = function () {
|
|
1471
|
-
var args = [];
|
|
1472
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1473
|
-
args[_i] = arguments[_i];
|
|
1474
|
-
}
|
|
1475
|
-
return PowiainaNum.max.apply(PowiainaNum, __spreadArray([this], args, false));
|
|
1476
|
-
};
|
|
1477
|
-
PowiainaNum.prototype.min = function () {
|
|
1478
|
-
var args = [];
|
|
1479
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1480
|
-
args[_i] = arguments[_i];
|
|
1481
|
-
}
|
|
1482
|
-
return PowiainaNum.min.apply(PowiainaNum, __spreadArray([this], args, false));
|
|
1483
|
-
};
|
|
1484
|
-
/**
|
|
1485
|
-
* Compare what PowiainaNum's absolute value is max
|
|
1486
|
-
* @param args
|
|
1487
|
-
* @returns absolute value max number's absolute value
|
|
1488
|
-
*/
|
|
1489
|
-
PowiainaNum.prototype.maxabs = function () {
|
|
1490
|
-
var args = [];
|
|
1491
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1492
|
-
args[_i] = arguments[_i];
|
|
1493
|
-
}
|
|
1494
|
-
var other = args.map(function (x) {
|
|
1495
|
-
return new PowiainaNum(x).abs();
|
|
1496
|
-
});
|
|
1497
|
-
return PowiainaNum.max.apply(PowiainaNum, __spreadArray([this.abs()], other, false));
|
|
1498
|
-
};
|
|
1499
|
-
PowiainaNum.prototype.minabs = function () {
|
|
1500
|
-
var args = [];
|
|
1501
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1502
|
-
args[_i] = arguments[_i];
|
|
1233
|
+
/**
|
|
1234
|
+
* Restrict a number be not higher than a number
|
|
1235
|
+
*
|
|
1236
|
+
* It's also an alias of `PowiainaNum.min`.
|
|
1237
|
+
* @returns restricted number
|
|
1238
|
+
*/
|
|
1239
|
+
}, {
|
|
1240
|
+
key: "clampMax",
|
|
1241
|
+
value:
|
|
1242
|
+
/**
|
|
1243
|
+
* Restrict a number be not higher than a number
|
|
1244
|
+
*
|
|
1245
|
+
* It's also an alias of `PowiainaNum.min`.
|
|
1246
|
+
* @returns restricted number
|
|
1247
|
+
*/
|
|
1248
|
+
function clampMax() {
|
|
1249
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1250
|
+
args[_key3] = arguments[_key3];
|
|
1251
|
+
}
|
|
1252
|
+
return PowiainaNum.min.apply(PowiainaNum, [this].concat(args));
|
|
1503
1253
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
};
|
|
1513
|
-
PowiainaNum.prototype.compare = function (x) {
|
|
1514
|
-
var other = new PowiainaNum(x);
|
|
1515
|
-
if (this.isNaN() || other.isNaN()) return 2;
|
|
1516
|
-
if (this.sign < other.sign) return -1;
|
|
1517
|
-
if (this.sign > other.sign) return 1;
|
|
1518
|
-
//this.sign = other.sign
|
|
1519
|
-
var allneg = this.sign == -1 && other.sign == -1;
|
|
1520
|
-
if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
|
|
1521
|
-
if (other.small && !this.small) return 1 * (allneg ? -1 : 1);
|
|
1522
|
-
var resultreverse = 1;
|
|
1523
|
-
if (this.small && other.small) resultreverse *= -1;
|
|
1524
|
-
if (allneg) resultreverse *= -1;
|
|
1525
|
-
var result = 0;
|
|
1526
|
-
for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
|
|
1527
|
-
var op1 = this.array[this.array.length - 1 - i];
|
|
1528
|
-
var op2 = other.array[other.array.length - 1 - i];
|
|
1529
|
-
var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
|
|
1530
|
-
if (cmp == 1) {
|
|
1531
|
-
result = 1;
|
|
1532
|
-
break;
|
|
1533
|
-
} else if (cmp == -1) {
|
|
1534
|
-
result = -1;
|
|
1535
|
-
break;
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
return result * resultreverse + 1 - 1;
|
|
1539
|
-
};
|
|
1540
|
-
PowiainaNum.prototype.cmp = function (other) {
|
|
1541
|
-
return this.compare(other);
|
|
1542
|
-
};
|
|
1543
|
-
PowiainaNum.prototype.eq = function (other) {
|
|
1544
|
-
return this.cmp(other) === 0;
|
|
1545
|
-
};
|
|
1546
|
-
PowiainaNum.prototype.neq = function (other) {
|
|
1547
|
-
return this.cmp(other) !== 0;
|
|
1548
|
-
};
|
|
1549
|
-
PowiainaNum.prototype.lt = function (other) {
|
|
1550
|
-
return this.cmp(other) === -1;
|
|
1551
|
-
};
|
|
1552
|
-
PowiainaNum.prototype.lte = function (other) {
|
|
1553
|
-
return this.cmp(other) <= 0;
|
|
1554
|
-
};
|
|
1555
|
-
PowiainaNum.prototype.gt = function (other) {
|
|
1556
|
-
return this.cmp(other) == 1;
|
|
1557
|
-
};
|
|
1558
|
-
PowiainaNum.prototype.gte = function (other) {
|
|
1559
|
-
var t = this.cmp(other);
|
|
1560
|
-
return t == 0 || t == 1;
|
|
1561
|
-
};
|
|
1562
|
-
PowiainaNum.prototype.eq_tolerance = function (value, tolerance) {
|
|
1563
|
-
if (tolerance === void 0) {
|
|
1564
|
-
tolerance = 1e-7;
|
|
1254
|
+
/**
|
|
1255
|
+
* A combination of minimum and maximum: the value returned by clamp is normally 'this', but it won't go below 'min' and it won't go above 'max'.
|
|
1256
|
+
* Therefore, if 'this' < 'min', then 'min' is returned, and if 'this' > 'max', then 'max' is returned.
|
|
1257
|
+
*/
|
|
1258
|
+
}, {
|
|
1259
|
+
key: "clamp",
|
|
1260
|
+
value: function clamp(min, max) {
|
|
1261
|
+
return this.max(min).min(max);
|
|
1565
1262
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
PowiainaNum.prototype.sin = function () {
|
|
1572
|
-
var x = this.clone();
|
|
1573
|
-
if (x.isneg()) {
|
|
1574
|
-
return x.neg().sin().neg();
|
|
1575
|
-
}
|
|
1576
|
-
var y = x.mod(7074237752028440);
|
|
1577
|
-
return PowiainaNum.fromNumber(Math.sin(y.toNumber()));
|
|
1578
|
-
};
|
|
1579
|
-
PowiainaNum.prototype.cos = function () {
|
|
1580
|
-
return this.sub(Math.PI / 2).sin();
|
|
1581
|
-
};
|
|
1582
|
-
PowiainaNum.prototype.tan = function () {
|
|
1583
|
-
return this.sin().div(this.cos());
|
|
1584
|
-
};
|
|
1585
|
-
PowiainaNum.prototype.cot = function () {
|
|
1586
|
-
return this.cos().div(this.sin());
|
|
1587
|
-
};
|
|
1588
|
-
PowiainaNum.prototype.sec = function () {
|
|
1589
|
-
return this.cos().rec();
|
|
1590
|
-
};
|
|
1591
|
-
PowiainaNum.prototype.csc = function () {
|
|
1592
|
-
return this.sin().rec();
|
|
1593
|
-
};
|
|
1594
|
-
//#endregion
|
|
1595
|
-
//#region neg, rec, floor, ceil, round, trunc, sign
|
|
1596
|
-
PowiainaNum.prototype.neg = function () {
|
|
1597
|
-
var a = this.clone();
|
|
1598
|
-
a.sign *= -1;
|
|
1599
|
-
a.normalize();
|
|
1600
|
-
return a;
|
|
1601
|
-
};
|
|
1602
|
-
PowiainaNum.prototype.rec = function () {
|
|
1603
|
-
var a = this.clone();
|
|
1604
|
-
a.small = !a.small;
|
|
1605
|
-
return a;
|
|
1606
|
-
};
|
|
1607
|
-
PowiainaNum.prototype.floor = function () {
|
|
1608
|
-
if (this.isInt()) return this.clone();
|
|
1609
|
-
if (this.small) {
|
|
1610
|
-
if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
|
|
1611
|
-
}
|
|
1612
|
-
var r = this.abs();
|
|
1613
|
-
r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
|
|
1614
|
-
return r;
|
|
1615
|
-
};
|
|
1616
|
-
PowiainaNum.prototype.ceil = function () {
|
|
1617
|
-
if (this.isInt()) return this.clone();
|
|
1618
|
-
if (this.small) {
|
|
1619
|
-
if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
|
|
1620
|
-
}
|
|
1621
|
-
var r = this.abs();
|
|
1622
|
-
r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
|
|
1623
|
-
r.sign = this.sign;
|
|
1624
|
-
return r;
|
|
1625
|
-
};
|
|
1626
|
-
PowiainaNum.prototype.round = function () {
|
|
1627
|
-
if (this.isInt()) return this.clone();
|
|
1628
|
-
if (this.small) {
|
|
1629
|
-
if (this.sign == 1) {
|
|
1630
|
-
if (this.rec().lte(2)) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
|
|
1631
|
-
} else {
|
|
1632
|
-
if (this.abs().rec().lte(2)) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
|
|
1263
|
+
}, {
|
|
1264
|
+
key: "max",
|
|
1265
|
+
value: function max() {
|
|
1266
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1267
|
+
args[_key4] = arguments[_key4];
|
|
1633
1268
|
}
|
|
1269
|
+
return PowiainaNum.max.apply(PowiainaNum, [this].concat(args));
|
|
1634
1270
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
/**
|
|
1641
|
-
* Work like `Math.trunc`,
|
|
1642
|
-
*
|
|
1643
|
-
* if `this > 0`, return `floor(this)`
|
|
1644
|
-
*
|
|
1645
|
-
* if `this < 0`, return `ceil(this)`
|
|
1646
|
-
*
|
|
1647
|
-
* @example
|
|
1648
|
-
* new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
|
|
1649
|
-
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
1650
|
-
* @returns
|
|
1651
|
-
*/
|
|
1652
|
-
PowiainaNum.prototype.trunc = function () {
|
|
1653
|
-
var y = this.clone();
|
|
1654
|
-
return y.gte(0) ? y.floor() : y.ceil();
|
|
1655
|
-
};
|
|
1656
|
-
/**
|
|
1657
|
-
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
1658
|
-
*/
|
|
1659
|
-
PowiainaNum.sign = function (a) {
|
|
1660
|
-
return new PowiainaNum(a).sign;
|
|
1661
|
-
};
|
|
1662
|
-
//#endregion
|
|
1663
|
-
//#region judge-numbers
|
|
1664
|
-
PowiainaNum.prototype.isNaN = function () {
|
|
1665
|
-
return isNaN(this.getOperator(0));
|
|
1666
|
-
};
|
|
1667
|
-
PowiainaNum.prototype.isZero = function () {
|
|
1668
|
-
return Boolean(this.small && !isFinite(this.getOperator(0)));
|
|
1669
|
-
};
|
|
1670
|
-
PowiainaNum.prototype.isFinite = function () {
|
|
1671
|
-
return Boolean(this.small || isFinite(this.getOperator(0))) && !this.isNaN();
|
|
1672
|
-
};
|
|
1673
|
-
PowiainaNum.prototype.isInfi = function () {
|
|
1674
|
-
return this.rec().isZero();
|
|
1675
|
-
};
|
|
1676
|
-
PowiainaNum.prototype.isInfiNaN = function () {
|
|
1677
|
-
return this.isInfi() || this.isNaN();
|
|
1678
|
-
};
|
|
1679
|
-
PowiainaNum.prototype.isInt = function () {
|
|
1680
|
-
if (this.isZero()) return true;
|
|
1681
|
-
if (!this.small && Number.isInteger(this.getOperator(0))) return true;
|
|
1682
|
-
if (this.abs().gte(MSI / 2)) return true;
|
|
1683
|
-
return false;
|
|
1684
|
-
};
|
|
1685
|
-
PowiainaNum.prototype.ispos = function () {
|
|
1686
|
-
return this.sign > 0;
|
|
1687
|
-
};
|
|
1688
|
-
PowiainaNum.prototype.isneg = function () {
|
|
1689
|
-
return this.sign < 0;
|
|
1690
|
-
};
|
|
1691
|
-
PowiainaNum.isNaN = function (x) {
|
|
1692
|
-
return new PowiainaNum(x).isNaN();
|
|
1693
|
-
};
|
|
1694
|
-
//#endregion
|
|
1695
|
-
/**
|
|
1696
|
-
* Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
|
|
1697
|
-
* @returns normalized number
|
|
1698
|
-
*/
|
|
1699
|
-
PowiainaNum.prototype.normalize = function () {
|
|
1700
|
-
//TODO: normalize
|
|
1701
|
-
var renormalize = true;
|
|
1702
|
-
var x = this;
|
|
1703
|
-
for (var i_1 = 0; i_1 < this.array.length; i_1++) {
|
|
1704
|
-
// Check what is infinity
|
|
1705
|
-
if (this.array[i_1].repeat == Infinity) {
|
|
1706
|
-
this.array = [{
|
|
1707
|
-
arrow: 0,
|
|
1708
|
-
expans: 1,
|
|
1709
|
-
megota: 1,
|
|
1710
|
-
repeat: Infinity
|
|
1711
|
-
}];
|
|
1712
|
-
this.layer = 0;
|
|
1713
|
-
return this;
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
for (var i = 1; i < x.array.length; ++i) {
|
|
1717
|
-
var e = x.array[i];
|
|
1718
|
-
if (e.arrow === null || e.arrow === undefined) {
|
|
1719
|
-
e.arrow = 0;
|
|
1720
|
-
}
|
|
1721
|
-
if (e.expans === null || e.expans === undefined) {
|
|
1722
|
-
e.expans = 1;
|
|
1723
|
-
}
|
|
1724
|
-
if (e.megota === null || e.megota === undefined) {
|
|
1725
|
-
e.megota = 1;
|
|
1726
|
-
}
|
|
1727
|
-
if (isNaN(e.arrow) || isNaN(e.repeat) || isNaN(e.expans) || isNaN(e.megota)) {
|
|
1728
|
-
x.array = [newOperator(NaN, 0, 1, 1)];
|
|
1729
|
-
return x;
|
|
1271
|
+
}, {
|
|
1272
|
+
key: "min",
|
|
1273
|
+
value: function min() {
|
|
1274
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
1275
|
+
args[_key5] = arguments[_key5];
|
|
1730
1276
|
}
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1277
|
+
return PowiainaNum.min.apply(PowiainaNum, [this].concat(args));
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Compare what PowiainaNum's absolute value is max
|
|
1281
|
+
* @param args
|
|
1282
|
+
* @returns absolute value max number's absolute value
|
|
1283
|
+
*/
|
|
1284
|
+
}, {
|
|
1285
|
+
key: "maxabs",
|
|
1286
|
+
value: function maxabs() {
|
|
1287
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
1288
|
+
args[_key6] = arguments[_key6];
|
|
1289
|
+
}
|
|
1290
|
+
var other = args.map(function (x) {
|
|
1291
|
+
return new PowiainaNum(x).abs();
|
|
1292
|
+
});
|
|
1293
|
+
return PowiainaNum.max.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
|
|
1294
|
+
}
|
|
1295
|
+
}, {
|
|
1296
|
+
key: "minabs",
|
|
1297
|
+
value: function minabs() {
|
|
1298
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
1299
|
+
args[_key7] = arguments[_key7];
|
|
1734
1300
|
}
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1301
|
+
var other = args.map(function (x) {
|
|
1302
|
+
return new PowiainaNum(x).abs();
|
|
1303
|
+
});
|
|
1304
|
+
return PowiainaNum.min.apply(PowiainaNum, [this.abs()].concat(_toConsumableArray(other)));
|
|
1305
|
+
}
|
|
1306
|
+
}, {
|
|
1307
|
+
key: "cmpabs",
|
|
1308
|
+
value: function cmpabs(x) {
|
|
1309
|
+
var other = new PowiainaNum(x).abs();
|
|
1310
|
+
return this.abs().cmp(other);
|
|
1311
|
+
}
|
|
1312
|
+
}, {
|
|
1313
|
+
key: "compare",
|
|
1314
|
+
value: function compare(x) {
|
|
1315
|
+
var other = new PowiainaNum(x);
|
|
1316
|
+
if (this.isNaN() || other.isNaN()) return 2;
|
|
1317
|
+
if (this.sign < other.sign) return -1;
|
|
1318
|
+
if (this.sign > other.sign) return 1;
|
|
1319
|
+
//this.sign = other.sign
|
|
1320
|
+
var allneg = this.sign == -1 && other.sign == -1;
|
|
1321
|
+
if (this.small && !other.small) return -1 * (allneg ? -1 : 1);
|
|
1322
|
+
if (other.small && !this.small) return 1 * (allneg ? -1 : 1);
|
|
1323
|
+
var resultreverse = 1;
|
|
1324
|
+
if (this.small && other.small) resultreverse *= -1;
|
|
1325
|
+
if (allneg) resultreverse *= -1;
|
|
1326
|
+
var result = 0;
|
|
1327
|
+
for (var i = 0; this.array.length - 1 - i >= 0 && other.array.length - 1 - i >= 0; i++) {
|
|
1328
|
+
var op1 = this.array[this.array.length - 1 - i];
|
|
1329
|
+
var op2 = other.array[other.array.length - 1 - i];
|
|
1330
|
+
var cmp = compareTuples([op1.megota, op1.expans, op1.arrow, op1.repeat], [op2.megota, op2.expans, op2.arrow, op2.repeat]);
|
|
1331
|
+
if (cmp == 1) {
|
|
1332
|
+
result = 1;
|
|
1333
|
+
break;
|
|
1334
|
+
} else if (cmp == -1) {
|
|
1335
|
+
result = -1;
|
|
1336
|
+
break;
|
|
1755
1337
|
}
|
|
1756
1338
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
};
|
|
1849
|
-
//#region operators
|
|
1850
|
-
/**
|
|
1851
|
-
* @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.
|
|
1852
|
-
*/
|
|
1853
|
-
PowiainaNum.prototype.getOperatorIndex = function (arrow, expans, megota) {
|
|
1854
|
-
if (expans === void 0) {
|
|
1855
|
-
expans = 1;
|
|
1856
|
-
}
|
|
1857
|
-
if (megota === void 0) {
|
|
1858
|
-
megota = 1;
|
|
1859
|
-
}
|
|
1860
|
-
for (var i = 0; i < this.array.length; i++) {
|
|
1861
|
-
var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
|
|
1862
|
-
if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
|
|
1863
|
-
if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
|
|
1864
|
-
}
|
|
1865
|
-
return this.array.length - 0.5;
|
|
1866
|
-
};
|
|
1867
|
-
/**
|
|
1868
|
-
* @returns number repeats of operators with given arguments.
|
|
1869
|
-
*/
|
|
1870
|
-
PowiainaNum.prototype.getOperator = function (arrow, expans, megota) {
|
|
1871
|
-
if (expans === void 0) {
|
|
1872
|
-
expans = 1;
|
|
1339
|
+
return result * resultreverse + 1 - 1;
|
|
1340
|
+
}
|
|
1341
|
+
}, {
|
|
1342
|
+
key: "cmp",
|
|
1343
|
+
value: function cmp(other) {
|
|
1344
|
+
return this.compare(other);
|
|
1345
|
+
}
|
|
1346
|
+
}, {
|
|
1347
|
+
key: "eq",
|
|
1348
|
+
value: function eq(other) {
|
|
1349
|
+
return this.cmp(other) === 0;
|
|
1350
|
+
}
|
|
1351
|
+
}, {
|
|
1352
|
+
key: "neq",
|
|
1353
|
+
value: function neq(other) {
|
|
1354
|
+
return this.cmp(other) !== 0;
|
|
1355
|
+
}
|
|
1356
|
+
}, {
|
|
1357
|
+
key: "lt",
|
|
1358
|
+
value: function lt(other) {
|
|
1359
|
+
return this.cmp(other) === -1;
|
|
1360
|
+
}
|
|
1361
|
+
}, {
|
|
1362
|
+
key: "lte",
|
|
1363
|
+
value: function lte(other) {
|
|
1364
|
+
return this.cmp(other) <= 0;
|
|
1365
|
+
}
|
|
1366
|
+
}, {
|
|
1367
|
+
key: "gt",
|
|
1368
|
+
value: function gt(other) {
|
|
1369
|
+
return this.cmp(other) == 1;
|
|
1370
|
+
}
|
|
1371
|
+
}, {
|
|
1372
|
+
key: "gte",
|
|
1373
|
+
value: function gte(other) {
|
|
1374
|
+
var t = this.cmp(other);
|
|
1375
|
+
return t == 0 || t == 1;
|
|
1376
|
+
}
|
|
1377
|
+
}, {
|
|
1378
|
+
key: "eq_tolerance",
|
|
1379
|
+
value: function eq_tolerance(value) {
|
|
1380
|
+
var tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e-7;
|
|
1381
|
+
var dec = new PowiainaNum(value);
|
|
1382
|
+
return this.sub(dec).lte(this.max(dec).mul(tolerance));
|
|
1383
|
+
}
|
|
1384
|
+
//#endregion
|
|
1385
|
+
//#region geometry
|
|
1386
|
+
}, {
|
|
1387
|
+
key: "sin",
|
|
1388
|
+
value: function sin() {
|
|
1389
|
+
var x = this.clone();
|
|
1390
|
+
if (x.isneg()) {
|
|
1391
|
+
return x.neg().sin().neg();
|
|
1392
|
+
}
|
|
1393
|
+
var y = x.mod(7074237752028440);
|
|
1394
|
+
return PowiainaNum.fromNumber(Math.sin(y.toNumber()));
|
|
1395
|
+
}
|
|
1396
|
+
}, {
|
|
1397
|
+
key: "cos",
|
|
1398
|
+
value: function cos() {
|
|
1399
|
+
return this.sub(Math.PI / 2).sin();
|
|
1400
|
+
}
|
|
1401
|
+
}, {
|
|
1402
|
+
key: "tan",
|
|
1403
|
+
value: function tan() {
|
|
1404
|
+
return this.sin().div(this.cos());
|
|
1405
|
+
}
|
|
1406
|
+
}, {
|
|
1407
|
+
key: "cot",
|
|
1408
|
+
value: function cot() {
|
|
1409
|
+
return this.cos().div(this.sin());
|
|
1410
|
+
}
|
|
1411
|
+
}, {
|
|
1412
|
+
key: "sec",
|
|
1413
|
+
value: function sec() {
|
|
1414
|
+
return this.cos().rec();
|
|
1415
|
+
}
|
|
1416
|
+
}, {
|
|
1417
|
+
key: "csc",
|
|
1418
|
+
value: function csc() {
|
|
1419
|
+
return this.sin().rec();
|
|
1420
|
+
}
|
|
1421
|
+
//#endregion
|
|
1422
|
+
//#region neg, rec, floor, ceil, round, trunc, sign
|
|
1423
|
+
}, {
|
|
1424
|
+
key: "neg",
|
|
1425
|
+
value: function neg() {
|
|
1426
|
+
var a = this.clone();
|
|
1427
|
+
a.sign *= -1;
|
|
1428
|
+
a.normalize();
|
|
1429
|
+
return a;
|
|
1873
1430
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1431
|
+
}, {
|
|
1432
|
+
key: "rec",
|
|
1433
|
+
value: function rec() {
|
|
1434
|
+
var a = this.clone();
|
|
1435
|
+
a.small = !a.small;
|
|
1436
|
+
return a;
|
|
1876
1437
|
}
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
if (expans === void 0) {
|
|
1888
|
-
expans = 1;
|
|
1889
|
-
}
|
|
1890
|
-
if (megota === void 0) {
|
|
1891
|
-
megota = 1;
|
|
1892
|
-
}
|
|
1893
|
-
// if (arrow!=0&&val==0) return false;
|
|
1894
|
-
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1895
|
-
if (!this.array[index]) {
|
|
1896
|
-
this.array.splice(Math.ceil(index), 0, {
|
|
1897
|
-
arrow: arrow,
|
|
1898
|
-
expans: expans,
|
|
1899
|
-
megota: megota,
|
|
1900
|
-
valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
|
|
1901
|
-
repeat: val
|
|
1902
|
-
});
|
|
1903
|
-
return true;
|
|
1438
|
+
}, {
|
|
1439
|
+
key: "floor",
|
|
1440
|
+
value: function floor() {
|
|
1441
|
+
if (this.isInt()) return this.clone();
|
|
1442
|
+
if (this.small) {
|
|
1443
|
+
if (this.sign == 1) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
|
|
1444
|
+
}
|
|
1445
|
+
var r = this.abs();
|
|
1446
|
+
r.array[0].repeat = Math[this.sign == 1 ? "floor" : "ceil"](r.getOperator(0));
|
|
1447
|
+
return r;
|
|
1904
1448
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
return obj;
|
|
1917
|
-
};
|
|
1918
|
-
/**
|
|
1919
|
-
* Set `this` from a object(deep-copy)
|
|
1920
|
-
* @param powlikeObject
|
|
1921
|
-
* @returns
|
|
1922
|
-
*/
|
|
1923
|
-
PowiainaNum.prototype.resetFromObject = function (powlikeObject) {
|
|
1924
|
-
this.array = [];
|
|
1925
|
-
for (var i = 0; i < powlikeObject.array.length; i++) {
|
|
1926
|
-
this.array[i] = {
|
|
1927
|
-
arrow: powlikeObject.array[i].arrow,
|
|
1928
|
-
expans: powlikeObject.array[i].expans,
|
|
1929
|
-
megota: powlikeObject.array[i].megota,
|
|
1930
|
-
repeat: powlikeObject.array[i].repeat,
|
|
1931
|
-
valuereplaced: powlikeObject.array[i].valuereplaced
|
|
1932
|
-
};
|
|
1449
|
+
}, {
|
|
1450
|
+
key: "ceil",
|
|
1451
|
+
value: function ceil() {
|
|
1452
|
+
if (this.isInt()) return this.clone();
|
|
1453
|
+
if (this.small) {
|
|
1454
|
+
if (this.sign == 1) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
|
|
1455
|
+
}
|
|
1456
|
+
var r = this.abs();
|
|
1457
|
+
r.array[0].repeat = Math[this.sign == 1 ? "ceil" : "floor"](r.getOperator(0));
|
|
1458
|
+
r.sign = this.sign;
|
|
1459
|
+
return r;
|
|
1933
1460
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
*/
|
|
1945
|
-
PowiainaNum.prototype.toNumber = function () {
|
|
1946
|
-
if (this.sign == -1) return -this.neg().toNumber();
|
|
1947
|
-
if (this.small) return 1 / this.rec().toNumber();
|
|
1948
|
-
if (this.array.length > 2) return Infinity;
|
|
1949
|
-
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));
|
|
1950
|
-
return NaN;
|
|
1951
|
-
};
|
|
1952
|
-
/**
|
|
1953
|
-
* Convert `this` to a string
|
|
1954
|
-
*/
|
|
1955
|
-
PowiainaNum.prototype.toString = function () {
|
|
1956
|
-
if (this.isNaN()) return "NaN";
|
|
1957
|
-
if (this.sign == -1) return "-".concat(this.neg().toString());
|
|
1958
|
-
if (this.small) {
|
|
1959
|
-
if (this.isZero()) return "0";
|
|
1960
|
-
return "/".concat(this.rec().toString());
|
|
1961
|
-
}
|
|
1962
|
-
if (this.isInfi()) return "Infinity";
|
|
1963
|
-
// P^a (10{arrow,expans,megota})^repeation base
|
|
1964
|
-
var res = "";
|
|
1965
|
-
if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
|
|
1966
|
-
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
1967
|
-
var oper = this.array[i];
|
|
1968
|
-
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) : "", "}");
|
|
1969
|
-
if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
|
|
1970
|
-
calc = "e".repeat(oper.repeat);
|
|
1971
|
-
} else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
|
|
1972
|
-
calc = oper.repeat.toString();
|
|
1973
|
-
} else if (oper.repeat > 1) {
|
|
1974
|
-
calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
|
|
1975
|
-
} else {
|
|
1976
|
-
calc = "".concat(calc);
|
|
1461
|
+
}, {
|
|
1462
|
+
key: "round",
|
|
1463
|
+
value: function round() {
|
|
1464
|
+
if (this.isInt()) return this.clone();
|
|
1465
|
+
if (this.small) {
|
|
1466
|
+
if (this.sign == 1) {
|
|
1467
|
+
if (this.rec().lte(2)) return PowiainaNum.ONE.clone();else return PowiainaNum.ZERO.clone();
|
|
1468
|
+
} else {
|
|
1469
|
+
if (this.abs().rec().lte(2)) return PowiainaNum.ZERO.clone();else return PowiainaNum.ONE.neg().clone();
|
|
1470
|
+
}
|
|
1977
1471
|
}
|
|
1978
|
-
|
|
1472
|
+
var r = this.abs();
|
|
1473
|
+
r.array[0].repeat = Math.round(r.array[0].repeat);
|
|
1474
|
+
r.sign = this.sign;
|
|
1475
|
+
return r;
|
|
1979
1476
|
}
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
} else if (y < MSI_REC) {
|
|
1998
|
-
obj.small = true;
|
|
1999
|
-
obj.array = [newOperator(-Math.log10(y), 0), newOperator(1, 1)];
|
|
2000
|
-
} else if (y <= MSI) {
|
|
2001
|
-
obj.array = [newOperator(y, 0)];
|
|
2002
|
-
} else {
|
|
2003
|
-
obj.setOperator(Math.log10(y), 0);
|
|
2004
|
-
obj.array = [newOperator(Math.log10(y), 0), newOperator(1, 1)];
|
|
1477
|
+
/**
|
|
1478
|
+
* Work like `Math.trunc`,
|
|
1479
|
+
*
|
|
1480
|
+
* if `this > 0`, return `floor(this)`
|
|
1481
|
+
*
|
|
1482
|
+
* if `this < 0`, return `ceil(this)`
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
* new PowiainaNum(3.3).trunc() == new PowiainaNum(3)
|
|
1486
|
+
* new PowiainaNum(-1.114514).trunc() == new PowiainaNum(-1)
|
|
1487
|
+
* @returns
|
|
1488
|
+
*/
|
|
1489
|
+
}, {
|
|
1490
|
+
key: "trunc",
|
|
1491
|
+
value: function trunc() {
|
|
1492
|
+
var y = this.clone();
|
|
1493
|
+
return y.gte(0) ? y.floor() : y.ceil();
|
|
2005
1494
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
1495
|
+
/**
|
|
1496
|
+
* @returns if this<other, return -1, if this=other, return 0, if this>other, return 1, if this!<=>, return 2
|
|
1497
|
+
*/
|
|
1498
|
+
}, {
|
|
1499
|
+
key: "isNaN",
|
|
1500
|
+
value: function (_isNaN) {
|
|
1501
|
+
function isNaN() {
|
|
1502
|
+
return _isNaN.apply(this, arguments);
|
|
1503
|
+
}
|
|
1504
|
+
isNaN.toString = function () {
|
|
1505
|
+
return _isNaN.toString();
|
|
1506
|
+
};
|
|
1507
|
+
return isNaN;
|
|
1508
|
+
}(
|
|
1509
|
+
//#endregion
|
|
1510
|
+
//#region judge-numbers
|
|
1511
|
+
function () {
|
|
1512
|
+
return isNaN(this.getOperator(0));
|
|
1513
|
+
})
|
|
1514
|
+
}, {
|
|
1515
|
+
key: "isZero",
|
|
1516
|
+
value: function isZero() {
|
|
1517
|
+
return Boolean(this.small && !isFinite(this.getOperator(0)));
|
|
1518
|
+
}
|
|
1519
|
+
}, {
|
|
1520
|
+
key: "isFinite",
|
|
1521
|
+
value: function (_isFinite) {
|
|
1522
|
+
function isFinite() {
|
|
1523
|
+
return _isFinite.apply(this, arguments);
|
|
1524
|
+
}
|
|
1525
|
+
isFinite.toString = function () {
|
|
1526
|
+
return _isFinite.toString();
|
|
1527
|
+
};
|
|
1528
|
+
return isFinite;
|
|
1529
|
+
}(function () {
|
|
1530
|
+
return Boolean(this.small || isFinite(this.getOperator(0))) && !this.isNaN();
|
|
1531
|
+
})
|
|
1532
|
+
}, {
|
|
1533
|
+
key: "isInfi",
|
|
1534
|
+
value: function isInfi() {
|
|
1535
|
+
return this.rec().isZero();
|
|
1536
|
+
}
|
|
1537
|
+
}, {
|
|
1538
|
+
key: "isInfiNaN",
|
|
1539
|
+
value: function isInfiNaN() {
|
|
1540
|
+
return this.isInfi() || this.isNaN();
|
|
1541
|
+
}
|
|
1542
|
+
}, {
|
|
1543
|
+
key: "isInt",
|
|
1544
|
+
value: function isInt() {
|
|
1545
|
+
if (this.isZero()) return true;
|
|
1546
|
+
if (!this.small && Number.isInteger(this.getOperator(0))) return true;
|
|
1547
|
+
if (this.abs().gte(MSI / 2)) return true;
|
|
1548
|
+
return false;
|
|
1549
|
+
}
|
|
1550
|
+
}, {
|
|
1551
|
+
key: "ispos",
|
|
1552
|
+
value: function ispos() {
|
|
1553
|
+
return this.sign > 0;
|
|
1554
|
+
}
|
|
1555
|
+
}, {
|
|
1556
|
+
key: "isneg",
|
|
1557
|
+
value: function isneg() {
|
|
1558
|
+
return this.sign < 0;
|
|
1559
|
+
}
|
|
1560
|
+
}, {
|
|
1561
|
+
key: "normalize",
|
|
1562
|
+
value:
|
|
1563
|
+
//#endregion
|
|
1564
|
+
/**
|
|
1565
|
+
* Normalize functions will make this number convert into standard format.(it also change `this`, like [].sort)
|
|
1566
|
+
* @returns normalized number
|
|
1567
|
+
*/
|
|
1568
|
+
function normalize() {
|
|
1569
|
+
//TODO: normalize
|
|
1570
|
+
var renormalize = true;
|
|
1571
|
+
var x = this;
|
|
1572
|
+
for (var _i = 0; _i < this.array.length; _i++) {
|
|
1573
|
+
// Check what is infinity
|
|
1574
|
+
if (this.array[_i].repeat == Infinity) {
|
|
1575
|
+
this.array = [{
|
|
1576
|
+
arrow: 0,
|
|
1577
|
+
expans: 1,
|
|
1578
|
+
megota: 1,
|
|
1579
|
+
repeat: Infinity
|
|
1580
|
+
}];
|
|
1581
|
+
this.layer = 0;
|
|
1582
|
+
return this;
|
|
2026
1583
|
}
|
|
2027
|
-
} else {
|
|
2028
|
-
a_1 = true;
|
|
2029
|
-
}
|
|
2030
|
-
if (!a_1) {
|
|
2031
|
-
var m = input.search(/e/);
|
|
2032
|
-
var exponent = input.substring((m == -1 ? input.length : m) + 1);
|
|
2033
|
-
var mantissa = input.substring(0, m == -1 ? undefined : m);
|
|
2034
|
-
var mantissaME = [0, 0];
|
|
2035
|
-
// Handle mantissa to ME
|
|
2036
|
-
mantissaME[1] = Number(exponent ? exponent : "0");
|
|
2037
|
-
// Is regular number gte 1:
|
|
2038
|
-
if (Number(mantissa) >= 1) {
|
|
2039
|
-
// check The mantissa is very long?
|
|
2040
|
-
var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
|
|
2041
|
-
var log10int = Math.floor(log10mant) - 1;
|
|
2042
|
-
var log10float = log10mant - log10int;
|
|
2043
|
-
mantissaME[0] = Math.pow(10, log10float);
|
|
2044
|
-
mantissaME[1] += log10float;
|
|
2045
|
-
} else {
|
|
2046
|
-
// If not , count how many zeros until reached non-zero numbers
|
|
2047
|
-
var zeros = countLeadingZerosAfterDecimal(mantissa);
|
|
2048
|
-
mantissa = mantissa.substring(mantissa.search(/[1-9]/));
|
|
2049
|
-
mantissa = mantissa.charAt(0) + "." + mantissa.substring(1);
|
|
2050
|
-
zeros += 1;
|
|
2051
|
-
mantissaME[0] = Number(mantissa);
|
|
2052
|
-
mantissaME[1] += -zeros;
|
|
2053
|
-
}
|
|
2054
|
-
// We'll get [a, b] which respents a*10^b;
|
|
2055
|
-
// actually b < 0; So we can ^-1
|
|
2056
|
-
// /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
|
|
2057
|
-
return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
|
|
2058
|
-
}
|
|
2059
|
-
if (isFinite(res) && a_1) {
|
|
2060
|
-
x = PowiainaNum.fromNumber(Number(input));
|
|
2061
|
-
return x;
|
|
2062
1584
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
(10^ - 匹配
|
|
2103
|
-
(10{ - 匹配
|
|
2104
|
-
10x - 不匹配(最后一个字符不是 ^ 或 {)
|
|
2105
|
-
110^ - 不匹配(不是以 10 开头)
|
|
2106
|
-
*/
|
|
2107
|
-
if (input[0] == "(") input = input.substring(1);
|
|
2108
|
-
//cutted, 10^.... or 10{....
|
|
2109
|
-
var arrows, expans, megota;
|
|
2110
|
-
if (input[2] == "^") {
|
|
2111
|
-
a = input.substring(2).search(/[^\^]/);
|
|
2112
|
-
//cut input to ^^...^^, and search how numbers
|
|
2113
|
-
arrows = a;
|
|
2114
|
-
// 10^^^
|
|
2115
|
-
b = a + 2; // b points to after ^'s.
|
|
2116
|
-
} else {
|
|
2117
|
-
// 10{...}
|
|
2118
|
-
a = input.indexOf("}");
|
|
2119
|
-
// select contents between {...}
|
|
2120
|
-
var tmp = input.substring(3, a).split(",");
|
|
2121
|
-
arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
|
|
2122
|
-
expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
|
|
2123
|
-
megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
|
|
2124
|
-
b = a + 1;
|
|
2125
|
-
// b points to after }.
|
|
1585
|
+
for (var i = 1; i < x.array.length; ++i) {
|
|
1586
|
+
var e = x.array[i];
|
|
1587
|
+
if (e.arrow === null || e.arrow === undefined) {
|
|
1588
|
+
e.arrow = 0;
|
|
1589
|
+
}
|
|
1590
|
+
if (e.expans === null || e.expans === undefined) {
|
|
1591
|
+
e.expans = 1;
|
|
1592
|
+
}
|
|
1593
|
+
if (e.megota === null || e.megota === undefined) {
|
|
1594
|
+
e.megota = 1;
|
|
1595
|
+
}
|
|
1596
|
+
if (isNaN(e.arrow) || isNaN(e.repeat) || isNaN(e.expans) || isNaN(e.megota)) {
|
|
1597
|
+
x.array = [newOperator(NaN, 0, 1, 1)];
|
|
1598
|
+
return x;
|
|
1599
|
+
}
|
|
1600
|
+
if (!isFinite(e.repeat) || !isFinite(e.megota)) {
|
|
1601
|
+
x.array = [newOperator(Infinity, 0, 1, 1)];
|
|
1602
|
+
return x;
|
|
1603
|
+
}
|
|
1604
|
+
if (!Number.isInteger(e.arrow)) e.arrow = Math.floor(e.arrow);
|
|
1605
|
+
if (!Number.isInteger(e.repeat)) e.repeat = Math.floor(e.repeat);
|
|
1606
|
+
if (!Number.isInteger(e.expans)) e.expans = Math.floor(e.expans);
|
|
1607
|
+
if (!Number.isInteger(e.megota)) e.megota = Math.floor(e.megota);
|
|
1608
|
+
}
|
|
1609
|
+
if (!x.array.length) {
|
|
1610
|
+
x.small = !x.small;
|
|
1611
|
+
x.array = [newOperator(Infinity)]; // if no array set zero
|
|
1612
|
+
}
|
|
1613
|
+
do {
|
|
1614
|
+
renormalize = false;
|
|
1615
|
+
// Sort arrays.
|
|
1616
|
+
this.array.sort(arraySortFunction);
|
|
1617
|
+
for (i = 1; i < x.array.length - 1; ++i) {
|
|
1618
|
+
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) {
|
|
1619
|
+
// same array's merge
|
|
1620
|
+
x.array[i].repeat += x.array[i + 1].repeat;
|
|
1621
|
+
x.array.splice(i + 1, 1);
|
|
1622
|
+
--i;
|
|
1623
|
+
renormalize = true;
|
|
2126
1624
|
}
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
c = 1; // There is only spaces, count as <ONE>
|
|
1625
|
+
}
|
|
1626
|
+
for (i = 1; i < x.array.length; ++i) {
|
|
1627
|
+
// If there is a 0 repeat operator, remove it.
|
|
1628
|
+
if (x.array[i].arrow !== 0 && (x.array[i].repeat === 0 || x.array[i].repeat === null || x.array[i].repeat === undefined)) {
|
|
1629
|
+
x.array.splice(i, 1);
|
|
1630
|
+
--i;
|
|
1631
|
+
continue;
|
|
2135
1632
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
} else if (arrows == 2 && expans == 1 && megota == 1) {
|
|
2143
|
-
a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
|
|
2144
|
-
b = x.array[0].repeat;
|
|
2145
|
-
if (b >= 1e10) ++a;
|
|
2146
|
-
if (b >= 10) ++a;
|
|
2147
|
-
x.array[0].repeat = a;
|
|
2148
|
-
if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
|
|
2149
|
-
d = x.getOperatorIndex(2);
|
|
2150
|
-
if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
|
|
2151
|
-
} else if (isFinite(arrows)) {
|
|
2152
|
-
a = x.getOperator(arrows - 1);
|
|
2153
|
-
b = x.getOperator(arrows - 2);
|
|
2154
|
-
if (b >= 10) ++a;
|
|
2155
|
-
d = x.getOperatorIndex(arrows);
|
|
2156
|
-
x.array.splice(1, Math.ceil(d) - 1);
|
|
2157
|
-
x.array[0].repeat = a;
|
|
2158
|
-
if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
2159
|
-
} else {
|
|
2160
|
-
x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
1633
|
+
// If there is a operator which arrow 0 and brace count >=2
|
|
1634
|
+
// replace it as arrow replacement operaotr
|
|
1635
|
+
if (x.array[i].arrow == 0 && x.array[i].expans >= 2) {
|
|
1636
|
+
x.array[i].arrow = Infinity;
|
|
1637
|
+
x.array[i].valuereplaced = 0;
|
|
1638
|
+
x.array[i].expans = x.array[i].expans - 1;
|
|
2161
1639
|
}
|
|
2162
|
-
} else {
|
|
2163
|
-
break;
|
|
2164
1640
|
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
1641
|
+
if (x.array.length > PowiainaNum.maxOps) x.array.splice(1, x.array.length - PowiainaNum.maxOps); // max operators check
|
|
1642
|
+
// for any 10^a but a >log10(MSI), replace to regular 10^a
|
|
1643
|
+
if (this.array.length >= 2 && this.array[1].arrow == 1 && this.array[1].repeat >= 1 && this.array[0].repeat < MSI_LOG10) {
|
|
1644
|
+
this.setOperator(this.array[1].repeat - 1, 1);
|
|
1645
|
+
this.setOperator(Math.pow(10, this.array[0].repeat), 0);
|
|
1646
|
+
renormalize = true;
|
|
1647
|
+
}
|
|
1648
|
+
if (this.getOperator(0) > MSI && isFinite(this.getOperator(0))) {
|
|
1649
|
+
this.setOperator(this.getOperator(1) + 1, 1);
|
|
1650
|
+
this.setOperator(Math.log10(this.getOperator(0)), 0);
|
|
1651
|
+
renormalize = true;
|
|
1652
|
+
}
|
|
1653
|
+
if (this.array[this.array.length - 1].megota > MSI) {
|
|
1654
|
+
this.layer++;
|
|
1655
|
+
this.array = [newOperator(this.array[this.array.length - 1].megota)];
|
|
1656
|
+
renormalize = true;
|
|
1657
|
+
} else if (this.layer && this.array.length == 1 && this.array[0].arrow === 0) {
|
|
1658
|
+
this.layer--;
|
|
1659
|
+
this.array = [newOperator(10), newOperator(1, 10, 10, this.array[0].repeat)];
|
|
1660
|
+
renormalize = true;
|
|
1661
|
+
}
|
|
1662
|
+
// for a<1, turn into reciprocate
|
|
1663
|
+
if (this.array.length == 1 && this.array[0].repeat < 1) {
|
|
1664
|
+
this.array[0].repeat = 1 / this.array[0].repeat;
|
|
1665
|
+
this.small = !this.small;
|
|
1666
|
+
renormalize = true;
|
|
1667
|
+
}
|
|
1668
|
+
// for any 10{X>9e15}10, replace into 10{!}X;
|
|
1669
|
+
if (this.array.length >= 2 && this.array[1].arrow >= MSI) {
|
|
1670
|
+
this.array[0].repeat = this.array[1].arrow;
|
|
1671
|
+
this.array[1] = newOperator(1, Infinity, this.array[1].expans, this.array[1].megota);
|
|
1672
|
+
}
|
|
1673
|
+
while (x.array.length >= 2 && x.array[0].repeat == 1 && x.array[1].repeat) {
|
|
1674
|
+
// for any 10{X}10{X} 1, turn into 10{X}10
|
|
1675
|
+
// [1, [R=sth, A=sth, E=sth, M=sth]]
|
|
1676
|
+
if (x.array[1].repeat > 1) {
|
|
1677
|
+
x.array[1].repeat--;
|
|
2178
1678
|
} else {
|
|
2179
|
-
|
|
1679
|
+
x.array.splice(1, 1);
|
|
2180
1680
|
}
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
b[1]++;
|
|
1681
|
+
x.array[0].repeat = 10;
|
|
1682
|
+
renormalize = true;
|
|
2184
1683
|
}
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
b[0] += Math.log10(1 + Math.pow(10, Math.log10(d) - b[0]));
|
|
2196
|
-
}
|
|
1684
|
+
if (x.array.length >= 2 && x.array.length < PowiainaNum.maxOps && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat > 1 &&
|
|
1685
|
+
//10^^^ 10
|
|
1686
|
+
isFinite(x.array[1].arrow)) {
|
|
1687
|
+
// for any (10{A sample=2})^k 1e9, turn into (10{A})^k-1 (10{A-1})^1e9-1 10
|
|
1688
|
+
// But dont convert when a is infinite
|
|
1689
|
+
// [1e9, [R=K, A=2, sth, sth]]
|
|
1690
|
+
x.array[1].repeat--;
|
|
1691
|
+
x.array.splice(1, 0, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
|
|
1692
|
+
x.array[0].repeat = 10;
|
|
1693
|
+
renormalize = true;
|
|
2197
1694
|
}
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
1695
|
+
if (x.array.length >= 2 && x.array[0].repeat < MSI && x.array[1].arrow >= 2 && x.array[1].repeat == 1 &&
|
|
1696
|
+
//10^^^ 10
|
|
1697
|
+
isFinite(x.array[1].arrow)) {
|
|
1698
|
+
// for any 10{A sample=2}1e9, turn into (10{A-1})^1e9-1 10
|
|
1699
|
+
// But dont convert when a is infinite
|
|
1700
|
+
// [1e9, [R=1, A=2, sth, sth]]
|
|
1701
|
+
x.array.splice(1, 1, newOperator(x.array[0].repeat - 1, x.array[1].arrow - 1, x.array[1].expans, x.array[1].megota));
|
|
1702
|
+
x.array[0].repeat = 10;
|
|
1703
|
+
renormalize = true;
|
|
2205
1704
|
}
|
|
1705
|
+
// for any (10{A=2})^1e16 10, turn into (10{A+1}) 1e16
|
|
1706
|
+
if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow !== Infinity) {
|
|
1707
|
+
x.array[1].arrow++;
|
|
1708
|
+
x.array[0].repeat = x.array[1].repeat;
|
|
1709
|
+
x.array[1].repeat = 1;
|
|
1710
|
+
renormalize = true;
|
|
1711
|
+
}
|
|
1712
|
+
// for any (10{x})^1e16 10, turn into (10{1,2}) 1e16
|
|
1713
|
+
if (x.array.length >= 2 && x.array[1].repeat > MSI && x.array[1].arrow === Infinity) {
|
|
1714
|
+
x.array[1].arrow = 1;
|
|
1715
|
+
x.array[1].expans++;
|
|
1716
|
+
x.array[0].repeat = x.array[1].repeat;
|
|
1717
|
+
x.array[1].repeat = 1;
|
|
1718
|
+
renormalize = true;
|
|
1719
|
+
}
|
|
1720
|
+
} while (renormalize);
|
|
1721
|
+
return this;
|
|
1722
|
+
}
|
|
1723
|
+
//#region operators
|
|
1724
|
+
/**
|
|
1725
|
+
* @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.
|
|
1726
|
+
*/
|
|
1727
|
+
}, {
|
|
1728
|
+
key: "getOperatorIndex",
|
|
1729
|
+
value: function getOperatorIndex(arrow) {
|
|
1730
|
+
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1731
|
+
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1732
|
+
for (var i = 0; i < this.array.length; i++) {
|
|
1733
|
+
var cmp = compareTuples([this.array[i].megota, this.array[i].expans, this.array[i].arrow], [megota, expans, arrow]);
|
|
1734
|
+
if (cmp == 0) return i; // I find it was [xx,xxx,*xxx*,xxx]!
|
|
1735
|
+
if (cmp == 1) return i - 0.5; // It's between [xx, xx,xx*,?,*xx]!
|
|
2206
1736
|
}
|
|
2207
|
-
|
|
2208
|
-
if (b[1]) {
|
|
2209
|
-
if (x.array.length >= 2 && x.array[1].arrow == 1 && x.array[1].expans == 1 && x.array[1].megota == 1) x.array[1].repeat += b[1];else x.array.splice(1, 0, newOperator(b[1], 1, 1, 1));
|
|
2210
|
-
}
|
|
1737
|
+
return this.array.length - 0.5;
|
|
2211
1738
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
1739
|
+
/**
|
|
1740
|
+
* @returns number repeats of operators with given arguments.
|
|
1741
|
+
*/
|
|
1742
|
+
}, {
|
|
1743
|
+
key: "getOperator",
|
|
1744
|
+
value: function getOperator(arrow) {
|
|
1745
|
+
var expans = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1746
|
+
var megota = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1747
|
+
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1748
|
+
if (!this.array[index]) return 0;
|
|
1749
|
+
return this.array[index].repeat;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Modify the repeat of operator
|
|
1753
|
+
* @param number val the repeat of operator will modify to array.
|
|
1754
|
+
* @returns bool Is the operators array changed?
|
|
1755
|
+
*/
|
|
1756
|
+
}, {
|
|
1757
|
+
key: "setOperator",
|
|
1758
|
+
value: function setOperator(val, arrow) {
|
|
1759
|
+
var expans = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1760
|
+
var megota = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
1761
|
+
// if (arrow!=0&&val==0) return false;
|
|
1762
|
+
var index = this.getOperatorIndex(arrow, expans, megota);
|
|
1763
|
+
if (!this.array[index]) {
|
|
1764
|
+
this.array.splice(Math.ceil(index), 0, {
|
|
1765
|
+
arrow: arrow,
|
|
1766
|
+
expans: expans,
|
|
1767
|
+
megota: megota,
|
|
1768
|
+
valuereplaced: expans === Infinity ? 1 : arrow == Infinity ? 0 : -1,
|
|
1769
|
+
repeat: val
|
|
1770
|
+
});
|
|
1771
|
+
return true;
|
|
2229
1772
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
1773
|
+
this.array[index].repeat = val;
|
|
1774
|
+
// this.normalize()
|
|
1775
|
+
return false;
|
|
1776
|
+
}
|
|
1777
|
+
//#endregion
|
|
1778
|
+
/**
|
|
1779
|
+
* @returns a PowiainaNum object which deep copied from `this` object.
|
|
1780
|
+
*/
|
|
1781
|
+
}, {
|
|
1782
|
+
key: "clone",
|
|
1783
|
+
value: function clone() {
|
|
1784
|
+
var obj = new PowiainaNum();
|
|
1785
|
+
obj.resetFromObject(this);
|
|
2233
1786
|
return obj;
|
|
2234
|
-
}
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Set `this` from a object(deep-copy)
|
|
1790
|
+
* @param powlikeObject
|
|
1791
|
+
* @returns
|
|
1792
|
+
*/
|
|
1793
|
+
}, {
|
|
1794
|
+
key: "resetFromObject",
|
|
1795
|
+
value: function resetFromObject(powlikeObject) {
|
|
1796
|
+
this.array = [];
|
|
2235
1797
|
for (var i = 0; i < powlikeObject.array.length; i++) {
|
|
2236
|
-
|
|
1798
|
+
this.array[i] = {
|
|
2237
1799
|
arrow: powlikeObject.array[i].arrow,
|
|
2238
1800
|
expans: powlikeObject.array[i].expans,
|
|
2239
1801
|
megota: powlikeObject.array[i].megota,
|
|
@@ -2241,17 +1803,75 @@ var PowiainaNum = /** @class */function () {
|
|
|
2241
1803
|
valuereplaced: powlikeObject.array[i].valuereplaced
|
|
2242
1804
|
};
|
|
2243
1805
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
return
|
|
1806
|
+
this.small = powlikeObject.small;
|
|
1807
|
+
this.sign = powlikeObject.sign;
|
|
1808
|
+
this.layer = powlikeObject.layer;
|
|
1809
|
+
return this;
|
|
1810
|
+
}
|
|
1811
|
+
//#region converters
|
|
1812
|
+
/**
|
|
1813
|
+
* Convert `this` to Javascript `number`
|
|
1814
|
+
*
|
|
1815
|
+
* returns `Infinity` when the number is greater than `Number.MAX_VALUE`
|
|
1816
|
+
*/
|
|
1817
|
+
}, {
|
|
1818
|
+
key: "toNumber",
|
|
1819
|
+
value: function toNumber() {
|
|
1820
|
+
if (this.sign == -1) return -this.neg().toNumber();
|
|
1821
|
+
if (this.small) return 1 / this.rec().toNumber();
|
|
1822
|
+
if (this.array.length > 2) return Infinity;
|
|
1823
|
+
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));
|
|
1824
|
+
return NaN;
|
|
2248
1825
|
}
|
|
2249
|
-
|
|
2250
|
-
|
|
1826
|
+
/**
|
|
1827
|
+
* Convert `this` to a string
|
|
1828
|
+
*/
|
|
1829
|
+
}, {
|
|
1830
|
+
key: "toString",
|
|
1831
|
+
value: function toString() {
|
|
1832
|
+
if (this.isNaN()) return "NaN";
|
|
1833
|
+
if (this.sign == -1) return "-".concat(this.neg().toString());
|
|
1834
|
+
if (this.small) {
|
|
1835
|
+
if (this.isZero()) return "0";
|
|
1836
|
+
return "/".concat(this.rec().toString());
|
|
1837
|
+
}
|
|
1838
|
+
if (this.isInfi()) return "Infinity";
|
|
1839
|
+
// P^a (10{arrow,expans,megota})^repeation base
|
|
1840
|
+
var res = "";
|
|
1841
|
+
if (!this.layer) res += "";else if (this.layer < 3) res += "P".repeat(this.layer);else res += "P^" + this.layer + " ";
|
|
1842
|
+
for (var i = this.array.length - 1; i >= 0; i--) {
|
|
1843
|
+
var oper = this.array[i];
|
|
1844
|
+
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) : "", "}");
|
|
1845
|
+
if (oper.arrow == 1 && oper.expans == 1 && oper.megota == 1 && oper.repeat < 5) {
|
|
1846
|
+
calc = "e".repeat(oper.repeat);
|
|
1847
|
+
} else if (oper.arrow == 0 && oper.expans == 1 && oper.megota == 1) {
|
|
1848
|
+
calc = oper.repeat.toString();
|
|
1849
|
+
} else if (oper.repeat > 1) {
|
|
1850
|
+
calc = "(".concat(calc, ")^").concat(oper.repeat, " ");
|
|
1851
|
+
} else {
|
|
1852
|
+
calc = "".concat(calc);
|
|
1853
|
+
}
|
|
1854
|
+
res += "".concat(calc);
|
|
1855
|
+
}
|
|
1856
|
+
return res;
|
|
1857
|
+
}
|
|
1858
|
+
}, {
|
|
1859
|
+
key: "toJSON",
|
|
1860
|
+
value:
|
|
1861
|
+
/**
|
|
1862
|
+
* Convert `this` to a JSON object
|
|
1863
|
+
* @returns a JSON object
|
|
1864
|
+
*/
|
|
1865
|
+
function toJSON() {
|
|
1866
|
+
return "PN" + this.toString();
|
|
1867
|
+
}
|
|
1868
|
+
}, {
|
|
1869
|
+
key: "arr01",
|
|
1870
|
+
get:
|
|
2251
1871
|
/**
|
|
2252
1872
|
* A property array value for version 0.1.x PowiainaNum.
|
|
2253
1873
|
*/
|
|
2254
|
-
|
|
1874
|
+
function get() {
|
|
2255
1875
|
var res = [0];
|
|
2256
1876
|
for (var i = 0; i < this.array.length; i++) {
|
|
2257
1877
|
if (i == 0) res[0] = this.array[i].repeat;else {
|
|
@@ -2268,226 +1888,837 @@ var PowiainaNum = /** @class */function () {
|
|
|
2268
1888
|
}
|
|
2269
1889
|
}
|
|
2270
1890
|
return res;
|
|
2271
|
-
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
}
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
1891
|
+
}
|
|
1892
|
+
}], [{
|
|
1893
|
+
key: "add",
|
|
1894
|
+
value: function add(t, other) {
|
|
1895
|
+
return new PowiainaNum(t).add(other);
|
|
1896
|
+
}
|
|
1897
|
+
}, {
|
|
1898
|
+
key: "sub",
|
|
1899
|
+
value: function sub(t, other) {
|
|
1900
|
+
return new PowiainaNum(t).sub(other);
|
|
1901
|
+
}
|
|
1902
|
+
}, {
|
|
1903
|
+
key: "mul",
|
|
1904
|
+
value: function mul(t, other) {
|
|
1905
|
+
return new PowiainaNum(t).mul(other);
|
|
1906
|
+
}
|
|
1907
|
+
}, {
|
|
1908
|
+
key: "div",
|
|
1909
|
+
value: function div(t, other) {
|
|
1910
|
+
return new PowiainaNum(t).div(other);
|
|
1911
|
+
}
|
|
1912
|
+
}, {
|
|
1913
|
+
key: "pow",
|
|
1914
|
+
value: function pow(t, other) {
|
|
1915
|
+
return new PowiainaNum(t).pow(other);
|
|
1916
|
+
}
|
|
1917
|
+
}, {
|
|
1918
|
+
key: "root",
|
|
1919
|
+
value: function root(t, other) {
|
|
1920
|
+
return new PowiainaNum(t).root(other);
|
|
1921
|
+
}
|
|
1922
|
+
}, {
|
|
1923
|
+
key: "sqrt",
|
|
1924
|
+
value: function sqrt(t) {
|
|
1925
|
+
return new PowiainaNum(t).sqrt();
|
|
1926
|
+
}
|
|
1927
|
+
}, {
|
|
1928
|
+
key: "cbrt",
|
|
1929
|
+
value: function cbrt(t) {
|
|
1930
|
+
return new PowiainaNum(t).cbrt();
|
|
1931
|
+
}
|
|
1932
|
+
}, {
|
|
1933
|
+
key: "log10",
|
|
1934
|
+
value: function log10(t) {
|
|
1935
|
+
return new PowiainaNum(t).log10();
|
|
1936
|
+
}
|
|
1937
|
+
}, {
|
|
1938
|
+
key: "log",
|
|
1939
|
+
value: function log(t) {
|
|
1940
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.E;
|
|
1941
|
+
return new PowiainaNum(t).log(base);
|
|
1942
|
+
}
|
|
1943
|
+
}, {
|
|
1944
|
+
key: "pLog10",
|
|
1945
|
+
value: function pLog10(t) {
|
|
1946
|
+
return new PowiainaNum(t).pLog10();
|
|
1947
|
+
}
|
|
1948
|
+
}, {
|
|
1949
|
+
key: "exp",
|
|
1950
|
+
value: function exp(x) {
|
|
1951
|
+
var y = new PowiainaNum(x);
|
|
1952
|
+
return y.pow_base(Math.E);
|
|
1953
|
+
}
|
|
1954
|
+
}, {
|
|
1955
|
+
key: "factorial",
|
|
1956
|
+
value: function factorial(x) {
|
|
1957
|
+
return new PowiainaNum(x).factorial();
|
|
1958
|
+
}
|
|
1959
|
+
}, {
|
|
1960
|
+
key: "gamma",
|
|
1961
|
+
value: function gamma(x) {
|
|
1962
|
+
return new PowiainaNum(x).gamma();
|
|
1963
|
+
}
|
|
1964
|
+
}, {
|
|
1965
|
+
key: "lambertw",
|
|
1966
|
+
value: function lambertw(x) {
|
|
1967
|
+
var principal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1968
|
+
return new PowiainaNum(x).lambertw(principal);
|
|
1969
|
+
}
|
|
1970
|
+
}, {
|
|
1971
|
+
key: "tetrate",
|
|
1972
|
+
value: function tetrate(t, other2) {
|
|
1973
|
+
var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1974
|
+
return new PowiainaNum(t).tetrate(other2, payload);
|
|
1975
|
+
}
|
|
1976
|
+
}, {
|
|
1977
|
+
key: "tetrate_10",
|
|
1978
|
+
value: function tetrate_10(other2) {
|
|
1979
|
+
return PowiainaNum.fromNumber(10).tetrate(other2);
|
|
1980
|
+
}
|
|
1981
|
+
}, {
|
|
1982
|
+
key: "arrowMSI",
|
|
1983
|
+
value: function arrowMSI(arrowsNum) {
|
|
1984
|
+
return new PowiainaNum("10{".concat(arrowsNum, "}").concat(MSI));
|
|
1985
|
+
}
|
|
1986
|
+
}, {
|
|
1987
|
+
key: "hyper",
|
|
1988
|
+
value: function hyper(arr) {
|
|
1989
|
+
var z = new PowiainaNum(arr);
|
|
1990
|
+
if (z.eq(0)) return function (x, y) {
|
|
1991
|
+
return new PowiainaNum(y).eq(0) ? new PowiainaNum(x) : new PowiainaNum(x).add(1);
|
|
1992
|
+
};
|
|
1993
|
+
if (z.eq(1)) return PowiainaNum.add;else if (z.eq(2)) return PowiainaNum.mul;else if (z.eq(3)) return PowiainaNum.pow;else {
|
|
1994
|
+
return function (x, y) {
|
|
1995
|
+
return new PowiainaNum(x).arrow(z.sub(2))(y);
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
}, {
|
|
2000
|
+
key: "expansion",
|
|
2001
|
+
value: function expansion(t, other) {
|
|
2002
|
+
return new PowiainaNum(t).expansion(other);
|
|
2003
|
+
}
|
|
2004
|
+
}, {
|
|
2005
|
+
key: "multiExpansion",
|
|
2006
|
+
value: function multiExpansion(t, other) {
|
|
2007
|
+
return new PowiainaNum(t).multiExpansion(other);
|
|
2008
|
+
}
|
|
2009
|
+
}, {
|
|
2010
|
+
key: "powerExpansion",
|
|
2011
|
+
value: function powerExpansion(t, other) {
|
|
2012
|
+
return new PowiainaNum(t).powerExpansion(other);
|
|
2013
|
+
}
|
|
2014
|
+
}, {
|
|
2015
|
+
key: "BEAF",
|
|
2016
|
+
value: function BEAF(base2, power2) {
|
|
2017
|
+
var arrow2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
2018
|
+
var expans2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
2019
|
+
var megota2 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
2020
|
+
var powiaina2 = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
|
|
2021
|
+
var depth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
|
|
2022
|
+
// console.warn(
|
|
2023
|
+
// "This function is unstable when calculating numbers greater than *megotion*",
|
|
2024
|
+
// );
|
|
2025
|
+
var base = new PowiainaNum(base2);
|
|
2026
|
+
var power = new PowiainaNum(power2);
|
|
2027
|
+
function readArg(a) {
|
|
2028
|
+
var _b;
|
|
2029
|
+
return new PowiainaNum((_b = [arrow2, expans2, megota2, powiaina2][a]) !== null && _b !== void 0 ? _b : 1);
|
|
2030
|
+
}
|
|
2031
|
+
if (base.eq(1)) return new PowiainaNum(1);
|
|
2032
|
+
if (power.eq(1)) return new PowiainaNum(base);
|
|
2033
|
+
if (power.isZero()) return new PowiainaNum(1);
|
|
2034
|
+
if (base.lt(0)) return PowiainaNum.NaN.clone();
|
|
2035
|
+
// // check infinite
|
|
2036
|
+
// let sufpowiaina = args.slice(4);
|
|
2037
|
+
// if (sufpowiaina.filter((f) => new PowiainaNum(f).gte(2)).length > 0) {
|
|
2038
|
+
// return PowiainaNum.POSITIVE_INFINITY;
|
|
2039
|
+
// }
|
|
2040
|
+
if (new PowiainaNum(powiaina2).gte(3)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
2041
|
+
if (readArg(0).eq(1) && readArg(1).eq(1) && readArg(2).eq(1)) {
|
|
2042
|
+
return base.pow(power);
|
|
2043
|
+
}
|
|
2044
|
+
if (readArg(0).eq(2) && readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
|
|
2045
|
+
return base.tetrate(power);
|
|
2046
|
+
}
|
|
2047
|
+
if (readArg(1).eq(1) && readArg(2).eq(1) && readArg(3).eq(1)) {
|
|
2048
|
+
return base.arrow(readArg(0))(power);
|
|
2049
|
+
}
|
|
2050
|
+
if (readArg(1).eq(2) && readArg(2).eq(1) && readArg(3).eq(1)) {
|
|
2051
|
+
return base.expansionArrow(readArg(0))(power);
|
|
2052
|
+
}
|
|
2053
|
+
var arrow = readArg(0).toNumber();
|
|
2054
|
+
var expans = readArg(1);
|
|
2055
|
+
var megota = readArg(2);
|
|
2056
|
+
var powiaina = readArg(3);
|
|
2057
|
+
if (powiaina.eq(2)) {
|
|
2058
|
+
if (arrow != 1) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
2059
|
+
if (expans.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
2060
|
+
if (megota.neq(1)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
2061
|
+
if (power.gte(MSI)) return PowiainaNum.POSITIVE_INFINITY.clone();
|
|
2062
|
+
var r = new PowiainaNum(10);
|
|
2063
|
+
r.layer = power.toNumber();
|
|
2064
|
+
r.normalize();
|
|
2065
|
+
return r;
|
|
2066
|
+
}
|
|
2067
|
+
function convertOperator(arrows, expans, megota) {
|
|
2068
|
+
var a = arrows;
|
|
2069
|
+
var e = expans;
|
|
2070
|
+
var m = megota;
|
|
2071
|
+
if (a == 0 && e > 1) {
|
|
2072
|
+
return [1 / 0, e - 1, m];
|
|
2073
|
+
}
|
|
2074
|
+
if (a == 0 && e == 1 && m > 1) {
|
|
2075
|
+
return [1, 1 / 0, m - 1];
|
|
2076
|
+
}
|
|
2077
|
+
return [a, e, m];
|
|
2078
|
+
}
|
|
2079
|
+
if (megota.gt(MSI)) {
|
|
2080
|
+
var temp = new PowiainaNum(megota);
|
|
2081
|
+
temp.layer++;
|
|
2082
|
+
temp.normalize();
|
|
2083
|
+
return temp;
|
|
2084
|
+
}
|
|
2085
|
+
function infToBang(x) {
|
|
2086
|
+
if (!isFinite(x)) return "!";
|
|
2087
|
+
return x.toString();
|
|
2088
|
+
}
|
|
2089
|
+
function getMSIForm(arrow, expans, megota) {
|
|
2090
|
+
return "10{".concat(infToBang(arrow), ",").concat(infToBang(expans), ",").concat(megota, "}").concat(MSI);
|
|
2091
|
+
}
|
|
2092
|
+
var t = base.clone();
|
|
2093
|
+
var arrows = new PowiainaNum(readArg(0));
|
|
2094
|
+
var result = function (other2) {
|
|
2095
|
+
var _r, _r2;
|
|
2096
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2097
|
+
console.log("".concat("-".repeat(depth), " {").concat(base2, ",").concat(power2, ",").concat(arrow2, ",").concat(expans2, ",").concat(megota2, "}"));
|
|
2098
|
+
var other = new PowiainaNum(other2);
|
|
2099
|
+
var r;
|
|
2100
|
+
if (t.isNaN() || other.isNaN()) return PowiainaNum.NaN.clone();
|
|
2101
|
+
if (other.lt(PowiainaNum.ZERO)) return PowiainaNum.NaN.clone();
|
|
2102
|
+
if (t.eq(PowiainaNum.ZERO)) {
|
|
2103
|
+
if (other.eq(PowiainaNum.ONE)) return PowiainaNum.ZERO.clone();
|
|
2104
|
+
return PowiainaNum.NaN.clone();
|
|
2105
|
+
}
|
|
2106
|
+
if (t.eq(PowiainaNum.ONE)) return PowiainaNum.ONE.clone();
|
|
2107
|
+
if (other.eq(PowiainaNum.ZERO)) return PowiainaNum.ONE.clone();
|
|
2108
|
+
if (other.eq(PowiainaNum.ONE)) return t.clone();
|
|
2109
|
+
if (arrows.eq(0)) {
|
|
2110
|
+
return PowiainaNum.BEAF(t, t, power, expans.sub(1), megota, powiaina2, depth + 1);
|
|
2111
|
+
// {this, this, power, expans-1, megota}
|
|
2112
|
+
}
|
|
2113
|
+
if (megota.eq(0)) {
|
|
2114
|
+
return PowiainaNum.BEAF(t, t, t, t, expans, new PowiainaNum(powiaina2).sub(1), depth + 1);
|
|
2115
|
+
}
|
|
2116
|
+
// expans > 9e15, that using 10{?, x}, x=expans;
|
|
2117
|
+
if (expans.gt(MSI)) {
|
|
2118
|
+
r = new PowiainaNum(expans);
|
|
2119
|
+
r.setOperator(r.getOperator(1, Infinity, megota.toNumber()) + 1, 1, Infinity, megota.toNumber());
|
|
2120
|
+
return r;
|
|
2121
|
+
}
|
|
2122
|
+
// arrow > 9e15, that using 10{x,2}, x=arrow;
|
|
2123
|
+
if (arrows.gt(PowiainaNum.MSI)) {
|
|
2124
|
+
r = arrows.clone();
|
|
2125
|
+
r.setOperator(r.getOperator(Infinity, expans.toNumber(), megota.toNumber()) + 1, Infinity, expans.toNumber(), megota.toNumber());
|
|
2126
|
+
return r;
|
|
2127
|
+
}
|
|
2128
|
+
var arrowsNum = arrows.toNumber();
|
|
2129
|
+
// arrow < 9e15
|
|
2130
|
+
// 10{x}2 = 10{x-1}10
|
|
2131
|
+
if (other.eq(2)) return PowiainaNum.BEAF(t, t, arrowsNum - 1, expans, megota, powiaina2, depth + 1);
|
|
2132
|
+
if (t.max(other).gt(getMSIForm(arrowsNum + 1, expans.toNumber(), megota.toNumber()))) return t.max(other);
|
|
2133
|
+
if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber())) || other.gt(MSI)) {
|
|
2134
|
+
if (t.gt(getMSIForm(arrowsNum, expans.toNumber(), megota.toNumber()))) {
|
|
2135
|
+
r = t.clone();
|
|
2136
|
+
r.setOperator(r.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) - 1, arrowsNum, expans.toNumber(), megota.toNumber());
|
|
2137
|
+
r.normalize();
|
|
2138
|
+
} else if (t.gt(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))))) {
|
|
2139
|
+
r = new PowiainaNum(t.getOperator.apply(t, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
|
|
2140
|
+
} else {
|
|
2141
|
+
r = PowiainaNum.ZERO;
|
|
2142
|
+
}
|
|
2143
|
+
var j = r.add(other);
|
|
2144
|
+
j.setOperator(j.getOperator(arrowsNum, expans.toNumber(), megota.toNumber()) + 1, arrowsNum, expans.toNumber(), megota.toNumber());
|
|
2145
|
+
j.normalize();
|
|
2146
|
+
return j;
|
|
2147
|
+
}
|
|
2148
|
+
if (depth >= PowiainaNum.maxOps + 10) {
|
|
2149
|
+
return new PowiainaNum({
|
|
2150
|
+
small: false,
|
|
2151
|
+
sign: 1,
|
|
2152
|
+
layer: 0,
|
|
2153
|
+
array: [newOperator(10, 0), newOperator(1, arrowsNum, expans.toNumber(), megota.toNumber())]
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
var y = other.toNumber();
|
|
2157
|
+
var f = Math.floor(y);
|
|
2158
|
+
var arrows_m1 = arrows.sub(PowiainaNum.ONE);
|
|
2159
|
+
r = PowiainaNum.BEAF(t, y - f, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
|
|
2160
|
+
var i = 0;
|
|
2161
|
+
for (var m = new PowiainaNum(getMSIForm.apply(void 0, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber())))); f !== 0 && r.lt(m) && i < 100; i++) {
|
|
2162
|
+
if (f > 0) {
|
|
2163
|
+
r = PowiainaNum.BEAF(base, r, arrows_m1.toNumber(), expans, megota, powiaina2, depth + 1);
|
|
2164
|
+
--f;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
if (i == 100) f = 0;
|
|
2168
|
+
(_r = r).setOperator.apply(_r, [(_r2 = r).getOperator.apply(_r2, _toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))) + f].concat(_toConsumableArray(convertOperator(arrowsNum - 1, expans.toNumber(), megota.toNumber()))));
|
|
2169
|
+
r.normalize();
|
|
2170
|
+
return r;
|
|
2171
|
+
}(power, depth);
|
|
2172
|
+
console.log("".concat("-".repeat(depth), " = ").concat(result));
|
|
2173
|
+
return result;
|
|
2174
|
+
}
|
|
2175
|
+
}, {
|
|
2176
|
+
key: "abs",
|
|
2177
|
+
value: function abs(x) {
|
|
2178
|
+
return new PowiainaNum(x).abs();
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* Select the largest number of arguments.
|
|
2182
|
+
*/
|
|
2183
|
+
}, {
|
|
2184
|
+
key: "max",
|
|
2185
|
+
value: function max() {
|
|
2186
|
+
var max = PowiainaNum.NEGATIVE_INFINITY;
|
|
2187
|
+
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
2188
|
+
args[_key8] = arguments[_key8];
|
|
2189
|
+
}
|
|
2190
|
+
for (var i = 0; i < args.length; i++) {
|
|
2191
|
+
if (max.lt(args[i])) {
|
|
2192
|
+
max = new PowiainaNum(args[i]).clone();
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
return max;
|
|
2196
|
+
}
|
|
2197
|
+
/**
|
|
2198
|
+
* Select the smallest number of arguments.
|
|
2199
|
+
*/
|
|
2200
|
+
}, {
|
|
2201
|
+
key: "min",
|
|
2202
|
+
value: function min() {
|
|
2203
|
+
var max = PowiainaNum.POSITIVE_INFINITY;
|
|
2204
|
+
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
2205
|
+
args[_key9] = arguments[_key9];
|
|
2206
|
+
}
|
|
2207
|
+
for (var i = 0; i < args.length; i++) {
|
|
2208
|
+
if (max.gt(args[i])) {
|
|
2209
|
+
max = new PowiainaNum(args[i]).clone();
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
return max;
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Restrict a number be not lower than a number
|
|
2216
|
+
*
|
|
2217
|
+
* It's also an alias of `PowiainaNum.max`.
|
|
2218
|
+
* @returns restricted number
|
|
2219
|
+
*/
|
|
2220
|
+
}, {
|
|
2221
|
+
key: "clampMin",
|
|
2222
|
+
value: function clampMin() {
|
|
2223
|
+
return PowiainaNum.max.apply(PowiainaNum, arguments);
|
|
2224
|
+
}
|
|
2225
|
+
}, {
|
|
2226
|
+
key: "clampMax",
|
|
2227
|
+
value: function clampMax() {
|
|
2228
|
+
return PowiainaNum.min.apply(PowiainaNum, arguments);
|
|
2229
|
+
}
|
|
2230
|
+
}, {
|
|
2231
|
+
key: "sign",
|
|
2232
|
+
value: function sign(a) {
|
|
2233
|
+
return new PowiainaNum(a).sign;
|
|
2234
|
+
}
|
|
2235
|
+
}, {
|
|
2236
|
+
key: "isNaN",
|
|
2237
|
+
value: function isNaN(x) {
|
|
2238
|
+
return new PowiainaNum(x).isNaN();
|
|
2239
|
+
}
|
|
2240
|
+
}, {
|
|
2241
|
+
key: "fromNumber",
|
|
2242
|
+
value: function fromNumber(x) {
|
|
2243
|
+
var obj = new PowiainaNum(); // NaN
|
|
2244
|
+
if (x < 0) obj.sign = -1; // negative
|
|
2245
|
+
else if (x == 0) {
|
|
2246
|
+
obj.sign = 0;
|
|
2247
|
+
obj.small = true;
|
|
2248
|
+
obj.array = [newOperator(Infinity, 0)];
|
|
2249
|
+
return obj;
|
|
2250
|
+
} else if (x > 0) obj.sign = 1;
|
|
2251
|
+
var y = Math.abs(x);
|
|
2252
|
+
if (y == Infinity) {
|
|
2253
|
+
obj.array = [newOperator(Infinity, 0)];
|
|
2254
|
+
} else if (y >= MSI_REC && y < 1) {
|
|
2255
|
+
obj.small = true;
|
|
2256
|
+
obj.array = [newOperator(1 / y, 0)];
|
|
2257
|
+
} else if (y < MSI_REC) {
|
|
2258
|
+
obj.small = true;
|
|
2259
|
+
obj.array = [newOperator(-Math.log10(y), 0), newOperator(1, 1)];
|
|
2260
|
+
} else if (y <= MSI) {
|
|
2261
|
+
obj.array = [newOperator(y, 0)];
|
|
2262
|
+
} else {
|
|
2263
|
+
obj.setOperator(Math.log10(y), 0);
|
|
2264
|
+
obj.array = [newOperator(Math.log10(y), 0), newOperator(1, 1)];
|
|
2265
|
+
}
|
|
2266
|
+
return obj;
|
|
2267
|
+
}
|
|
2268
|
+
}, {
|
|
2269
|
+
key: "fromString",
|
|
2270
|
+
value: function fromString(input) {
|
|
2271
|
+
var _b, _c, _d, _e, _f, _g;
|
|
2272
|
+
var x = new PowiainaNum();
|
|
2273
|
+
// Judge the string was a number
|
|
2274
|
+
if (input.startsWith("PN")) input = input.substring(2);
|
|
2275
|
+
if (!isNaN(Number(input))) {
|
|
2276
|
+
var res = Number(input);
|
|
2277
|
+
var _a2 = false;
|
|
2278
|
+
if (res == 0) {
|
|
2279
|
+
if (/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(input)) {
|
|
2280
|
+
_a2 = true;
|
|
2281
|
+
}
|
|
2282
|
+
} else {
|
|
2283
|
+
_a2 = true;
|
|
2284
|
+
}
|
|
2285
|
+
if (!_a2) {
|
|
2286
|
+
var m = input.search(/e/);
|
|
2287
|
+
var exponent = input.substring((m == -1 ? input.length : m) + 1);
|
|
2288
|
+
var mantissa = input.substring(0, m == -1 ? undefined : m);
|
|
2289
|
+
var mantissaME = [0, 0];
|
|
2290
|
+
// Handle mantissa to ME
|
|
2291
|
+
mantissaME[1] = Number(exponent ? exponent : "0");
|
|
2292
|
+
// Is regular number gte 1:
|
|
2293
|
+
if (Number(mantissa) >= 1) {
|
|
2294
|
+
// check The mantissa is very long?
|
|
2295
|
+
var log10mant = mantissa.length >= LONG_STRING_MIN_LENGTH ? log10LongString(mantissa) : Math.log10(Number(mantissa));
|
|
2296
|
+
var log10int = Math.floor(log10mant) - 1;
|
|
2297
|
+
var log10float = log10mant - log10int;
|
|
2298
|
+
mantissaME[0] = Math.pow(10, log10float);
|
|
2299
|
+
mantissaME[1] += log10float;
|
|
2300
|
+
} else {
|
|
2301
|
+
// If not , count how many zeros until reached non-zero numbers
|
|
2302
|
+
var zeros = countLeadingZerosAfterDecimal(mantissa);
|
|
2303
|
+
mantissa = mantissa.substring(mantissa.search(/[1-9]/));
|
|
2304
|
+
mantissa = mantissa.charAt(0) + "." + mantissa.substring(1);
|
|
2305
|
+
zeros += 1;
|
|
2306
|
+
mantissaME[0] = Number(mantissa);
|
|
2307
|
+
mantissaME[1] += -zeros;
|
|
2308
|
+
}
|
|
2309
|
+
// We'll get [a, b] which respents a*10^b;
|
|
2310
|
+
// actually b < 0; So we can ^-1
|
|
2311
|
+
// /((a*10^b)^-1) = /(a^-1*10^-b) = /(a^-1 * 10 * 10^(-b-1))
|
|
2312
|
+
return PowiainaNum.pow(10, -mantissaME[1] - 1).mul(Math.pow(mantissaME[0], -1) * 10).rec();
|
|
2313
|
+
}
|
|
2314
|
+
if (isFinite(res) && _a2) {
|
|
2315
|
+
x = PowiainaNum.fromNumber(Number(input));
|
|
2316
|
+
return x;
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
input = replaceETo10(input);
|
|
2320
|
+
if (!isPowiainaNum.test(input)) {
|
|
2321
|
+
throw powiainaNumError + "malformed input: " + input;
|
|
2322
|
+
}
|
|
2323
|
+
var negateIt = false;
|
|
2324
|
+
var recipIt = false;
|
|
2325
|
+
if (input[0] == "-" || input[0] == "+") {
|
|
2326
|
+
var numSigns = input.search(/[^-\+]/);
|
|
2327
|
+
var signs = input.substring(0, numSigns);
|
|
2328
|
+
negateIt = ((_c = (_b = signs.match(/-/g)) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) % 2 == 1;
|
|
2329
|
+
input = input.substring(numSigns);
|
|
2330
|
+
}
|
|
2331
|
+
if (input[0] == "/") {
|
|
2332
|
+
var numSigns = input.search(/[^\/]/);
|
|
2333
|
+
var signs = input.substring(0, numSigns);
|
|
2334
|
+
recipIt = ((_e = (_d = signs.match(/\//g)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) % 2 == 1;
|
|
2335
|
+
input = input.substring(numSigns);
|
|
2336
|
+
}
|
|
2337
|
+
if (input == "NaN") x.array = [newOperator(NaN)];else if (input == "Infinity") x.array = [newOperator(Infinity)];else {
|
|
2338
|
+
x.sign = 1;
|
|
2339
|
+
x.array = [newOperator(0)];
|
|
2340
|
+
var a, b, c, d;
|
|
2341
|
+
if (input[0] == "P") {
|
|
2342
|
+
if (input[1] == "^") {
|
|
2343
|
+
a = input.substring(2).search(/[^0-9]/) + 2;
|
|
2344
|
+
x.layer = Number(input.substring(2, a));
|
|
2345
|
+
input = input.substring(a + 1);
|
|
2346
|
+
} else {
|
|
2347
|
+
a = input.search(/[^P]/);
|
|
2348
|
+
x.layer = a;
|
|
2349
|
+
input = input.substring(a);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
while (input) {
|
|
2353
|
+
if (/^(\(?10[\^\{])/.test(input)) {
|
|
2354
|
+
/*
|
|
2355
|
+
10^ - 匹配
|
|
2356
|
+
10{ - 匹配
|
|
2357
|
+
(10^ - 匹配
|
|
2358
|
+
(10{ - 匹配
|
|
2359
|
+
10x - 不匹配(最后一个字符不是 ^ 或 {)
|
|
2360
|
+
110^ - 不匹配(不是以 10 开头)
|
|
2361
|
+
*/
|
|
2362
|
+
if (input[0] == "(") input = input.substring(1);
|
|
2363
|
+
//cutted, 10^.... or 10{....
|
|
2364
|
+
var arrows, expans, megota;
|
|
2365
|
+
if (input[2] == "^") {
|
|
2366
|
+
a = input.substring(2).search(/[^\^]/);
|
|
2367
|
+
//cut input to ^^...^^, and search how numbers
|
|
2368
|
+
arrows = a;
|
|
2369
|
+
// 10^^^
|
|
2370
|
+
b = a + 2; // b points to after ^'s.
|
|
2371
|
+
} else {
|
|
2372
|
+
// 10{...}
|
|
2373
|
+
a = input.indexOf("}");
|
|
2374
|
+
// select contents between {...}
|
|
2375
|
+
var tmp = input.substring(3, a).split(",");
|
|
2376
|
+
arrows = Number(tmp[0] == "!" ? Infinity : tmp[0]);
|
|
2377
|
+
expans = Number((_f = tmp[1] == "!" ? Infinity : tmp[1]) !== null && _f !== void 0 ? _f : 1);
|
|
2378
|
+
megota = Number((_g = tmp[2]) !== null && _g !== void 0 ? _g : 1);
|
|
2379
|
+
b = a + 1;
|
|
2380
|
+
// b points to after }.
|
|
2381
|
+
}
|
|
2382
|
+
input = input.substring(b);
|
|
2383
|
+
if (input[0] == ")") {
|
|
2384
|
+
// )^....<Space>
|
|
2385
|
+
a = input.indexOf(" ");
|
|
2386
|
+
c = Number(input.substring(2, a)); // Select contents between )^....<Space>
|
|
2387
|
+
input = input.substring(a + 1); // c points to after <Space>
|
|
2388
|
+
} else {
|
|
2389
|
+
c = 1; // There is only spaces, count as <ONE>
|
|
2390
|
+
}
|
|
2391
|
+
if (arrows == 1 && expans == 1 && megota == 1) {
|
|
2392
|
+
if (x.array.length >= 2 && x.array[1].arrow == 1) {
|
|
2393
|
+
x.array[1].repeat += c;
|
|
2394
|
+
} else {
|
|
2395
|
+
x.array.splice(1, 0, newOperator(c, 1, expans, megota));
|
|
2396
|
+
}
|
|
2397
|
+
} else if (arrows == 2 && expans == 1 && megota == 1) {
|
|
2398
|
+
a = x.array.length >= 2 && x.array[1].arrow == 1 ? x.array[1].repeat : 0;
|
|
2399
|
+
b = x.array[0].repeat;
|
|
2400
|
+
if (b >= 1e10) ++a;
|
|
2401
|
+
if (b >= 10) ++a;
|
|
2402
|
+
x.array[0].repeat = a;
|
|
2403
|
+
if (x.array.length >= 2 && x.array[1].arrow == 1) x.array.splice(1, 1);
|
|
2404
|
+
d = x.getOperatorIndex(2);
|
|
2405
|
+
if (Number.isInteger(d)) x.array[d].repeat += c;else x.array.splice(Math.ceil(d), 0, newOperator(c, 2, expans, megota));
|
|
2406
|
+
} else if (isFinite(arrows)) {
|
|
2407
|
+
a = x.getOperator(arrows - 1);
|
|
2408
|
+
b = x.getOperator(arrows - 2);
|
|
2409
|
+
if (b >= 10) ++a;
|
|
2410
|
+
d = x.getOperatorIndex(arrows);
|
|
2411
|
+
x.array.splice(1, Math.ceil(d) - 1);
|
|
2412
|
+
x.array[0].repeat = a;
|
|
2413
|
+
if (Number.isInteger(d)) x.array[1].repeat += c;else x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
2414
|
+
} else {
|
|
2415
|
+
x.array.splice(1, 0, newOperator(c, arrows, expans, megota));
|
|
2416
|
+
}
|
|
2417
|
+
} else {
|
|
2418
|
+
break;
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
a = input.split(/[Ee]/);
|
|
2422
|
+
b = [x.array[0].repeat, 0];
|
|
2423
|
+
c = 1;
|
|
2424
|
+
for (var _i2 = a.length - 1; _i2 >= 0; --_i2) {
|
|
2425
|
+
//The things that are already there
|
|
2426
|
+
if (b[0] < MSI_LOG10 && b[1] === 0) {
|
|
2427
|
+
b[0] = Math.pow(10, c * b[0]);
|
|
2428
|
+
} else if (c == -1) {
|
|
2429
|
+
if (b[1] === 0) {
|
|
2430
|
+
b[0] = Math.pow(10, c * b[0]);
|
|
2431
|
+
} else if (b[1] == 1 && b[0] <= Math.log10(Number.MAX_VALUE)) {
|
|
2432
|
+
b[0] = Math.pow(10, c * Math.pow(10, b[0]));
|
|
2433
|
+
} else {
|
|
2434
|
+
b[0] = 0;
|
|
2435
|
+
}
|
|
2436
|
+
b[1] = 0;
|
|
2437
|
+
} else {
|
|
2438
|
+
b[1]++;
|
|
2439
|
+
}
|
|
2440
|
+
//Multiplying coefficient
|
|
2441
|
+
var decimalPointPos = a[_i2].indexOf(".");
|
|
2442
|
+
var intPartLen = decimalPointPos == -1 ? a[_i2].length : decimalPointPos;
|
|
2443
|
+
if (b[1] === 0) {
|
|
2444
|
+
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]);
|
|
2445
|
+
} else {
|
|
2446
|
+
d = intPartLen >= LONG_STRING_MIN_LENGTH ? log10LongString(a[_i2].substring(0, intPartLen)) : a[_i2] ? Math.log10(Number(a[_i2])) : 0;
|
|
2447
|
+
if (b[1] == 1) {
|
|
2448
|
+
b[0] += d;
|
|
2449
|
+
} else if (b[1] == 2 && b[0] < MSI_LOG10 + Math.log10(d)) {
|
|
2450
|
+
b[0] += Math.log10(1 + Math.pow(10, Math.log10(d) - b[0]));
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
//Carrying
|
|
2454
|
+
if (b[0] < MSI_LOG10 && b[1]) {
|
|
2455
|
+
b[0] = Math.pow(10, b[0]);
|
|
2456
|
+
b[1]--;
|
|
2457
|
+
} else if (b[0] > MSI) {
|
|
2458
|
+
b[0] = Math.log10(b[0]);
|
|
2459
|
+
b[1]++;
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
x.array[0].repeat = b[0];
|
|
2463
|
+
if (b[1]) {
|
|
2464
|
+
if (x.array.length >= 2 && x.array[1].arrow == 1 && x.array[1].expans == 1 && x.array[1].megota == 1) x.array[1].repeat += b[1];else x.array.splice(1, 0, newOperator(b[1], 1, 1, 1));
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
if (negateIt) x.sign *= -1;
|
|
2468
|
+
if (recipIt) x.small = !x.small;
|
|
2469
|
+
x.normalize();
|
|
2470
|
+
x.normalize();
|
|
2471
|
+
return x;
|
|
2472
|
+
}
|
|
2473
|
+
}, {
|
|
2474
|
+
key: "fromObject",
|
|
2475
|
+
value: function fromObject(powlikeObject) {
|
|
2476
|
+
var obj = new PowiainaNum();
|
|
2477
|
+
obj.array = [];
|
|
2478
|
+
if (isExpantaNumArray(powlikeObject)) {
|
|
2479
|
+
for (var i = 0; i < powlikeObject.length; i++) {
|
|
2480
|
+
obj.array[i] = {
|
|
2481
|
+
arrow: powlikeObject[i][0],
|
|
2482
|
+
expans: 1,
|
|
2483
|
+
megota: 1,
|
|
2484
|
+
repeat: powlikeObject[i][1]
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
obj.small = false;
|
|
2488
|
+
obj.sign = 1;
|
|
2489
|
+
obj.layer = 0;
|
|
2490
|
+
return obj;
|
|
2491
|
+
} else {
|
|
2492
|
+
for (var _i3 = 0; _i3 < powlikeObject.array.length; _i3++) {
|
|
2493
|
+
obj.array[_i3] = {
|
|
2494
|
+
arrow: powlikeObject.array[_i3].arrow,
|
|
2495
|
+
expans: powlikeObject.array[_i3].expans,
|
|
2496
|
+
megota: powlikeObject.array[_i3].megota,
|
|
2497
|
+
repeat: powlikeObject.array[_i3].repeat,
|
|
2498
|
+
valuereplaced: powlikeObject.array[_i3].valuereplaced
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
obj.small = powlikeObject.small;
|
|
2502
|
+
obj.sign = powlikeObject.sign;
|
|
2503
|
+
obj.layer = powlikeObject.layer;
|
|
2504
|
+
return obj;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
}]);
|
|
2491
2508
|
}();
|
|
2509
|
+
_a = Symbol.toStringTag;
|
|
2510
|
+
//#endregion
|
|
2511
|
+
//#region constants
|
|
2512
|
+
/**
|
|
2513
|
+
* Zero
|
|
2514
|
+
*/
|
|
2515
|
+
PowiainaNum.ZERO = new PowiainaNum({
|
|
2516
|
+
array: [{
|
|
2517
|
+
arrow: 0,
|
|
2518
|
+
expans: 1,
|
|
2519
|
+
megota: 1,
|
|
2520
|
+
repeat: Infinity
|
|
2521
|
+
}],
|
|
2522
|
+
small: true,
|
|
2523
|
+
layer: 0,
|
|
2524
|
+
sign: 0
|
|
2525
|
+
});
|
|
2526
|
+
/**
|
|
2527
|
+
* One
|
|
2528
|
+
*/
|
|
2529
|
+
PowiainaNum.ONE = new PowiainaNum({
|
|
2530
|
+
array: [{
|
|
2531
|
+
arrow: 0,
|
|
2532
|
+
expans: 1,
|
|
2533
|
+
megota: 1,
|
|
2534
|
+
repeat: 1
|
|
2535
|
+
}],
|
|
2536
|
+
small: false,
|
|
2537
|
+
layer: 0,
|
|
2538
|
+
sign: 1
|
|
2539
|
+
});
|
|
2540
|
+
/**
|
|
2541
|
+
* The value of the largest integer n such that n and n + 1 are both
|
|
2542
|
+
* exactly representable as a Number value = 9007199254740991 = 2^53 − 1.
|
|
2543
|
+
*/
|
|
2544
|
+
PowiainaNum.MSI = new PowiainaNum(MSI);
|
|
2545
|
+
/**
|
|
2546
|
+
* MSI's reciprocate value, = 1/9007199254740991.
|
|
2547
|
+
*/
|
|
2548
|
+
PowiainaNum.MSI_REC = function () {
|
|
2549
|
+
var obj = new PowiainaNum(MSI);
|
|
2550
|
+
obj.small = true;
|
|
2551
|
+
return obj;
|
|
2552
|
+
}();
|
|
2553
|
+
/**
|
|
2554
|
+
* 10^(MSI) = 10^9007199254740991.
|
|
2555
|
+
*/
|
|
2556
|
+
PowiainaNum.E_MSI = new PowiainaNum({
|
|
2557
|
+
array: [{
|
|
2558
|
+
arrow: 0,
|
|
2559
|
+
expans: 1,
|
|
2560
|
+
megota: 1,
|
|
2561
|
+
repeat: MSI
|
|
2562
|
+
}, {
|
|
2563
|
+
arrow: 1,
|
|
2564
|
+
expans: 1,
|
|
2565
|
+
megota: 1,
|
|
2566
|
+
repeat: 1
|
|
2567
|
+
}],
|
|
2568
|
+
small: false,
|
|
2569
|
+
layer: 0,
|
|
2570
|
+
sign: 1
|
|
2571
|
+
});
|
|
2572
|
+
/**
|
|
2573
|
+
* 10^10^(MSI) = 10^10^9007199254740991.
|
|
2574
|
+
*/
|
|
2575
|
+
PowiainaNum.EE_MSI = new PowiainaNum({
|
|
2576
|
+
array: [{
|
|
2577
|
+
arrow: 0,
|
|
2578
|
+
expans: 1,
|
|
2579
|
+
megota: 1,
|
|
2580
|
+
repeat: MSI
|
|
2581
|
+
}, {
|
|
2582
|
+
arrow: 1,
|
|
2583
|
+
expans: 1,
|
|
2584
|
+
megota: 1,
|
|
2585
|
+
repeat: 2
|
|
2586
|
+
}],
|
|
2587
|
+
small: false,
|
|
2588
|
+
layer: 0,
|
|
2589
|
+
sign: 1
|
|
2590
|
+
});
|
|
2591
|
+
/**
|
|
2592
|
+
* 10^(MSI) 's reciprocate value, = 10^-9007199254740991.
|
|
2593
|
+
*/
|
|
2594
|
+
PowiainaNum.E_MSI_REC = new PowiainaNum({
|
|
2595
|
+
array: [{
|
|
2596
|
+
arrow: 0,
|
|
2597
|
+
expans: 1,
|
|
2598
|
+
megota: 1,
|
|
2599
|
+
repeat: MSI
|
|
2600
|
+
}, {
|
|
2601
|
+
arrow: 1,
|
|
2602
|
+
expans: 1,
|
|
2603
|
+
megota: 1,
|
|
2604
|
+
repeat: 1
|
|
2605
|
+
}],
|
|
2606
|
+
small: true,
|
|
2607
|
+
layer: 0,
|
|
2608
|
+
sign: 1
|
|
2609
|
+
});
|
|
2610
|
+
/**
|
|
2611
|
+
* Tetrated MSI, = 10↑↑9007199254740991.
|
|
2612
|
+
*/
|
|
2613
|
+
PowiainaNum.TETRATED_MSI = new PowiainaNum({
|
|
2614
|
+
array: [{
|
|
2615
|
+
arrow: 0,
|
|
2616
|
+
expans: 1,
|
|
2617
|
+
megota: 1,
|
|
2618
|
+
repeat: 1e10
|
|
2619
|
+
}, {
|
|
2620
|
+
arrow: 1,
|
|
2621
|
+
expans: 1,
|
|
2622
|
+
megota: 1,
|
|
2623
|
+
repeat: MSI - 2
|
|
2624
|
+
}],
|
|
2625
|
+
small: false,
|
|
2626
|
+
layer: 0,
|
|
2627
|
+
sign: 1
|
|
2628
|
+
});
|
|
2629
|
+
/**
|
|
2630
|
+
* Pentated MSI, = 10↑↑↑9007199254740991.
|
|
2631
|
+
*/
|
|
2632
|
+
PowiainaNum.PENTATED_MSI = new PowiainaNum({
|
|
2633
|
+
array: [{
|
|
2634
|
+
arrow: 0,
|
|
2635
|
+
expans: 1,
|
|
2636
|
+
megota: 1,
|
|
2637
|
+
repeat: 10
|
|
2638
|
+
}, {
|
|
2639
|
+
arrow: 2,
|
|
2640
|
+
expans: 1,
|
|
2641
|
+
megota: 1,
|
|
2642
|
+
repeat: MSI - 1
|
|
2643
|
+
}],
|
|
2644
|
+
small: false,
|
|
2645
|
+
layer: 0,
|
|
2646
|
+
sign: 1
|
|
2647
|
+
});
|
|
2648
|
+
/**
|
|
2649
|
+
* Tritri, = 3↑↑↑3 = power tower with height 7625597484987 base 3.
|
|
2650
|
+
*/
|
|
2651
|
+
PowiainaNum.TRITRI = new PowiainaNum({
|
|
2652
|
+
small: false,
|
|
2653
|
+
layer: 0,
|
|
2654
|
+
sign: 1,
|
|
2655
|
+
array: [newOperator(3638334640023.7783, 0, 1, 1), newOperator(7625587484984, 1, 1, 1)]
|
|
2656
|
+
});
|
|
2657
|
+
/**
|
|
2658
|
+
* The Graham's Number, = G^64(4)
|
|
2659
|
+
*
|
|
2660
|
+
* = 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{
|
|
2661
|
+
* 3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3{3↑↑↑↑3
|
|
2662
|
+
* }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
|
|
2663
|
+
* }3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3}3
|
|
2664
|
+
*/
|
|
2665
|
+
PowiainaNum.GRAHAMS_NUMBER = new PowiainaNum("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783");
|
|
2666
|
+
/**
|
|
2667
|
+
* Positive Infinity.
|
|
2668
|
+
*/
|
|
2669
|
+
PowiainaNum.POSITIVE_INFINITY = new PowiainaNum(Infinity);
|
|
2670
|
+
/**
|
|
2671
|
+
* Negative Infinity.
|
|
2672
|
+
*/
|
|
2673
|
+
PowiainaNum.NEGATIVE_INFINITY = new PowiainaNum(-Infinity);
|
|
2674
|
+
PowiainaNum.NaN = new PowiainaNum({
|
|
2675
|
+
array: [{
|
|
2676
|
+
arrow: 0,
|
|
2677
|
+
expans: 1,
|
|
2678
|
+
megota: 1,
|
|
2679
|
+
repeat: NaN
|
|
2680
|
+
}],
|
|
2681
|
+
small: false,
|
|
2682
|
+
layer: 0,
|
|
2683
|
+
sign: 0
|
|
2684
|
+
});
|
|
2685
|
+
/**
|
|
2686
|
+
* The mathematical constant e. This is Euler's number, the base of natural logarithms.
|
|
2687
|
+
*/
|
|
2688
|
+
PowiainaNum.E = new PowiainaNum(Math.E);
|
|
2689
|
+
/**
|
|
2690
|
+
* The natural logarithm of 2 = ln(2).
|
|
2691
|
+
*/
|
|
2692
|
+
PowiainaNum.LN2 = new PowiainaNum(Math.LN2);
|
|
2693
|
+
/**
|
|
2694
|
+
* The natural logarithm of 10.
|
|
2695
|
+
*/
|
|
2696
|
+
PowiainaNum.LN10 = new PowiainaNum(Math.LN10);
|
|
2697
|
+
/**
|
|
2698
|
+
* The base-2 logarithm of e = log_2(e).
|
|
2699
|
+
*/
|
|
2700
|
+
PowiainaNum.LOG2E = new PowiainaNum(Math.LOG2E);
|
|
2701
|
+
/**
|
|
2702
|
+
* The base-10 logarithm of e = log_10(e).
|
|
2703
|
+
*/
|
|
2704
|
+
PowiainaNum.LOG10E = new PowiainaNum(Math.LOG10E);
|
|
2705
|
+
/**
|
|
2706
|
+
* Pi(). This is the ratio of the circumference of a circle to its diameter.
|
|
2707
|
+
*/
|
|
2708
|
+
PowiainaNum.PI = new PowiainaNum(Math.PI);
|
|
2709
|
+
/**
|
|
2710
|
+
* The square root of 0.5, or, equivalently, one divided by the square root of 2.
|
|
2711
|
+
*
|
|
2712
|
+
* = (√2)/2 = √(0.5)
|
|
2713
|
+
*/
|
|
2714
|
+
PowiainaNum.SQRT1_2 = new PowiainaNum(Math.SQRT1_2);
|
|
2715
|
+
/**
|
|
2716
|
+
* The square root of 2 = √2.
|
|
2717
|
+
*/
|
|
2718
|
+
PowiainaNum.SQRT2 = new PowiainaNum(Math.SQRT2);
|
|
2719
|
+
PowiainaNum.maxOps = 100;
|
|
2720
|
+
PowiainaNum.POW_2_44_MOD_PI = 1.701173079953;
|
|
2721
|
+
//#endregion
|
|
2722
|
+
PowiainaNum.arrowFuncMap = new Map();
|
|
2492
2723
|
|
|
2493
2724
|
export { arraySortFunction, PowiainaNum as default, mergeSameArrays };
|