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