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