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