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