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