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