diff --git a/dist/game/eMath.game.js b/dist/game/eMath.game.js index 23b5955b..13e27d66 100644 --- a/dist/game/eMath.game.js +++ b/dist/game/eMath.game.js @@ -2424,25 +2424,31 @@ var Decimal = class { return D(value).reciprocate(); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value, other) { - return D(value).mod(other); + static mod(value, other, floored = false) { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value, other) { - return D(value).modulo(other); + static modulo(value, other, floored = false) { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value, other) { - return D(value).modular(other); + static modular(value, other, floored = false) { + return D(value).modular(other, floored); } /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. @@ -2892,6 +2898,31 @@ var Decimal = class { static pentate(value, height = 2, payload = FC_NN(1, 0, 1), linear = false) { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value, base = 10, linear = false) { + return D(value).penta_log(base, 100, linear); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value, degree) { + return D(value).linear_penta_root(degree); + } /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -3383,6 +3414,12 @@ var Decimal = class { } else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + if (this.layer < 0 || this.layer % 1 != 0) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -3879,12 +3916,20 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - mod(value) { - const decimal = D(value).abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + mod(value, floored = false) { + const vd = D(value); + const decimal = vd.abs(); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if (this.sign == -1 != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); if (isFinite(num_this) && isFinite(num_decimal) && num_this != 0 && num_decimal != 0) { @@ -3901,17 +3946,21 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value) { - return this.mod(value); + modulo(value, floored = false) { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value) { - return this.mod(value); + modular(value, floored = false) { + return this.mod(value, floored); } /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. @@ -5251,45 +5300,406 @@ var Decimal = class { } } } + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func, decreasing = false, iterations = 120, minX = Decimal.dLayerMax.neg(), maxX = Decimal.dLayerMax, minY = Decimal.dLayerMax.neg(), maxY = Decimal.dLayerMax) { + return function(value) { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let rangeApply = function(value2) { + return new Decimal(value2); + }; + let currentCheck = true; + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return new Decimal(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()); + }; + } + } + } + } else { + reciprocal = true; + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip().neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip().neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip().neg(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.neg(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).neg(); + }; + } + } + } + } + let searchIncreasing = positive != reciprocal != decreasing; + let comparative = searchIncreasing ? function(a, b) { + return Decimal.gt(a, b); + } : function(a, b) { + return Decimal.lt(a, b); + }; + let step_size = 1e-3; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { + break; + } + let currently_rose = comparative(new_decimal, value); + if (i > 1) { + if (previously_rose != currently_rose) { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) { + step_size /= 2; + } else { + step_size *= 2; + } + if (currently_rose != searchIncreasing && appliedResult.eq(maxX) || currently_rose == searchIncreasing && appliedResult.eq(minX)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { + break; + } + } + return rangeApply(result); + }; + } /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation - * + * * Tetration for non-integer heights does not have a single agreed-upon definition, * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. * Analytic approximation is not currently supported for bases > 10. - * + * * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height = 2, payload = FC_NN(1, 0, 1), linear = false) { payload = new Decimal(payload); const oldheight = height; - height = Math.trunc(height); + height = Math.floor(height); const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; if (fracheight !== 0) { if (payload.eq(Decimal.dOne)) { ++height; payload = Decimal.fromNumber(fracheight); } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + return this.pentate(payload.penta_log(this, void 0, linear).plus(oldheight).toNumber(), 1, linear); } } - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + if (payload.eq(prevpayload) || payload.eq(prevtwopayload) && i % 2 == height % 2) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 1e4) { + return payload; + } } - if (i > 10) { - return payload; + } else { + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, void 0, linear); + if (payload.eq(prevpayload)) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 100) { + return payload; + } } } return payload; } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + penta_log(base = 10, iterations = 100, linear = false) { + base = new Decimal(base); + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1e3) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { + break; + } + } + return Decimal.fromNumber(result); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree) { + if (degree == 1) { + return this; + } + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (degree > 0 && degree < 1) { + return this.root(degree); + } + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.lt(1)) { + return this.linear_sroot(degree); + } + return Decimal.increasingInverse(function(value) { + return Decimal.pentate(value, degree, 1, true); + })(this); + } // trig functions! /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. @@ -5627,16 +6037,64 @@ var Decimal = class { return new Decimal(Math.random()).lt(rng); } }; +/** + * Represents the number 0. + */ Decimal.dZero = FC_NN(0, 0, 0); +/** + * Represents the number 1. + */ Decimal.dOne = FC_NN(1, 0, 1); +/** + * Represents the number -1. + */ Decimal.dNegOne = FC_NN(-1, 0, 1); +/** + * Represents the number 2. + */ Decimal.dTwo = FC_NN(1, 0, 2); +/** + * Represents the number 10. + */ Decimal.dTen = FC_NN(1, 0, 10); +/** + * Represents a NaN (Not A Number) value. + */ Decimal.dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); +/** + * Represents positive infinity. + */ Decimal.dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents negative infinity. + */ Decimal.dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ Decimal.dNumberMax = FC(1, 0, Number.MAX_VALUE); +/** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ Decimal.dNumberMin = FC(1, 0, Number.MIN_VALUE); +/** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ +Decimal.dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); +/** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ +Decimal.dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); +/** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ +Decimal.dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); +/** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ +Decimal.dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); Decimal.fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); __decorateClass([ (0, import_class_transformer.Expose)() diff --git a/dist/game/eMath.game.min.js b/dist/game/eMath.game.min.js index c3622046..c929e252 100644 --- a/dist/game/eMath.game.min.js +++ b/dist/game/eMath.game.min.js @@ -1,4 +1,4 @@ -"use strict";(function(Ot,ut){var Ft=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],ut);else if(typeof module=="object"&&module.exports)module.exports=ut();else{var ct=ut(),Pt=Ft?exports:Ot;for(var Ct in ct)Pt[Ct]=ct[Ct]}})(typeof self<"u"?self:exports,()=>{var Ot={},ut={exports:Ot},Ft=Object.create,ct=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,Ct=Object.getOwnPropertyNames,Xe=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty,bt=(t,e)=>function(){return e||(0,t[Ct(t)[0]])((e={exports:{}}).exports,e),e.exports},Ut=(t,e)=>{for(var r in e)ct(t,r,{get:e[r],enumerable:!0})},oe=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ct(e))!Je.call(t,n)&&n!==r&&ct(t,n,{get:()=>e[n],enumerable:!(i=Pt(e,n))||i.enumerable});return t},ot=(t,e,r)=>(r=t!=null?Ft(Xe(t)):{},oe(e||!t||!t.__esModule?ct(r,"default",{value:t,enumerable:!0}):r,t)),Qe=t=>oe(ct({},"__esModule",{value:!0}),t),st=(t,e,r,i)=>{for(var n=i>1?void 0:i?Pt(e,r):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(n=(i?u(e,r,n):u(n))||n);return i&&n&&ct(e,r,n),n},ft=bt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:g(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(l,v){return function(c,f){Object.defineProperty(l,c,{configurable:!0,writable:!0,value:f}),v&&v(c,f)}}function u(){try{return Function("return this;")()}catch{}}function m(){try{return(0,eval)("(function() { return this; })()")}catch{}}function g(){return u()||m()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",u=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",m=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",g=typeof Object.create=="function",l={__proto__:[]}instanceof Array,v=!g&&!l,c={create:g?function(){return ie(Object.create(null))}:l?function(){return ie({__proto__:null})}:function(){return ie({})},has:v?function(N,b){return n.call(N,b)}:function(N,b){return b in N},get:v?function(N,b){return n.call(N,b)?N[b]:void 0}:function(N,b){return N[b]}},f=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Yr(),p=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Vr(),d=typeof WeakMap=="function"?WeakMap:Hr(),O=o?Symbol.for("@reflect-metadata:registry"):void 0,T=$r(),k=zr(T);function a(N,b,A,E){if(U(A)){if(!De(N))throw new TypeError;if(!je(b))throw new TypeError;return K(N,b)}else{if(!De(N))throw new TypeError;if(!X(b))throw new TypeError;if(!X(E)&&!U(E)&&!It(E))throw new TypeError;return It(E)&&(E=void 0),A=lt(A),nt(N,b,A,E)}}r("decorate",a);function S(N,b){function A(E,R){if(!X(E))throw new TypeError;if(!U(R)&&!Gr(R))throw new TypeError;Dt(N,b,E,R)}return A}r("metadata",S);function y(N,b,A,E){if(!X(A))throw new TypeError;return U(E)||(E=lt(E)),Dt(N,b,A,E)}r("defineMetadata",y);function I(N,b,A){if(!X(b))throw new TypeError;return U(A)||(A=lt(A)),H(N,b,A)}r("hasMetadata",I);function _(N,b,A){if(!X(b))throw new TypeError;return U(A)||(A=lt(A)),Z(N,b,A)}r("hasOwnMetadata",_);function M(N,b,A){if(!X(b))throw new TypeError;return U(A)||(A=lt(A)),W(N,b,A)}r("getMetadata",M);function F(N,b,A){if(!X(b))throw new TypeError;return U(A)||(A=lt(A)),pt(N,b,A)}r("getOwnMetadata",F);function P(N,b){if(!X(N))throw new TypeError;return U(b)||(b=lt(b)),jt(N,b)}r("getMetadataKeys",P);function G(N,b){if(!X(N))throw new TypeError;return U(b)||(b=lt(b)),Rt(N,b)}r("getOwnMetadataKeys",G);function Y(N,b,A){if(!X(b))throw new TypeError;if(U(A)||(A=lt(A)),!X(b))throw new TypeError;U(A)||(A=lt(A));var E=Et(b,A,!1);return U(E)?!1:E.OrdinaryDeleteMetadata(N,b,A)}r("deleteMetadata",Y);function K(N,b){for(var A=N.length-1;A>=0;--A){var E=N[A],R=E(b);if(!U(R)&&!It(R)){if(!je(R))throw new TypeError;b=R}}return b}function nt(N,b,A,E){for(var R=N.length-1;R>=0;--R){var J=N[R],tt=J(b,A,E);if(!U(tt)&&!It(tt)){if(!X(tt))throw new TypeError;E=tt}}return E}function H(N,b,A){var E=Z(N,b,A);if(E)return!0;var R=re(b);return It(R)?!1:H(N,R,A)}function Z(N,b,A){var E=Et(b,A,!1);return U(E)?!1:qe(E.OrdinaryHasOwnMetadata(N,b,A))}function W(N,b,A){var E=Z(N,b,A);if(E)return pt(N,b,A);var R=re(b);if(!It(R))return W(N,R,A)}function pt(N,b,A){var E=Et(b,A,!1);if(!U(E))return E.OrdinaryGetOwnMetadata(N,b,A)}function Dt(N,b,A,E){var R=Et(A,E,!0);R.OrdinaryDefineOwnMetadata(N,b,A,E)}function jt(N,b){var A=Rt(N,b),E=re(N);if(E===null)return A;var R=jt(E,b);if(R.length<=0)return A;if(A.length<=0)return R;for(var J=new p,tt=[],$=0,x=A;$=0&&x=this._keys.length?(this._index=-1,this._keys=b,this._values=b):this._index++,{value:L,done:!1}}return{value:void 0,done:!0}},$.prototype.throw=function(x){throw this._index>=0&&(this._index=-1,this._keys=b,this._values=b),x},$.prototype.return=function(x){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{value:x,done:!0}},$}(),E=function(){function $(){this._keys=[],this._values=[],this._cacheKey=N,this._cacheIndex=-2}return Object.defineProperty($.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),$.prototype.has=function(x){return this._find(x,!1)>=0},$.prototype.get=function(x){var L=this._find(x,!1);return L>=0?this._values[L]:void 0},$.prototype.set=function(x,L){var q=this._find(x,!0);return this._values[q]=L,this},$.prototype.delete=function(x){var L=this._find(x,!1);if(L>=0){for(var q=this._keys.length,D=L+1;D>>8,c[f*2+1]=p%256}return c},decompressFromUint8Array:function(l){if(l==null)return g.decompress(l);for(var v=new Array(l.length/2),c=0,f=v.length;c>1}else{for(h=1,f=0;f>1}a--,a==0&&(a=Math.pow(2,y),y++),delete d[k]}else for(h=p[k],f=0;f>1;a--,a==0&&(a=Math.pow(2,y),y++),p[T]=S++,k=String(O)}if(k!==""){if(Object.prototype.hasOwnProperty.call(d,k)){if(k.charCodeAt(0)<256){for(f=0;f>1}else{for(h=1,f=0;f>1}a--,a==0&&(a=Math.pow(2,y),y++),delete d[k]}else for(h=p[k],f=0;f>1;a--,a==0&&(a=Math.pow(2,y),y++)}for(h=2,f=0;f>1;for(;;)if(_=_<<1,M==v-1){I.push(c(_));break}else M++;return I.join("")},decompress:function(l){return l==null?"":l==""?null:g._decompress(l.length,32768,function(v){return l.charCodeAt(v)})},_decompress:function(l,v,c){var f=[],h,p=4,d=4,O=3,T="",k=[],a,S,y,I,_,M,F,P={val:c(0),position:v,index:1};for(a=0;a<3;a+=1)f[a]=a;for(y=0,_=Math.pow(2,2),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;switch(h=y){case 0:for(y=0,_=Math.pow(2,8),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;F=i(y);break;case 1:for(y=0,_=Math.pow(2,16),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;F=i(y);break;case 2:return""}for(f[3]=F,S=F,k.push(F);;){if(P.index>l)return"";for(y=0,_=Math.pow(2,O),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;switch(F=y){case 0:for(y=0,_=Math.pow(2,8),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;f[d++]=i(y),F=d-1,p--;break;case 1:for(y=0,_=Math.pow(2,16),M=1;M!=_;)I=P.val&P.position,P.position>>=1,P.position==0&&(P.position=v,P.val=c(P.index++)),y|=(I>0?1:0)*M,M<<=1;f[d++]=i(y),F=d-1,p--;break;case 2:return k.join("")}if(p==0&&(p=Math.pow(2,O),O++),f[F])T=f[F];else if(F===d)T=S+S.charAt(0);else return null;k.push(T),f[d++]=S+T.charAt(0),p--,S=T,p==0&&(p=Math.pow(2,O),O++)}}};return g}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),tr=bt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,o){return n<>>32-o},rotr:function(n,o){return n<<32-o|n>>>o},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var o=0;o0;n--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(n){for(var o=[],u=0,m=0;u>>5]|=n[u]<<24-m%32;return o},wordsToBytes:function(n){for(var o=[],u=0;u>>5]>>>24-u%32&255);return o},bytesToHex:function(n){for(var o=[],u=0;u>>4).toString(16)),o.push((n[u]&15).toString(16));return o.join("")},hexToBytes:function(n){for(var o=[],u=0;u>>6*(3-g)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],u=0,m=0;u>>6-m*2);return o}};e.exports=i})()}}),ae=bt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(i){return r.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(r.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var n=[],o=0;o>>24)&16711935|(l[d]<<24|l[d]>>>8)&4278255360;l[v>>>5]|=128<>>9<<4)+14]=v;for(var O=u._ff,T=u._gg,k=u._hh,a=u._ii,d=0;d>>0,f=f+y>>>0,h=h+I>>>0,p=p+_>>>0}return r.endian([c,f,h,p])};u._ff=function(m,g,l,v,c,f,h){var p=m+(g&l|~g&v)+(c>>>0)+h;return(p<>>32-f)+g},u._gg=function(m,g,l,v,c,f,h){var p=m+(g&v|l&~v)+(c>>>0)+h;return(p<>>32-f)+g},u._hh=function(m,g,l,v,c,f,h){var p=m+(g^l^v)+(c>>>0)+h;return(p<>>32-f)+g},u._ii=function(m,g,l,v,c,f,h){var p=m+(l^(g|~v))+(c>>>0)+h;return(p<>>32-f)+g},u._blocksize=16,u._digestsize=16,e.exports=function(m,g){if(m==null)throw new Error("Illegal argument "+m);var l=r.wordsToBytes(u(m,g));return g&&g.asBytes?l:g&&g.asString?o.bytesToString(l):r.bytesToHex(l)}})()}}),ue={};Ut(ue,{default:()=>Lr}),ut.exports=Qe(ue);var Jr=ot(ft()),Qr=ot(ft()),le={};Ut(le,{Attribute:()=>xt,AttributeStatic:()=>Se,Boost:()=>Vt,BoostObject:()=>St,Currency:()=>gt,CurrencyStatic:()=>_e,DEFAULT_ITERATIONS:()=>kt,Decimal:()=>s,E:()=>Cr,FORMATS:()=>Sr,FormatTypeList:()=>lr,Grid:()=>Qt,GridCell:()=>Lt,GridCellCollection:()=>rt,Item:()=>Me,ItemData:()=>vt,LRUCache:()=>Gt,ListNode:()=>fe,ST_NAMES:()=>ht,UpgradeData:()=>yt,UpgradeStatic:()=>be,calculateItem:()=>we,calculateSum:()=>Jt,calculateSumApprox:()=>Ne,calculateSumLoop:()=>pe,calculateUpgrade:()=>ye,decimalToJSONString:()=>ve,equalsTolerance:()=>Wt,formats:()=>dt,inverseFunctionApprox:()=>Xt,roundingBase:()=>Ar,upgradeToCacheNameEL:()=>Or});var Kr=ot(ft()),Gt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new fe(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},fe=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},B;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(B||(B={}));var ir=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===B.CLASS_TO_CLASS||i===B.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===B.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===B.CLASS_TO_CLASS||r===B.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===B.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===B.CLASS_TO_CLASS||r===B.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===B.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(c){return c.propertyName!==void 0}));for(var o=[],u=0,m=this.getAncestors(r);u0&&(u=u.filter(function(c){return!l.includes(c)})),this.options.version!==void 0&&(u=u.filter(function(c){var f=et.findExposeMetadata(e,c);return!f||!f.options?!0:n.checkVersion(f.options.since,f.options.until)})),this.options.groups&&this.options.groups.length?u=u.filter(function(c){var f=et.findExposeMetadata(e,c);return!f||!f.options?!0:n.checkGroups(f.options.groups)}):u=u.filter(function(c){var f=et.findExposeMetadata(e,c);return!f||!f.options||!f.options.groups||!f.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(u=u.filter(function(v){return n.options.excludePrefixes.every(function(c){return v.substr(0,c.length)!==c})})),u=u.filter(function(v,c,f){return f.indexOf(v)===c}),u},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(y.equals(0))return I;if(y.gt(0)&&y.lte(3)){let G=[];for(let Y=0;YNumber.MAX_SAFE_INTEGER)&&(I="\u03C9");let M=t.log(a,8e3).toNumber();if(y.equals(0))return I;if(y.gt(0)&&y.lte(2)){let G=[];for(let Y=0;Y118?e.elemental.beyondOg(_):e.elemental.config.element_lists[a-1][I]},beyondOg(a){let S=Math.floor(Math.log10(a)),y=["n","u","b","t","q","p","h","s","o","e"],I="";for(let _=S;_>=0;_--){let M=Math.floor(a/Math.pow(10,_))%10;I==""?I=y[M].toUpperCase():I+=y[M]}return I},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let S=a.log(118).toNumber(),y=Math.floor(S)+1,I=e.elemental.abbreviationLength(y),_=S-y+1,M=Math.floor(_*I),F=e.elemental.getAbbreviation(y,_),P=new t(118).pow(y+M/I-1);return[F,P]},formatElementalPart(a,S){return S.eq(1)?a:`${S.toString()} ${a}`},format(a,S=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),S);let y=a.log(118),_=y.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),F=[];for(;y.gte(1)&&F.length=M)return F.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ");let P=new t(118).pow(y).toFixed(F.length===1?3:S);return F.length===0?P:F.length===1?`${P} \xD7 ${e.elemental.formatElementalPart(F[0][0],F[0][1])}`:`${P} \xD7 (${F.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let y=a.log10().floor();if(y.lt(9))return y.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":t.dTen.pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let I=a.div(t.dTen.pow(y));return(y.log10().gte(9)?"":I.toFixed(4))+"e"+e.old_sc.format(y,0)}}},eng:{format(a,S=2){a=new t(a);let y=a.log10().floor();if(y.lt(9))return y.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":t.dTen.pow(_.sub(_.floor())).toFixed(4))+"F"+e.eng.format(_.floor(),0)}let I=a.div(new t(1e3).pow(y.div(3).floor()));return(y.log10().gte(9)?"":I.toFixed(new t(4).sub(y.sub(y.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(y.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,y=9){a=new t(a);let I=a.log10().floor();return I.lt(303)&&I.gte(y)?g(a,S,y,"st"):g(a,S,y,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,y){a=new t(a);let I=a.max(1).log10().max(1).log(r.log10()).floor();if(I.lte(0))return g(a,S,y,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(I)).sub(I.gte(1)?1:0));let _=I.div(10).floor(),M=I.toNumber()%10-1;return g(a,Math.max(4,S),y,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+g(_,0,y,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return ht[0][0][a%10]+ht[0][1][Math.floor(a/10)%10]+ht[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,y=Math.floor(a/10)%10,I=Math.floor(a/100)%10,_="";return a<10?ht[1][0][a]:(y==1&&S==0?_+="Vec":_+=ht[1][1][S]+ht[1][2][y],_+=ht[1][3][I],_)}},inf:{format(a,S,y){a=new t(a);let I=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],F=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),I++;return I==0?g(a,S,y,"sc"):a.gte(3)?F[I]+M[I]+"\u03C9^"+g(a.sub(1),S,y,"sc"):a.gte(2)?F[I]+"\u03C9"+M[I]+"-"+g(_.pow(a.sub(2)),S,y,"sc"):F[I]+M[I]+"-"+g(_.pow(a.sub(1)),S,y,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),y=!1,I=9){if(a=new t(a),S=new t(S).div(1e3),a.lt(S.mul(1e3)))return"";let{alphabet:_}=e.alphabet.config,M=_.length,F=a.log(1e3).sub(S.log(1e3)).floor(),P=F.add(1).log(M+1).ceil(),G="",Y=(K,nt)=>{let H=K,Z="";for(let W=0;W=M)return"\u03C9";Z=_[pt]+Z,H=H.sub(1).div(M).floor()}return Z};if(P.lt(I))G=Y(F,P);else{let K=P.sub(I).add(1),nt=F.div(t.pow(M+1,K.sub(1))).floor();G=`${Y(nt,new t(I))}(${K.gt("1e9")?K.format():K.format(0)})`}return G},format(a,S=2,y=9,I="mixed_sc",_=new t(1e15),M=!1,F){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return g(a,S,y,I);let P=e.alphabet.getAbbreviation(a,_,M,F),G=a.div(t.pow(1e3,a.log(1e3).floor()));return`${P.length>(F??9)+2?"":G.toFixed(S)+" "}${P}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function u(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function m(a,S=2,y=9,I="st"){return g(a,S,y,I)}function g(a,S=2,y=9,I="mixed_sc"){a=new t(a);let _=a.lt(0)?"-":"";if(a.mag==1/0)return _+"Infinity";if(Number.isNaN(a.mag))return _+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(S);let M=a.log10().floor();switch(I){case"sc":case"scientific":if(a.log10().lt(Math.min(-S,0))&&S>1){let F=a.log10().ceil(),P=a.div(F.eq(-1)?new t(.1):t.dTen.pow(F)),G=F.mul(-1).max(1).log10().gte(9);return _+(G?"":P.toFixed(2))+"e"+g(F,0,y,"mixed_sc")}else if(M.lt(y)){let F=Math.max(Math.min(S-M.toNumber(),S),0);return _+(F>0?a.toFixed(F):a.toFixed(F).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let G=a.slog();return(G.gte(1e9)?"":t.dTen.pow(G.sub(G.floor())).toFixed(2))+"F"+g(G.floor(),0)}let F=a.div(t.dTen.pow(M)),P=M.log10().gte(9);return _+(P?"":F.toFixed(2))+"e"+g(M,0,y,"mixed_sc")}case"st":case"standard":{let F=a.log(1e3).floor();if(F.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let P=F.mul(3),G=F.log10().floor();if(G.gte(3e3))return"e"+g(M,S,y,"st");let Y="";if(F.lt(4))Y=["","K","M","B"][Math.round(F.toNumber())];else{let H=Math.floor(F.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),F=F.sub(1).div(t.dTen.pow(H*3));F.gt(0);){let Z=F.div(1e3).floor(),W=F.sub(Z.mul(1e3)).floor().toNumber();W>0&&(W==1&&!H&&(Y="U"),H&&(Y=e.standard.tier2(H)+(Y?"-"+Y:"")),W>1&&(Y=e.standard.tier1(W)+Y)),F=Z,H++}}let K=a.div(t.dTen.pow(P)),nt=S===2?t.dTwo.sub(M.sub(P)).add(1).toNumber():S;return _+(G.gte(10)?"":K.toFixed(nt)+" ")+Y}default:return e[I]||console.error('Invalid format type "',I,'"'),_+e[I].format(a,S,y)}}function l(a,S,y="mixed_sc",I,_){a=new t(a),S=new t(S);let M=a.add(S),F,P=M.div(a);return P.gte(10)&&a.gte(1e100)?(P=P.log10().mul(20),F="(+"+g(P,I,_,y)+" OoMs/sec)"):F="(+"+g(S,I,_,y)+"/sec)",F}function v(a,S=2,y="s"){return a=new t(a),a.gte(86400)?g(a.div(86400).floor(),0,12,"sc")+":"+v(a.mod(86400),S,"d"):a.gte(3600)||y=="d"?(a.div(3600).gte(10)||y!="d"?"":"0")+g(a.div(3600).floor(),0,12,"sc")+":"+v(a.mod(3600),S,"h"):a.gte(60)||y=="h"?(a.div(60).gte(10)||y!="h"?"":"0")+g(a.div(60).floor(),0,12,"sc")+":"+v(a.mod(60),S,"m"):(a.gte(10)||y!="m"?"":"0")+g(a,S,12,"sc")}function c(a,S=!1,y=0,I=9,_="mixed_sc"){let M=Rt=>g(Rt,y,I,_);a=new t(a);let F=a.mul(1e3).mod(1e3).floor(),P=a.mod(60).floor(),G=a.div(60).mod(60).floor(),Y=a.div(3600).mod(24).floor(),K=a.div(86400).mod(365.2425).floor(),nt=a.div(31556952).floor(),H=nt.eq(1)?" year":" years",Z=K.eq(1)?" day":" days",W=Y.eq(1)?" hour":" hours",pt=G.eq(1)?" minute":" minutes",Dt=P.eq(1)?" second":" seconds",jt=F.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+H+", ":""}${K.gt(0)?M(K)+Z+", ":""}${Y.gt(0)?M(Y)+W+", ":""}${G.gt(0)?M(G)+pt+", ":""}${P.gt(0)?M(P)+Dt+",":""}${S&&F.gt(0)?" "+M(F)+jt:""}`.replace(/,([^,]*)$/,"$1").trim()}function f(a){return a=new t(a),g(t.dOne.sub(a).mul(100))+"%"}function h(a){return a=new t(a),g(a.mul(100))+"%"}function p(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function d(a,S,y=10){return t.gte(a,10)?t.pow(y,t.log(a,y).pow(S)):new t(a)}function O(a,S=0){a=new t(a);let y=(F=>F.map((P,G)=>({name:P.name,altName:P.altName,value:t.pow(1e3,new t(G).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),I="",_=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),y.length-1).floor().toNumber(),M=y[_];if(_===0)switch(S){case 1:I="";break;case 2:case 0:default:I=a.format();break}switch(S){case 1:I=M.name;break;case 2:I=a.divide(M.value).format();break;case 3:I=M.altName;break;case 0:default:I=`${a.divide(M.value).format()} ${M.name}`;break}return I}function T(a,S=!1){return`${O(a,2)} ${O(a,1)}eV${S?"/c^2":""}`}let k={...e,toSubscript:o,toSuperscript:u,formatST:m,format:g,formatGain:l,formatTime:v,formatTimeLong:c,formatReduction:f,formatPercent:h,formatMult:p,expMult:d,metric:O,ev:T};return{FORMATS:e,formats:k}}var zt=17,cr=9e15,hr=Math.log10(9e15),mr=1/9e15,dr=308,gr=-324,me=5,pr=1023,Nr=!0,yr=!1,vr=function(){let t=[];for(let r=gr+1;r<=dr;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),Nt=[2,Math.E,3,4,5,6,7,8,9,10],br=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],wr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],w=function(e){return s.fromValue_noAlloc(e)},j=function(t,e,r){return s.fromComponents(t,e,r)},C=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},mt=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},Zt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Mr=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r-1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r-1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r-691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r-3617/(122400*n),Math.exp(r)/e},_r=.36787944117144233,de=.5671432904097838,Yt=function(t,e=1e-10,r=!0){let i,n;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return de;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(n-i).5?1:-1;if(Math.random()*20<1)return C(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),j(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),u=o.pow(2);return o.neg().add(u.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=cr)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);Nr?t=t.replace(",",""):yr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let d=parseFloat(n[0]),O=parseFloat(n[1]),T=n[1].split(";"),k=1;if(T.length===2&&(k=parseFloat(T[1]),isFinite(k)||(k=1)),isFinite(d)&&isFinite(O)){let a=s.pentate(d,O,k,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let d=parseFloat(o[0]),O=parseFloat(o[1]),T=o[1].split(";"),k=1;if(T.length===2&&(k=parseFloat(T[1]),isFinite(k)||(k=1)),isFinite(d)&&isFinite(O)){let a=s.tetrate(d,O,k,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let u=t.split("^");if(u.length===2){let d=parseFloat(u[0]),O=parseFloat(u[1]);if(isFinite(d)&&isFinite(O)){let T=s.pow(d,O);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let m,g,l=t.split("pt");if(l.length===2){m=10;let d=!1;l[0].startsWith("-")&&(d=!0,l[0]=l[0].slice(1)),g=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let O=parseFloat(l[1]);if(isFinite(O)||(O=1),isFinite(m)&&isFinite(g)){let T=s.tetrate(m,g,O,e);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}if(l=t.split("p"),l.length===2){m=10;let d=!1;l[0].startsWith("-")&&(d=!0,l[0]=l[0].slice(1)),g=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let O=parseFloat(l[1]);if(isFinite(O)||(O=1),isFinite(m)&&isFinite(g)){let T=s.tetrate(m,g,O,e);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}if(l=t.split("f"),l.length===2){m=10;let d=!1;l[0].startsWith("-")&&(d=!0,l[0]=l[0].slice(1)),l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let O=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),g=parseFloat(l[1]),isFinite(O)||(O=1),isFinite(m)&&isFinite(g)){let T=s.tetrate(m,g,O,e);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),d&&(this.sign*=-1),this}}let v=t.split("e"),c=v.length-1;if(c===0){let d=parseFloat(t);if(isFinite(d))return this.fromNumber(d),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(c===1){let d=parseFloat(t);if(isFinite(d)&&d!==0)return this.fromNumber(d),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let f=t.split("e^");if(f.length===2){this.sign=1,f[0].startsWith("-")&&(this.sign=-1);let d="";for(let O=0;O=43&&T<=57||T===101)d+=f[1].charAt(O);else return this.layer=parseFloat(d),this.mag=parseFloat(f[1].substr(O+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(c<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let h=parseFloat(v[0]);if(h===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let p=parseFloat(v[v.length-1]);if(c>=2){let d=parseFloat(v[v.length-2]);isFinite(d)&&(p*=Math.sign(d),p+=Zt(d))}if(!isFinite(h))this.sign=v[0]==="-"?-1:1,this.layer=c,this.mag=p;else if(c===1)this.sign=Math.sign(h),this.layer=1,this.mag=p+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=c,c===2){let d=s.mul(j(1,2,p),w(h));return this.sign=d.sign,this.layer=d.layer,this.mag=d.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=p;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:mt(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:mt(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=me?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):mt(this.m,t)+"e"+mt(this.e,t):this.layer===1?mt(this.m,t)+"e"+mt(this.e,t):this.layer<=me?(this.sign===-1?"-":"")+"e".repeat(this.layer)+mt(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+mt(this.mag,t)}abs(){return C(this.sign===0?0:1,this.layer,this.mag)}neg(){return C(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?C(0,0,0):this.layer===0?j(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?C(-1,0,1):C(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?j(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?C(1,0,1):C(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?j(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?C(0,0,0):this.layer===0?j(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=w(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return C(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return C(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>zt)return r;{let u=Math.pow(10,Math.log10(r.mag)-i.mag),m=i.sign+r.sign*u;return j(Math.sign(m),1,i.mag+Math.log10(Math.abs(m)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>zt)return r;{let u=Math.pow(10,r.mag-Math.log10(i.mag)),m=i.sign+r.sign*u;return j(Math.sign(m),1,Math.log10(i.mag)+Math.log10(Math.abs(m)))}}if(Math.abs(r.mag-i.mag)>zt)return r;{let u=Math.pow(10,r.mag-i.mag),m=i.sign+r.sign*u;return j(Math.sign(m),1,i.mag+Math.log10(Math.abs(m)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(w(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=w(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return C(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return C(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return C(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return C(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return j(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return j(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return j(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=j(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(j(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return j(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=j(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(j(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return j(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=w(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?C(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?C(0,0,0):this.layer===0?j(this.sign,0,1/this.mag):j(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=w(t).abs();if(e.eq(s.dZero))return C(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new s(r%i):this.sub(e).eq(this)?C(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=w(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=w(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=w(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=Zt(n)),this.layer0?j(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):j(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?C(Number.NaN,Number.NaN,Number.NaN):this.layer>0?j(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):j(this.sign,0,Math.log10(this.mag))}log(t){return t=w(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?C(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?j(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?C(Number.NaN,Number.NaN,Number.NaN):this.layer===0?j(this.sign,0,Math.log2(this.mag)):this.layer===1?j(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?j(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):j(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?C(Number.NaN,Number.NaN,Number.NaN):this.layer===0?j(this.sign,0,Math.log(this.mag)):this.layer===1?j(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?j(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):j(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=w(t),r=new s(this),i=new s(e);if(r.sign===0)return i.eq(0)?C(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return C(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:C(Number.NaN,Number.NaN,Number.NaN):n}pow10(){if(this.eq(s.dInf))return C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return C(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return C(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return j(1,0,e);if(t.sign===0)return C(1,0,1);t=C(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?j(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?j(-t.sign,t.layer+1,-t.mag):C(1,0,1)}pow_base(t){return w(t).pow(this)}root(t){let e=w(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(C(1,0,24)))return s.fromNumber(Mr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,u=e+o;if(u===e||(e=u,i=i*r,n=360*i,o=1/n,u=e-o,u===e))return s.exp(e);e=u,i=i*r,n=1260*i;let m=1/n;return e=e+m,i=i*r,n=1680*i,m=1/n,e=e-m,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?C(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?j(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?j(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):j(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return j(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(C(this.sign,this.layer-1,this.mag),C(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=C(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return C(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let u=s.ln(this).neg(),m=u.lambertw().div(u);if(o<1)return m;let g=u.lambertw(!1).div(u);return o>1.444667861009099&&(m=g=s.fromNumber(Math.E)),e=w(e),e.eq(g)?g:e.lt(g)?m:C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):C(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let u=0;u1e4&&Math.ceil(i)%2==1?this.pow(e):e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return C(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=C(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=w(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let u=Math.min(e,i.layer-t.layer-3);e-=u,i.layer-=u}for(let u=0;u1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,u=this.slog_internal(t,r).toNumber();for(let m=1;m1&&o!=l&&(n=!0),o=l,n?i/=2:i*=2,i=Math.abs(i)*(l?-1:1),u+=i,i===0)break}return s.fromNumber(u)}slog_internal(t=10,e=!1){if(t=w(t),t.lte(s.dZero)||t.eq(s.dOne))return C(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?C(0,0,0):this.eq(s.dZero)?C(-1,0,1):C(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return C(-1,0,1);if(t.lt(1.444667861009766)){let n=s.ln(t).neg(),o=n.lambertw().div(n);if(this.eq(o))return C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return C(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,wr)}static tetrate_critical(t,e){return s.critical_section(t,e,br)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let m=0;mt){let g=(t-Nt[m])/(Nt[m+1]-Nt[m]);n=r[m][Math.floor(e)]*(1-g)+r[m+1][Math.floor(e)]*g,o=r[m][Math.ceil(e)]*(1-g)+r[m+1][Math.ceil(e)]*g;break}let u=e-Math.floor(e);return n<=0||o<=0?n*(1-u)+o*u:Math.pow(t,Math.log(n)/Math.log(t)*(1-u)+Math.log(o)/Math.log(t)*u)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=w(e);if(i.gt(1)&&i.lte(1.444667861009766)){let u=s.excess_slog(this,e,r),m=u[0].toNumber(),g=u[1],l=m+t,v=s.ln(e).neg(),c=v.lambertw().div(v),f=v.lambertw(!1).div(v),h=s.dOne;g==1?h=c.mul(f).sqrt():g==2&&(h=f.mul(2));let p=i.pow(h),d=Math.floor(l),O=l-d,T=h.pow(1-O).mul(p.pow(O));return s.tetrate(i,d,T,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?s.tetrate(e,o,s.dOne,r):Number.isFinite(o)?o>=-1?s.log(s.tetrate(e,o+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,o+2,s.dOne,r),e),e):C(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=w(t),e=w(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[C(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let n=s.ln(e).neg(),o=n.lambertw().div(n),u=s.dInf;if(e>1&&(u=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=u=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(u))return[C(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(u)){let m=u.mul(2),g=i.pow(m),l=0;if(t.gte(m)&&t.lt(g))l=0;else if(t.gte(g)){let d=g;for(l=1;d.lt(t);)if(d=i.pow(d),l=l+1,d.layer>3){let O=Math.floor(t.layer-d.layer+1);d=i.iteratedexp(O,d,r),l=l+O}d.gt(t)&&(d=d.log(e),l=l-1)}else if(t.lt(m)){let d=m;for(l=0;d.gt(t);)d=d.log(e),l=l-1}let v=0,c=0,f=.5,h=m,p=s.dZero;for(;f>1e-16;){if(c=v+f,h=m.pow(1-c).mul(g.pow(c)),p=s.iteratedexp(e,l,h),p.eq(t))return[new s(l+c),2];p.lt(t)&&(v+=f),f/=2}return p.neq_tolerance(t,1e-7)?[C(Number.NaN,Number.NaN,Number.NaN),0]:[new s(l+v),2]}if(t.lt(u)&&t.gt(o)){let m=o.mul(u).sqrt(),g=i.pow(m),l=0;if(t.lte(m)&&t.gt(g))l=0;else if(t.lte(g)){let d=g;for(l=1;d.gt(t);)d=i.pow(d),l=l+1;d.lt(t)&&(d=d.log(e),l=l-1)}else if(t.gt(m)){let d=m;for(l=0;d.lt(t);)d=d.log(e),l=l-1}let v=0,c=0,f=.5,h=m,p=s.dZero;for(;f>1e-16;){if(c=v+f,h=m.pow(1-c).mul(g.pow(c)),p=s.iteratedexp(e,l,h),p.eq(t))return[new s(l+c),1];p.gt(t)&&(v+=f),f/=2}return p.neq_tolerance(t,1e-7)?[C(Number.NaN,Number.NaN,Number.NaN),0]:[new s(l+v),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?C(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new s(this):this.mag<0?s.fromNumber(Yt(this.toNumber())):this.layer===0?s.fromNumber(Yt(this.sign*this.mag)):this.lt("eee15")?ge(this):this.ln():this.sign===1?C(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Yt(this.sign*this.mag,1e-10,!1)):this.layer==1?ge(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return C(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return C(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return e_r?this.pow(this.recip()):C(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return C(1,0,1);if(this.lt(0))return C(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):C(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,u=n.div(2),m=!0;for(;m;)u=r.add(n).div(2),s.iteratedexp(10,i,u,!0).tetrate(t,1,!0).gt(this)?n=u:r=u,u.eq(o)?m=!1:o=u;return s.iteratedexp(10,i,u,!0)}else{let e=1,r=j(1,10,1),i=j(1,10,1),n=j(1,10,1),o=j(1,1,-16),u=s.dZero,m=j(1,10,1),g=o.pow10().recip(),l=s.dZero,v=g,c=g,f=Math.ceil(t)%2==0,h=0,p=j(1,10,1),d=!1,O=s.dZero,T=!1;for(;e<4;){if(e==2){if(f)break;n=j(1,10,1),o=r,e=3,m=j(1,10,1),p=j(1,10,1)}for(d=!1;o.neq(n);){if(O=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))g=o.pow10().recip(),v=o.pow10().recip(),c=o.pow10().recip(),l=s.dZero,h=-1,e==3&&(p=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!f&&o.pow10().recip().lt(.4))g=o.pow10().recip(),v=o.pow10().recip(),c=o.pow10().recip(),l=s.dZero,h=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))g=o.pow10().recip(),v=s.dZero,c=g.mul(2),l=g,f?h=-1:h=0;else{for(u=o.mul(12e-17),g=o.pow10().recip(),v=o.add(u).pow10().recip(),l=g.sub(v),c=g.add(l);v.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||c.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||v.gte(g)||c.lte(g);)u=u.mul(2),v=o.add(u).pow10().recip(),l=g.sub(v),c=g.add(l);if((e==1&&c.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&v.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&c.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&v.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(p=o),c.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))h=-1;else if(f)h=1;else if(e==3&&o.gt_tolerance(r,1e-8))h=0;else{for(;v.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||c.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||v.gte(g)||c.lte(g);)u=u.mul(2),v=o.add(u).pow10().recip(),l=g.sub(v),c=g.add(l);c.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.tetrate(t,1,!0).sub(v.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(T=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(j(1,10,1)))o=o.mul(2);else{let y=!1;if(d&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),o=o.add(n).div(2),y)break}else if(n.eq(j(1,10,1)))n=o,o=o.div(2);else{let y=!1;if(d&&(h==1&&e==1||h==-1&&e==3)&&(y=!0),n=n.sub(m),o=o.sub(m),y)break}if(n.sub(o).div(2).abs().gt(m.mul(1.5))&&(d=!0),m=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(O))break}if(o.gt("1e18")||!T||p==j(1,10,1))break;e==1?r=p:e==3&&(i=p),e++}n=r,o=j(1,1,-18);let k=o,a=s.dZero,S=!0;for(;S;)if(n.eq(j(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(k)?S=!1:k=a,o.gt("1e18"))return C(Number.NaN,Number.NaN,Number.NaN);if(a.eq_tolerance(r,1e-15)){if(i.eq(j(1,10,1)))return C(Number.NaN,Number.NaN,Number.NaN);for(n=j(1,10,1),o=i,k=o,a=s.dZero,S=!0;S;)if(n.eq(j(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(k)?S=!1:k=a,o.gt("1e18"))return C(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=C(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):C(0,0,0)}cos(){return this.mag<0?C(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):C(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):C(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):C(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):C(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?C(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return dt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return dt.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return dt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return dt.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return dt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return dt.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let u=Math.floor(r/i[o]);r-=u*i[o],n+=o.repeat(u)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=C(0,0,0),s.dOne=C(1,0,1),s.dNegOne=C(-1,0,1),s.dTwo=C(1,0,2),s.dTen=C(1,0,10),s.dNaN=C(Number.NaN,Number.NaN,Number.NaN),s.dInf=C(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=C(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=j(1,0,Number.MAX_VALUE),s.dNumberMin=j(1,0,Number.MIN_VALUE),s.fromStringCache=new Gt(pr),st([Tt()],s.prototype,"sign",2),st([Tt()],s.prototype,"mag",2),st([Tt()],s.prototype,"layer",2),s=st([ur()],s);var{formats:dt,FORMATS:Sr}=fr(s);s.formats=dt;var St=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},Vt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new s(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new St(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nc),l=n,v=this.getBoosts(o,!0);v[0][0]?this.boostArray[v[1][0]]=new St({id:o,name:u,description:m,value:g,order:l}):this.boostArray.push(new St({id:o,name:u,description:m,value:g,order:l}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let u=this.getBoosts(o.id,!0);u[0][0]?this.boostArray[u[1][0]]=new St(o):this.boostArray.push(new St(o))}}}clearBoosts(){this.boostArray.length=0}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},ti=ot(ft()),kt=30,Ht=.001;function Ir(t,e,r="geometric"){switch(t=new s(t),e=new s(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return s.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function Wt(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new s(t),e=new s(e),r=new s(r);let n,o;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=n.lte(r)):(n=t.sub(e).abs(),o=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:o}),o}function Xt(t,e,r="geometric",i=kt,n=Ht,o=1,u){if(o=new s(o),u=new s(u??e),o.gt(u)&&([o,u]=[u,o]),t(u).eq(0))return{value:s.dZero,lowerBound:s.dZero,upperBound:s.dZero};if(t(u).lt(e))return console.warn("eMath.js: The function is not monotonically increasing. (f(n) < n)"),{value:u,lowerBound:u,upperBound:u};for(let g=0;g=0;m--){let g=r.add(u.mul(m)),l=r.add(u.mul(m+1)),v=o;if(o=o.add(t(g).add(t(l)).div(2).mul(u)),Wt(v,o,n,{verbose:!1,mode:"geometric"}))break}return o}function Jt(t,e,r=0,i,n){return r=new s(r),e=new s(e),e.sub(r).lte(kt)?pe(t,e,r,i):Ne(t,e,r,n)}function Ar(t,e=10,r=0,i=1e3){if(t=new s(t),e=new s(e),r=new s(r),i=new s(i),e.lt(1)||r.lt(1))return s.dNaN;let n=t.sign;if(t=t.abs(),t.gte(s.pow(e,i)))return t;let o=s.floor(s.log(t,e)),u=t.div(s.pow(e,o));return u=u.mul(s.pow(e,r)).round(),u=u.div(s.pow(e,r)),u=u.mul(s.pow(e,o)).mul(n),u}function ye(t,e,r,i=s.dInf,n,o,u=!1){t=new s(t),r=new s(r??e.level),i=new s(i);let m=i.sub(r);if(m.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",m),[s.dZero,s.dZero];if(u=(typeof e.el=="function"?e.el():e.el)??u,m.eq(1)){let c=e.cost(e.level),f=t.gte(c),h=[s.dZero,s.dZero];return u?(h[0]=f?s.dOne:s.dZero,h):(h=[f?s.dOne:s.dZero,f?c:s.dZero],h)}if(e.costBulk){let[c,f]=e.costBulk(t,e.level,m),h=t.gte(f);return[h?c:s.dZero,h&&!u?f:s.dZero]}if(u){let c=p=>e.cost(p.add(r)),f=s.min(i,Xt(c,t,n,o).value.floor()),h=s.dZero;return[f,h]}let g=Xt(c=>Jt(e.cost,c,r),t,n,o).value.floor().min(r.add(m).sub(1)),l=Jt(e.cost,g,r);return[g.sub(r).add(1).max(0),l]}function ve(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function Or(t){return`el/${ve(t)}`}var yt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):s.dOne}};st([Tt()],yt.prototype,"id",2),st([_t(()=>s)],yt.prototype,"level",2);var be=class Ze{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:s.dOne}}).data??{level:s.dOne}).level}set level(e){this.data.level=new s(e)}constructor(e,r,i,n){let o=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>o,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new Gt(n??Ze.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??s.dOne}},ei=ot(ft());function we(t,e,r=s.dOne,i=s.dInf){if(t=new s(t),r=new s(r),i=new s(i),i.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",i),[s.dZero,s.dZero];if(i.eq(1)){let u=e.cost(r);return[t.gte(u)?s.dOne:s.dZero,t.gte(u)?u:s.dZero]}let n=t.div(e.cost(r)).floor().min(i),o=e.cost(r).mul(n);return[n,o]}var Me=class{constructor(t,e,r){this.defaultAmount=s.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??s.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:s.dOne}}).data??{amount:s.dOne}).amount}set amount(t){this.data.amount=new s(t)}},vt=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??s.dZero}};st([Tt()],vt.prototype,"id",2),st([_t(()=>s)],vt.prototype,"amount",2);var ri=ot(ft()),gt=class{constructor(){this.value=s.dZero,this.upgrades={},this.items={}}};st([_t(()=>s)],gt.prototype,"value",2),st([_t(()=>yt)],gt.prototype,"upgrades",2),st([_t(()=>vt)],gt.prototype,"items",2);var _e=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new gt,e,r,i={defaultVal:s.dZero,defaultBoost:s.dOne}){this.defaultVal=i.defaultVal,this.defaultBoost=i.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Vt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e),this.items={},r&&this.addItem(r)}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(n);if(i.resetItemAmounts)for(let n of Object.values(this.items))n.amount=new s(n.defaultAmount),i.runUpgradeEffect&&this.runItemEffect(n)}gain(t=1e3){let e=this.boost.calculate().mul(new s(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new yt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(o=>i.test(o)).map(o=>this.upgrades[o])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let n=new be(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(n),this.upgrades[i.id]=n,r.push(n)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t.effect?.(t.level,t,this)}runItemEffect(t,e=s.dOne){e=new s(e),t.effect?.(t.amount,e,t,this)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`eMath.js: Upgrade "${t}" not found.`),[s.dZero,s.dZero]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=s.min(e,n.maxLevel)),ye(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),!1;let[o,u]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(u),n.level=n.level.add(o),this.runUpgradeEffect(n),!0)}pointerAddItem(t){let e=new vt(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new Me(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runItemEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e,r){let i=this.getItem(t);return i===null?(console.warn(`eMath.js: Item "${t}" not found.`),[s.dZero,s.dZero]):we(this.value,i,e,r)}buyItem(t,e,r){let i=this.getItem(t);if(i===null)return console.warn(`eMath.js: Item "${t}" not found.`),!1;let[n,o]=this.calculateItem(t,e,r);return n.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(o),i.amount=i.amount.add(n),this.runItemEffect(i,e),!0)}},ii=ot(ft()),xt=class{constructor(t=0){this.value=new s(t)}};st([_t(()=>s)],xt.prototype,"value",2);var Se=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new xt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Vt(this.initial):null}update(){console.warn("eMath.js: AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},Lt=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=typeof r=="function"?r(this):{...r},this.gridSymbol=i}get grid(){return Qt.getInstance(this.gridSymbol)}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Qt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=this.grid;return(()=>{switch(t){case"up":return i.getCell(this.x,this.y-e);case"right":return i.getCell(this.x+e,this.y);case"down":return i.getCell(this.x,this.y+e);case"left":return i.getCell(this.x-e,this.y);case"adjacent":return i.getAdjacent(this.x,this.y,e,r);case"diagonal":return i.getDiagonal(this.x,this.y,e,r);case"encircling":return i.getEncircling(this.x,this.y,e,r);default:throw new Error("Invalid direction")}})()}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}};function Ie(t,e,r=!0){let i=r?"Size":"Coordinates";if(typeof t!="number"||typeof e!="number")throw new RangeError(`${i} must be numbers: ${t}, ${e}`);if(!Number.isInteger(t)||!Number.isInteger(e))throw new RangeError(`${i} must be integers: ${t}, ${e}`);if(t<0||e<0)throw new RangeError(`${i} must be positive: ${t}, ${e}`);if(!Number.isFinite(t)||!Number.isFinite(e))throw new RangeError(`${i} must be finite: ${t}, ${e}`);if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e))throw new RangeError(`${i} must be safe integers: ${t}, ${e}`)}var rt=class ne extends Array{constructor(e){e=Array.isArray(e)?e:[e],e=e.filter(r=>r!==void 0),super(...e),this.removeDuplicates()}removeDuplicates(){let e=[];this.forEach((r,i)=>{this.indexOf(r)!==i&&e.push(i)}),e.forEach(r=>this.splice(r,1))}translate(e=0,r=0){return new ne(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new ne(this.flatMap(n=>n.direction(e,r,i)))}up(e){return this.direction("up",e)}right(e){return this.direction("right",e)}down(e){return this.direction("down",e)}left(e){return this.direction("left",e)}adjacent(e,r){return this.direction("adjacent",e,r)}diagonal(e,r){return this.direction("diagonal",e,r)}encircling(e,r){return this.direction("encircling",e,r)}},Qt=class se{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),se.instances[this.gridSymbol]=this,this.starterProps=i??{},this.xSize=e,this.ySize=r??e,Ie(this.xSize,this.ySize,!0);for(let n=0;n{if(this.ySize!==n&&(this.ySizen))for(let o=n;o{if(this.xSize!==i){if(this.xSizei)for(let o=0;o{let t=!1,e=r=>(t||(console.warn("eMath.js: The E function is deprecated. Use the Decimal class directly."),t=!0),new s(r));return Object.getOwnPropertyNames(s).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=s[r]}),e})(),Tr=le,Ae={};Ut(Ae,{ConfigManager:()=>qt,DataManager:()=>Fe,EventManager:()=>Te,EventTypes:()=>Ce,Game:()=>kr,GameAttribute:()=>ke,GameCurrency:()=>Pe,GameReset:()=>te,KeyManager:()=>Oe,gameDefaultConfig:()=>xe,keys:()=>Fr});var ni=ot(ft()),qt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,i){for(let n in i)typeof r[n]>"u"?r[n]=i[n]:typeof r[n]=="object"&&typeof i[n]=="object"&&!Array.isArray(r[n])&&!Array.isArray(i[n])&&(r[n]=e(r[n],i[n]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Er={autoAddInterval:!0,fps:30},Fr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),Oe=class Ye{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=Ye.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let i of this.tickers)i(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let i of this.binds)(typeof i.onDownContinuous<"u"||typeof i.fn<"u")&&this.isPressing(i.id)&&(i.onDownContinuous?.(r),i.fn?.(r))}),document.addEventListener("keydown",r=>{this.logKey(r,!0),this.onAll("down",r.key)}),document.addEventListener("keyup",r=>{this.logKey(r,!1),this.onAll("up",r.key)}),document.addEventListener("keypress",r=>{this.onAll("press",r.key)}))}static{this.configManager=new qt(Er)}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{for(let r of this.tickers)r(1e3/e)},1e3/e))}logKey(e,r){let i=e.key;r&&!this.keysPressed.includes(i)?this.keysPressed.push(i):!r&&this.keysPressed.includes(i)&&this.keysPressed.splice(this.keysPressed.indexOf(i),1)}onAll(e,r){for(let i of this.binds)if(i.key===r)switch(e){case"down":i.onDown?.();break;case"press":default:i.onPress?.();break;case"up":i.onUp?.();break}}isPressing(e){for(let r of this.binds)if(r.id===e)return this.keysPressed.includes(r.key);return!1}getBind(e){return this.binds.find(r=>r.id===e)}addKey(e,r,i){e=typeof e=="string"?{id:e,name:e,key:r??"",fn:i}:e,e=Array.isArray(e)?e:[e];for(let n of e){n.id=n.id??n.name;let o=this.getBind(n.id);if(o){Object.assign(o,n);continue}this.binds.push(n)}}},Ce=(t=>(t.interval="interval",t.timeout="timeout",t))(Ce||{}),Pr={autoAddInterval:!0,fps:30},Te=class Ve{constructor(e,r){if(this.addEvent=this.setEvent.bind(this),this.config=Ve.configManager.parse(e),this.events={},this.callbackEvents={},r)for(let i of r)this.callbackEvents[i]=[];if(this.config.autoAddInterval){let i=this.config.fps??30;this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/i)}}static{this.configManager=new qt(Pr)}on(e,r){this.callbackEvents[e]||(this.callbackEvents[e]=[]),this.callbackEvents[e].push({type:e,callback:r})}dispatch(e){if(this.callbackEvents[e])for(let r of this.callbackEvents[e])r.callback()}tickerFunction(){let e=Date.now();for(let r of Object.values(this.events))switch(r.type){case"interval":if(e-r.intervalLast>=r.delay){let i=e-r.intervalLast;r.callback(i),r.intervalLast=e}break;case"timeout":{let i=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callback(i),delete this.events[r.name])}break}}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/e))}timeWarp(e){for(let r of Object.values(this.events))switch(r.type){case"interval":r.intervalLast-=e;break;case"timeout":r.timeCreated-=e;break}}setEvent(e,r,i,n){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callback:n,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callback:n,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},si=ot(ft()),Ee=ot(Ke()),Kt=ot(rr()),Fe=class{constructor(t,e){this.data={},this.static={},this.eventsOnLoad=[],this.gameRef=typeof t=="function"?t():t,this.localStorage=e??(typeof window>"u"?(console.warn("eMath.js: Local storage is not supported. Methods that rely on local storage will not work. You can use compileData() and decompileData() instead to implement a custom save system."),null):window.localStorage)}addEventOnLoad(t){this.eventsOnLoad.push(t)}setData(t,e){typeof this.data[t]>"u"&&this.normalData&&console.warn("eMath.js: After initializing data, you should not add new properties to data."),this.data[t]=e;let r=()=>this.data;return{get value(){return r()[t]},set value(i){r()[t]=i},setValue(i){r()[t]=i}}}getData(t){return this.data[t]}setStatic(t,e){return console.warn("eMath.js: setStatic: Static data is basically useless and should not be used. Use variables in local scope instead."),typeof this.static[t]>"u"&&this.normalData&&console.warn("eMath.js: After initializing data, you should not add new properties to staticData."),this.static[t]=e,this.static[t]}getStatic(t){return console.warn("eMath.js: Static data is basically useless and should not be used. Use variables in local scope instead."),this.static[t]}init(){this.normalData=this.data,this.normalDataPlain=Bt(this.data)}compileDataRaw(t=this.data){this.gameRef.eventManager.dispatch("beforeCompileData");let e=Bt(t),r=(0,Kt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.5.0"}catch{i="9.3.0"}return[{hash:r,game:{title:this.gameRef.config.name.title,id:this.gameRef.config.name.id,version:this.gameRef.config.name.version},emath:{version:i}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,Ee.compressToBase64)(e)}decompileData(t){if(!t&&this.localStorage&&(t=this.localStorage.getItem(`${this.gameRef.config.name.id}-data`)),!t&&!this.localStorage)return console.warn("eMath.js: Local storage is not supported. Methods that rely on local storage will not work: decompileData() requires the data to be passed as an argument."),null;if(!t)return null;let e;try{return e=JSON.parse((0,Ee.decompressFromBase64)(t)),e}catch(r){if(r instanceof SyntaxError)console.error(`Failed to decompile data (corrupted) "${t}":`,r);else throw r;return null}}validateData(t){let[e,r]=t;if(typeof e=="string")return(0,Kt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Kt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return i===n}resetData(t=!1){if(!this.normalData)throw new Error("dataManager.resetData(): You must call init() before writing to data.");this.data=this.normalData,this.saveData(),t&&window.location.reload()}saveData(t=this.compileData()){if(this.gameRef.eventManager.dispatch("beforeSaveData"),!t)throw new Error("dataManager.saveData(): Data to save is empty.");if(!this.localStorage)throw new Error("dataManager.saveData(): Local storage is not supported. You can use compileData() instead to implement a custom save system.");this.localStorage.setItem(`${this.gameRef.config.name.id}-data`,t),this.gameRef.eventManager.dispatch("saveData")}exportData(){let t=this.compileData();if(prompt("Download save data?:",t)!=null){let e=new Blob([t],{type:"text/plain"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=`${this.gameRef.config.name.id}-data.txt`,r.textContent=`Download ${this.gameRef.config.name.id}-data.txt file`,document.body.appendChild(r),r.click(),document.body.removeChild(r)}}parseData(t=this.decompileData(),e=!0){if((!this.normalData||!this.normalDataPlain)&&e)throw new Error("dataManager.parseData(): You must call init() before writing to data.");if(!t)return null;let[,r]=t;function i(c){return typeof c=="object"&&c?.constructor===Object}let n=(c,f)=>Object.prototype.hasOwnProperty.call(c,f);function o(c,f,h){if(!c||!f||!h)return console.warn("eMath.js: dataManager.deepMerge(): Missing arguments:",c,f,h),h??{};let p=h;for(let d in c)if(n(c,d)&&!n(h,d)&&(p[d]=c[d]),f[d]instanceof gt){let O=c[d],T=h[d];if(Array.isArray(T.upgrades)){let k=T.upgrades;T.upgrades={};for(let a of k)T.upgrades[a.id]=a}T.upgrades={...O.upgrades,...T.upgrades},p[d]=T,T.items={...O.items,...T.items}}else i(c[d])&&i(h[d])&&(p[d]=o(c[d],f[d],h[d]));return p}let u=e?o(this.normalDataPlain,this.normalData,r):r,m=Object.getOwnPropertyNames(new yt({id:"",level:s.dZero})),g=Object.getOwnPropertyNames(new vt({id:"",amount:s.dZero}));function l(c,f){let h=$t(c,f);if(h instanceof gt){for(let p in h.upgrades){let d=h.upgrades[p];if(!d||!m.every(O=>Object.getOwnPropertyNames(d).includes(O))){delete h.upgrades[p];continue}h.upgrades[p]=$t(yt,d)}for(let p in h.items){let d=h.items[p];if(!d||!g.every(O=>Object.getOwnPropertyNames(d).includes(O))){delete h.items[p];continue}h.items[p]=$t(vt,d)}}if(!h)throw new Error(`Failed to convert ${c.name} to class instance.`);return h}function v(c,f){if(!c||!f)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let h=f;for(let p in c){if(f[p]===void 0){console.warn(`eMath.js: Missing property "${p}" in loaded data.`);continue}if(!i(f[p]))continue;let d=c[p].constructor;if(d===Object){h[p]=v(c[p],f[p]);continue}h[p]=l(d,f[p])}return h}return u=v(this.normalData,u),u}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],Bt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return this.gameRef.eventManager.dispatch("loadData"),e}},Pe=class extends _e{get data(){return this.pointer}get static(){return this}constructor(t,e,r){if(typeof t=="function")throw new Error("GameCurrency constructor does not accept a function as the first parameter. Use the .addCurrency method instead.");super(...t),this.game=e,this.name=r,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}},ke=class extends Se{get data(){return this.pointer}get static(){return this}constructor(t,e){if(typeof t=="function")throw new Error("GameAttribute constructor does not accept a function as the first parameter. Use the .addAttribute method instead.");super(...t),this.game=e}},te=class He{static fromObject(e){return new He(e.currenciesToReset,e.extender,e.onReset,e.condition)}constructor(e,r,i,n){this.currenciesToReset=Array.isArray(e)?e:[e],r=r??[],this.extender=Array.isArray(r)?r:[r],this.onReset=i,this.condition=n,this.id=Symbol()}reset(e=!1,r=!0,i=new Set){if(e||(typeof this.condition=="function"?!this.condition(this):!this.condition)&&typeof this.condition<"u")return;let n=()=>{this.onReset?.(this),this.currenciesToReset.forEach(o=>{o.static.reset()})};if(this.extender.length===0){n();return}this.extender.forEach(o=>{i.has(o.id)||(i.add(o.id),o.reset(r||e,r,i))}),n()}},xe={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0,localStorage:void 0},kr=class We{static{this.configManager=new qt(xe)}constructor(e){this.config=We.configManager.parse(e),this.dataManager=new Fe(this,this.config.localStorage),this.keyManager=new Oe({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new Te({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.tickers=[]}init(){this.dataManager.init()}changeFps(e){this.keyManager.changeFps(e),this.eventManager.changeFps(e)}addCurrency(e,r=[],i=[]){return this.dataManager.setData(e,{currency:new gt}),new Pe([()=>this.dataManager.getData(e).currency,r,i],this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new xt(i)),new ke([this.dataManager.getData(e),r,i],this)}addReset(...e){return console.warn("eMath.js: Game.addReset is deprecated. Use the GameReset class instead."),new te(...e)}addResetFromObject(e){return console.warn("eMath.js: Game.addResetFromObject is deprecated. Use the GameReset.fromObject static method instead."),te.fromObject(e)}},xr={...Tr,...Ae},Lr=xr;if(typeof ut.exports=="object"&&typeof Ot=="object"){var qr=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};ut.exports=qr(ut.exports,Ot)}return ut.exports}); +"use strict";(function(Et,lt){var Pt=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],lt);else if(typeof module=="object"&&module.exports)module.exports=lt();else{var ht=lt(),Lt=Pt?exports:Et;for(var Tt in ht)Lt[Tt]=ht[Tt]}})(typeof self<"u"?self:exports,()=>{var Et={},lt={exports:Et},Pt=Object.create,ht=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,Tt=Object.getOwnPropertyNames,Ke=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty,Mt=(t,e)=>function(){return e||(0,t[Tt(t)[0]])((e={exports:{}}).exports,e),e.exports},Bt=(t,e)=>{for(var r in e)ht(t,r,{get:e[r],enumerable:!0})},ue=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Tt(e))!Xe.call(t,n)&&n!==r&&ht(t,n,{get:()=>e[n],enumerable:!(i=Lt(e,n))||i.enumerable});return t},at=(t,e,r)=>(r=t!=null?Pt(Ke(t)):{},ue(e||!t||!t.__esModule?ht(r,"default",{value:t,enumerable:!0}):r,t)),tr=t=>ue(ht({},"__esModule",{value:!0}),t),ot=(t,e,r,i)=>{for(var n=i>1?void 0:i?Lt(e,r):e,o=t.length-1,l;o>=0;o--)(l=t[o])&&(n=(i?l(e,r,n):l(n))||n);return i&&n&&ht(e,r,n),n},ct=Mt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:d(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(a,M){return function(h,f){Object.defineProperty(a,h,{configurable:!0,writable:!0,value:f}),M&&M(h,f)}}function l(){try{return Function("return this;")()}catch{}}function c(){try{return(0,eval)("(function() { return this; })()")}catch{}}function d(){return l()||c()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",l=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",c=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",d=typeof Object.create=="function",a={__proto__:[]}instanceof Array,M=!d&&!a,h={create:d?function(){return se(Object.create(null))}:a?function(){return se({__proto__:null})}:function(){return se({})},has:M?function(v,_){return n.call(v,_)}:function(v,_){return _ in v},get:M?function(v,_){return n.call(v,_)?v[_]:void 0}:function(v,_){return v[_]}},f=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Yr(),p=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Vr(),g=typeof WeakMap=="function"?WeakMap:Hr(),C=o?Symbol.for("@reflect-metadata:registry"):void 0,E=zr(),T=$r(E);function u(v,_,A,F){if(U(A)){if(!Re(v))throw new TypeError;if(!Ue(_))throw new TypeError;return X(v,_)}else{if(!Re(v))throw new TypeError;if(!J(_))throw new TypeError;if(!J(F)&&!U(F)&&!Ot(F))throw new TypeError;return Ot(F)&&(F=void 0),A=ft(A),st(v,_,A,F)}}r("decorate",u);function S(v,_){function A(F,R){if(!J(F))throw new TypeError;if(!U(R)&&!Gr(R))throw new TypeError;Rt(v,_,F,R)}return A}r("metadata",S);function y(v,_,A,F){if(!J(A))throw new TypeError;return U(F)||(F=ft(F)),Rt(v,_,A,F)}r("defineMetadata",y);function w(v,_,A){if(!J(_))throw new TypeError;return U(A)||(A=ft(A)),H(v,_,A)}r("hasMetadata",w);function N(v,_,A){if(!J(_))throw new TypeError;return U(A)||(A=ft(A)),Z(v,_,A)}r("hasOwnMetadata",N);function b(v,_,A){if(!J(_))throw new TypeError;return U(A)||(A=ft(A)),W(v,_,A)}r("getMetadata",b);function k(v,_,A){if(!J(_))throw new TypeError;return U(A)||(A=ft(A)),Nt(v,_,A)}r("getOwnMetadata",k);function P(v,_){if(!J(v))throw new TypeError;return U(_)||(_=ft(_)),Ut(v,_)}r("getMetadataKeys",P);function G(v,_){if(!J(v))throw new TypeError;return U(_)||(_=ft(_)),Gt(v,_)}r("getOwnMetadataKeys",G);function Y(v,_,A){if(!J(_))throw new TypeError;if(U(A)||(A=ft(A)),!J(_))throw new TypeError;U(A)||(A=ft(A));var F=kt(_,A,!1);return U(F)?!1:F.OrdinaryDeleteMetadata(v,_,A)}r("deleteMetadata",Y);function X(v,_){for(var A=v.length-1;A>=0;--A){var F=v[A],R=F(_);if(!U(R)&&!Ot(R)){if(!Ue(R))throw new TypeError;_=R}}return _}function st(v,_,A,F){for(var R=v.length-1;R>=0;--R){var Q=v[R],et=Q(_,A,F);if(!U(et)&&!Ot(et)){if(!J(et))throw new TypeError;F=et}}return F}function H(v,_,A){var F=Z(v,_,A);if(F)return!0;var R=ne(_);return Ot(R)?!1:H(v,R,A)}function Z(v,_,A){var F=kt(_,A,!1);return U(F)?!1:je(F.OrdinaryHasOwnMetadata(v,_,A))}function W(v,_,A){var F=Z(v,_,A);if(F)return Nt(v,_,A);var R=ne(_);if(!Ot(R))return W(v,R,A)}function Nt(v,_,A){var F=kt(_,A,!1);if(!U(F))return F.OrdinaryGetOwnMetadata(v,_,A)}function Rt(v,_,A,F){var R=kt(A,F,!0);R.OrdinaryDefineOwnMetadata(v,_,A,F)}function Ut(v,_){var A=Gt(v,_),F=ne(v);if(F===null)return A;var R=Ut(F,_);if(R.length<=0)return A;if(A.length<=0)return R;for(var Q=new p,et=[],z=0,L=A;z=0&&L=this._keys.length?(this._index=-1,this._keys=_,this._values=_):this._index++,{value:x,done:!1}}return{value:void 0,done:!0}},z.prototype.throw=function(L){throw this._index>=0&&(this._index=-1,this._keys=_,this._values=_),L},z.prototype.return=function(L){return this._index>=0&&(this._index=-1,this._keys=_,this._values=_),{value:L,done:!0}},z}(),F=function(){function z(){this._keys=[],this._values=[],this._cacheKey=v,this._cacheIndex=-2}return Object.defineProperty(z.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),z.prototype.has=function(L){return this._find(L,!1)>=0},z.prototype.get=function(L){var x=this._find(L,!1);return x>=0?this._values[x]:void 0},z.prototype.set=function(L,x){var D=this._find(L,!0);return this._values[D]=x,this},z.prototype.delete=function(L){var x=this._find(L,!1);if(x>=0){for(var D=this._keys.length,j=x+1;j>>8,h[f*2+1]=p%256}return h},decompressFromUint8Array:function(a){if(a==null)return d.decompress(a);for(var M=new Array(a.length/2),h=0,f=M.length;h>1}else{for(m=1,f=0;f>1}u--,u==0&&(u=Math.pow(2,y),y++),delete g[T]}else for(m=p[T],f=0;f>1;u--,u==0&&(u=Math.pow(2,y),y++),p[E]=S++,T=String(C)}if(T!==""){if(Object.prototype.hasOwnProperty.call(g,T)){if(T.charCodeAt(0)<256){for(f=0;f>1}else{for(m=1,f=0;f>1}u--,u==0&&(u=Math.pow(2,y),y++),delete g[T]}else for(m=p[T],f=0;f>1;u--,u==0&&(u=Math.pow(2,y),y++)}for(m=2,f=0;f>1;for(;;)if(N=N<<1,b==M-1){w.push(h(N));break}else b++;return w.join("")},decompress:function(a){return a==null?"":a==""?null:d._decompress(a.length,32768,function(M){return a.charCodeAt(M)})},_decompress:function(a,M,h){var f=[],m,p=4,g=4,C=3,E="",T=[],u,S,y,w,N,b,k,P={val:h(0),position:M,index:1};for(u=0;u<3;u+=1)f[u]=u;for(y=0,N=Math.pow(2,2),b=1;b!=N;)w=P.val&P.position,P.position>>=1,P.position==0&&(P.position=M,P.val=h(P.index++)),y|=(w>0?1:0)*b,b<<=1;switch(m=y){case 0:for(y=0,N=Math.pow(2,8),b=1;b!=N;)w=P.val&P.position,P.position>>=1,P.position==0&&(P.position=M,P.val=h(P.index++)),y|=(w>0?1:0)*b,b<<=1;k=i(y);break;case 1:for(y=0,N=Math.pow(2,16),b=1;b!=N;)w=P.val&P.position,P.position>>=1,P.position==0&&(P.position=M,P.val=h(P.index++)),y|=(w>0?1:0)*b,b<<=1;k=i(y);break;case 2:return""}for(f[3]=k,S=k,T.push(k);;){if(P.index>a)return"";for(y=0,N=Math.pow(2,C),b=1;b!=N;)w=P.val&P.position,P.position>>=1,P.position==0&&(P.position=M,P.val=h(P.index++)),y|=(w>0?1:0)*b,b<<=1;switch(k=y){case 0:for(y=0,N=Math.pow(2,8),b=1;b!=N;)w=P.val&P.position,P.position>>=1,P.position==0&&(P.position=M,P.val=h(P.index++)),y|=(w>0?1:0)*b,b<<=1;f[g++]=i(y),k=g-1,p--;break;case 1:for(y=0,N=Math.pow(2,16),b=1;b!=N;)w=P.val&P.position,P.position>>=1,P.position==0&&(P.position=M,P.val=h(P.index++)),y|=(w>0?1:0)*b,b<<=1;f[g++]=i(y),k=g-1,p--;break;case 2:return T.join("")}if(p==0&&(p=Math.pow(2,C),C++),f[k])E=f[k];else if(k===g)E=S+S.charAt(0);else return null;T.push(E),f[g++]=S+E.charAt(0),p--,S=E,p==0&&(p=Math.pow(2,C),C++)}}};return d}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),rr=Mt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,o){return n<>>32-o},rotr:function(n,o){return n<<32-o|n>>>o},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var o=0;o0;n--)o.push(Math.floor(Math.random()*256));return o},bytesToWords:function(n){for(var o=[],l=0,c=0;l>>5]|=n[l]<<24-c%32;return o},wordsToBytes:function(n){for(var o=[],l=0;l>>5]>>>24-l%32&255);return o},bytesToHex:function(n){for(var o=[],l=0;l>>4).toString(16)),o.push((n[l]&15).toString(16));return o.join("")},hexToBytes:function(n){for(var o=[],l=0;l>>6*(3-d)&63)):o.push("=");return o.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var o=[],l=0,c=0;l>>6-c*2);return o}};e.exports=i})()}}),le=Mt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(i){return r.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(r.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var n=[],o=0;o>>24)&16711935|(a[g]<<24|a[g]>>>8)&4278255360;a[M>>>5]|=128<>>9<<4)+14]=M;for(var C=l._ff,E=l._gg,T=l._hh,u=l._ii,g=0;g>>0,f=f+y>>>0,m=m+w>>>0,p=p+N>>>0}return r.endian([h,f,m,p])};l._ff=function(c,d,a,M,h,f,m){var p=c+(d&a|~d&M)+(h>>>0)+m;return(p<>>32-f)+d},l._gg=function(c,d,a,M,h,f,m){var p=c+(d&M|a&~M)+(h>>>0)+m;return(p<>>32-f)+d},l._hh=function(c,d,a,M,h,f,m){var p=c+(d^a^M)+(h>>>0)+m;return(p<>>32-f)+d},l._ii=function(c,d,a,M,h,f,m){var p=c+(a^(d|~M))+(h>>>0)+m;return(p<>>32-f)+d},l._blocksize=16,l._digestsize=16,e.exports=function(c,d){if(c==null)throw new Error("Illegal argument "+c);var a=r.wordsToBytes(l(c,d));return d&&d.asBytes?a:d&&d.asString?o.bytesToString(a):r.bytesToHex(a)}})()}}),fe={};Bt(fe,{default:()=>xr}),lt.exports=tr(fe);var Qr=at(ct()),Kr=at(ct()),ce={};Bt(ce,{Attribute:()=>qt,AttributeStatic:()=>Ae,Boost:()=>Wt,BoostObject:()=>At,Currency:()=>pt,CurrencyStatic:()=>Se,DEFAULT_ITERATIONS:()=>xt,Decimal:()=>s,E:()=>Cr,FORMATS:()=>Ir,FormatTypeList:()=>cr,Grid:()=>te,GridCell:()=>Dt,GridCellCollection:()=>it,Item:()=>Ie,ItemData:()=>wt,LRUCache:()=>zt,ListNode:()=>he,ST_NAMES:()=>mt,UpgradeData:()=>vt,UpgradeStatic:()=>Me,calculateItem:()=>_e,calculateSum:()=>Xt,calculateSumApprox:()=>be,calculateSumLoop:()=>ye,calculateUpgrade:()=>ve,decimalToJSONString:()=>we,equalsTolerance:()=>Qt,formats:()=>gt,inverseFunctionApprox:()=>Kt,roundingBase:()=>Ar,upgradeToCacheNameEL:()=>Or});var Xr=at(ct()),zt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new he(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},he=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},B;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(B||(B={}));var sr=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===B.CLASS_TO_CLASS||i===B.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===B.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===B.CLASS_TO_CLASS||r===B.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===B.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===B.CLASS_TO_CLASS||r===B.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===B.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(h){return h.propertyName!==void 0}));for(var o=[],l=0,c=this.getAncestors(r);l0&&(l=l.filter(function(h){return!a.includes(h)})),this.options.version!==void 0&&(l=l.filter(function(h){var f=rt.findExposeMetadata(e,h);return!f||!f.options?!0:n.checkVersion(f.options.since,f.options.until)})),this.options.groups&&this.options.groups.length?l=l.filter(function(h){var f=rt.findExposeMetadata(e,h);return!f||!f.options?!0:n.checkGroups(f.options.groups)}):l=l.filter(function(h){var f=rt.findExposeMetadata(e,h);return!f||!f.options||!f.options.groups||!f.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(l=l.filter(function(M){return n.options.excludePrefixes.every(function(h){return M.substr(0,h.length)!==h})})),l=l.filter(function(M,h,f){return f.indexOf(M)===h}),l},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(w="\u03C9");let b=t.log(u,8e3).toNumber();if(y.equals(0))return w;if(y.gt(0)&&y.lte(3)){let G=[];for(let Y=0;YNumber.MAX_SAFE_INTEGER)&&(w="\u03C9");let b=t.log(u,8e3).toNumber();if(y.equals(0))return w;if(y.gt(0)&&y.lte(2)){let G=[];for(let Y=0;Y118?e.elemental.beyondOg(N):e.elemental.config.element_lists[u-1][w]},beyondOg(u){let S=Math.floor(Math.log10(u)),y=["n","u","b","t","q","p","h","s","o","e"],w="";for(let N=S;N>=0;N--){let b=Math.floor(u/Math.pow(10,N))%10;w==""?w=y[b].toUpperCase():w+=y[b]}return w},abbreviationLength(u){return u==1?1:Math.pow(Math.floor(u/2)+1,2)*2},getAbbreviationAndValue(u){let S=u.log(118).toNumber(),y=Math.floor(S)+1,w=e.elemental.abbreviationLength(y),N=S-y+1,b=Math.floor(N*w),k=e.elemental.getAbbreviation(y,N),P=new t(118).pow(y+b/w-1);return[k,P]},formatElementalPart(u,S){return S.eq(1)?u:`${S.toString()} ${u}`},format(u,S=2){if(u.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(u.log10(),S);let y=u.log(118),N=y.log(118).log(118).toNumber(),b=Math.max(4-N*2,1),k=[];for(;y.gte(1)&&k.length=b)return k.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ");let P=new t(118).pow(y).toFixed(k.length===1?3:S);return k.length===0?P:k.length===1?`${P} \xD7 ${e.elemental.formatElementalPart(k[0][0],k[0][1])}`:`${P} \xD7 (${k.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ")})`}},old_sc:{format(u,S){u=new t(u);let y=u.log10().floor();if(y.lt(9))return y.lt(3)?u.toFixed(S):u.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(u.gte("eeee10")){let N=u.slog();return(N.gte(1e9)?"":t.dTen.pow(N.sub(N.floor())).toFixed(4))+"F"+e.old_sc.format(N.floor(),0)}let w=u.div(t.dTen.pow(y));return(y.log10().gte(9)?"":w.toFixed(4))+"e"+e.old_sc.format(y,0)}}},eng:{format(u,S=2){u=new t(u);let y=u.log10().floor();if(y.lt(9))return y.lt(3)?u.toFixed(S):u.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(u.gte("eeee10")){let N=u.slog();return(N.gte(1e9)?"":t.dTen.pow(N.sub(N.floor())).toFixed(4))+"F"+e.eng.format(N.floor(),0)}let w=u.div(new t(1e3).pow(y.div(3).floor()));return(y.log10().gte(9)?"":w.toFixed(new t(4).sub(y.sub(y.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(y.div(3).floor().mul(3),0)}}},mixed_sc:{format(u,S,y=9){u=new t(u);let w=u.log10().floor();return w.lt(303)&&w.gte(y)?d(u,S,y,"st"):d(u,S,y,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(u,S=2,y){u=new t(u);let w=u.max(1).log10().max(1).log(r.log10()).floor();if(w.lte(0))return d(u,S,y,"sc");u=t.dTen.pow(u.max(1).log10().div(r.log10().pow(w)).sub(w.gte(1)?1:0));let N=w.div(10).floor(),b=w.toNumber()%10-1;return d(u,Math.max(4,S),y,"sc")+" "+(N.gte(1)?"meta"+(N.gte(2)?"^"+d(N,0,y,"sc"):"")+"-":"")+(isNaN(b)?"nanity":e.layer.layers[b])}},standard:{tier1(u){return mt[0][0][u%10]+mt[0][1][Math.floor(u/10)%10]+mt[0][2][Math.floor(u/100)]},tier2(u){let S=u%10,y=Math.floor(u/10)%10,w=Math.floor(u/100)%10,N="";return u<10?mt[1][0][u]:(y==1&&S==0?N+="Vec":N+=mt[1][1][S]+mt[1][2][y],N+=mt[1][3][w],N)}},inf:{format(u,S,y){u=new t(u);let w=0,N=new t(Number.MAX_VALUE),b=["","\u221E","\u03A9","\u03A8","\u028A"],k=["","","m","mm","mmm"];for(;u.gte(N);)u=u.log(N),w++;return w==0?d(u,S,y,"sc"):u.gte(3)?k[w]+b[w]+"\u03C9^"+d(u.sub(1),S,y,"sc"):u.gte(2)?k[w]+"\u03C9"+b[w]+"-"+d(N.pow(u.sub(2)),S,y,"sc"):k[w]+b[w]+"-"+d(N.pow(u.sub(1)),S,y,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(u,S=new t(1e15),y=!1,w=9){if(u=new t(u),S=new t(S).div(1e3),u.lt(S.mul(1e3)))return"";let{alphabet:N}=e.alphabet.config,b=N.length,k=u.log(1e3).sub(S.log(1e3)).floor(),P=k.add(1).log(b+1).ceil(),G="",Y=(X,st)=>{let H=X,Z="";for(let W=0;W=b)return"\u03C9";Z=N[Nt]+Z,H=H.sub(1).div(b).floor()}return Z};if(P.lt(w))G=Y(k,P);else{let X=P.sub(w).add(1),st=k.div(t.pow(b+1,X.sub(1))).floor();G=`${Y(st,new t(w))}(${X.gt("1e9")?X.format():X.format(0)})`}return G},format(u,S=2,y=9,w="mixed_sc",N=new t(1e15),b=!1,k){if(u=new t(u),N=new t(N).div(1e3),u.lt(N.mul(1e3)))return d(u,S,y,w);let P=e.alphabet.getAbbreviation(u,N,b,k),G=u.div(t.pow(1e3,u.log(1e3).floor()));return`${P.length>(k??9)+2?"":G.toFixed(S)+" "}${P}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(u){return u.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function l(u){return u.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function c(u,S=2,y=9,w="st"){return d(u,S,y,w)}function d(u,S=2,y=9,w="mixed_sc"){u=new t(u);let N=u.lt(0)?"-":"";if(u.mag==1/0)return N+"Infinity";if(Number.isNaN(u.mag))return N+"NaN";if(u.lt(0)&&(u=u.mul(-1)),u.eq(0))return u.toFixed(S);let b=u.log10().floor();switch(w){case"sc":case"scientific":if(u.log10().lt(Math.min(-S,0))&&S>1){let k=u.log10().ceil(),P=u.div(k.eq(-1)?new t(.1):t.dTen.pow(k)),G=k.mul(-1).max(1).log10().gte(9);return N+(G?"":P.toFixed(2))+"e"+d(k,0,y,"mixed_sc")}else if(b.lt(y)){let k=Math.max(Math.min(S-b.toNumber(),S),0);return N+(k>0?u.toFixed(k):u.toFixed(k).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(u.gte("eeee10")){let G=u.slog();return(G.gte(1e9)?"":t.dTen.pow(G.sub(G.floor())).toFixed(2))+"F"+d(G.floor(),0)}let k=u.div(t.dTen.pow(b)),P=b.log10().gte(9);return N+(P?"":k.toFixed(2))+"e"+d(b,0,y,"mixed_sc")}case"st":case"standard":{let k=u.log(1e3).floor();if(k.lt(1))return N+u.toFixed(Math.max(Math.min(S-b.toNumber(),S),0));let P=k.mul(3),G=k.log10().floor();if(G.gte(3e3))return"e"+d(b,S,y,"st");let Y="";if(k.lt(4))Y=["","K","M","B"][Math.round(k.toNumber())];else{let H=Math.floor(k.log(1e3).toNumber());for(H<100&&(H=Math.max(H-1,0)),k=k.sub(1).div(t.dTen.pow(H*3));k.gt(0);){let Z=k.div(1e3).floor(),W=k.sub(Z.mul(1e3)).floor().toNumber();W>0&&(W==1&&!H&&(Y="U"),H&&(Y=e.standard.tier2(H)+(Y?"-"+Y:"")),W>1&&(Y=e.standard.tier1(W)+Y)),k=Z,H++}}let X=u.div(t.dTen.pow(P)),st=S===2?t.dTwo.sub(b.sub(P)).add(1).toNumber():S;return N+(G.gte(10)?"":X.toFixed(st)+" ")+Y}default:return e[w]||console.error('Invalid format type "',w,'"'),N+e[w].format(u,S,y)}}function a(u,S,y="mixed_sc",w,N){u=new t(u),S=new t(S);let b=u.add(S),k,P=b.div(u);return P.gte(10)&&u.gte(1e100)?(P=P.log10().mul(20),k="(+"+d(P,w,N,y)+" OoMs/sec)"):k="(+"+d(S,w,N,y)+"/sec)",k}function M(u,S=2,y="s"){return u=new t(u),u.gte(86400)?d(u.div(86400).floor(),0,12,"sc")+":"+M(u.mod(86400),S,"d"):u.gte(3600)||y=="d"?(u.div(3600).gte(10)||y!="d"?"":"0")+d(u.div(3600).floor(),0,12,"sc")+":"+M(u.mod(3600),S,"h"):u.gte(60)||y=="h"?(u.div(60).gte(10)||y!="h"?"":"0")+d(u.div(60).floor(),0,12,"sc")+":"+M(u.mod(60),S,"m"):(u.gte(10)||y!="m"?"":"0")+d(u,S,12,"sc")}function h(u,S=!1,y=0,w=9,N="mixed_sc"){let b=Gt=>d(Gt,y,w,N);u=new t(u);let k=u.mul(1e3).mod(1e3).floor(),P=u.mod(60).floor(),G=u.div(60).mod(60).floor(),Y=u.div(3600).mod(24).floor(),X=u.div(86400).mod(365.2425).floor(),st=u.div(31556952).floor(),H=st.eq(1)?" year":" years",Z=X.eq(1)?" day":" days",W=Y.eq(1)?" hour":" hours",Nt=G.eq(1)?" minute":" minutes",Rt=P.eq(1)?" second":" seconds",Ut=k.eq(1)?" millisecond":" milliseconds";return`${st.gt(0)?b(st)+H+", ":""}${X.gt(0)?b(X)+Z+", ":""}${Y.gt(0)?b(Y)+W+", ":""}${G.gt(0)?b(G)+Nt+", ":""}${P.gt(0)?b(P)+Rt+",":""}${S&&k.gt(0)?" "+b(k)+Ut:""}`.replace(/,([^,]*)$/,"$1").trim()}function f(u){return u=new t(u),d(t.dOne.sub(u).mul(100))+"%"}function m(u){return u=new t(u),d(u.mul(100))+"%"}function p(u,S=2){return u=new t(u),u.gte(1)?"\xD7"+u.format(S):"/"+u.pow(-1).format(S)}function g(u,S,y=10){return t.gte(u,10)?t.pow(y,t.log(u,y).pow(S)):new t(u)}function C(u,S=0){u=new t(u);let y=(k=>k.map((P,G)=>({name:P.name,altName:P.altName,value:t.pow(1e3,new t(G).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),w="",N=u.lte(0)?0:t.min(t.log(u,1e3).sub(1),y.length-1).floor().toNumber(),b=y[N];if(N===0)switch(S){case 1:w="";break;case 2:case 0:default:w=u.format();break}switch(S){case 1:w=b.name;break;case 2:w=u.divide(b.value).format();break;case 3:w=b.altName;break;case 0:default:w=`${u.divide(b.value).format()} ${b.name}`;break}return w}function E(u,S=!1){return`${C(u,2)} ${C(u,1)}eV${S?"/c^2":""}`}let T={...e,toSubscript:o,toSuperscript:l,formatST:c,format:d,formatGain:a,formatTime:M,formatTimeLong:h,formatReduction:f,formatPercent:m,formatMult:p,expMult:g,metric:C,ev:E};return{FORMATS:e,formats:T}}var Yt=17,tt=9e15,mr=Math.log10(9e15),yt=1/9e15,dr=308,gr=-324,ge=5,pr=1023,Nr=!0,yr=!1,br=function(){let t=[];for(let r=gr+1;r<=dr;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),bt=[2,Math.E,3,4,5,6,7,8,9,10],vr=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],wr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],I=function(e){return s.fromValue_noAlloc(e)},q=function(t,e,r){return s.fromComponents(t,e,r)},O=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},dt=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},Vt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Mr=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r-1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r-1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r-691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r-3617/(122400*n),Math.exp(r)/e},_r=.36787944117144233,pe=.5671432904097838,Ht=function(t,e=1e-10,r=!0){let i,n;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return pe;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(n-i).5?1:-1;if(Math.random()*20<1)return O(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),q(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),l=o.pow(2);return o.neg().add(l.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=tt)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);Nr?t=t.replace(",",""):yr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let g=parseFloat(n[0]),C=parseFloat(n[1]),E=n[1].split(";"),T=1;if(E.length===2&&(T=parseFloat(E[1]),isFinite(T)||(T=1)),isFinite(g)&&isFinite(C)){let u=s.pentate(g,C,T,e);return this.sign=u.sign,this.layer=u.layer,this.mag=u.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let g=parseFloat(o[0]),C=parseFloat(o[1]),E=o[1].split(";"),T=1;if(E.length===2&&(T=parseFloat(E[1]),isFinite(T)||(T=1)),isFinite(g)&&isFinite(C)){let u=s.tetrate(g,C,T,e);return this.sign=u.sign,this.layer=u.layer,this.mag=u.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let l=t.split("^");if(l.length===2){let g=parseFloat(l[0]),C=parseFloat(l[1]);if(isFinite(g)&&isFinite(C)){let E=s.pow(g,C);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let c,d,a=t.split("pt");if(a.length===2){c=10;let g=!1;a[0].startsWith("-")&&(g=!0,a[0]=a[0].slice(1)),d=parseFloat(a[0]),a[1]=a[1].replace("(",""),a[1]=a[1].replace(")","");let C=parseFloat(a[1]);if(isFinite(C)||(C=1),isFinite(c)&&isFinite(d)){let E=s.tetrate(c,d,C,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),g&&(this.sign*=-1),this}}if(a=t.split("p"),a.length===2){c=10;let g=!1;a[0].startsWith("-")&&(g=!0,a[0]=a[0].slice(1)),d=parseFloat(a[0]),a[1]=a[1].replace("(",""),a[1]=a[1].replace(")","");let C=parseFloat(a[1]);if(isFinite(C)||(C=1),isFinite(c)&&isFinite(d)){let E=s.tetrate(c,d,C,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),g&&(this.sign*=-1),this}}if(a=t.split("f"),a.length===2){c=10;let g=!1;a[0].startsWith("-")&&(g=!0,a[0]=a[0].slice(1)),a[0]=a[0].replace("(",""),a[0]=a[0].replace(")","");let C=parseFloat(a[0]);if(a[1]=a[1].replace("(",""),a[1]=a[1].replace(")",""),d=parseFloat(a[1]),isFinite(C)||(C=1),isFinite(c)&&isFinite(d)){let E=s.tetrate(c,d,C,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),g&&(this.sign*=-1),this}}let M=t.split("e"),h=M.length-1;if(h===0){let g=parseFloat(t);if(isFinite(g))return this.fromNumber(g),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(h===1){let g=parseFloat(t);if(isFinite(g)&&g!==0)return this.fromNumber(g),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let f=t.split("e^");if(f.length===2){this.sign=1,f[0].startsWith("-")&&(this.sign=-1);let g="";for(let C=0;C=43&&E<=57||E===101)g+=f[1].charAt(C);else{if(this.layer=parseFloat(g),this.mag=parseFloat(f[1].substr(C+1)),this.layer<0||this.layer%1!=0){let T=s.tetrate(10,this.layer,this.mag,e);this.sign=T.sign,this.layer=T.layer,this.mag=T.mag}return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}}if(h<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let m=parseFloat(M[0]);if(m===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let p=parseFloat(M[M.length-1]);if(h>=2){let g=parseFloat(M[M.length-2]);isFinite(g)&&(p*=Math.sign(g),p+=Vt(g))}if(!isFinite(m))this.sign=M[0]==="-"?-1:1,this.layer=h,this.mag=p;else if(h===1)this.sign=Math.sign(m),this.layer=1,this.mag=p+Math.log10(Math.abs(m));else if(this.sign=Math.sign(m),this.layer=h,h===2){let g=s.mul(q(1,2,p),I(m));return this.sign=g.sign,this.layer=g.layer,this.mag=g.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=p;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:dt(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:dt(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ge?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):dt(this.m,t)+"e"+dt(this.e,t):this.layer===1?dt(this.m,t)+"e"+dt(this.e,t):this.layer<=ge?(this.sign===-1?"-":"")+"e".repeat(this.layer)+dt(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+dt(this.mag,t)}abs(){return O(this.sign===0?0:1,this.layer,this.mag)}neg(){return O(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?O(0,0,0):this.layer===0?q(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?O(-1,0,1):O(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?q(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?O(1,0,1):O(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?q(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?O(0,0,0):this.layer===0?q(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=I(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return O(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return O(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Yt)return r;{let l=Math.pow(10,Math.log10(r.mag)-i.mag),c=i.sign+r.sign*l;return q(Math.sign(c),1,i.mag+Math.log10(Math.abs(c)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>Yt)return r;{let l=Math.pow(10,r.mag-Math.log10(i.mag)),c=i.sign+r.sign*l;return q(Math.sign(c),1,Math.log10(i.mag)+Math.log10(Math.abs(c)))}}if(Math.abs(r.mag-i.mag)>Yt)return r;{let l=Math.pow(10,r.mag-i.mag),c=i.sign+r.sign*l;return q(Math.sign(c),1,i.mag+Math.log10(Math.abs(c)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(I(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=I(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return O(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return O(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return O(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return O(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return q(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return q(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return q(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=q(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(q(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return q(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=q(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(q(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return q(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=I(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?O(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?O(0,0,0):this.layer===0?q(this.sign,0,1/this.mag):q(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t,e=!1){let r=I(t),i=r.abs();if(this.eq(s.dZero)||i.eq(s.dZero))return O(0,0,0);if(e){let l=this.abs().mod(i);return this.sign==-1!=(r.sign==-1)&&(l=r.abs().sub(l)),l.mul(r.sign)}let n=this.toNumber(),o=i.toNumber();return isFinite(n)&&isFinite(o)&&n!=0&&o!=0?new s(n%o):this.sub(i).eq(this)?O(0,0,0):i.sub(this).eq(i)?new s(this):this.sign==-1?this.abs().mod(i).neg():this.sub(this.div(i).floor().mul(i))}modulo(t,e=!1){return this.mod(t,e)}modular(t,e=!1){return this.mod(t,e)}cmp(t){let e=I(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=I(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=I(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=Vt(n)),this.layer0?q(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):q(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?O(Number.NaN,Number.NaN,Number.NaN):this.layer>0?q(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):q(this.sign,0,Math.log10(this.mag))}log(t){return t=I(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?O(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?q(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?O(Number.NaN,Number.NaN,Number.NaN):this.layer===0?q(this.sign,0,Math.log2(this.mag)):this.layer===1?q(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?q(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):q(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?O(Number.NaN,Number.NaN,Number.NaN):this.layer===0?q(this.sign,0,Math.log(this.mag)):this.layer===1?q(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?q(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):q(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=I(t),r=new s(this),i=new s(e);if(r.sign===0)return i.eq(0)?O(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return O(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:O(Number.NaN,Number.NaN,Number.NaN):n}pow10(){if(this.eq(s.dInf))return O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return O(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return O(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return q(1,0,e);if(t.sign===0)return O(1,0,1);t=O(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?q(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?q(-t.sign,t.layer+1,-t.mag):O(1,0,1)}pow_base(t){return I(t).pow(this)}root(t){let e=I(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(O(1,0,24)))return s.fromNumber(Mr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,l=e+o;if(l===e||(e=l,i=i*r,n=360*i,o=1/n,l=e-o,l===e))return s.exp(e);e=l,i=i*r,n=1260*i;let c=1/n;return e=e+c,i=i*r,n=1680*i,c=1/n,e=e-c,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?O(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?q(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?q(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):q(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return q(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(O(this.sign,this.layer-1,this.mag),O(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=O(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return O(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let l=s.ln(this).neg(),c=l.lambertw().div(l);if(o<1)return c;let d=l.lambertw(!1).div(l);return o>1.444667861009099&&(c=d=s.fromNumber(Math.E)),e=I(e),e.eq(d)?d:e.lt(d)?c:O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):O(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let l=0;l1e4&&Math.ceil(i)%2==1?this.pow(e):e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return O(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=O(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=I(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let l=Math.min(e,i.layer-t.layer-3);e-=l,i.layer-=l}for(let l=0;l1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,l=this.slog_internal(t,r).toNumber();for(let c=1;c1&&o!=a&&(n=!0),o=a,n?i/=2:i*=2,i=Math.abs(i)*(a?-1:1),l+=i,i===0)break}return s.fromNumber(l)}slog_internal(t=10,e=!1){if(t=I(t),t.lte(s.dZero)||t.eq(s.dOne))return O(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?O(0,0,0):this.eq(s.dZero)?O(-1,0,1):O(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return O(-1,0,1);if(t.lt(1.444667861009766)){let n=s.ln(t).neg(),o=n.lambertw().div(n);if(this.eq(o))return O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return O(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,wr)}static tetrate_critical(t,e){return s.critical_section(t,e,vr)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let c=0;ct){let d=(t-bt[c])/(bt[c+1]-bt[c]);n=r[c][Math.floor(e)]*(1-d)+r[c+1][Math.floor(e)]*d,o=r[c][Math.ceil(e)]*(1-d)+r[c+1][Math.ceil(e)]*d;break}let l=e-Math.floor(e);return n<=0||o<=0?n*(1-l)+o*l:Math.pow(t,Math.log(n)/Math.log(t)*(1-l)+Math.log(o)/Math.log(t)*l)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=I(e);if(i.gt(1)&&i.lte(1.444667861009766)){let l=s.excess_slog(this,e,r),c=l[0].toNumber(),d=l[1],a=c+t,M=s.ln(e).neg(),h=M.lambertw().div(M),f=M.lambertw(!1).div(M),m=s.dOne;d==1?m=h.mul(f).sqrt():d==2&&(m=f.mul(2));let p=i.pow(m),g=Math.floor(a),C=a-g,E=m.pow(1-C).mul(p.pow(C));return s.tetrate(i,g,E,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?s.tetrate(e,o,s.dOne,r):Number.isFinite(o)?o>=-1?s.log(s.tetrate(e,o+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,o+2,s.dOne,r),e),e):O(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=I(t),e=I(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[O(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let n=s.ln(e).neg(),o=n.lambertw().div(n),l=s.dInf;if(e>1&&(l=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=l=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(l))return[O(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(l)){let c=l.mul(2),d=i.pow(c),a=0;if(t.gte(c)&&t.lt(d))a=0;else if(t.gte(d)){let g=d;for(a=1;g.lt(t);)if(g=i.pow(g),a=a+1,g.layer>3){let C=Math.floor(t.layer-g.layer+1);g=i.iteratedexp(C,g,r),a=a+C}g.gt(t)&&(g=g.log(e),a=a-1)}else if(t.lt(c)){let g=c;for(a=0;g.gt(t);)g=g.log(e),a=a-1}let M=0,h=0,f=.5,m=c,p=s.dZero;for(;f>1e-16;){if(h=M+f,m=c.pow(1-h).mul(d.pow(h)),p=s.iteratedexp(e,a,m),p.eq(t))return[new s(a+h),2];p.lt(t)&&(M+=f),f/=2}return p.neq_tolerance(t,1e-7)?[O(Number.NaN,Number.NaN,Number.NaN),0]:[new s(a+M),2]}if(t.lt(l)&&t.gt(o)){let c=o.mul(l).sqrt(),d=i.pow(c),a=0;if(t.lte(c)&&t.gt(d))a=0;else if(t.lte(d)){let g=d;for(a=1;g.gt(t);)g=i.pow(g),a=a+1;g.lt(t)&&(g=g.log(e),a=a-1)}else if(t.gt(c)){let g=c;for(a=0;g.lt(t);)g=g.log(e),a=a-1}let M=0,h=0,f=.5,m=c,p=s.dZero;for(;f>1e-16;){if(h=M+f,m=c.pow(1-h).mul(d.pow(h)),p=s.iteratedexp(e,a,m),p.eq(t))return[new s(a+h),1];p.gt(t)&&(M+=f),f/=2}return p.neq_tolerance(t,1e-7)?[O(Number.NaN,Number.NaN,Number.NaN),0]:[new s(a+M),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?O(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new s(this):this.mag<0?s.fromNumber(Ht(this.toNumber())):this.layer===0?s.fromNumber(Ht(this.sign*this.mag)):this.lt("eee15")?Ne(this):this.ln():this.sign===1?O(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(Ht(this.sign*this.mag,1e-10,!1)):this.layer==1?Ne(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return O(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return O(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return e_r?this.pow(this.recip()):O(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return O(1,0,1);if(this.lt(0))return O(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):O(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,l=n.div(2),c=!0;for(;c;)l=r.add(n).div(2),s.iteratedexp(10,i,l,!0).tetrate(t,1,!0).gt(this)?n=l:r=l,l.eq(o)?c=!1:o=l;return s.iteratedexp(10,i,l,!0)}else{let e=1,r=q(1,10,1),i=q(1,10,1),n=q(1,10,1),o=q(1,1,-16),l=s.dZero,c=q(1,10,1),d=o.pow10().recip(),a=s.dZero,M=d,h=d,f=Math.ceil(t)%2==0,m=0,p=q(1,10,1),g=!1,C=s.dZero,E=!1;for(;e<4;){if(e==2){if(f)break;n=q(1,10,1),o=r,e=3,c=q(1,10,1),p=q(1,10,1)}for(g=!1;o.neq(n);){if(C=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))d=o.pow10().recip(),M=o.pow10().recip(),h=o.pow10().recip(),a=s.dZero,m=-1,e==3&&(p=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!f&&o.pow10().recip().lt(.4))d=o.pow10().recip(),M=o.pow10().recip(),h=o.pow10().recip(),a=s.dZero,m=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))d=o.pow10().recip(),M=s.dZero,h=d.mul(2),a=d,f?m=-1:m=0;else{for(l=o.mul(12e-17),d=o.pow10().recip(),M=o.add(l).pow10().recip(),a=d.sub(M),h=d.add(a);M.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||h.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||M.gte(d)||h.lte(d);)l=l.mul(2),M=o.add(l).pow10().recip(),a=d.sub(M),h=d.add(a);if((e==1&&h.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))&&M.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))||e==3&&h.tetrate(t,1,!0).lt(d.tetrate(t,1,!0))&&M.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))&&(p=o),h.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))m=-1;else if(f)m=1;else if(e==3&&o.gt_tolerance(r,1e-8))m=0;else{for(;M.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||h.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||M.gte(d)||h.lte(d);)l=l.mul(2),M=o.add(l).pow10().recip(),a=d.sub(M),h=d.add(a);h.tetrate(t,1,!0).sub(d.tetrate(t,1,!0)).lt(d.tetrate(t,1,!0).sub(M.tetrate(t,1,!0)))?m=0:m=1}}if(m==-1&&(E=!0),e==1&&m==1||e==3&&m!=0)if(n.eq(q(1,10,1)))o=o.mul(2);else{let y=!1;if(g&&(m==1&&e==1||m==-1&&e==3)&&(y=!0),o=o.add(n).div(2),y)break}else if(n.eq(q(1,10,1)))n=o,o=o.div(2);else{let y=!1;if(g&&(m==1&&e==1||m==-1&&e==3)&&(y=!0),n=n.sub(c),o=o.sub(c),y)break}if(n.sub(o).div(2).abs().gt(c.mul(1.5))&&(g=!0),c=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(C))break}if(o.gt("1e18")||!E||p==q(1,10,1))break;e==1?r=p:e==3&&(i=p),e++}n=r,o=q(1,1,-18);let T=o,u=s.dZero,S=!0;for(;S;)if(n.eq(q(1,10,1))?u=o.mul(2):u=n.add(o).div(2),s.pow(10,u).recip().tetrate(t,1,!0).gt(this)?o=u:n=u,u.eq(T)?S=!1:T=u,o.gt("1e18"))return O(Number.NaN,Number.NaN,Number.NaN);if(u.eq_tolerance(r,1e-15)){if(i.eq(q(1,10,1)))return O(Number.NaN,Number.NaN,Number.NaN);for(n=q(1,10,1),o=i,T=o,u=s.dZero,S=!0;S;)if(n.eq(q(1,10,1))?u=o.mul(2):u=n.add(o).div(2),s.pow(10,u).recip().tetrate(t,1,!0).gt(this)?o=u:n=u,u.eq(T)?S=!1:T=u,o.gt("1e18"))return O(Number.NaN,Number.NaN,Number.NaN);return u.pow10().recip()}else return u.pow10().recip()}}static increasingInverse(t,e=!1,r=120,i=s.dLayerMax.neg(),n=s.dLayerMax,o=s.dLayerMax.neg(),l=s.dLayerMax){return function(c){if(c=new s(c),i=new s(i),n=new s(n),o=new s(o),l=new s(l),c.isNan()||n.lt(i)||c.lt(o)||c.gt(l))return O(Number.NaN,Number.NaN,Number.NaN);let d=function(w){return new s(w)},a=!0;if(n.lt(0))a=!1;else if(i.gt(0))a=!0;else{let w=t(s.dZero);if(w.eq(c))return O(0,0,0);a=c.gt(w),e&&(a=!a)}let M=a,h;if(a){if(n.lt(yt))a=!0;else if(i.gt(yt))a=!1;else{let w=t(new s(yt));a=c.lt(w),e&&(a=!a)}if(a){h=!0;let w=s.pow(10,tt).recip();if(n.lt(w))a=!1;else if(i.gt(w))a=!0;else{let N=t(new s(w));a=c.gt(N),e&&(a=!a)}if(a)d=function(N){return s.pow(10,N).recip()};else{let N=s.tetrate(10,tt);if(n.lt(N))a=!1;else if(i.gt(N))a=!0;else{let b=t(new s(N));a=c.gt(b),e&&(a=!a)}a?d=function(b){return s.tetrate(10,new s(b).toNumber()).recip()}:d=function(b){return new s(b).gt(Math.log10(Number.MAX_VALUE))?s.dZero:s.tetrate(10,s.pow(10,b).toNumber()).recip()}}}else{if(h=!1,n.lt(tt))a=!0;else if(i.gt(tt))a=!1;else{let w=t(new s(tt));a=c.lt(w),e&&(a=!a)}if(a)d=function(w){return new s(w)};else{let w=s.pow(10,tt);if(n.lt(w))a=!0;else if(i.gt(w))a=!1;else{let N=t(new s(w));a=c.lt(N),e&&(a=!a)}if(a)d=function(N){return s.pow(10,N)};else{let N=s.tetrate(10,tt);if(n.lt(N))a=!0;else if(i.gt(N))a=!1;else{let b=t(new s(N));a=c.lt(b),e&&(a=!a)}a?d=function(b){return s.tetrate(10,new s(b).toNumber())}:d=function(b){return new s(b).gt(Math.log10(Number.MAX_VALUE))?s.dInf:s.tetrate(10,s.pow(10,b).toNumber())}}}}}else{if(h=!0,n.lt(-yt))a=!1;else if(i.gt(-yt))a=!0;else{let w=t(new s(-yt));a=c.gt(w),e&&(a=!a)}if(a){let w=s.pow(10,tt).recip().neg();if(n.lt(w))a=!0;else if(i.gt(w))a=!1;else{let N=t(new s(w));a=c.lt(N),e&&(a=!a)}if(a)d=function(N){return s.pow(10,N).recip().neg()};else{let N=s.tetrate(10,tt).neg();if(n.lt(N))a=!0;else if(i.gt(N))a=!1;else{let b=t(new s(N));a=c.lt(b),e&&(a=!a)}a?d=function(b){return s.tetrate(10,new s(b).toNumber()).recip().neg()}:d=function(b){return new s(b).gt(Math.log10(Number.MAX_VALUE))?s.dZero:s.tetrate(10,s.pow(10,b).toNumber()).recip().neg()}}}else{if(h=!1,n.lt(-tt))a=!1;else if(i.gt(-tt))a=!0;else{let w=t(new s(-tt));a=c.gt(w),e&&(a=!a)}if(a)d=function(w){return s.neg(w)};else{let w=s.pow(10,tt).neg();if(n.lt(w))a=!1;else if(i.gt(w))a=!0;else{let N=t(new s(w));a=c.gt(N),e&&(a=!a)}if(a)d=function(N){return s.pow(10,N).neg()};else{let N=s.tetrate(10,tt).neg();if(n.lt(N))a=!1;else if(i.gt(N))a=!0;else{let b=t(new s(N));a=c.gt(b),e&&(a=!a)}a?d=function(b){return s.tetrate(10,new s(b).toNumber()).neg()}:d=function(b){return new s(b).gt(Math.log10(Number.MAX_VALUE))?s.dNegInf:s.tetrate(10,s.pow(10,b).toNumber()).neg()}}}}}let f=M!=h!=e,m=f?function(w,N){return s.gt(w,N)}:function(w,N){return s.lt(w,N)},p=.001,g=!1,C=!1,E=1,T=s.dOne,u=0,S=!1;for(var y=1;y1&&C!=N&&(g=!0),C=N,g?p/=2:p*=2,N!=f&&T.eq(n)||N==f&&T.eq(i))return O(Number.NaN,Number.NaN,Number.NaN);if(p=Math.abs(p)*(N?-1:1),E+=p,p===0||u==E)break}return d(E)}}pentate(t=2,e=O(1,0,1),r=!1){e=new s(e);let i=t;t=Math.floor(t);let n=i-t,o=s.dZero,l=s.dZero;if(n!==0)if(e.eq(s.dOne))++t,e=s.fromNumber(n);else return this.pentate(e.penta_log(this,void 0,r).plus(i).toNumber(),1,r);if(t>0)for(let c=0;c1e4)return e}else for(let c=0;c<-t;++c){if(o=e,e=e.slog(this,void 0,r),e.eq(o)||!isFinite(e.layer)||!isFinite(e.mag))return e.normalize();if(c>100)return e}return e}penta_log(t=10,e=100,r=!1){if(t=new s(t),t.lte(1))return O(Number.NaN,Number.NaN,Number.NaN);if(this.eq(1))return O(0,0,0);if(this.eq(s.dInf))return O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);let i=new s(1),n=0,o=1;if(this.lt(-1)){if(this.lte(-2))return O(Number.NaN,Number.NaN,Number.NaN);let c=t.tetrate(this.toNumber(),1,r);if(this.eq(c))return O(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(c))return O(Number.NaN,Number.NaN,Number.NaN)}if(this.gt(1)){for(;i.lt(this);)if(n++,i=s.tetrate(t,i.toNumber(),1,r),n>1e3)return O(Number.NaN,Number.NaN,Number.NaN)}else for(;i.gt(this);)if(n--,i=s.slog(i,t,r),n>100)return O(Number.NaN,Number.NaN,Number.NaN);for(var l=1;l0&&t<1?this.root(t):this.eq(1)?O(1,0,1):this.lt(0)?O(Number.NaN,Number.NaN,Number.NaN):this.lt(1)?this.linear_sroot(t):s.increasingInverse(function(e){return s.pentate(e,t,1,!0)})(this):O(Number.NaN,Number.NaN,Number.NaN)}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):O(0,0,0)}cos(){return this.mag<0?O(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):O(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):O(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):O(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):O(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?O(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return gt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return gt.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return gt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return gt.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return gt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return gt.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let l=Math.floor(r/i[o]);r-=l*i[o],n+=o.repeat(l)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=O(0,0,0),s.dOne=O(1,0,1),s.dNegOne=O(-1,0,1),s.dTwo=O(1,0,2),s.dTen=O(1,0,10),s.dNaN=O(Number.NaN,Number.NaN,Number.NaN),s.dInf=O(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=O(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=q(1,0,Number.MAX_VALUE),s.dNumberMin=q(1,0,Number.MIN_VALUE),s.dLayerSafeMax=q(1,Number.MAX_SAFE_INTEGER,tt-1),s.dLayerSafeMin=q(1,Number.MAX_SAFE_INTEGER,-(tt-1)),s.dLayerMax=q(1,Number.MAX_VALUE,tt-1),s.dLayerMin=q(1,Number.MAX_VALUE,-(tt-1)),s.fromStringCache=new zt(pr),ot([Ft()],s.prototype,"sign",2),ot([Ft()],s.prototype,"mag",2),ot([Ft()],s.prototype,"layer",2),s=ot([fr()],s);var{formats:gt,FORMATS:Ir}=hr(s);s.formats=gt;var At=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},Wt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new s(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new At(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nh),a=n,M=this.getBoosts(o,!0);M[0][0]?this.boostArray[M[1][0]]=new At({id:o,name:l,description:c,value:d,order:a}):this.boostArray.push(new At({id:o,name:l,description:c,value:d,order:a}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let l=this.getBoosts(o.id,!0);l[0][0]?this.boostArray[l[1][0]]=new At(o):this.boostArray.push(new At(o))}}}clearBoosts(){this.boostArray.length=0}calculate(t=this.baseEffect){let e=new s(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},ti=at(ct()),xt=30,Jt=.001;function Sr(t,e,r="geometric"){switch(t=new s(t),e=new s(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return s.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function Qt(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new s(t),e=new s(e),r=new s(r);let n,o;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=n.lte(r)):(n=t.sub(e).abs(),o=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:o}),o}function Kt(t,e,r="geometric",i=xt,n=Jt,o=1,l){if(o=new s(o),l=new s(l??e),o.gt(l)&&([o,l]=[l,o]),t(l).eq(0))return{value:s.dZero,lowerBound:s.dZero,upperBound:s.dZero};if(t(l).lt(e))return console.warn("eMath.js: The function is not monotonically increasing. (f(n) < n)"),{value:l,lowerBound:l,upperBound:l};for(let d=0;d=0;c--){let d=r.add(l.mul(c)),a=r.add(l.mul(c+1)),M=o;if(o=o.add(t(d).add(t(a)).div(2).mul(l)),Qt(M,o,n,{verbose:!1,mode:"geometric"}))break}return o}function Xt(t,e,r=0,i,n){return r=new s(r),e=new s(e),e.sub(r).lte(xt)?ye(t,e,r,i):be(t,e,r,n)}function Ar(t,e=10,r=0,i=1e3){if(t=new s(t),e=new s(e),r=new s(r),i=new s(i),e.lt(1)||r.lt(1))return s.dNaN;let n=t.sign;if(t=t.abs(),t.gte(s.pow(e,i)))return t;let o=s.floor(s.log(t,e)),l=t.div(s.pow(e,o));return l=l.mul(s.pow(e,r)).round(),l=l.div(s.pow(e,r)),l=l.mul(s.pow(e,o)).mul(n),l}function ve(t,e,r,i=s.dInf,n,o,l=!1){t=new s(t),r=new s(r??e.level),i=new s(i);let c=i.sub(r);if(c.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",c),[s.dZero,s.dZero];if(l=(typeof e.el=="function"?e.el():e.el)??l,c.eq(1)){let h=e.cost(e.level),f=t.gte(h),m=[s.dZero,s.dZero];return l?(m[0]=f?s.dOne:s.dZero,m):(m=[f?s.dOne:s.dZero,f?h:s.dZero],m)}if(e.costBulk){let[h,f]=e.costBulk(t,e.level,c),m=t.gte(f);return[m?h:s.dZero,m&&!l?f:s.dZero]}if(l){let h=p=>e.cost(p.add(r)),f=s.min(i,Kt(h,t,n,o).value.floor()),m=s.dZero;return[f,m]}let d=Kt(h=>Xt(e.cost,h,r),t,n,o).value.floor().min(r.add(c).sub(1)),a=Xt(e.cost,d,r);return[d.sub(r).add(1).max(0),a]}function we(t){return t=new s(t),`${t.sign}/${t.mag}/${t.layer}`}function Or(t){return`el/${we(t)}`}var vt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new s(t.level):s.dOne}};ot([Ft()],vt.prototype,"id",2),ot([St(()=>s)],vt.prototype,"level",2);var Me=class Ve{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:s.dOne}}).data??{level:s.dOne}).level}set level(e){this.data.level=new s(e)}constructor(e,r,i,n){let o=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>o,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new zt(n??Ve.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??s.dOne}},ei=at(ct());function _e(t,e,r=s.dOne,i=s.dInf){if(t=new s(t),r=new s(r),i=new s(i),i.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",i),[s.dZero,s.dZero];if(i.eq(1)){let l=e.cost(r);return[t.gte(l)?s.dOne:s.dZero,t.gte(l)?l:s.dZero]}let n=t.div(e.cost(r)).floor().min(i),o=e.cost(r).mul(n);return[n,o]}var Ie=class{constructor(t,e,r){this.defaultAmount=s.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??s.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:s.dOne}}).data??{amount:s.dOne}).amount}set amount(t){this.data.amount=new s(t)}},wt=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??s.dZero}};ot([Ft()],wt.prototype,"id",2),ot([St(()=>s)],wt.prototype,"amount",2);var ri=at(ct()),pt=class{constructor(){this.value=s.dZero,this.upgrades={},this.items={}}};ot([St(()=>s)],pt.prototype,"value",2),ot([St(()=>vt)],pt.prototype,"upgrades",2),ot([St(()=>wt)],pt.prototype,"items",2);var Se=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new pt,e,r,i={defaultVal:s.dZero,defaultBoost:s.dOne}){this.defaultVal=i.defaultVal,this.defaultBoost=i.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Wt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e),this.items={},r&&this.addItem(r)}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let n of Object.values(this.upgrades))n.level=new s(n.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(n);if(i.resetItemAmounts)for(let n of Object.values(this.items))n.amount=new s(n.defaultAmount),i.runUpgradeEffect&&this.runItemEffect(n)}gain(t=1e3){let e=this.boost.calculate().mul(new s(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new vt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(o=>i.test(o)).map(o=>this.upgrades[o])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let n=new Me(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(n),this.upgrades[i.id]=n,r.push(n)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t.effect?.(t.level,t,this)}runItemEffect(t,e=s.dOne){e=new s(e),t.effect?.(t.amount,e,t,this)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`eMath.js: Upgrade "${t}" not found.`),[s.dZero,s.dZero]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=s.min(e,n.maxLevel)),ve(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),s.dZero;let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),!1;let[o,l]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(l),n.level=n.level.add(o),this.runUpgradeEffect(n),!0)}pointerAddItem(t){let e=new wt(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new Ie(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runItemEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e,r){let i=this.getItem(t);return i===null?(console.warn(`eMath.js: Item "${t}" not found.`),[s.dZero,s.dZero]):_e(this.value,i,e,r)}buyItem(t,e,r){let i=this.getItem(t);if(i===null)return console.warn(`eMath.js: Item "${t}" not found.`),!1;let[n,o]=this.calculateItem(t,e,r);return n.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(o),i.amount=i.amount.add(n),this.runItemEffect(i,e),!0)}},ii=at(ct()),qt=class{constructor(t=0){this.value=new s(t)}};ot([St(()=>s)],qt.prototype,"value",2);var Ae=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new s(r),t??=new qt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Wt(this.initial):null}update(){console.warn("eMath.js: AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},Dt=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=typeof r=="function"?r(this):{...r},this.gridSymbol=i}get grid(){return te.getInstance(this.gridSymbol)}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return te.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=this.grid;return(()=>{switch(t){case"up":return i.getCell(this.x,this.y-e);case"right":return i.getCell(this.x+e,this.y);case"down":return i.getCell(this.x,this.y+e);case"left":return i.getCell(this.x-e,this.y);case"adjacent":return i.getAdjacent(this.x,this.y,e,r);case"diagonal":return i.getDiagonal(this.x,this.y,e,r);case"encircling":return i.getEncircling(this.x,this.y,e,r);default:throw new Error("Invalid direction")}})()}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}};function Oe(t,e,r=!0){let i=r?"Size":"Coordinates";if(typeof t!="number"||typeof e!="number")throw new RangeError(`${i} must be numbers: ${t}, ${e}`);if(!Number.isInteger(t)||!Number.isInteger(e))throw new RangeError(`${i} must be integers: ${t}, ${e}`);if(t<0||e<0)throw new RangeError(`${i} must be positive: ${t}, ${e}`);if(!Number.isFinite(t)||!Number.isFinite(e))throw new RangeError(`${i} must be finite: ${t}, ${e}`);if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e))throw new RangeError(`${i} must be safe integers: ${t}, ${e}`)}var it=class oe extends Array{constructor(e){e=Array.isArray(e)?e:[e],e=e.filter(r=>r!==void 0),super(...e),this.removeDuplicates()}removeDuplicates(){let e=[];this.forEach((r,i)=>{this.indexOf(r)!==i&&e.push(i)}),e.forEach(r=>this.splice(r,1))}translate(e=0,r=0){return new oe(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new oe(this.flatMap(n=>n.direction(e,r,i)))}up(e){return this.direction("up",e)}right(e){return this.direction("right",e)}down(e){return this.direction("down",e)}left(e){return this.direction("left",e)}adjacent(e,r){return this.direction("adjacent",e,r)}diagonal(e,r){return this.direction("diagonal",e,r)}encircling(e,r){return this.direction("encircling",e,r)}},te=class ae{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),ae.instances[this.gridSymbol]=this,this.starterProps=i??{},this.xSize=e,this.ySize=r??e,Oe(this.xSize,this.ySize,!0);for(let n=0;n{if(this.ySize!==n&&(this.ySizen))for(let o=n;o{if(this.xSize!==i){if(this.xSizei)for(let o=0;o{let t=!1,e=r=>(t||(console.warn("eMath.js: The E function is deprecated. Use the Decimal class directly."),t=!0),new s(r));return Object.getOwnPropertyNames(s).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=s[r]}),e})(),Er=ce,Ce={};Bt(Ce,{ConfigManager:()=>jt,DataManager:()=>Pe,EventManager:()=>Fe,EventTypes:()=>Te,Game:()=>Pr,GameAttribute:()=>xe,GameCurrency:()=>Le,GameReset:()=>re,KeyManager:()=>Ee,gameDefaultConfig:()=>qe,keys:()=>Fr});var ni=at(ct()),jt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,i){for(let n in i)typeof r[n]>"u"?r[n]=i[n]:typeof r[n]=="object"&&typeof i[n]=="object"&&!Array.isArray(r[n])&&!Array.isArray(i[n])&&(r[n]=e(r[n],i[n]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Tr={autoAddInterval:!0,fps:30},Fr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),Ee=class He{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=He.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let i of this.tickers)i(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let i of this.binds)(typeof i.onDownContinuous<"u"||typeof i.fn<"u")&&this.isPressing(i.id)&&(i.onDownContinuous?.(r),i.fn?.(r))}),document.addEventListener("keydown",r=>{this.logKey(r,!0),this.onAll("down",r.key)}),document.addEventListener("keyup",r=>{this.logKey(r,!1),this.onAll("up",r.key)}),document.addEventListener("keypress",r=>{this.onAll("press",r.key)}))}static{this.configManager=new jt(Tr)}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{for(let r of this.tickers)r(1e3/e)},1e3/e))}logKey(e,r){let i=e.key;r&&!this.keysPressed.includes(i)?this.keysPressed.push(i):!r&&this.keysPressed.includes(i)&&this.keysPressed.splice(this.keysPressed.indexOf(i),1)}onAll(e,r){for(let i of this.binds)if(i.key===r)switch(e){case"down":i.onDown?.();break;case"press":default:i.onPress?.();break;case"up":i.onUp?.();break}}isPressing(e){for(let r of this.binds)if(r.id===e)return this.keysPressed.includes(r.key);return!1}getBind(e){return this.binds.find(r=>r.id===e)}addKey(e,r,i){e=typeof e=="string"?{id:e,name:e,key:r??"",fn:i}:e,e=Array.isArray(e)?e:[e];for(let n of e){n.id=n.id??n.name;let o=this.getBind(n.id);if(o){Object.assign(o,n);continue}this.binds.push(n)}}},Te=(t=>(t.interval="interval",t.timeout="timeout",t))(Te||{}),kr={autoAddInterval:!0,fps:30},Fe=class We{constructor(e,r){if(this.addEvent=this.setEvent.bind(this),this.config=We.configManager.parse(e),this.events={},this.callbackEvents={},r)for(let i of r)this.callbackEvents[i]=[];if(this.config.autoAddInterval){let i=this.config.fps??30;this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/i)}}static{this.configManager=new jt(kr)}on(e,r){this.callbackEvents[e]||(this.callbackEvents[e]=[]),this.callbackEvents[e].push({type:e,callback:r})}dispatch(e){if(this.callbackEvents[e])for(let r of this.callbackEvents[e])r.callback()}tickerFunction(){let e=Date.now();for(let r of Object.values(this.events))switch(r.type){case"interval":if(e-r.intervalLast>=r.delay){let i=e-r.intervalLast;r.callback(i),r.intervalLast=e}break;case"timeout":{let i=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callback(i),delete this.events[r.name])}break}}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/e))}timeWarp(e){for(let r of Object.values(this.events))switch(r.type){case"interval":r.intervalLast-=e;break;case"timeout":r.timeCreated-=e;break}}setEvent(e,r,i,n){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callback:n,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callback:n,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},si=at(ct()),ke=at(er()),ee=at(nr()),Pe=class{constructor(t,e){this.data={},this.static={},this.eventsOnLoad=[],this.gameRef=typeof t=="function"?t():t,this.localStorage=e??(typeof window>"u"?(console.warn("eMath.js: Local storage is not supported. Methods that rely on local storage will not work. You can use compileData() and decompileData() instead to implement a custom save system."),null):window.localStorage)}addEventOnLoad(t){this.eventsOnLoad.push(t)}setData(t,e){typeof this.data[t]>"u"&&this.normalData&&console.warn("eMath.js: After initializing data, you should not add new properties to data."),this.data[t]=e;let r=()=>this.data;return{get value(){return r()[t]},set value(i){r()[t]=i},setValue(i){r()[t]=i}}}getData(t){return this.data[t]}setStatic(t,e){return console.warn("eMath.js: setStatic: Static data is basically useless and should not be used. Use variables in local scope instead."),typeof this.static[t]>"u"&&this.normalData&&console.warn("eMath.js: After initializing data, you should not add new properties to staticData."),this.static[t]=e,this.static[t]}getStatic(t){return console.warn("eMath.js: Static data is basically useless and should not be used. Use variables in local scope instead."),this.static[t]}init(){this.normalData=this.data,this.normalDataPlain=$t(this.data)}compileDataRaw(t=this.data){this.gameRef.eventManager.dispatch("beforeCompileData");let e=$t(t),r=(0,ee.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="9.5.0"}catch{i="9.3.0"}return[{hash:r,game:{title:this.gameRef.config.name.title,id:this.gameRef.config.name.id,version:this.gameRef.config.name.version},emath:{version:i}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,ke.compressToBase64)(e)}decompileData(t){if(!t&&this.localStorage&&(t=this.localStorage.getItem(`${this.gameRef.config.name.id}-data`)),!t&&!this.localStorage)return console.warn("eMath.js: Local storage is not supported. Methods that rely on local storage will not work: decompileData() requires the data to be passed as an argument."),null;if(!t)return null;let e;try{return e=JSON.parse((0,ke.decompressFromBase64)(t)),e}catch(r){if(r instanceof SyntaxError)console.error(`Failed to decompile data (corrupted) "${t}":`,r);else throw r;return null}}validateData(t){let[e,r]=t;if(typeof e=="string")return(0,ee.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,ee.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return i===n}resetData(t=!1){if(!this.normalData)throw new Error("dataManager.resetData(): You must call init() before writing to data.");this.data=this.normalData,this.saveData(),t&&window.location.reload()}saveData(t=this.compileData()){if(this.gameRef.eventManager.dispatch("beforeSaveData"),!t)throw new Error("dataManager.saveData(): Data to save is empty.");if(!this.localStorage)throw new Error("dataManager.saveData(): Local storage is not supported. You can use compileData() instead to implement a custom save system.");this.localStorage.setItem(`${this.gameRef.config.name.id}-data`,t),this.gameRef.eventManager.dispatch("saveData")}exportData(){let t=this.compileData();if(prompt("Download save data?:",t)!=null){let e=new Blob([t],{type:"text/plain"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=`${this.gameRef.config.name.id}-data.txt`,r.textContent=`Download ${this.gameRef.config.name.id}-data.txt file`,document.body.appendChild(r),r.click(),document.body.removeChild(r)}}parseData(t=this.decompileData(),e=!0){if((!this.normalData||!this.normalDataPlain)&&e)throw new Error("dataManager.parseData(): You must call init() before writing to data.");if(!t)return null;let[,r]=t;function i(h){return typeof h=="object"&&h?.constructor===Object}let n=(h,f)=>Object.prototype.hasOwnProperty.call(h,f);function o(h,f,m){if(!h||!f||!m)return console.warn("eMath.js: dataManager.deepMerge(): Missing arguments:",h,f,m),m??{};let p=m;for(let g in h)if(n(h,g)&&!n(m,g)&&(p[g]=h[g]),f[g]instanceof pt){let C=h[g],E=m[g];if(Array.isArray(E.upgrades)){let T=E.upgrades;E.upgrades={};for(let u of T)E.upgrades[u.id]=u}E.upgrades={...C.upgrades,...E.upgrades},p[g]=E,E.items={...C.items,...E.items}}else i(h[g])&&i(m[g])&&(p[g]=o(h[g],f[g],m[g]));return p}let l=e?o(this.normalDataPlain,this.normalData,r):r,c=Object.getOwnPropertyNames(new vt({id:"",level:s.dZero})),d=Object.getOwnPropertyNames(new wt({id:"",amount:s.dZero}));function a(h,f){let m=Zt(h,f);if(m instanceof pt){for(let p in m.upgrades){let g=m.upgrades[p];if(!g||!c.every(C=>Object.getOwnPropertyNames(g).includes(C))){delete m.upgrades[p];continue}m.upgrades[p]=Zt(vt,g)}for(let p in m.items){let g=m.items[p];if(!g||!d.every(C=>Object.getOwnPropertyNames(g).includes(C))){delete m.items[p];continue}m.items[p]=Zt(wt,g)}}if(!m)throw new Error(`Failed to convert ${h.name} to class instance.`);return m}function M(h,f){if(!h||!f)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let m=f;for(let p in h){if(f[p]===void 0){console.warn(`eMath.js: Missing property "${p}" in loaded data.`);continue}if(!i(f[p]))continue;let g=h[p].constructor;if(g===Object){m[p]=M(h[p],f[p]);continue}m[p]=a(g,f[p])}return m}return l=M(this.normalData,l),l}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],$t(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return this.gameRef.eventManager.dispatch("loadData"),e}},Le=class extends Se{get data(){return this.pointer}get static(){return this}constructor(t,e,r){if(typeof t=="function")throw new Error("GameCurrency constructor does not accept a function as the first parameter. Use the .addCurrency method instead.");super(...t),this.game=e,this.name=r,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}},xe=class extends Ae{get data(){return this.pointer}get static(){return this}constructor(t,e){if(typeof t=="function")throw new Error("GameAttribute constructor does not accept a function as the first parameter. Use the .addAttribute method instead.");super(...t),this.game=e}},re=class Je{static fromObject(e){return new Je(e.currenciesToReset,e.extender,e.onReset,e.condition)}constructor(e,r,i,n){this.currenciesToReset=Array.isArray(e)?e:[e],r=r??[],this.extender=Array.isArray(r)?r:[r],this.onReset=i,this.condition=n,this.id=Symbol()}reset(e=!1,r=!0,i=new Set){if(e||(typeof this.condition=="function"?!this.condition(this):!this.condition)&&typeof this.condition<"u")return;let n=()=>{this.onReset?.(this),this.currenciesToReset.forEach(o=>{o.static.reset()})};if(this.extender.length===0){n();return}this.extender.forEach(o=>{i.has(o.id)||(i.add(o.id),o.reset(r||e,r,i))}),n()}},qe={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0,localStorage:void 0},Pr=class Qe{static{this.configManager=new jt(qe)}constructor(e){this.config=Qe.configManager.parse(e),this.dataManager=new Pe(this,this.config.localStorage),this.keyManager=new Ee({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new Fe({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.tickers=[]}init(){this.dataManager.init()}changeFps(e){this.keyManager.changeFps(e),this.eventManager.changeFps(e)}addCurrency(e,r=[],i=[]){return this.dataManager.setData(e,{currency:new pt}),new Le([()=>this.dataManager.getData(e).currency,r,i],this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new qt(i)),new xe([this.dataManager.getData(e),r,i],this)}addReset(...e){return console.warn("eMath.js: Game.addReset is deprecated. Use the GameReset class instead."),new re(...e)}addResetFromObject(e){return console.warn("eMath.js: Game.addResetFromObject is deprecated. Use the GameReset.fromObject static method instead."),re.fromObject(e)}},Lr={...Er,...Ce},xr=Lr;if(typeof lt.exports=="object"&&typeof Et=="object"){var qr=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};lt.exports=qr(lt.exports,Et)}return lt.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/game/eMath.game.mjs b/dist/game/eMath.game.mjs index 359bf015..6b808363 100644 --- a/dist/game/eMath.game.mjs +++ b/dist/game/eMath.game.mjs @@ -2390,25 +2390,31 @@ var Decimal = class { return D(value).reciprocate(); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value, other) { - return D(value).mod(other); + static mod(value, other, floored = false) { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value, other) { - return D(value).modulo(other); + static modulo(value, other, floored = false) { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value, other) { - return D(value).modular(other); + static modular(value, other, floored = false) { + return D(value).modular(other, floored); } /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. @@ -2858,6 +2864,31 @@ var Decimal = class { static pentate(value, height = 2, payload = FC_NN(1, 0, 1), linear = false) { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value, base = 10, linear = false) { + return D(value).penta_log(base, 100, linear); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value, degree) { + return D(value).linear_penta_root(degree); + } /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -3349,6 +3380,12 @@ var Decimal = class { } else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + if (this.layer < 0 || this.layer % 1 != 0) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -3845,12 +3882,20 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - mod(value) { - const decimal = D(value).abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + mod(value, floored = false) { + const vd = D(value); + const decimal = vd.abs(); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if (this.sign == -1 != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); if (isFinite(num_this) && isFinite(num_decimal) && num_this != 0 && num_decimal != 0) { @@ -3867,17 +3912,21 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value) { - return this.mod(value); + modulo(value, floored = false) { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value) { - return this.mod(value); + modular(value, floored = false) { + return this.mod(value, floored); } /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. @@ -5217,45 +5266,406 @@ var Decimal = class { } } } + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func, decreasing = false, iterations = 120, minX = Decimal.dLayerMax.neg(), maxX = Decimal.dLayerMax, minY = Decimal.dLayerMax.neg(), maxY = Decimal.dLayerMax) { + return function(value) { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let rangeApply = function(value2) { + return new Decimal(value2); + }; + let currentCheck = true; + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return new Decimal(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()); + }; + } + } + } + } else { + reciprocal = true; + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip().neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip().neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip().neg(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.neg(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).neg(); + }; + } + } + } + } + let searchIncreasing = positive != reciprocal != decreasing; + let comparative = searchIncreasing ? function(a, b) { + return Decimal.gt(a, b); + } : function(a, b) { + return Decimal.lt(a, b); + }; + let step_size = 1e-3; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { + break; + } + let currently_rose = comparative(new_decimal, value); + if (i > 1) { + if (previously_rose != currently_rose) { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) { + step_size /= 2; + } else { + step_size *= 2; + } + if (currently_rose != searchIncreasing && appliedResult.eq(maxX) || currently_rose == searchIncreasing && appliedResult.eq(minX)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { + break; + } + } + return rangeApply(result); + }; + } /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation - * + * * Tetration for non-integer heights does not have a single agreed-upon definition, * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. * Analytic approximation is not currently supported for bases > 10. - * + * * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height = 2, payload = FC_NN(1, 0, 1), linear = false) { payload = new Decimal(payload); const oldheight = height; - height = Math.trunc(height); + height = Math.floor(height); const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; if (fracheight !== 0) { if (payload.eq(Decimal.dOne)) { ++height; payload = Decimal.fromNumber(fracheight); } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + return this.pentate(payload.penta_log(this, void 0, linear).plus(oldheight).toNumber(), 1, linear); } } - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + if (payload.eq(prevpayload) || payload.eq(prevtwopayload) && i % 2 == height % 2) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 1e4) { + return payload; + } } - if (i > 10) { - return payload; + } else { + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, void 0, linear); + if (payload.eq(prevpayload)) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 100) { + return payload; + } } } return payload; } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + penta_log(base = 10, iterations = 100, linear = false) { + base = new Decimal(base); + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1e3) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { + break; + } + } + return Decimal.fromNumber(result); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree) { + if (degree == 1) { + return this; + } + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (degree > 0 && degree < 1) { + return this.root(degree); + } + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.lt(1)) { + return this.linear_sroot(degree); + } + return Decimal.increasingInverse(function(value) { + return Decimal.pentate(value, degree, 1, true); + })(this); + } // trig functions! /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. @@ -5593,16 +6003,64 @@ var Decimal = class { return new Decimal(Math.random()).lt(rng); } }; +/** + * Represents the number 0. + */ Decimal.dZero = FC_NN(0, 0, 0); +/** + * Represents the number 1. + */ Decimal.dOne = FC_NN(1, 0, 1); +/** + * Represents the number -1. + */ Decimal.dNegOne = FC_NN(-1, 0, 1); +/** + * Represents the number 2. + */ Decimal.dTwo = FC_NN(1, 0, 2); +/** + * Represents the number 10. + */ Decimal.dTen = FC_NN(1, 0, 10); +/** + * Represents a NaN (Not A Number) value. + */ Decimal.dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); +/** + * Represents positive infinity. + */ Decimal.dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents negative infinity. + */ Decimal.dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ Decimal.dNumberMax = FC(1, 0, Number.MAX_VALUE); +/** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ Decimal.dNumberMin = FC(1, 0, Number.MIN_VALUE); +/** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ +Decimal.dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); +/** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ +Decimal.dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); +/** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ +Decimal.dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); +/** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ +Decimal.dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); Decimal.fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); __decorateClass([ Expose() diff --git a/dist/main/eMath.js b/dist/main/eMath.js index 2421f8a2..01fea2e4 100644 --- a/dist/main/eMath.js +++ b/dist/main/eMath.js @@ -1738,25 +1738,31 @@ var Decimal = class { return D(value).reciprocate(); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value, other) { - return D(value).mod(other); + static mod(value, other, floored = false) { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value, other) { - return D(value).modulo(other); + static modulo(value, other, floored = false) { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value, other) { - return D(value).modular(other); + static modular(value, other, floored = false) { + return D(value).modular(other, floored); } /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. @@ -2206,6 +2212,31 @@ var Decimal = class { static pentate(value, height = 2, payload = FC_NN(1, 0, 1), linear = false) { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value, base = 10, linear = false) { + return D(value).penta_log(base, 100, linear); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value, degree) { + return D(value).linear_penta_root(degree); + } /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -2697,6 +2728,12 @@ var Decimal = class { } else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + if (this.layer < 0 || this.layer % 1 != 0) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -3193,12 +3230,20 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - mod(value) { - const decimal = D(value).abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + mod(value, floored = false) { + const vd = D(value); + const decimal = vd.abs(); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if (this.sign == -1 != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); if (isFinite(num_this) && isFinite(num_decimal) && num_this != 0 && num_decimal != 0) { @@ -3215,17 +3260,21 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value) { - return this.mod(value); + modulo(value, floored = false) { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value) { - return this.mod(value); + modular(value, floored = false) { + return this.mod(value, floored); } /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. @@ -4565,45 +4614,406 @@ var Decimal = class { } } } + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func, decreasing = false, iterations = 120, minX = Decimal.dLayerMax.neg(), maxX = Decimal.dLayerMax, minY = Decimal.dLayerMax.neg(), maxY = Decimal.dLayerMax) { + return function(value) { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let rangeApply = function(value2) { + return new Decimal(value2); + }; + let currentCheck = true; + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return new Decimal(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()); + }; + } + } + } + } else { + reciprocal = true; + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip().neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip().neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip().neg(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.neg(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).neg(); + }; + } + } + } + } + let searchIncreasing = positive != reciprocal != decreasing; + let comparative = searchIncreasing ? function(a, b) { + return Decimal.gt(a, b); + } : function(a, b) { + return Decimal.lt(a, b); + }; + let step_size = 1e-3; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { + break; + } + let currently_rose = comparative(new_decimal, value); + if (i > 1) { + if (previously_rose != currently_rose) { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) { + step_size /= 2; + } else { + step_size *= 2; + } + if (currently_rose != searchIncreasing && appliedResult.eq(maxX) || currently_rose == searchIncreasing && appliedResult.eq(minX)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { + break; + } + } + return rangeApply(result); + }; + } /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation - * + * * Tetration for non-integer heights does not have a single agreed-upon definition, * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. * Analytic approximation is not currently supported for bases > 10. - * + * * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height = 2, payload = FC_NN(1, 0, 1), linear = false) { payload = new Decimal(payload); const oldheight = height; - height = Math.trunc(height); + height = Math.floor(height); const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; if (fracheight !== 0) { if (payload.eq(Decimal.dOne)) { ++height; payload = Decimal.fromNumber(fracheight); } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + return this.pentate(payload.penta_log(this, void 0, linear).plus(oldheight).toNumber(), 1, linear); } } - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + if (payload.eq(prevpayload) || payload.eq(prevtwopayload) && i % 2 == height % 2) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 1e4) { + return payload; + } } - if (i > 10) { - return payload; + } else { + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, void 0, linear); + if (payload.eq(prevpayload)) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 100) { + return payload; + } } } return payload; } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + penta_log(base = 10, iterations = 100, linear = false) { + base = new Decimal(base); + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1e3) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { + break; + } + } + return Decimal.fromNumber(result); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree) { + if (degree == 1) { + return this; + } + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (degree > 0 && degree < 1) { + return this.root(degree); + } + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.lt(1)) { + return this.linear_sroot(degree); + } + return Decimal.increasingInverse(function(value) { + return Decimal.pentate(value, degree, 1, true); + })(this); + } // trig functions! /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. @@ -4941,16 +5351,64 @@ var Decimal = class { return new Decimal(Math.random()).lt(rng); } }; +/** + * Represents the number 0. + */ Decimal.dZero = FC_NN(0, 0, 0); +/** + * Represents the number 1. + */ Decimal.dOne = FC_NN(1, 0, 1); +/** + * Represents the number -1. + */ Decimal.dNegOne = FC_NN(-1, 0, 1); +/** + * Represents the number 2. + */ Decimal.dTwo = FC_NN(1, 0, 2); +/** + * Represents the number 10. + */ Decimal.dTen = FC_NN(1, 0, 10); +/** + * Represents a NaN (Not A Number) value. + */ Decimal.dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); +/** + * Represents positive infinity. + */ Decimal.dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents negative infinity. + */ Decimal.dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ Decimal.dNumberMax = FC(1, 0, Number.MAX_VALUE); +/** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ Decimal.dNumberMin = FC(1, 0, Number.MIN_VALUE); +/** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ +Decimal.dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); +/** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ +Decimal.dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); +/** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ +Decimal.dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); +/** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ +Decimal.dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); Decimal.fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); __decorateClass([ (0, import_class_transformer.Expose)() diff --git a/dist/main/eMath.min.js b/dist/main/eMath.min.js index 8547f2cd..6d00d6f1 100644 --- a/dist/main/eMath.min.js +++ b/dist/main/eMath.min.js @@ -1,4 +1,4 @@ -"use strict";(function(yt,st){var Ot=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],st);else if(typeof module=="object"&&module.exports)module.exports=st();else{var ot=st(),Tt=Ot?exports:yt;for(var wt in ot)Tt[wt]=ot[wt]}})(typeof self<"u"?self:exports,()=>{var yt={},st={exports:yt},Ot=Object.create,ot=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyNames,_e=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty,Se=(t,e)=>function(){return e||(0,t[wt(t)[0]])((e={exports:{}}).exports,e),e.exports},Xt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},Qt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of wt(e))!Ie.call(t,s)&&s!==r&&ot(t,s,{get:()=>e[s],enumerable:!(i=Tt(e,s))||i.enumerable});return t},mt=(t,e,r)=>(r=t!=null?Ot(_e(t)):{},Qt(e||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t)),Oe=t=>Qt(ot({},"__esModule",{value:!0}),t),K=(t,e,r,i)=>{for(var s=i>1?void 0:i?Tt(e,r):e,a=t.length-1,u;a>=0;a--)(u=t[a])&&(s=(i?u(e,r,s):u(s))||s);return i&&s&&ot(e,r,s),s},gt=Se({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:g(),s=a(e);typeof i.Reflect<"u"&&(s=a(i.Reflect,s)),r(s,i),typeof i.Reflect>"u"&&(i.Reflect=e);function a(d,I){return function(E,x){Object.defineProperty(d,E,{configurable:!0,writable:!0,value:x}),I&&I(E,x)}}function u(){try{return Function("return this;")()}catch{}}function c(){try{return(0,eval)("(function() { return this; })()")}catch{}}function g(){return u()||c()}})(function(r,i){var s=Object.prototype.hasOwnProperty,a=typeof Symbol=="function",u=a&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",c=a&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",g=typeof Object.create=="function",d={__proto__:[]}instanceof Array,I=!g&&!d,E={create:g?function(){return Dt(Object.create(null))}:d?function(){return Dt({__proto__:null})}:function(){return Dt({})},has:I?function(l,h){return s.call(l,h)}:function(l,h){return h in l},get:I?function(l,h){return s.call(l,h)?l[h]:void 0}:function(l,h){return l[h]}},x=Object.getPrototypeOf(Function),q=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:ur(),R=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:lr(),w=typeof WeakMap=="function"?WeakMap:hr(),k=a?Symbol.for("@reflect-metadata:registry"):void 0,U=sr(),H=ar(U);function o(l,h,m,y){if(L(m)){if(!ge(l))throw new TypeError;if(!de(h))throw new TypeError;return Q(l,h)}else{if(!ge(l))throw new TypeError;if(!Y(h))throw new TypeError;if(!Y(y)&&!L(y)&&!Nt(y))throw new TypeError;return Nt(y)&&(y=void 0),m=at(m),it(l,h,m,y)}}r("decorate",o);function N(l,h){function m(y,P){if(!Y(y))throw new TypeError;if(!L(P)&&!ir(P))throw new TypeError;Ct(l,h,y,P)}return m}r("metadata",N);function p(l,h,m,y){if(!Y(m))throw new TypeError;return L(y)||(y=at(y)),Ct(l,h,m,y)}r("defineMetadata",p);function v(l,h,m){if(!Y(h))throw new TypeError;return L(m)||(m=at(m)),X(l,h,m)}r("hasMetadata",v);function S(l,h,m){if(!Y(h))throw new TypeError;return L(m)||(m=at(m)),tt(l,h,m)}r("hasOwnMetadata",S);function F(l,h,m){if(!Y(h))throw new TypeError;return L(m)||(m=at(m)),et(l,h,m)}r("getMetadata",F);function O(l,h,m){if(!Y(h))throw new TypeError;return L(m)||(m=at(m)),ft(l,h,m)}r("getOwnMetadata",O);function G(l,h){if(!Y(l))throw new TypeError;return L(h)||(h=at(h)),At(l,h)}r("getMetadataKeys",G);function V(l,h){if(!Y(l))throw new TypeError;return L(h)||(h=at(h)),Pt(l,h)}r("getOwnMetadataKeys",V);function z(l,h,m){if(!Y(h))throw new TypeError;if(L(m)||(m=at(m)),!Y(h))throw new TypeError;L(m)||(m=at(m));var y=St(h,m,!1);return L(y)?!1:y.OrdinaryDeleteMetadata(l,h,m)}r("deleteMetadata",z);function Q(l,h){for(var m=l.length-1;m>=0;--m){var y=l[m],P=y(h);if(!L(P)&&!Nt(P)){if(!de(P))throw new TypeError;h=P}}return h}function it(l,h,m,y){for(var P=l.length-1;P>=0;--P){var B=l[P],W=B(h,m,y);if(!L(W)&&!Nt(W)){if(!Y(W))throw new TypeError;y=W}}return y}function X(l,h,m){var y=tt(l,h,m);if(y)return!0;var P=Bt(h);return Nt(P)?!1:X(l,P,m)}function tt(l,h,m){var y=St(h,m,!1);return L(y)?!1:me(y.OrdinaryHasOwnMetadata(l,h,m))}function et(l,h,m){var y=tt(l,h,m);if(y)return ft(l,h,m);var P=Bt(h);if(!Nt(P))return et(l,P,m)}function ft(l,h,m){var y=St(h,m,!1);if(!L(y))return y.OrdinaryGetOwnMetadata(l,h,m)}function Ct(l,h,m,y){var P=St(m,y,!0);P.OrdinaryDefineOwnMetadata(l,h,m,y)}function At(l,h){var m=Pt(l,h),y=Bt(l);if(y===null)return m;var P=At(y,h);if(P.length<=0)return m;if(m.length<=0)return P;for(var B=new R,W=[],j=0,M=m;j=0&&M=this._keys.length?(this._index=-1,this._keys=h,this._values=h):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},j.prototype.throw=function(M){throw this._index>=0&&(this._index=-1,this._keys=h,this._values=h),M},j.prototype.return=function(M){return this._index>=0&&(this._index=-1,this._keys=h,this._values=h),{value:M,done:!0}},j}(),y=function(){function j(){this._keys=[],this._values=[],this._cacheKey=l,this._cacheIndex=-2}return Object.defineProperty(j.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),j.prototype.has=function(M){return this._find(M,!1)>=0},j.prototype.get=function(M){var _=this._find(M,!1);return _>=0?this._values[_]:void 0},j.prototype.set=function(M,_){var T=this._find(M,!0);return this._values[T]=_,this},j.prototype.delete=function(M){var _=this._find(M,!1);if(_>=0){for(var T=this._keys.length,C=_+1;CQe}),st.exports=Oe(Jt);var mr=mt(gt()),Kt={};Xt(Kt,{Attribute:()=>zt,AttributeStatic:()=>We,Boost:()=>Vt,BoostObject:()=>pt,Currency:()=>It,CurrencyStatic:()=>He,DEFAULT_ITERATIONS:()=>Et,Decimal:()=>n,E:()=>Xe,FORMATS:()=>Ze,FormatTypeList:()=>Fe,Grid:()=>Zt,GridCell:()=>Ft,GridCellCollection:()=>J,Item:()=>he,ItemData:()=>_t,LRUCache:()=>qt,ListNode:()=>te,ST_NAMES:()=>ut,UpgradeData:()=>Mt,UpgradeStatic:()=>ue,calculateItem:()=>le,calculateSum:()=>Rt,calculateSumApprox:()=>se,calculateSumLoop:()=>ne,calculateUpgrade:()=>ae,decimalToJSONString:()=>oe,equalsTolerance:()=>$t,formats:()=>ht,inverseFunctionApprox:()=>Gt,roundingBase:()=>Be,upgradeToCacheNameEL:()=>De});var gr=mt(gt()),qt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new te(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},te=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},rt;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(rt||(rt={}));var Te=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(s){return!s.options||s.options.toClassOnly===!0&&s.options.toPlainOnly===!0?!0:s.options.toClassOnly===!0?i===rt.CLASS_TO_CLASS||i===rt.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?i===rt.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),s=this._exposeMetadatas.get(e),a=s&&s.get(void 0);return i&&a||!i&&!a?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===rt.CLASS_TO_CLASS||r===rt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===rt.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===rt.CLASS_TO_CLASS||r===rt.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===rt.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),s;i&&(s=Array.from(i.values()).filter(function(E){return E.propertyName!==void 0}));for(var a=[],u=0,c=this.getAncestors(r);uNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let F=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(3)){let V=[];for(let z=0;zNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let F=t.log(o,8e3).toNumber();if(p.equals(0))return v;if(p.gt(0)&&p.lte(2)){let V=[];for(let z=0;z118?e.elemental.beyondOg(S):e.elemental.config.element_lists[o-1][v]},beyondOg(o){let N=Math.floor(Math.log10(o)),p=["n","u","b","t","q","p","h","s","o","e"],v="";for(let S=N;S>=0;S--){let F=Math.floor(o/Math.pow(10,S))%10;v==""?v=p[F].toUpperCase():v+=p[F]}return v},abbreviationLength(o){return o==1?1:Math.pow(Math.floor(o/2)+1,2)*2},getAbbreviationAndValue(o){let N=o.log(118).toNumber(),p=Math.floor(N)+1,v=e.elemental.abbreviationLength(p),S=N-p+1,F=Math.floor(S*v),O=e.elemental.getAbbreviation(p,S),G=new t(118).pow(p+F/v-1);return[O,G]},formatElementalPart(o,N){return N.eq(1)?o:`${N.toString()} ${o}`},format(o,N=2){if(o.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(o.log10(),N);let p=o.log(118),S=p.log(118).log(118).toNumber(),F=Math.max(4-S*2,1),O=[];for(;p.gte(1)&&O.length=F)return O.map(V=>e.elemental.formatElementalPart(V[0],V[1])).join(" + ");let G=new t(118).pow(p).toFixed(O.length===1?3:N);return O.length===0?G:O.length===1?`${G} \xD7 ${e.elemental.formatElementalPart(O[0][0],O[0][1])}`:`${G} \xD7 (${O.map(V=>e.elemental.formatElementalPart(V[0],V[1])).join(" + ")})`}},old_sc:{format(o,N){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.old_sc.format(S.floor(),0)}let v=o.div(t.dTen.pow(p));return(p.log10().gte(9)?"":v.toFixed(4))+"e"+e.old_sc.format(p,0)}}},eng:{format(o,N=2){o=new t(o);let p=o.log10().floor();if(p.lt(9))return p.lt(3)?o.toFixed(N):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let S=o.slog();return(S.gte(1e9)?"":t.dTen.pow(S.sub(S.floor())).toFixed(4))+"F"+e.eng.format(S.floor(),0)}let v=o.div(new t(1e3).pow(p.div(3).floor()));return(p.log10().gte(9)?"":v.toFixed(new t(4).sub(p.sub(p.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(p.div(3).floor().mul(3),0)}}},mixed_sc:{format(o,N,p=9){o=new t(o);let v=o.log10().floor();return v.lt(303)&&v.gte(p)?g(o,N,p,"st"):g(o,N,p,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(o,N=2,p){o=new t(o);let v=o.max(1).log10().max(1).log(r.log10()).floor();if(v.lte(0))return g(o,N,p,"sc");o=t.dTen.pow(o.max(1).log10().div(r.log10().pow(v)).sub(v.gte(1)?1:0));let S=v.div(10).floor(),F=v.toNumber()%10-1;return g(o,Math.max(4,N),p,"sc")+" "+(S.gte(1)?"meta"+(S.gte(2)?"^"+g(S,0,p,"sc"):"")+"-":"")+(isNaN(F)?"nanity":e.layer.layers[F])}},standard:{tier1(o){return ut[0][0][o%10]+ut[0][1][Math.floor(o/10)%10]+ut[0][2][Math.floor(o/100)]},tier2(o){let N=o%10,p=Math.floor(o/10)%10,v=Math.floor(o/100)%10,S="";return o<10?ut[1][0][o]:(p==1&&N==0?S+="Vec":S+=ut[1][1][N]+ut[1][2][p],S+=ut[1][3][v],S)}},inf:{format(o,N,p){o=new t(o);let v=0,S=new t(Number.MAX_VALUE),F=["","\u221E","\u03A9","\u03A8","\u028A"],O=["","","m","mm","mmm"];for(;o.gte(S);)o=o.log(S),v++;return v==0?g(o,N,p,"sc"):o.gte(3)?O[v]+F[v]+"\u03C9^"+g(o.sub(1),N,p,"sc"):o.gte(2)?O[v]+"\u03C9"+F[v]+"-"+g(S.pow(o.sub(2)),N,p,"sc"):O[v]+F[v]+"-"+g(S.pow(o.sub(1)),N,p,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(o,N=new t(1e15),p=!1,v=9){if(o=new t(o),N=new t(N).div(1e3),o.lt(N.mul(1e3)))return"";let{alphabet:S}=e.alphabet.config,F=S.length,O=o.log(1e3).sub(N.log(1e3)).floor(),G=O.add(1).log(F+1).ceil(),V="",z=(Q,it)=>{let X=Q,tt="";for(let et=0;et=F)return"\u03C9";tt=S[ft]+tt,X=X.sub(1).div(F).floor()}return tt};if(G.lt(v))V=z(O,G);else{let Q=G.sub(v).add(1),it=O.div(t.pow(F+1,Q.sub(1))).floor();V=`${z(it,new t(v))}(${Q.gt("1e9")?Q.format():Q.format(0)})`}return V},format(o,N=2,p=9,v="mixed_sc",S=new t(1e15),F=!1,O){if(o=new t(o),S=new t(S).div(1e3),o.lt(S.mul(1e3)))return g(o,N,p,v);let G=e.alphabet.getAbbreviation(o,S,F,O),V=o.div(t.pow(1e3,o.log(1e3).floor()));return`${G.length>(O??9)+2?"":V.toFixed(N)+" "}${G}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",s="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function a(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":i[parseInt(N,10)]).join("")}function u(o){return o.toFixed(0).split("").map(N=>N==="-"?"\u208B":s[parseInt(N,10)]).join("")}function c(o,N=2,p=9,v="st"){return g(o,N,p,v)}function g(o,N=2,p=9,v="mixed_sc"){o=new t(o);let S=o.lt(0)?"-":"";if(o.mag==1/0)return S+"Infinity";if(Number.isNaN(o.mag))return S+"NaN";if(o.lt(0)&&(o=o.mul(-1)),o.eq(0))return o.toFixed(N);let F=o.log10().floor();switch(v){case"sc":case"scientific":if(o.log10().lt(Math.min(-N,0))&&N>1){let O=o.log10().ceil(),G=o.div(O.eq(-1)?new t(.1):t.dTen.pow(O)),V=O.mul(-1).max(1).log10().gte(9);return S+(V?"":G.toFixed(2))+"e"+g(O,0,p,"mixed_sc")}else if(F.lt(p)){let O=Math.max(Math.min(N-F.toNumber(),N),0);return S+(O>0?o.toFixed(O):o.toFixed(O).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(o.gte("eeee10")){let V=o.slog();return(V.gte(1e9)?"":t.dTen.pow(V.sub(V.floor())).toFixed(2))+"F"+g(V.floor(),0)}let O=o.div(t.dTen.pow(F)),G=F.log10().gte(9);return S+(G?"":O.toFixed(2))+"e"+g(F,0,p,"mixed_sc")}case"st":case"standard":{let O=o.log(1e3).floor();if(O.lt(1))return S+o.toFixed(Math.max(Math.min(N-F.toNumber(),N),0));let G=O.mul(3),V=O.log10().floor();if(V.gte(3e3))return"e"+g(F,N,p,"st");let z="";if(O.lt(4))z=["","K","M","B"][Math.round(O.toNumber())];else{let X=Math.floor(O.log(1e3).toNumber());for(X<100&&(X=Math.max(X-1,0)),O=O.sub(1).div(t.dTen.pow(X*3));O.gt(0);){let tt=O.div(1e3).floor(),et=O.sub(tt.mul(1e3)).floor().toNumber();et>0&&(et==1&&!X&&(z="U"),X&&(z=e.standard.tier2(X)+(z?"-"+z:"")),et>1&&(z=e.standard.tier1(et)+z)),O=tt,X++}}let Q=o.div(t.dTen.pow(G)),it=N===2?t.dTwo.sub(F.sub(G)).add(1).toNumber():N;return S+(V.gte(10)?"":Q.toFixed(it)+" ")+z}default:return e[v]||console.error('Invalid format type "',v,'"'),S+e[v].format(o,N,p)}}function d(o,N,p="mixed_sc",v,S){o=new t(o),N=new t(N);let F=o.add(N),O,G=F.div(o);return G.gte(10)&&o.gte(1e100)?(G=G.log10().mul(20),O="(+"+g(G,v,S,p)+" OoMs/sec)"):O="(+"+g(N,v,S,p)+"/sec)",O}function I(o,N=2,p="s"){return o=new t(o),o.gte(86400)?g(o.div(86400).floor(),0,12,"sc")+":"+I(o.mod(86400),N,"d"):o.gte(3600)||p=="d"?(o.div(3600).gte(10)||p!="d"?"":"0")+g(o.div(3600).floor(),0,12,"sc")+":"+I(o.mod(3600),N,"h"):o.gte(60)||p=="h"?(o.div(60).gte(10)||p!="h"?"":"0")+g(o.div(60).floor(),0,12,"sc")+":"+I(o.mod(60),N,"m"):(o.gte(10)||p!="m"?"":"0")+g(o,N,12,"sc")}function E(o,N=!1,p=0,v=9,S="mixed_sc"){let F=Pt=>g(Pt,p,v,S);o=new t(o);let O=o.mul(1e3).mod(1e3).floor(),G=o.mod(60).floor(),V=o.div(60).mod(60).floor(),z=o.div(3600).mod(24).floor(),Q=o.div(86400).mod(365.2425).floor(),it=o.div(31556952).floor(),X=it.eq(1)?" year":" years",tt=Q.eq(1)?" day":" days",et=z.eq(1)?" hour":" hours",ft=V.eq(1)?" minute":" minutes",Ct=G.eq(1)?" second":" seconds",At=O.eq(1)?" millisecond":" milliseconds";return`${it.gt(0)?F(it)+X+", ":""}${Q.gt(0)?F(Q)+tt+", ":""}${z.gt(0)?F(z)+et+", ":""}${V.gt(0)?F(V)+ft+", ":""}${G.gt(0)?F(G)+Ct+",":""}${N&&O.gt(0)?" "+F(O)+At:""}`.replace(/,([^,]*)$/,"$1").trim()}function x(o){return o=new t(o),g(t.dOne.sub(o).mul(100))+"%"}function q(o){return o=new t(o),g(o.mul(100))+"%"}function R(o,N=2){return o=new t(o),o.gte(1)?"\xD7"+o.format(N):"/"+o.pow(-1).format(N)}function w(o,N,p=10){return t.gte(o,10)?t.pow(p,t.log(o,p).pow(N)):new t(o)}function k(o,N=0){o=new t(o);let p=(O=>O.map((G,V)=>({name:G.name,altName:G.altName,value:t.pow(1e3,new t(V).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),v="",S=o.lte(0)?0:t.min(t.log(o,1e3).sub(1),p.length-1).floor().toNumber(),F=p[S];if(S===0)switch(N){case 1:v="";break;case 2:case 0:default:v=o.format();break}switch(N){case 1:v=F.name;break;case 2:v=o.divide(F.value).format();break;case 3:v=F.altName;break;case 0:default:v=`${o.divide(F.value).format()} ${F.name}`;break}return v}function U(o,N=!1){return`${k(o,2)} ${k(o,1)}eV${N?"/c^2":""}`}let H={...e,toSubscript:a,toSuperscript:u,formatST:c,format:g,formatGain:d,formatTime:I,formatTimeLong:E,formatReduction:x,formatPercent:q,formatMult:R,expMult:w,metric:k,ev:U};return{FORMATS:e,formats:H}}var Lt=17,Ae=9e15,Pe=Math.log10(9e15),qe=1/9e15,ke=308,Le=-324,ee=5,xe=1023,Ue=!0,Ve=!1,je=function(){let t=[];for(let r=Le+1;r<=ke;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ct=[2,Math.E,3,4,5,6,7,8,9,10],$e=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],Ge=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],f=function(e){return n.fromValue_noAlloc(e)},A=function(t,e,r){return n.fromComponents(t,e,r)},b=function(e,r,i){return n.fromComponents_noNormalize(e,r,i)},lt=function(e,r){let i=r+1,s=Math.ceil(Math.log10(Math.abs(e))),a=Math.round(e*Math.pow(10,i-s))*Math.pow(10,s-i);return parseFloat(a.toFixed(Math.max(i-s,0)))},xt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Re=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,s=t;return r=r+1/(12*s),s=s*i,r=r-1/(360*s),s=s*i,r=r+1/(1260*s),s=s*i,r=r-1/(1680*s),s=s*i,r=r+1/(1188*s),s=s*i,r=r-691/(360360*s),s=s*i,r=r+7/(1092*s),s=s*i,r=r-3617/(122400*s),Math.exp(r)/e},ze=.36787944117144233,re=.5671432904097838,Ut=function(t,e=1e-10,r=!0){let i,s;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return re;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let a=0;a<100;++a){if(s=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(s-i).5?1:-1;if(Math.random()*20<1)return b(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let s=Math.pow(10,i);return Math.random()>.9&&(s=Math.trunc(s)),A(e,r,s)}static affordGeometricSeries_core(t,e,r,i){let s=e.mul(r.pow(i));return n.floor(t.div(s).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(n.sub(1,r.pow(t))).div(n.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r)).sub(r.div(2)),u=a.pow(2);return a.neg().add(u.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r));return t.div(2).mul(s.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=Ae)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=n.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);Ue?t=t.replace(",",""):Ve&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let w=parseFloat(s[0]),k=parseFloat(s[1]),U=s[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(w)&&isFinite(k)){let o=n.pentate(w,k,H,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let a=t.split("^^");if(a.length===2){let w=parseFloat(a[0]),k=parseFloat(a[1]),U=a[1].split(";"),H=1;if(U.length===2&&(H=parseFloat(U[1]),isFinite(H)||(H=1)),isFinite(w)&&isFinite(k)){let o=n.tetrate(w,k,H,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let u=t.split("^");if(u.length===2){let w=parseFloat(u[0]),k=parseFloat(u[1]);if(isFinite(w)&&isFinite(k)){let U=n.pow(w,k);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}t=t.trim().toLowerCase();let c,g,d=t.split("pt");if(d.length===2){c=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),g=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let k=parseFloat(d[1]);if(isFinite(k)||(k=1),isFinite(c)&&isFinite(g)){let U=n.tetrate(c,g,k,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("p"),d.length===2){c=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),g=parseFloat(d[0]),d[1]=d[1].replace("(",""),d[1]=d[1].replace(")","");let k=parseFloat(d[1]);if(isFinite(k)||(k=1),isFinite(c)&&isFinite(g)){let U=n.tetrate(c,g,k,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}if(d=t.split("f"),d.length===2){c=10;let w=!1;d[0].startsWith("-")&&(w=!0,d[0]=d[0].slice(1)),d[0]=d[0].replace("(",""),d[0]=d[0].replace(")","");let k=parseFloat(d[0]);if(d[1]=d[1].replace("(",""),d[1]=d[1].replace(")",""),g=parseFloat(d[1]),isFinite(k)||(k=1),isFinite(c)&&isFinite(g)){let U=n.tetrate(c,g,k,e);return this.sign=U.sign,this.layer=U.layer,this.mag=U.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),w&&(this.sign*=-1),this}}let I=t.split("e"),E=I.length-1;if(E===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(E===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let x=t.split("e^");if(x.length===2){this.sign=1,x[0].startsWith("-")&&(this.sign=-1);let w="";for(let k=0;k=43&&U<=57||U===101)w+=x[1].charAt(k);else return this.layer=parseFloat(w),this.mag=parseFloat(x[1].substr(k+1)),this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}if(E<1)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let q=parseFloat(I[0]);if(q===0)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let R=parseFloat(I[I.length-1]);if(E>=2){let w=parseFloat(I[I.length-2]);isFinite(w)&&(R*=Math.sign(w),R+=xt(w))}if(!isFinite(q))this.sign=I[0]==="-"?-1:1,this.layer=E,this.mag=R;else if(E===1)this.sign=Math.sign(q),this.layer=1,this.mag=R+Math.log10(Math.abs(q));else if(this.sign=Math.sign(q),this.layer=E,E===2){let w=n.mul(A(1,2,R),f(q));return this.sign=w.sign,this.layer=w.layer,this.mag=w.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else this.mag=R;return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}fromValue(t){return t instanceof n?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:lt(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:lt(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ee?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):lt(this.m,t)+"e"+lt(this.e,t):this.layer===1?lt(this.m,t)+"e"+lt(this.e,t):this.layer<=ee?(this.sign===-1?"-":"")+"e".repeat(this.layer)+lt(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+lt(this.mag,t)}abs(){return b(this.sign===0?0:1,this.layer,this.mag)}neg(){return b(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?b(0,0,0):this.layer===0?A(this.sign,0,Math.round(this.mag)):new n(this)}floor(){return this.mag<0?this.sign===-1?b(-1,0,1):b(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?A(this.sign,0,Math.floor(this.mag)):new n(this)}ceil(){return this.mag<0?this.sign===1?b(1,0,1):b(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?A(this.sign,0,Math.ceil(this.mag)):new n(this)}trunc(){return this.mag<0?b(0,0,0):this.layer===0?A(this.sign,0,Math.trunc(this.mag)):new n(this)}add(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0)return new n(e);if(e.sign===0)return new n(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return b(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(n.cmpabs(this,e)>0?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*r.mag+i.sign*i.mag);let s=r.layer*Math.sign(r.mag),a=i.layer*Math.sign(i.mag);if(s-a>=2)return r;if(s===0&&a===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Lt)return r;{let u=Math.pow(10,Math.log10(r.mag)-i.mag),c=i.sign+r.sign*u;return A(Math.sign(c),1,i.mag+Math.log10(Math.abs(c)))}}if(s===1&&a===0){if(Math.abs(r.mag-Math.log10(i.mag))>Lt)return r;{let u=Math.pow(10,r.mag-Math.log10(i.mag)),c=i.sign+r.sign*u;return A(Math.sign(c),1,Math.log10(i.mag)+Math.log10(Math.abs(c)))}}if(Math.abs(r.mag-i.mag)>Lt)return r;{let u=Math.pow(10,r.mag-i.mag),c=i.sign+r.sign*u;return A(Math.sign(c),1,i.mag+Math.log10(Math.abs(c)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(f(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=f(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(n.dZero)||this.eq(n.dZero)&&this.mag==Number.POSITIVE_INFINITY)return b(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0||e.sign===0)return b(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return b(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return A(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return A(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return A(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let s=A(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(A(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return A(r.sign*i.sign,s.layer+1,s.sign*s.mag)}if(r.layer===2&&i.layer===2){let s=A(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(A(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return A(r.sign*i.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=f(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?b(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?b(0,0,0):this.layer===0?A(this.sign,0,1/this.mag):A(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=f(t).abs();if(e.eq(n.dZero))return b(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new n(r%i):this.sub(e).eq(this)?b(0,0,0):e.sub(this).eq(e)?new n(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=f(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new n(e):new n(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=f(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=f(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,s=r.mag;return this.layer>r.layer&&(s=xt(s)),this.layer0?A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):A(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer>0?A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):A(this.sign,0,Math.log10(this.mag))}log(t){return t=f(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?A(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):n.div(this.log10(),t.log10())}log2(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?A(this.sign,0,Math.log2(this.mag)):this.layer===1?A(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?A(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?A(this.sign,0,Math.log(this.mag)):this.layer===1?A(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?A(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=f(t),r=new n(this),i=new n(e);if(r.sign===0)return i.eq(0)?b(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return b(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let s=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?s.neg():Math.abs(i.toNumber()%2)%2===0?s:b(Number.NaN,Number.NaN,Number.NaN):s}pow10(){if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(n.dNegInf))return b(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return b(Number.NaN,Number.NaN,Number.NaN);let t=new n(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return A(1,0,e);if(t.sign===0)return b(1,0,1);t=b(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?A(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?A(-t.sign,t.layer+1,-t.mag):b(1,0,1)}pow_base(t){return f(t).pow(this)}root(t){let e=f(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(b(1,0,24)))return n.fromNumber(Re(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,s=12*i,a=1/s,u=e+a;if(u===e||(e=u,i=i*r,s=360*i,a=1/s,u=e-a,u===e))return n.exp(e);e=u,i=i*r,s=1260*i;let c=1/s;return e=e+c,i=i*r,s=1680*i,c=1/s,e=e-c,n.exp(e)}else return this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?b(1,0,1):this.layer===0&&this.mag<=709.7?n.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?A(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?A(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):A(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return n.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return A(1,2,Math.log10(this.mag)-.3010299956639812);{let t=n.div(b(this.sign,this.layer-1,this.mag),b(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=b(1,0,1),r=!1){if(t===1)return n.pow(this,e);if(t===0)return new n(e);if(this.eq(n.dOne))return b(1,0,1);if(this.eq(-1))return n.pow(this,e);if(t===Number.POSITIVE_INFINITY){let a=this.toNumber();if(a<=1.444667861009766&&a>=.06598803584531254){let u=n.ln(this).neg(),c=u.lambertw().div(u);if(a<1)return c;let g=u.lambertw(!1).div(u);return a>1.444667861009099&&(c=g=n.fromNumber(Math.E)),e=f(e),e.eq(g)?g:e.lt(g)?c:b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return a>1.444667861009766?b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(n.dZero)){let a=Math.abs((t+1)%2);return a>1&&(a=2-a),n.fromNumber(a)}if(t<0)return n.iteratedlog(e,this,-t,r);e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;if(this.gt(n.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(n.ln(this).neg().lambertw(!1).div(n.ln(this).neg())))&&(i>1e4||!r)){let a=Math.min(1e4,t);e.eq(n.dOne)?e=this.pow(s):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this);for(let u=0;u1e4&&Math.ceil(i)%2==1?this.pow(e):e}s!==0&&(e.eq(n.dOne)?this.gt(10)||r?e=this.pow(s):(e=n.fromNumber(n.tetrate_critical(this.toNumber(),s)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(s,r):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this,r));for(let a=0;a3)return b(e.sign,e.layer+(t-a-1),e.mag);if(a>1e4)return e}return e}iteratedexp(t=2,e=b(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return n.tetrate(t,-e,this,r);t=f(t);let i=n.fromDecimal(this),s=e;e=Math.trunc(e);let a=s-e;if(i.layer-t.layer>3){let u=Math.min(e,i.layer-t.layer-3);e-=u,i.layer-=u}for(let u=0;u1e4)return i}return a>0&&a<1&&(t.eq(10)?i=i.layeradd10(-a,r):i=i.layeradd(-a,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,s=!1,a=!1,u=this.slog_internal(t,r).toNumber();for(let c=1;c1&&a!=d&&(s=!0),a=d,s?i/=2:i*=2,i=Math.abs(i)*(d?-1:1),u+=i,i===0)break}return n.fromNumber(u)}slog_internal(t=10,e=!1){if(t=f(t),t.lte(n.dZero)||t.eq(n.dOne))return b(Number.NaN,Number.NaN,Number.NaN);if(t.lt(n.dOne))return this.eq(n.dOne)?b(0,0,0):this.eq(n.dZero)?b(-1,0,1):b(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(n.dZero))return b(-1,0,1);if(t.lt(1.444667861009766)){let s=n.ln(t).neg(),a=s.lambertw().div(s);if(this.eq(a))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(a))return b(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=n.fromDecimal(this);if(i.layer-t.layer>3){let s=i.layer-t.layer-3;r+=s,i.layer-=s}for(let s=0;s<100;++s)if(i.lt(n.dZero))i=n.pow(t,i),r-=1;else{if(i.lte(n.dOne))return e?n.fromNumber(r+i.toNumber()-1):n.fromNumber(r+n.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=n.log(i,t)}return n.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:n.critical_section(t,e,Ge)}static tetrate_critical(t,e){return n.critical_section(t,e,$e)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let s=0,a=0;for(let c=0;ct){let g=(t-ct[c])/(ct[c+1]-ct[c]);s=r[c][Math.floor(e)]*(1-g)+r[c+1][Math.floor(e)]*g,a=r[c][Math.ceil(e)]*(1-g)+r[c+1][Math.ceil(e)]*g;break}let u=e-Math.floor(e);return s<=0||a<=0?s*(1-u)+a*u:Math.pow(t,Math.log(s)/Math.log(t)*(1-u)+Math.log(a)/Math.log(t)*u)}layeradd10(t,e=!1){t=n.fromValue_noAlloc(t).toNumber();let r=n.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=f(e);if(i.gt(1)&&i.lte(1.444667861009766)){let u=n.excess_slog(this,e,r),c=u[0].toNumber(),g=u[1],d=c+t,I=n.ln(e).neg(),E=I.lambertw().div(I),x=I.lambertw(!1).div(I),q=n.dOne;g==1?q=E.mul(x).sqrt():g==2&&(q=x.mul(2));let R=i.pow(q),w=Math.floor(d),k=d-w,U=q.pow(1-k).mul(R.pow(k));return n.tetrate(i,w,U,r)}let a=this.slog(e,100,r).toNumber()+t;return a>=0?n.tetrate(e,a,n.dOne,r):Number.isFinite(a)?a>=-1?n.log(n.tetrate(e,a+1,n.dOne,r),e):n.log(n.log(n.tetrate(e,a+2,n.dOne,r),e),e):b(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=f(t),e=f(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[b(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let s=n.ln(e).neg(),a=s.lambertw().div(s),u=n.dInf;if(e>1&&(u=s.lambertw(!1).div(s)),e>1.444667861009099&&(a=u=n.fromNumber(Math.E)),t.lt(a))return[t.slog(e,100,r),0];if(t.eq(a))return[b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(u))return[b(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(u)){let c=u.mul(2),g=i.pow(c),d=0;if(t.gte(c)&&t.lt(g))d=0;else if(t.gte(g)){let w=g;for(d=1;w.lt(t);)if(w=i.pow(w),d=d+1,w.layer>3){let k=Math.floor(t.layer-w.layer+1);w=i.iteratedexp(k,w,r),d=d+k}w.gt(t)&&(w=w.log(e),d=d-1)}else if(t.lt(c)){let w=c;for(d=0;w.gt(t);)w=w.log(e),d=d-1}let I=0,E=0,x=.5,q=c,R=n.dZero;for(;x>1e-16;){if(E=I+x,q=c.pow(1-E).mul(g.pow(E)),R=n.iteratedexp(e,d,q),R.eq(t))return[new n(d+E),2];R.lt(t)&&(I+=x),x/=2}return R.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),2]}if(t.lt(u)&&t.gt(a)){let c=a.mul(u).sqrt(),g=i.pow(c),d=0;if(t.lte(c)&&t.gt(g))d=0;else if(t.lte(g)){let w=g;for(d=1;w.gt(t);)w=i.pow(w),d=d+1;w.lt(t)&&(w=w.log(e),d=d-1)}else if(t.gt(c)){let w=c;for(d=0;w.lt(t);)w=w.log(e),d=d-1}let I=0,E=0,x=.5,q=c,R=n.dZero;for(;x>1e-16;){if(E=I+x,q=c.pow(1-E).mul(g.pow(E)),R=n.iteratedexp(e,d,q),R.eq(t))return[new n(d+E),1];R.gt(t)&&(I+=x),x/=2}return R.neq_tolerance(t,1e-7)?[b(Number.NaN,Number.NaN,Number.NaN),0]:[new n(d+I),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?b(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new n(this):this.mag<0?n.fromNumber(Ut(this.toNumber())):this.layer===0?n.fromNumber(Ut(this.sign*this.mag)):this.lt("eee15")?ie(this):this.ln():this.sign===1?b(Number.NaN,Number.NaN,Number.NaN):this.layer===0?n.fromNumber(Ut(this.sign*this.mag,1e-10,!1)):this.layer==1?ie(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(n.dInf))return b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return b(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return n.fromNumber(t).add(2).pow(this.recip());if(t<=0)return b(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eze?this.pow(this.recip()):b(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return b(1,0,1);if(this.lt(0))return b(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new n(this):b(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=n.dTen;this.gte(n.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=n.dZero,i=e.layer,s=e.iteratedlog(10,i,!0),a=s,u=s.div(2),c=!0;for(;c;)u=r.add(s).div(2),n.iteratedexp(10,i,u,!0).tetrate(t,1,!0).gt(this)?s=u:r=u,u.eq(a)?c=!1:a=u;return n.iteratedexp(10,i,u,!0)}else{let e=1,r=A(1,10,1),i=A(1,10,1),s=A(1,10,1),a=A(1,1,-16),u=n.dZero,c=A(1,10,1),g=a.pow10().recip(),d=n.dZero,I=g,E=g,x=Math.ceil(t)%2==0,q=0,R=A(1,10,1),w=!1,k=n.dZero,U=!1;for(;e<4;){if(e==2){if(x)break;s=A(1,10,1),a=r,e=3,c=A(1,10,1),R=A(1,10,1)}for(w=!1;a.neq(s);){if(k=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))g=a.pow10().recip(),I=a.pow10().recip(),E=a.pow10().recip(),d=n.dZero,q=-1,e==3&&(R=a);else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip())&&!x&&a.pow10().recip().lt(.4))g=a.pow10().recip(),I=a.pow10().recip(),E=a.pow10().recip(),d=n.dZero,q=0;else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip().mul(2).tetrate(t,1,!0)))g=a.pow10().recip(),I=n.dZero,E=g.mul(2),d=g,x?q=-1:q=0;else{for(u=a.mul(12e-17),g=a.pow10().recip(),I=a.add(u).pow10().recip(),d=g.sub(I),E=g.add(d);I.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||E.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||I.gte(g)||E.lte(g);)u=u.mul(2),I=a.add(u).pow10().recip(),d=g.sub(I),E=g.add(d);if((e==1&&E.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&E.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(R=a),E.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))q=-1;else if(x)q=1;else if(e==3&&a.gt_tolerance(r,1e-8))q=0;else{for(;I.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||E.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||I.gte(g)||E.lte(g);)u=u.mul(2),I=a.add(u).pow10().recip(),d=g.sub(I),E=g.add(d);E.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.tetrate(t,1,!0).sub(I.tetrate(t,1,!0)))?q=0:q=1}}if(q==-1&&(U=!0),e==1&&q==1||e==3&&q!=0)if(s.eq(A(1,10,1)))a=a.mul(2);else{let p=!1;if(w&&(q==1&&e==1||q==-1&&e==3)&&(p=!0),a=a.add(s).div(2),p)break}else if(s.eq(A(1,10,1)))s=a,a=a.div(2);else{let p=!1;if(w&&(q==1&&e==1||q==-1&&e==3)&&(p=!0),s=s.sub(c),a=a.sub(c),p)break}if(s.sub(a).div(2).abs().gt(c.mul(1.5))&&(w=!0),c=s.sub(a).div(2).abs(),a.gt("1e18")||a.eq(k))break}if(a.gt("1e18")||!U||R==A(1,10,1))break;e==1?r=R:e==3&&(i=R),e++}s=r,a=A(1,1,-18);let H=a,o=n.dZero,N=!0;for(;N;)if(s.eq(A(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(H)?N=!1:H=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);if(o.eq_tolerance(r,1e-15)){if(i.eq(A(1,10,1)))return b(Number.NaN,Number.NaN,Number.NaN);for(s=A(1,10,1),a=i,H=a,o=n.dZero,N=!0;N;)if(s.eq(A(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(H)?N=!1:H=o,a.gt("1e18"))return b(Number.NaN,Number.NaN,Number.NaN);return o.pow10().recip()}else return o.pow10().recip()}}pentate(t=2,e=b(1,0,1),r=!1){e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;s!==0&&(e.eq(n.dOne)?(++t,e=n.fromNumber(s)):this.eq(10)?e=e.layeradd10(s,r):e=e.layeradd(s,this,r));for(let a=0;a10)return e}return e}sin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.sin(this.sign*this.mag)):b(0,0,0)}cos(){return this.mag<0?b(1,0,1):this.layer===0?n.fromNumber(Math.cos(this.sign*this.mag)):b(0,0,0)}tan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.tan(this.sign*this.mag)):b(0,0,0)}asin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.asin(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?n.fromNumber(Math.acos(this.toNumber())):this.layer===0?n.fromNumber(Math.acos(this.sign*this.mag)):b(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.atan(this.sign*this.mag)):n.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return n.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return n.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?b(Number.NaN,Number.NaN,Number.NaN):n.ln(this.add(1).div(n.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new n(this):this.root(n.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new n(t).add(new n(e).minus(new n(t)).times(new n(r)).times(new n(i)))}clone(){return this}static clone(t){return n.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new n(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new n(t),e=new n(e);let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=i?s.mul(t.pow(e.sub(1))).root(e):s.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(s=i?s.div(t).max(1).log(e).add(t):n.pow(e,s.sub(t)).mul(t))),s}static scale(t,e,r,i,s=!1){return new n(t).scale(e,r,i,s)}format(t=2,e=9,r="mixed_sc"){return ht.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return ht.format(new n(t),e,r,i)}formatST(t=2,e=9,r="st"){return ht.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return ht.format(new n(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return ht.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,s){return ht.formatGain(new n(t),e,r,i,s)}toRoman(t=5e3){t=new n(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},s="";for(let a of Object.keys(i)){let u=Math.floor(r/i[a]);r-=u*i[a],s+=a.repeat(u)}return s}static toRoman(t,e){return new n(t).toRoman(e)}static random(t=0,e=1){return t=new n(t),e=new n(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new n(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new n(Math.random()).lt(t)}};n.dZero=b(0,0,0),n.dOne=b(1,0,1),n.dNegOne=b(-1,0,1),n.dTwo=b(1,0,2),n.dTen=b(1,0,10),n.dNaN=b(Number.NaN,Number.NaN,Number.NaN),n.dInf=b(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNegInf=b(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNumberMax=A(1,0,Number.MAX_VALUE),n.dNumberMin=A(1,0,Number.MIN_VALUE),n.fromStringCache=new qt(xe),K([vt()],n.prototype,"sign",2),K([vt()],n.prototype,"mag",2),K([vt()],n.prototype,"layer",2),n=K([Ee()],n);var{formats:ht,FORMATS:Ze}=Ce(n);n.formats=ht;var pt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},Vt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new n(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new pt(r))})}getBoosts(t,e){let r=[],i=[];for(let s=0;sE),d=s,I=this.getBoosts(a,!0);I[0][0]?this.boostArray[I[1][0]]=new pt({id:a,name:u,description:c,value:g,order:d}):this.boostArray.push(new pt({id:a,name:u,description:c,value:g,order:d}))}else{t=Array.isArray(t)?t:[t];for(let a of t){let u=this.getBoosts(a.id,!0);u[0][0]?this.boostArray[u[1][0]]=new pt(a):this.boostArray.push(new pt(a))}}}clearBoosts(){this.boostArray.length=0}calculate(t=this.baseEffect){let e=new n(t),r=this.boostArray;r=r.sort((i,s)=>i.order-s.order);for(let i of r)e=i.value(e);return e}},dr=mt(gt()),Et=30,jt=.001;function Ye(t,e,r="geometric"){switch(t=new n(t),e=new n(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return n.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function $t(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new n(t),e=new n(e),r=new n(r);let s,a;return i.mode==="geometric"?(s=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),a=s.lte(r)):(s=t.sub(e).abs(),a=s.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!a)&&console.log({a:t,b:e,tolerance:r,config:i,diff:s,result:a}),a}function Gt(t,e,r="geometric",i=Et,s=jt,a=1,u){if(a=new n(a),u=new n(u??e),a.gt(u)&&([a,u]=[u,a]),t(u).eq(0))return{value:n.dZero,lowerBound:n.dZero,upperBound:n.dZero};if(t(u).lt(e))return console.warn("eMath.js: The function is not monotonically increasing. (f(n) < n)"),{value:u,lowerBound:u,upperBound:u};for(let g=0;g=0;c--){let g=r.add(u.mul(c)),d=r.add(u.mul(c+1)),I=a;if(a=a.add(t(g).add(t(d)).div(2).mul(u)),$t(I,a,s,{verbose:!1,mode:"geometric"}))break}return a}function Rt(t,e,r=0,i,s){return r=new n(r),e=new n(e),e.sub(r).lte(Et)?ne(t,e,r,i):se(t,e,r,s)}function Be(t,e=10,r=0,i=1e3){if(t=new n(t),e=new n(e),r=new n(r),i=new n(i),e.lt(1)||r.lt(1))return n.dNaN;let s=t.sign;if(t=t.abs(),t.gte(n.pow(e,i)))return t;let a=n.floor(n.log(t,e)),u=t.div(n.pow(e,a));return u=u.mul(n.pow(e,r)).round(),u=u.div(n.pow(e,r)),u=u.mul(n.pow(e,a)).mul(s),u}function ae(t,e,r,i=n.dInf,s,a,u=!1){t=new n(t),r=new n(r??e.level),i=new n(i);let c=i.sub(r);if(c.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",c),[n.dZero,n.dZero];if(u=(typeof e.el=="function"?e.el():e.el)??u,c.eq(1)){let E=e.cost(e.level),x=t.gte(E),q=[n.dZero,n.dZero];return u?(q[0]=x?n.dOne:n.dZero,q):(q=[x?n.dOne:n.dZero,x?E:n.dZero],q)}if(e.costBulk){let[E,x]=e.costBulk(t,e.level,c),q=t.gte(x);return[q?E:n.dZero,q&&!u?x:n.dZero]}if(u){let E=R=>e.cost(R.add(r)),x=n.min(i,Gt(E,t,s,a).value.floor()),q=n.dZero;return[x,q]}let g=Gt(E=>Rt(e.cost,E,r),t,s,a).value.floor().min(r.add(c).sub(1)),d=Rt(e.cost,g,r);return[g.sub(r).add(1).max(0),d]}function oe(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function De(t){return`el/${oe(t)}`}var Mt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):n.dOne}};K([vt()],Mt.prototype,"id",2),K([dt(()=>n)],Mt.prototype,"level",2);var ue=class Me{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:n.dOne}}).data??{level:n.dOne}).level}set level(e){this.data.level=new n(e)}constructor(e,r,i,s){let a=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>a,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new qt(s??Me.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??n.dOne}},pr=mt(gt());function le(t,e,r=n.dOne,i=n.dInf){if(t=new n(t),r=new n(r),i=new n(i),i.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",i),[n.dZero,n.dZero];if(i.eq(1)){let u=e.cost(r);return[t.gte(u)?n.dOne:n.dZero,t.gte(u)?u:n.dZero]}let s=t.div(e.cost(r)).floor().min(i),a=e.cost(r).mul(s);return[s,a]}var he=class{constructor(t,e,r){this.defaultAmount=n.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??n.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:n.dOne}}).data??{amount:n.dOne}).amount}set amount(t){this.data.amount=new n(t)}},_t=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??n.dZero}};K([vt()],_t.prototype,"id",2),K([dt(()=>n)],_t.prototype,"amount",2);var Nr=mt(gt()),It=class{constructor(){this.value=n.dZero,this.upgrades={},this.items={}}};K([dt(()=>n)],It.prototype,"value",2),K([dt(()=>Mt)],It.prototype,"upgrades",2),K([dt(()=>_t)],It.prototype,"items",2);var He=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new It,e,r,i={defaultVal:n.dZero,defaultBoost:n.dOne}){this.defaultVal=i.defaultVal,this.defaultBoost=i.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Vt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e),this.items={},r&&this.addItem(r)}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let s of Object.values(this.upgrades))s.level=new n(s.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(s);if(i.resetItemAmounts)for(let s of Object.values(this.items))s.amount=new n(s.defaultAmount),i.runUpgradeEffect&&this.runItemEffect(s)}gain(t=1e3){let e=this.boost.calculate().mul(new n(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new Mt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(a=>i.test(a)).map(a=>this.upgrades[a])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let s=new ue(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(s),this.upgrades[i.id]=s,r.push(s)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t.effect?.(t.level,t,this)}runItemEffect(t,e=n.dOne){e=new n(e),t.effect?.(t.amount,e,t,this)}calculateUpgrade(t,e=1/0,r,i){let s=this.getUpgrade(t);return s===null?(console.warn(`eMath.js: Upgrade "${t}" not found.`),[n.dZero,n.dZero]):(e=s.level.add(e),s.maxLevel!==void 0&&(e=n.min(e,s.maxLevel)),ae(this.value,s,s.level,e,r,i))}getNextCost(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i)[0];return s.cost(s.level.add(a))}getNextCostMax(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i);return s.cost(s.level.add(a[0])).add(a[1])}buyUpgrade(t,e,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),!1;let[a,u]=this.calculateUpgrade(t,e,r,i);return a.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(u),s.level=s.level.add(a),this.runUpgradeEffect(s),!0)}pointerAddItem(t){let e=new _t(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new he(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runItemEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e,r){let i=this.getItem(t);return i===null?(console.warn(`eMath.js: Item "${t}" not found.`),[n.dZero,n.dZero]):le(this.value,i,e,r)}buyItem(t,e,r){let i=this.getItem(t);if(i===null)return console.warn(`eMath.js: Item "${t}" not found.`),!1;let[s,a]=this.calculateItem(t,e,r);return s.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(a),i.amount=i.amount.add(s),this.runItemEffect(i,e),!0)}},br=mt(gt()),zt=class{constructor(t=0){this.value=new n(t)}};K([dt(()=>n)],zt.prototype,"value",2);var We=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new n(r),t??=new zt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Vt(this.initial):null}update(){console.warn("eMath.js: AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},Ft=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=typeof r=="function"?r(this):{...r},this.gridSymbol=i}get grid(){return Zt.getInstance(this.gridSymbol)}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Zt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=this.grid;return(()=>{switch(t){case"up":return i.getCell(this.x,this.y-e);case"right":return i.getCell(this.x+e,this.y);case"down":return i.getCell(this.x,this.y+e);case"left":return i.getCell(this.x-e,this.y);case"adjacent":return i.getAdjacent(this.x,this.y,e,r);case"diagonal":return i.getDiagonal(this.x,this.y,e,r);case"encircling":return i.getEncircling(this.x,this.y,e,r);default:throw new Error("Invalid direction")}})()}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}};function fe(t,e,r=!0){let i=r?"Size":"Coordinates";if(typeof t!="number"||typeof e!="number")throw new RangeError(`${i} must be numbers: ${t}, ${e}`);if(!Number.isInteger(t)||!Number.isInteger(e))throw new RangeError(`${i} must be integers: ${t}, ${e}`);if(t<0||e<0)throw new RangeError(`${i} must be positive: ${t}, ${e}`);if(!Number.isFinite(t)||!Number.isFinite(e))throw new RangeError(`${i} must be finite: ${t}, ${e}`);if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e))throw new RangeError(`${i} must be safe integers: ${t}, ${e}`)}var J=class Ht extends Array{constructor(e){e=Array.isArray(e)?e:[e],e=e.filter(r=>r!==void 0),super(...e),this.removeDuplicates()}removeDuplicates(){let e=[];this.forEach((r,i)=>{this.indexOf(r)!==i&&e.push(i)}),e.forEach(r=>this.splice(r,1))}translate(e=0,r=0){return new Ht(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new Ht(this.flatMap(s=>s.direction(e,r,i)))}up(e){return this.direction("up",e)}right(e){return this.direction("right",e)}down(e){return this.direction("down",e)}left(e){return this.direction("left",e)}adjacent(e,r){return this.direction("adjacent",e,r)}diagonal(e,r){return this.direction("diagonal",e,r)}encircling(e,r){return this.direction("encircling",e,r)}},Zt=class Wt{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),Wt.instances[this.gridSymbol]=this,this.starterProps=i??{},this.xSize=e,this.ySize=r??e,fe(this.xSize,this.ySize,!0);for(let s=0;s{if(this.ySize!==s&&(this.ySizes))for(let a=s;a{if(this.xSize!==i){if(this.xSizei)for(let a=0;a{let t=!1,e=r=>(t||(console.warn("eMath.js: The E function is deprecated. Use the Decimal class directly."),t=!0),new n(r));return Object.getOwnPropertyNames(n).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=n[r]}),e})(),Qe=Kt;if(typeof st.exports=="object"&&typeof yt=="object"){var Je=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,s)&&s!==r&&Object.defineProperty(t,s,{get:()=>e[s],enumerable:!(i=Object.getOwnPropertyDescriptor(e,s))||i.enumerable});return t};st.exports=Je(st.exports,yt)}return st.exports}); +"use strict";(function(Mt,at){var Tt=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],at);else if(typeof module=="object"&&module.exports)module.exports=at();else{var ut=at(),Ft=Tt?exports:Mt;for(var vt in ut)Ft[vt]=ut[vt]}})(typeof self<"u"?self:exports,()=>{var Mt={},at={exports:Mt},Tt=Object.create,ut=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,vt=Object.getOwnPropertyNames,Se=Object.getPrototypeOf,Ee=Object.prototype.hasOwnProperty,Oe=(t,e)=>function(){return e||(0,t[vt(t)[0]])((e={exports:{}}).exports,e),e.exports},Xt=(t,e)=>{for(var r in e)ut(t,r,{get:e[r],enumerable:!0})},Kt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of vt(e))!Ee.call(t,s)&&s!==r&&ut(t,s,{get:()=>e[s],enumerable:!(i=Ft(e,s))||i.enumerable});return t},dt=(t,e,r)=>(r=t!=null?Tt(Se(t)):{},Kt(e||!t||!t.__esModule?ut(r,"default",{value:t,enumerable:!0}):r,t)),Te=t=>Kt(ut({},"__esModule",{value:!0}),t),tt=(t,e,r,i)=>{for(var s=i>1?void 0:i?Ft(e,r):e,a=t.length-1,u;a>=0;a--)(u=t[a])&&(s=(i?u(e,r,s):u(s))||s);return i&&s&&ut(e,r,s),s},Nt=Oe({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:g(),s=a(e);typeof i.Reflect<"u"&&(s=a(i.Reflect,s)),r(s,i),typeof i.Reflect>"u"&&(i.Reflect=e);function a(l,S){return function(E,V){Object.defineProperty(l,E,{configurable:!0,writable:!0,value:V}),S&&S(E,V)}}function u(){try{return Function("return this;")()}catch{}}function f(){try{return(0,eval)("(function() { return this; })()")}catch{}}function g(){return u()||f()}})(function(r,i){var s=Object.prototype.hasOwnProperty,a=typeof Symbol=="function",u=a&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",f=a&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",g=typeof Object.create=="function",l={__proto__:[]}instanceof Array,S=!g&&!l,E={create:g?function(){return Wt(Object.create(null))}:l?function(){return Wt({__proto__:null})}:function(){return Wt({})},has:S?function(h,c){return s.call(h,c)}:function(h,c){return c in h},get:S?function(h,c){return s.call(h,c)?h[c]:void 0}:function(h,c){return h[c]}},V=Object.getPrototypeOf(Function),q=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:ur(),U=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:lr(),_=typeof WeakMap=="function"?WeakMap:fr(),k=a?Symbol.for("@reflect-metadata:registry"):void 0,x=sr(),Z=ar(x);function o(h,c,d,v){if(L(d)){if(!Ne(h))throw new TypeError;if(!pe(c))throw new TypeError;return X(h,c)}else{if(!Ne(h))throw new TypeError;if(!B(c))throw new TypeError;if(!B(v)&&!L(v)&&!wt(v))throw new TypeError;return wt(v)&&(v=void 0),d=ot(d),nt(h,c,d,v)}}r("decorate",o);function b(h,c){function d(v,P){if(!B(v))throw new TypeError;if(!L(P)&&!ir(P))throw new TypeError;qt(h,c,v,P)}return d}r("metadata",b);function w(h,c,d,v){if(!B(d))throw new TypeError;return L(v)||(v=ot(v)),qt(h,c,d,v)}r("defineMetadata",w);function N(h,c,d){if(!B(c))throw new TypeError;return L(d)||(d=ot(d)),J(h,c,d)}r("hasMetadata",N);function y(h,c,d){if(!B(c))throw new TypeError;return L(d)||(d=ot(d)),et(h,c,d)}r("hasOwnMetadata",y);function M(h,c,d){if(!B(c))throw new TypeError;return L(d)||(d=ot(d)),rt(h,c,d)}r("getMetadata",M);function F(h,c,d){if(!B(c))throw new TypeError;return L(d)||(d=ot(d)),ct(h,c,d)}r("getOwnMetadata",F);function $(h,c){if(!B(h))throw new TypeError;return L(c)||(c=ot(c)),Pt(h,c)}r("getMetadataKeys",$);function j(h,c){if(!B(h))throw new TypeError;return L(c)||(c=ot(c)),kt(h,c)}r("getOwnMetadataKeys",j);function z(h,c,d){if(!B(c))throw new TypeError;if(L(d)||(d=ot(d)),!B(c))throw new TypeError;L(d)||(d=ot(d));var v=Ot(c,d,!1);return L(v)?!1:v.OrdinaryDeleteMetadata(h,c,d)}r("deleteMetadata",z);function X(h,c){for(var d=h.length-1;d>=0;--d){var v=h[d],P=v(c);if(!L(P)&&!wt(P)){if(!pe(P))throw new TypeError;c=P}}return c}function nt(h,c,d,v){for(var P=h.length-1;P>=0;--P){var D=h[P],Q=D(c,d,v);if(!L(Q)&&!wt(Q)){if(!B(Q))throw new TypeError;v=Q}}return v}function J(h,c,d){var v=et(h,c,d);if(v)return!0;var P=Ht(c);return wt(P)?!1:J(h,P,d)}function et(h,c,d){var v=Ot(c,d,!1);return L(v)?!1:de(v.OrdinaryHasOwnMetadata(h,c,d))}function rt(h,c,d){var v=et(h,c,d);if(v)return ct(h,c,d);var P=Ht(c);if(!wt(P))return rt(h,P,d)}function ct(h,c,d){var v=Ot(c,d,!1);if(!L(v))return v.OrdinaryGetOwnMetadata(h,c,d)}function qt(h,c,d,v){var P=Ot(d,v,!0);P.OrdinaryDefineOwnMetadata(h,c,d,v)}function Pt(h,c){var d=kt(h,c),v=Ht(h);if(v===null)return d;var P=Pt(v,c);if(P.length<=0)return d;if(d.length<=0)return P;for(var D=new U,Q=[],G=0,I=d;G=0&&I=this._keys.length?(this._index=-1,this._keys=c,this._values=c):this._index++,{value:O,done:!1}}return{value:void 0,done:!0}},G.prototype.throw=function(I){throw this._index>=0&&(this._index=-1,this._keys=c,this._values=c),I},G.prototype.return=function(I){return this._index>=0&&(this._index=-1,this._keys=c,this._values=c),{value:I,done:!0}},G}(),v=function(){function G(){this._keys=[],this._values=[],this._cacheKey=h,this._cacheIndex=-2}return Object.defineProperty(G.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),G.prototype.has=function(I){return this._find(I,!1)>=0},G.prototype.get=function(I){var O=this._find(I,!1);return O>=0?this._values[O]:void 0},G.prototype.set=function(I,O){var A=this._find(I,!0);return this._values[A]=O,this},G.prototype.delete=function(I){var O=this._find(I,!1);if(O>=0){for(var A=this._keys.length,C=O+1;CJe}),at.exports=Te(te);var mr=dt(Nt()),ee={};Xt(ee,{Attribute:()=>Yt,AttributeStatic:()=>We,Boost:()=>Gt,BoostObject:()=>bt,Currency:()=>Et,CurrencyStatic:()=>He,DEFAULT_ITERATIONS:()=>At,Decimal:()=>n,E:()=>Qe,FORMATS:()=>ze,FormatTypeList:()=>Ce,Grid:()=>Bt,GridCell:()=>Ct,GridCellCollection:()=>K,Item:()=>ce,ItemData:()=>St,LRUCache:()=>Lt,ListNode:()=>re,ST_NAMES:()=>lt,UpgradeData:()=>It,UpgradeStatic:()=>fe,calculateItem:()=>he,calculateSum:()=>zt,calculateSumApprox:()=>oe,calculateSumLoop:()=>ae,calculateUpgrade:()=>ue,decimalToJSONString:()=>le,equalsTolerance:()=>$t,formats:()=>ht,inverseFunctionApprox:()=>Zt,roundingBase:()=>Be,upgradeToCacheNameEL:()=>De});var gr=dt(Nt()),Lt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new re(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},re=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},it;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(it||(it={}));var Fe=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(s){return!s.options||s.options.toClassOnly===!0&&s.options.toPlainOnly===!0?!0:s.options.toClassOnly===!0?i===it.CLASS_TO_CLASS||i===it.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?i===it.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),s=this._exposeMetadatas.get(e),a=s&&s.get(void 0);return i&&a||!i&&!a?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===it.CLASS_TO_CLASS||r===it.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===it.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===it.CLASS_TO_CLASS||r===it.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===it.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),s;i&&(s=Array.from(i.values()).filter(function(E){return E.propertyName!==void 0}));for(var a=[],u=0,f=this.getAncestors(r);uNumber.MAX_SAFE_INTEGER)&&(N="\u03C9");let M=t.log(o,8e3).toNumber();if(w.equals(0))return N;if(w.gt(0)&&w.lte(3)){let j=[];for(let z=0;zNumber.MAX_SAFE_INTEGER)&&(N="\u03C9");let M=t.log(o,8e3).toNumber();if(w.equals(0))return N;if(w.gt(0)&&w.lte(2)){let j=[];for(let z=0;z118?e.elemental.beyondOg(y):e.elemental.config.element_lists[o-1][N]},beyondOg(o){let b=Math.floor(Math.log10(o)),w=["n","u","b","t","q","p","h","s","o","e"],N="";for(let y=b;y>=0;y--){let M=Math.floor(o/Math.pow(10,y))%10;N==""?N=w[M].toUpperCase():N+=w[M]}return N},abbreviationLength(o){return o==1?1:Math.pow(Math.floor(o/2)+1,2)*2},getAbbreviationAndValue(o){let b=o.log(118).toNumber(),w=Math.floor(b)+1,N=e.elemental.abbreviationLength(w),y=b-w+1,M=Math.floor(y*N),F=e.elemental.getAbbreviation(w,y),$=new t(118).pow(w+M/N-1);return[F,$]},formatElementalPart(o,b){return b.eq(1)?o:`${b.toString()} ${o}`},format(o,b=2){if(o.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(o.log10(),b);let w=o.log(118),y=w.log(118).log(118).toNumber(),M=Math.max(4-y*2,1),F=[];for(;w.gte(1)&&F.length=M)return F.map(j=>e.elemental.formatElementalPart(j[0],j[1])).join(" + ");let $=new t(118).pow(w).toFixed(F.length===1?3:b);return F.length===0?$:F.length===1?`${$} \xD7 ${e.elemental.formatElementalPart(F[0][0],F[0][1])}`:`${$} \xD7 (${F.map(j=>e.elemental.formatElementalPart(j[0],j[1])).join(" + ")})`}},old_sc:{format(o,b){o=new t(o);let w=o.log10().floor();if(w.lt(9))return w.lt(3)?o.toFixed(b):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let y=o.slog();return(y.gte(1e9)?"":t.dTen.pow(y.sub(y.floor())).toFixed(4))+"F"+e.old_sc.format(y.floor(),0)}let N=o.div(t.dTen.pow(w));return(w.log10().gte(9)?"":N.toFixed(4))+"e"+e.old_sc.format(w,0)}}},eng:{format(o,b=2){o=new t(o);let w=o.log10().floor();if(w.lt(9))return w.lt(3)?o.toFixed(b):o.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(o.gte("eeee10")){let y=o.slog();return(y.gte(1e9)?"":t.dTen.pow(y.sub(y.floor())).toFixed(4))+"F"+e.eng.format(y.floor(),0)}let N=o.div(new t(1e3).pow(w.div(3).floor()));return(w.log10().gte(9)?"":N.toFixed(new t(4).sub(w.sub(w.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(w.div(3).floor().mul(3),0)}}},mixed_sc:{format(o,b,w=9){o=new t(o);let N=o.log10().floor();return N.lt(303)&&N.gte(w)?g(o,b,w,"st"):g(o,b,w,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(o,b=2,w){o=new t(o);let N=o.max(1).log10().max(1).log(r.log10()).floor();if(N.lte(0))return g(o,b,w,"sc");o=t.dTen.pow(o.max(1).log10().div(r.log10().pow(N)).sub(N.gte(1)?1:0));let y=N.div(10).floor(),M=N.toNumber()%10-1;return g(o,Math.max(4,b),w,"sc")+" "+(y.gte(1)?"meta"+(y.gte(2)?"^"+g(y,0,w,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(o){return lt[0][0][o%10]+lt[0][1][Math.floor(o/10)%10]+lt[0][2][Math.floor(o/100)]},tier2(o){let b=o%10,w=Math.floor(o/10)%10,N=Math.floor(o/100)%10,y="";return o<10?lt[1][0][o]:(w==1&&b==0?y+="Vec":y+=lt[1][1][b]+lt[1][2][w],y+=lt[1][3][N],y)}},inf:{format(o,b,w){o=new t(o);let N=0,y=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],F=["","","m","mm","mmm"];for(;o.gte(y);)o=o.log(y),N++;return N==0?g(o,b,w,"sc"):o.gte(3)?F[N]+M[N]+"\u03C9^"+g(o.sub(1),b,w,"sc"):o.gte(2)?F[N]+"\u03C9"+M[N]+"-"+g(y.pow(o.sub(2)),b,w,"sc"):F[N]+M[N]+"-"+g(y.pow(o.sub(1)),b,w,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(o,b=new t(1e15),w=!1,N=9){if(o=new t(o),b=new t(b).div(1e3),o.lt(b.mul(1e3)))return"";let{alphabet:y}=e.alphabet.config,M=y.length,F=o.log(1e3).sub(b.log(1e3)).floor(),$=F.add(1).log(M+1).ceil(),j="",z=(X,nt)=>{let J=X,et="";for(let rt=0;rt=M)return"\u03C9";et=y[ct]+et,J=J.sub(1).div(M).floor()}return et};if($.lt(N))j=z(F,$);else{let X=$.sub(N).add(1),nt=F.div(t.pow(M+1,X.sub(1))).floor();j=`${z(nt,new t(N))}(${X.gt("1e9")?X.format():X.format(0)})`}return j},format(o,b=2,w=9,N="mixed_sc",y=new t(1e15),M=!1,F){if(o=new t(o),y=new t(y).div(1e3),o.lt(y.mul(1e3)))return g(o,b,w,N);let $=e.alphabet.getAbbreviation(o,y,M,F),j=o.div(t.pow(1e3,o.log(1e3).floor()));return`${$.length>(F??9)+2?"":j.toFixed(b)+" "}${$}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",s="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function a(o){return o.toFixed(0).split("").map(b=>b==="-"?"\u208B":i[parseInt(b,10)]).join("")}function u(o){return o.toFixed(0).split("").map(b=>b==="-"?"\u208B":s[parseInt(b,10)]).join("")}function f(o,b=2,w=9,N="st"){return g(o,b,w,N)}function g(o,b=2,w=9,N="mixed_sc"){o=new t(o);let y=o.lt(0)?"-":"";if(o.mag==1/0)return y+"Infinity";if(Number.isNaN(o.mag))return y+"NaN";if(o.lt(0)&&(o=o.mul(-1)),o.eq(0))return o.toFixed(b);let M=o.log10().floor();switch(N){case"sc":case"scientific":if(o.log10().lt(Math.min(-b,0))&&b>1){let F=o.log10().ceil(),$=o.div(F.eq(-1)?new t(.1):t.dTen.pow(F)),j=F.mul(-1).max(1).log10().gte(9);return y+(j?"":$.toFixed(2))+"e"+g(F,0,w,"mixed_sc")}else if(M.lt(w)){let F=Math.max(Math.min(b-M.toNumber(),b),0);return y+(F>0?o.toFixed(F):o.toFixed(F).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(o.gte("eeee10")){let j=o.slog();return(j.gte(1e9)?"":t.dTen.pow(j.sub(j.floor())).toFixed(2))+"F"+g(j.floor(),0)}let F=o.div(t.dTen.pow(M)),$=M.log10().gte(9);return y+($?"":F.toFixed(2))+"e"+g(M,0,w,"mixed_sc")}case"st":case"standard":{let F=o.log(1e3).floor();if(F.lt(1))return y+o.toFixed(Math.max(Math.min(b-M.toNumber(),b),0));let $=F.mul(3),j=F.log10().floor();if(j.gte(3e3))return"e"+g(M,b,w,"st");let z="";if(F.lt(4))z=["","K","M","B"][Math.round(F.toNumber())];else{let J=Math.floor(F.log(1e3).toNumber());for(J<100&&(J=Math.max(J-1,0)),F=F.sub(1).div(t.dTen.pow(J*3));F.gt(0);){let et=F.div(1e3).floor(),rt=F.sub(et.mul(1e3)).floor().toNumber();rt>0&&(rt==1&&!J&&(z="U"),J&&(z=e.standard.tier2(J)+(z?"-"+z:"")),rt>1&&(z=e.standard.tier1(rt)+z)),F=et,J++}}let X=o.div(t.dTen.pow($)),nt=b===2?t.dTwo.sub(M.sub($)).add(1).toNumber():b;return y+(j.gte(10)?"":X.toFixed(nt)+" ")+z}default:return e[N]||console.error('Invalid format type "',N,'"'),y+e[N].format(o,b,w)}}function l(o,b,w="mixed_sc",N,y){o=new t(o),b=new t(b);let M=o.add(b),F,$=M.div(o);return $.gte(10)&&o.gte(1e100)?($=$.log10().mul(20),F="(+"+g($,N,y,w)+" OoMs/sec)"):F="(+"+g(b,N,y,w)+"/sec)",F}function S(o,b=2,w="s"){return o=new t(o),o.gte(86400)?g(o.div(86400).floor(),0,12,"sc")+":"+S(o.mod(86400),b,"d"):o.gte(3600)||w=="d"?(o.div(3600).gte(10)||w!="d"?"":"0")+g(o.div(3600).floor(),0,12,"sc")+":"+S(o.mod(3600),b,"h"):o.gte(60)||w=="h"?(o.div(60).gte(10)||w!="h"?"":"0")+g(o.div(60).floor(),0,12,"sc")+":"+S(o.mod(60),b,"m"):(o.gte(10)||w!="m"?"":"0")+g(o,b,12,"sc")}function E(o,b=!1,w=0,N=9,y="mixed_sc"){let M=kt=>g(kt,w,N,y);o=new t(o);let F=o.mul(1e3).mod(1e3).floor(),$=o.mod(60).floor(),j=o.div(60).mod(60).floor(),z=o.div(3600).mod(24).floor(),X=o.div(86400).mod(365.2425).floor(),nt=o.div(31556952).floor(),J=nt.eq(1)?" year":" years",et=X.eq(1)?" day":" days",rt=z.eq(1)?" hour":" hours",ct=j.eq(1)?" minute":" minutes",qt=$.eq(1)?" second":" seconds",Pt=F.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+J+", ":""}${X.gt(0)?M(X)+et+", ":""}${z.gt(0)?M(z)+rt+", ":""}${j.gt(0)?M(j)+ct+", ":""}${$.gt(0)?M($)+qt+",":""}${b&&F.gt(0)?" "+M(F)+Pt:""}`.replace(/,([^,]*)$/,"$1").trim()}function V(o){return o=new t(o),g(t.dOne.sub(o).mul(100))+"%"}function q(o){return o=new t(o),g(o.mul(100))+"%"}function U(o,b=2){return o=new t(o),o.gte(1)?"\xD7"+o.format(b):"/"+o.pow(-1).format(b)}function _(o,b,w=10){return t.gte(o,10)?t.pow(w,t.log(o,w).pow(b)):new t(o)}function k(o,b=0){o=new t(o);let w=(F=>F.map(($,j)=>({name:$.name,altName:$.altName,value:t.pow(1e3,new t(j).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),N="",y=o.lte(0)?0:t.min(t.log(o,1e3).sub(1),w.length-1).floor().toNumber(),M=w[y];if(y===0)switch(b){case 1:N="";break;case 2:case 0:default:N=o.format();break}switch(b){case 1:N=M.name;break;case 2:N=o.divide(M.value).format();break;case 3:N=M.altName;break;case 0:default:N=`${o.divide(M.value).format()} ${M.name}`;break}return N}function x(o,b=!1){return`${k(o,2)} ${k(o,1)}eV${b?"/c^2":""}`}let Z={...e,toSubscript:a,toSuperscript:u,formatST:f,format:g,formatGain:l,formatTime:S,formatTimeLong:E,formatReduction:V,formatPercent:q,formatMult:U,expMult:_,metric:k,ev:x};return{FORMATS:e,formats:Z}}var xt=17,W=9e15,Pe=Math.log10(9e15),mt=1/9e15,ke=308,Le=-324,ie=5,Ve=1023,xe=!0,Ue=!1,je=function(){let t=[];for(let r=Le+1;r<=ke;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),gt=[2,Math.E,3,4,5,6,7,8,9,10],Ge=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],Re=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],m=function(e){return n.fromValue_noAlloc(e)},T=function(t,e,r){return n.fromComponents(t,e,r)},p=function(e,r,i){return n.fromComponents_noNormalize(e,r,i)},ft=function(e,r){let i=r+1,s=Math.ceil(Math.log10(Math.abs(e))),a=Math.round(e*Math.pow(10,i-s))*Math.pow(10,s-i);return parseFloat(a.toFixed(Math.max(i-s,0)))},Ut=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},$e=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,s=t;return r=r+1/(12*s),s=s*i,r=r-1/(360*s),s=s*i,r=r+1/(1260*s),s=s*i,r=r-1/(1680*s),s=s*i,r=r+1/(1188*s),s=s*i,r=r-691/(360360*s),s=s*i,r=r+7/(1092*s),s=s*i,r=r-3617/(122400*s),Math.exp(r)/e},Ze=.36787944117144233,ne=.5671432904097838,jt=function(t,e=1e-10,r=!0){let i,s;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ne;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let a=0;a<100;++a){if(s=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(s-i).5?1:-1;if(Math.random()*20<1)return p(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let s=Math.pow(10,i);return Math.random()>.9&&(s=Math.trunc(s)),T(e,r,s)}static affordGeometricSeries_core(t,e,r,i){let s=e.mul(r.pow(i));return n.floor(t.div(s).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(n.sub(1,r.pow(t))).div(n.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r)).sub(r.div(2)),u=a.pow(2);return a.neg().add(u.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r));return t.div(2).mul(s.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=W)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=n.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);xe?t=t.replace(",",""):Ue&&(t=t.replace(",","."));let s=t.split("^^^");if(s.length===2){let _=parseFloat(s[0]),k=parseFloat(s[1]),x=s[1].split(";"),Z=1;if(x.length===2&&(Z=parseFloat(x[1]),isFinite(Z)||(Z=1)),isFinite(_)&&isFinite(k)){let o=n.pentate(_,k,Z,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let a=t.split("^^");if(a.length===2){let _=parseFloat(a[0]),k=parseFloat(a[1]),x=a[1].split(";"),Z=1;if(x.length===2&&(Z=parseFloat(x[1]),isFinite(Z)||(Z=1)),isFinite(_)&&isFinite(k)){let o=n.tetrate(_,k,Z,e);return this.sign=o.sign,this.layer=o.layer,this.mag=o.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}let u=t.split("^");if(u.length===2){let _=parseFloat(u[0]),k=parseFloat(u[1]);if(isFinite(_)&&isFinite(k)){let x=n.pow(_,k);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}t=t.trim().toLowerCase();let f,g,l=t.split("pt");if(l.length===2){f=10;let _=!1;l[0].startsWith("-")&&(_=!0,l[0]=l[0].slice(1)),g=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let k=parseFloat(l[1]);if(isFinite(k)||(k=1),isFinite(f)&&isFinite(g)){let x=n.tetrate(f,g,k,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),_&&(this.sign*=-1),this}}if(l=t.split("p"),l.length===2){f=10;let _=!1;l[0].startsWith("-")&&(_=!0,l[0]=l[0].slice(1)),g=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let k=parseFloat(l[1]);if(isFinite(k)||(k=1),isFinite(f)&&isFinite(g)){let x=n.tetrate(f,g,k,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),_&&(this.sign*=-1),this}}if(l=t.split("f"),l.length===2){f=10;let _=!1;l[0].startsWith("-")&&(_=!0,l[0]=l[0].slice(1)),l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let k=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),g=parseFloat(l[1]),isFinite(k)||(k=1),isFinite(f)&&isFinite(g)){let x=n.tetrate(f,g,k,e);return this.sign=x.sign,this.layer=x.layer,this.mag=x.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),_&&(this.sign*=-1),this}}let S=t.split("e"),E=S.length-1;if(E===0){let _=parseFloat(t);if(isFinite(_))return this.fromNumber(_),n.fromStringCache.size>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else if(E===1){let _=parseFloat(t);if(isFinite(_)&&_!==0)return this.fromNumber(_),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}let V=t.split("e^");if(V.length===2){this.sign=1,V[0].startsWith("-")&&(this.sign=-1);let _="";for(let k=0;k=43&&x<=57||x===101)_+=V[1].charAt(k);else{if(this.layer=parseFloat(_),this.mag=parseFloat(V[1].substr(k+1)),this.layer<0||this.layer%1!=0){let Z=n.tetrate(10,this.layer,this.mag,e);this.sign=Z.sign,this.layer=Z.layer,this.mag=Z.mag}return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}}}if(E<1)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let q=parseFloat(S[0]);if(q===0)return this.sign=0,this.layer=0,this.mag=0,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this;let U=parseFloat(S[S.length-1]);if(E>=2){let _=parseFloat(S[S.length-2]);isFinite(_)&&(U*=Math.sign(_),U+=Ut(_))}if(!isFinite(q))this.sign=S[0]==="-"?-1:1,this.layer=E,this.mag=U;else if(E===1)this.sign=Math.sign(q),this.layer=1,this.mag=U+Math.log10(Math.abs(q));else if(this.sign=Math.sign(q),this.layer=E,E===2){let _=n.mul(T(1,2,U),m(q));return this.sign=_.sign,this.layer=_.layer,this.mag=_.mag,n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}else this.mag=U;return this.normalize(),n.fromStringCache.maxSize>=1&&n.fromStringCache.set(r,n.fromDecimal(this)),this}fromValue(t){return t instanceof n?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ft(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ft(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ie?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ft(this.m,t)+"e"+ft(this.e,t):this.layer===1?ft(this.m,t)+"e"+ft(this.e,t):this.layer<=ie?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ft(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ft(this.mag,t)}abs(){return p(this.sign===0?0:1,this.layer,this.mag)}neg(){return p(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?p(0,0,0):this.layer===0?T(this.sign,0,Math.round(this.mag)):new n(this)}floor(){return this.mag<0?this.sign===-1?p(-1,0,1):p(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?T(this.sign,0,Math.floor(this.mag)):new n(this)}ceil(){return this.mag<0?this.sign===1?p(1,0,1):p(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?T(this.sign,0,Math.ceil(this.mag)):new n(this)}trunc(){return this.mag<0?p(0,0,0):this.layer===0?T(this.sign,0,Math.trunc(this.mag)):new n(this)}add(t){let e=m(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return p(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0)return new n(e);if(e.sign===0)return new n(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return p(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(n.cmpabs(this,e)>0?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*r.mag+i.sign*i.mag);let s=r.layer*Math.sign(r.mag),a=i.layer*Math.sign(i.mag);if(s-a>=2)return r;if(s===0&&a===-1){if(Math.abs(i.mag-Math.log10(r.mag))>xt)return r;{let u=Math.pow(10,Math.log10(r.mag)-i.mag),f=i.sign+r.sign*u;return T(Math.sign(f),1,i.mag+Math.log10(Math.abs(f)))}}if(s===1&&a===0){if(Math.abs(r.mag-Math.log10(i.mag))>xt)return r;{let u=Math.pow(10,r.mag-Math.log10(i.mag)),f=i.sign+r.sign*u;return T(Math.sign(f),1,Math.log10(i.mag)+Math.log10(Math.abs(f)))}}if(Math.abs(r.mag-i.mag)>xt)return r;{let u=Math.pow(10,r.mag-i.mag),f=i.sign+r.sign*u;return T(Math.sign(f),1,i.mag+Math.log10(Math.abs(f)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(m(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=m(t);if(this.eq(n.dInf)&&e.eq(n.dNegInf)||this.eq(n.dNegInf)&&e.eq(n.dInf))return p(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(n.dZero)||this.eq(n.dZero)&&this.mag==Number.POSITIVE_INFINITY)return p(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new n(this);if(!Number.isFinite(e.layer))return new n(e);if(this.sign===0||e.sign===0)return p(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return p(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new n(this),i=new n(e)):(r=new n(e),i=new n(this)),r.layer===0&&i.layer===0)return n.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return T(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return T(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return T(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let s=T(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(T(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return T(r.sign*i.sign,s.layer+1,s.sign*s.mag)}if(r.layer===2&&i.layer===2){let s=T(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(T(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return T(r.sign*i.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=m(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?p(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?p(0,0,0):this.layer===0?T(this.sign,0,1/this.mag):T(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t,e=!1){let r=m(t),i=r.abs();if(this.eq(n.dZero)||i.eq(n.dZero))return p(0,0,0);if(e){let u=this.abs().mod(i);return this.sign==-1!=(r.sign==-1)&&(u=r.abs().sub(u)),u.mul(r.sign)}let s=this.toNumber(),a=i.toNumber();return isFinite(s)&&isFinite(a)&&s!=0&&a!=0?new n(s%a):this.sub(i).eq(this)?p(0,0,0):i.sub(this).eq(i)?new n(this):this.sign==-1?this.abs().mod(i).neg():this.sub(this.div(i).floor().mul(i))}modulo(t,e=!1){return this.mod(t,e)}modular(t,e=!1){return this.mod(t,e)}cmp(t){let e=m(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new n(e):new n(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=m(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=m(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,s=r.mag;return this.layer>r.layer&&(s=Ut(s)),this.layer0?T(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):T(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?p(Number.NaN,Number.NaN,Number.NaN):this.layer>0?T(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):T(this.sign,0,Math.log10(this.mag))}log(t){return t=m(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?p(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?T(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):n.div(this.log10(),t.log10())}log2(){return this.sign<=0?p(Number.NaN,Number.NaN,Number.NaN):this.layer===0?T(this.sign,0,Math.log2(this.mag)):this.layer===1?T(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?T(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):T(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?p(Number.NaN,Number.NaN,Number.NaN):this.layer===0?T(this.sign,0,Math.log(this.mag)):this.layer===1?T(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?T(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):T(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=m(t),r=new n(this),i=new n(e);if(r.sign===0)return i.eq(0)?p(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return p(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let s=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?s.neg():Math.abs(i.toNumber()%2)%2===0?s:p(Number.NaN,Number.NaN,Number.NaN):s}pow10(){if(this.eq(n.dInf))return p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(n.dNegInf))return p(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return p(Number.NaN,Number.NaN,Number.NaN);let t=new n(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return T(1,0,e);if(t.sign===0)return p(1,0,1);t=p(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?T(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?T(-t.sign,t.layer+1,-t.mag):p(1,0,1)}pow_base(t){return m(t).pow(this)}root(t){let e=m(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(p(1,0,24)))return n.fromNumber($e(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,s=12*i,a=1/s,u=e+a;if(u===e||(e=u,i=i*r,s=360*i,a=1/s,u=e-a,u===e))return n.exp(e);e=u,i=i*r,s=1260*i;let f=1/s;return e=e+f,i=i*r,s=1680*i,f=1/s,e=e-f,n.exp(e)}else return this.layer===1?n.exp(n.mul(this,n.ln(this).sub(1))):n.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?p(1,0,1):this.layer===0&&this.mag<=709.7?n.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?T(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?T(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):T(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return n.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return T(1,2,Math.log10(this.mag)-.3010299956639812);{let t=n.div(p(this.sign,this.layer-1,this.mag),p(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=p(1,0,1),r=!1){if(t===1)return n.pow(this,e);if(t===0)return new n(e);if(this.eq(n.dOne))return p(1,0,1);if(this.eq(-1))return n.pow(this,e);if(t===Number.POSITIVE_INFINITY){let a=this.toNumber();if(a<=1.444667861009766&&a>=.06598803584531254){let u=n.ln(this).neg(),f=u.lambertw().div(u);if(a<1)return f;let g=u.lambertw(!1).div(u);return a>1.444667861009099&&(f=g=n.fromNumber(Math.E)),e=m(e),e.eq(g)?g:e.lt(g)?f:p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return a>1.444667861009766?p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):p(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(n.dZero)){let a=Math.abs((t+1)%2);return a>1&&(a=2-a),n.fromNumber(a)}if(t<0)return n.iteratedlog(e,this,-t,r);e=new n(e);let i=t;t=Math.trunc(t);let s=i-t;if(this.gt(n.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(n.ln(this).neg().lambertw(!1).div(n.ln(this).neg())))&&(i>1e4||!r)){let a=Math.min(1e4,t);e.eq(n.dOne)?e=this.pow(s):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this);for(let u=0;u1e4&&Math.ceil(i)%2==1?this.pow(e):e}s!==0&&(e.eq(n.dOne)?this.gt(10)||r?e=this.pow(s):(e=n.fromNumber(n.tetrate_critical(this.toNumber(),s)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(s,r):this.lt(1)?e=e.pow(1-s).mul(this.pow(e).pow(s)):e=e.layeradd(s,this,r));for(let a=0;a3)return p(e.sign,e.layer+(t-a-1),e.mag);if(a>1e4)return e}return e}iteratedexp(t=2,e=p(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return n.tetrate(t,-e,this,r);t=m(t);let i=n.fromDecimal(this),s=e;e=Math.trunc(e);let a=s-e;if(i.layer-t.layer>3){let u=Math.min(e,i.layer-t.layer-3);e-=u,i.layer-=u}for(let u=0;u1e4)return i}return a>0&&a<1&&(t.eq(10)?i=i.layeradd10(-a,r):i=i.layeradd(-a,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,s=!1,a=!1,u=this.slog_internal(t,r).toNumber();for(let f=1;f1&&a!=l&&(s=!0),a=l,s?i/=2:i*=2,i=Math.abs(i)*(l?-1:1),u+=i,i===0)break}return n.fromNumber(u)}slog_internal(t=10,e=!1){if(t=m(t),t.lte(n.dZero)||t.eq(n.dOne))return p(Number.NaN,Number.NaN,Number.NaN);if(t.lt(n.dOne))return this.eq(n.dOne)?p(0,0,0):this.eq(n.dZero)?p(-1,0,1):p(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(n.dZero))return p(-1,0,1);if(t.lt(1.444667861009766)){let s=n.ln(t).neg(),a=s.lambertw().div(s);if(this.eq(a))return p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(a))return p(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=n.fromDecimal(this);if(i.layer-t.layer>3){let s=i.layer-t.layer-3;r+=s,i.layer-=s}for(let s=0;s<100;++s)if(i.lt(n.dZero))i=n.pow(t,i),r-=1;else{if(i.lte(n.dOne))return e?n.fromNumber(r+i.toNumber()-1):n.fromNumber(r+n.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=n.log(i,t)}return n.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:n.critical_section(t,e,Re)}static tetrate_critical(t,e){return n.critical_section(t,e,Ge)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let s=0,a=0;for(let f=0;ft){let g=(t-gt[f])/(gt[f+1]-gt[f]);s=r[f][Math.floor(e)]*(1-g)+r[f+1][Math.floor(e)]*g,a=r[f][Math.ceil(e)]*(1-g)+r[f+1][Math.ceil(e)]*g;break}let u=e-Math.floor(e);return s<=0||a<=0?s*(1-u)+a*u:Math.pow(t,Math.log(s)/Math.log(t)*(1-u)+Math.log(a)/Math.log(t)*u)}layeradd10(t,e=!1){t=n.fromValue_noAlloc(t).toNumber();let r=n.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=m(e);if(i.gt(1)&&i.lte(1.444667861009766)){let u=n.excess_slog(this,e,r),f=u[0].toNumber(),g=u[1],l=f+t,S=n.ln(e).neg(),E=S.lambertw().div(S),V=S.lambertw(!1).div(S),q=n.dOne;g==1?q=E.mul(V).sqrt():g==2&&(q=V.mul(2));let U=i.pow(q),_=Math.floor(l),k=l-_,x=q.pow(1-k).mul(U.pow(k));return n.tetrate(i,_,x,r)}let a=this.slog(e,100,r).toNumber()+t;return a>=0?n.tetrate(e,a,n.dOne,r):Number.isFinite(a)?a>=-1?n.log(n.tetrate(e,a+1,n.dOne,r),e):n.log(n.log(n.tetrate(e,a+2,n.dOne,r),e),e):p(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=m(t),e=m(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[p(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let s=n.ln(e).neg(),a=s.lambertw().div(s),u=n.dInf;if(e>1&&(u=s.lambertw(!1).div(s)),e>1.444667861009099&&(a=u=n.fromNumber(Math.E)),t.lt(a))return[t.slog(e,100,r),0];if(t.eq(a))return[p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(u))return[p(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(u)){let f=u.mul(2),g=i.pow(f),l=0;if(t.gte(f)&&t.lt(g))l=0;else if(t.gte(g)){let _=g;for(l=1;_.lt(t);)if(_=i.pow(_),l=l+1,_.layer>3){let k=Math.floor(t.layer-_.layer+1);_=i.iteratedexp(k,_,r),l=l+k}_.gt(t)&&(_=_.log(e),l=l-1)}else if(t.lt(f)){let _=f;for(l=0;_.gt(t);)_=_.log(e),l=l-1}let S=0,E=0,V=.5,q=f,U=n.dZero;for(;V>1e-16;){if(E=S+V,q=f.pow(1-E).mul(g.pow(E)),U=n.iteratedexp(e,l,q),U.eq(t))return[new n(l+E),2];U.lt(t)&&(S+=V),V/=2}return U.neq_tolerance(t,1e-7)?[p(Number.NaN,Number.NaN,Number.NaN),0]:[new n(l+S),2]}if(t.lt(u)&&t.gt(a)){let f=a.mul(u).sqrt(),g=i.pow(f),l=0;if(t.lte(f)&&t.gt(g))l=0;else if(t.lte(g)){let _=g;for(l=1;_.gt(t);)_=i.pow(_),l=l+1;_.lt(t)&&(_=_.log(e),l=l-1)}else if(t.gt(f)){let _=f;for(l=0;_.lt(t);)_=_.log(e),l=l-1}let S=0,E=0,V=.5,q=f,U=n.dZero;for(;V>1e-16;){if(E=S+V,q=f.pow(1-E).mul(g.pow(E)),U=n.iteratedexp(e,l,q),U.eq(t))return[new n(l+E),1];U.gt(t)&&(S+=V),V/=2}return U.neq_tolerance(t,1e-7)?[p(Number.NaN,Number.NaN,Number.NaN),0]:[new n(l+S),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?p(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new n(this):this.mag<0?n.fromNumber(jt(this.toNumber())):this.layer===0?n.fromNumber(jt(this.sign*this.mag)):this.lt("eee15")?se(this):this.ln():this.sign===1?p(Number.NaN,Number.NaN,Number.NaN):this.layer===0?n.fromNumber(jt(this.sign*this.mag,1e-10,!1)):this.layer==1?se(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(n.dInf))return p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return p(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return n.fromNumber(t).add(2).pow(this.recip());if(t<=0)return p(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eZe?this.pow(this.recip()):p(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return p(1,0,1);if(this.lt(0))return p(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new n(this):p(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=n.dTen;this.gte(n.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=n.dZero,i=e.layer,s=e.iteratedlog(10,i,!0),a=s,u=s.div(2),f=!0;for(;f;)u=r.add(s).div(2),n.iteratedexp(10,i,u,!0).tetrate(t,1,!0).gt(this)?s=u:r=u,u.eq(a)?f=!1:a=u;return n.iteratedexp(10,i,u,!0)}else{let e=1,r=T(1,10,1),i=T(1,10,1),s=T(1,10,1),a=T(1,1,-16),u=n.dZero,f=T(1,10,1),g=a.pow10().recip(),l=n.dZero,S=g,E=g,V=Math.ceil(t)%2==0,q=0,U=T(1,10,1),_=!1,k=n.dZero,x=!1;for(;e<4;){if(e==2){if(V)break;s=T(1,10,1),a=r,e=3,f=T(1,10,1),U=T(1,10,1)}for(_=!1;a.neq(s);){if(k=a,a.pow10().recip().tetrate(t,1,!0).eq(1)&&a.pow10().recip().lt(.4))g=a.pow10().recip(),S=a.pow10().recip(),E=a.pow10().recip(),l=n.dZero,q=-1,e==3&&(U=a);else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip())&&!V&&a.pow10().recip().lt(.4))g=a.pow10().recip(),S=a.pow10().recip(),E=a.pow10().recip(),l=n.dZero,q=0;else if(a.pow10().recip().tetrate(t,1,!0).eq(a.pow10().recip().mul(2).tetrate(t,1,!0)))g=a.pow10().recip(),S=n.dZero,E=g.mul(2),l=g,V?q=-1:q=0;else{for(u=a.mul(12e-17),g=a.pow10().recip(),S=a.add(u).pow10().recip(),l=g.sub(S),E=g.add(l);S.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||E.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||S.gte(g)||E.lte(g);)u=u.mul(2),S=a.add(u).pow10().recip(),l=g.sub(S),E=g.add(l);if((e==1&&E.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&S.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&E.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&S.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(U=a),E.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))q=-1;else if(V)q=1;else if(e==3&&a.gt_tolerance(r,1e-8))q=0;else{for(;S.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||E.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||S.gte(g)||E.lte(g);)u=u.mul(2),S=a.add(u).pow10().recip(),l=g.sub(S),E=g.add(l);E.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.tetrate(t,1,!0).sub(S.tetrate(t,1,!0)))?q=0:q=1}}if(q==-1&&(x=!0),e==1&&q==1||e==3&&q!=0)if(s.eq(T(1,10,1)))a=a.mul(2);else{let w=!1;if(_&&(q==1&&e==1||q==-1&&e==3)&&(w=!0),a=a.add(s).div(2),w)break}else if(s.eq(T(1,10,1)))s=a,a=a.div(2);else{let w=!1;if(_&&(q==1&&e==1||q==-1&&e==3)&&(w=!0),s=s.sub(f),a=a.sub(f),w)break}if(s.sub(a).div(2).abs().gt(f.mul(1.5))&&(_=!0),f=s.sub(a).div(2).abs(),a.gt("1e18")||a.eq(k))break}if(a.gt("1e18")||!x||U==T(1,10,1))break;e==1?r=U:e==3&&(i=U),e++}s=r,a=T(1,1,-18);let Z=a,o=n.dZero,b=!0;for(;b;)if(s.eq(T(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(Z)?b=!1:Z=o,a.gt("1e18"))return p(Number.NaN,Number.NaN,Number.NaN);if(o.eq_tolerance(r,1e-15)){if(i.eq(T(1,10,1)))return p(Number.NaN,Number.NaN,Number.NaN);for(s=T(1,10,1),a=i,Z=a,o=n.dZero,b=!0;b;)if(s.eq(T(1,10,1))?o=a.mul(2):o=s.add(a).div(2),n.pow(10,o).recip().tetrate(t,1,!0).gt(this)?a=o:s=o,o.eq(Z)?b=!1:Z=o,a.gt("1e18"))return p(Number.NaN,Number.NaN,Number.NaN);return o.pow10().recip()}else return o.pow10().recip()}}static increasingInverse(t,e=!1,r=120,i=n.dLayerMax.neg(),s=n.dLayerMax,a=n.dLayerMax.neg(),u=n.dLayerMax){return function(f){if(f=new n(f),i=new n(i),s=new n(s),a=new n(a),u=new n(u),f.isNan()||s.lt(i)||f.lt(a)||f.gt(u))return p(Number.NaN,Number.NaN,Number.NaN);let g=function(N){return new n(N)},l=!0;if(s.lt(0))l=!1;else if(i.gt(0))l=!0;else{let N=t(n.dZero);if(N.eq(f))return p(0,0,0);l=f.gt(N),e&&(l=!l)}let S=l,E;if(l){if(s.lt(mt))l=!0;else if(i.gt(mt))l=!1;else{let N=t(new n(mt));l=f.lt(N),e&&(l=!l)}if(l){E=!0;let N=n.pow(10,W).recip();if(s.lt(N))l=!1;else if(i.gt(N))l=!0;else{let y=t(new n(N));l=f.gt(y),e&&(l=!l)}if(l)g=function(y){return n.pow(10,y).recip()};else{let y=n.tetrate(10,W);if(s.lt(y))l=!1;else if(i.gt(y))l=!0;else{let M=t(new n(y));l=f.gt(M),e&&(l=!l)}l?g=function(M){return n.tetrate(10,new n(M).toNumber()).recip()}:g=function(M){return new n(M).gt(Math.log10(Number.MAX_VALUE))?n.dZero:n.tetrate(10,n.pow(10,M).toNumber()).recip()}}}else{if(E=!1,s.lt(W))l=!0;else if(i.gt(W))l=!1;else{let N=t(new n(W));l=f.lt(N),e&&(l=!l)}if(l)g=function(N){return new n(N)};else{let N=n.pow(10,W);if(s.lt(N))l=!0;else if(i.gt(N))l=!1;else{let y=t(new n(N));l=f.lt(y),e&&(l=!l)}if(l)g=function(y){return n.pow(10,y)};else{let y=n.tetrate(10,W);if(s.lt(y))l=!0;else if(i.gt(y))l=!1;else{let M=t(new n(y));l=f.lt(M),e&&(l=!l)}l?g=function(M){return n.tetrate(10,new n(M).toNumber())}:g=function(M){return new n(M).gt(Math.log10(Number.MAX_VALUE))?n.dInf:n.tetrate(10,n.pow(10,M).toNumber())}}}}}else{if(E=!0,s.lt(-mt))l=!1;else if(i.gt(-mt))l=!0;else{let N=t(new n(-mt));l=f.gt(N),e&&(l=!l)}if(l){let N=n.pow(10,W).recip().neg();if(s.lt(N))l=!0;else if(i.gt(N))l=!1;else{let y=t(new n(N));l=f.lt(y),e&&(l=!l)}if(l)g=function(y){return n.pow(10,y).recip().neg()};else{let y=n.tetrate(10,W).neg();if(s.lt(y))l=!0;else if(i.gt(y))l=!1;else{let M=t(new n(y));l=f.lt(M),e&&(l=!l)}l?g=function(M){return n.tetrate(10,new n(M).toNumber()).recip().neg()}:g=function(M){return new n(M).gt(Math.log10(Number.MAX_VALUE))?n.dZero:n.tetrate(10,n.pow(10,M).toNumber()).recip().neg()}}}else{if(E=!1,s.lt(-W))l=!1;else if(i.gt(-W))l=!0;else{let N=t(new n(-W));l=f.gt(N),e&&(l=!l)}if(l)g=function(N){return n.neg(N)};else{let N=n.pow(10,W).neg();if(s.lt(N))l=!1;else if(i.gt(N))l=!0;else{let y=t(new n(N));l=f.gt(y),e&&(l=!l)}if(l)g=function(y){return n.pow(10,y).neg()};else{let y=n.tetrate(10,W).neg();if(s.lt(y))l=!1;else if(i.gt(y))l=!0;else{let M=t(new n(y));l=f.gt(M),e&&(l=!l)}l?g=function(M){return n.tetrate(10,new n(M).toNumber()).neg()}:g=function(M){return new n(M).gt(Math.log10(Number.MAX_VALUE))?n.dNegInf:n.tetrate(10,n.pow(10,M).toNumber()).neg()}}}}}let V=S!=E!=e,q=V?function(N,y){return n.gt(N,y)}:function(N,y){return n.lt(N,y)},U=.001,_=!1,k=!1,x=1,Z=n.dOne,o=0,b=!1;for(var w=1;w1&&k!=y&&(_=!0),k=y,_?U/=2:U*=2,y!=V&&Z.eq(s)||y==V&&Z.eq(i))return p(Number.NaN,Number.NaN,Number.NaN);if(U=Math.abs(U)*(y?-1:1),x+=U,U===0||o==x)break}return g(x)}}pentate(t=2,e=p(1,0,1),r=!1){e=new n(e);let i=t;t=Math.floor(t);let s=i-t,a=n.dZero,u=n.dZero;if(s!==0)if(e.eq(n.dOne))++t,e=n.fromNumber(s);else return this.pentate(e.penta_log(this,void 0,r).plus(i).toNumber(),1,r);if(t>0)for(let f=0;f1e4)return e}else for(let f=0;f<-t;++f){if(a=e,e=e.slog(this,void 0,r),e.eq(a)||!isFinite(e.layer)||!isFinite(e.mag))return e.normalize();if(f>100)return e}return e}penta_log(t=10,e=100,r=!1){if(t=new n(t),t.lte(1))return p(Number.NaN,Number.NaN,Number.NaN);if(this.eq(1))return p(0,0,0);if(this.eq(n.dInf))return p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);let i=new n(1),s=0,a=1;if(this.lt(-1)){if(this.lte(-2))return p(Number.NaN,Number.NaN,Number.NaN);let f=t.tetrate(this.toNumber(),1,r);if(this.eq(f))return p(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(f))return p(Number.NaN,Number.NaN,Number.NaN)}if(this.gt(1)){for(;i.lt(this);)if(s++,i=n.tetrate(t,i.toNumber(),1,r),s>1e3)return p(Number.NaN,Number.NaN,Number.NaN)}else for(;i.gt(this);)if(s--,i=n.slog(i,t,r),s>100)return p(Number.NaN,Number.NaN,Number.NaN);for(var u=1;u0&&t<1?this.root(t):this.eq(1)?p(1,0,1):this.lt(0)?p(Number.NaN,Number.NaN,Number.NaN):this.lt(1)?this.linear_sroot(t):n.increasingInverse(function(e){return n.pentate(e,t,1,!0)})(this):p(Number.NaN,Number.NaN,Number.NaN)}sin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.sin(this.sign*this.mag)):p(0,0,0)}cos(){return this.mag<0?p(1,0,1):this.layer===0?n.fromNumber(Math.cos(this.sign*this.mag)):p(0,0,0)}tan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.tan(this.sign*this.mag)):p(0,0,0)}asin(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.asin(this.sign*this.mag)):p(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?n.fromNumber(Math.acos(this.toNumber())):this.layer===0?n.fromNumber(Math.acos(this.sign*this.mag)):p(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new n(this):this.layer===0?n.fromNumber(Math.atan(this.sign*this.mag)):n.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return n.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return n.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?p(Number.NaN,Number.NaN,Number.NaN):n.ln(this.add(1).div(n.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new n(this):this.root(n.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new n(t).add(new n(e).minus(new n(t)).times(new n(r)).times(new n(i)))}clone(){return this}static clone(t){return n.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new n(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new n(t),e=new n(e);let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=i?s.mul(t.pow(e.sub(1))).root(e):s.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(s=i?s.div(t).max(1).log(e).add(t):n.pow(e,s.sub(t)).mul(t))),s}static scale(t,e,r,i,s=!1){return new n(t).scale(e,r,i,s)}format(t=2,e=9,r="mixed_sc"){return ht.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return ht.format(new n(t),e,r,i)}formatST(t=2,e=9,r="st"){return ht.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return ht.format(new n(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return ht.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,s){return ht.formatGain(new n(t),e,r,i,s)}toRoman(t=5e3){t=new n(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},s="";for(let a of Object.keys(i)){let u=Math.floor(r/i[a]);r-=u*i[a],s+=a.repeat(u)}return s}static toRoman(t,e){return new n(t).toRoman(e)}static random(t=0,e=1){return t=new n(t),e=new n(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new n(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new n(Math.random()).lt(t)}};n.dZero=p(0,0,0),n.dOne=p(1,0,1),n.dNegOne=p(-1,0,1),n.dTwo=p(1,0,2),n.dTen=p(1,0,10),n.dNaN=p(Number.NaN,Number.NaN,Number.NaN),n.dInf=p(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNegInf=p(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),n.dNumberMax=T(1,0,Number.MAX_VALUE),n.dNumberMin=T(1,0,Number.MIN_VALUE),n.dLayerSafeMax=T(1,Number.MAX_SAFE_INTEGER,W-1),n.dLayerSafeMin=T(1,Number.MAX_SAFE_INTEGER,-(W-1)),n.dLayerMax=T(1,Number.MAX_VALUE,W-1),n.dLayerMin=T(1,Number.MAX_VALUE,-(W-1)),n.fromStringCache=new Lt(Ve),tt([_t()],n.prototype,"sign",2),tt([_t()],n.prototype,"mag",2),tt([_t()],n.prototype,"layer",2),n=tt([Ae()],n);var{formats:ht,FORMATS:ze}=qe(n);n.formats=ht;var bt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.value=t.value,this.order=t.order??99,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>""}},Gt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=new n(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new bt(r))})}getBoosts(t,e){let r=[],i=[];for(let s=0;sE),l=s,S=this.getBoosts(a,!0);S[0][0]?this.boostArray[S[1][0]]=new bt({id:a,name:u,description:f,value:g,order:l}):this.boostArray.push(new bt({id:a,name:u,description:f,value:g,order:l}))}else{t=Array.isArray(t)?t:[t];for(let a of t){let u=this.getBoosts(a.id,!0);u[0][0]?this.boostArray[u[1][0]]=new bt(a):this.boostArray.push(new bt(a))}}}clearBoosts(){this.boostArray.length=0}calculate(t=this.baseEffect){let e=new n(t),r=this.boostArray;r=r.sort((i,s)=>i.order-s.order);for(let i of r)e=i.value(e);return e}},dr=dt(Nt()),At=30,Rt=.001;function Ye(t,e,r="geometric"){switch(t=new n(t),e=new n(e),r){case"arithmetic":case 1:return t.add(e).div(2);case"geometric":case 2:default:return t.mul(e).sqrt();case"harmonic":case 3:return n.dTwo.div(t.reciprocal().add(e.reciprocal()))}}function $t(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=new n(t),e=new n(e),r=new n(r);let s,a;return i.mode==="geometric"?(s=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),a=s.lte(r)):(s=t.sub(e).abs(),a=s.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!a)&&console.log({a:t,b:e,tolerance:r,config:i,diff:s,result:a}),a}function Zt(t,e,r="geometric",i=At,s=Rt,a=1,u){if(a=new n(a),u=new n(u??e),a.gt(u)&&([a,u]=[u,a]),t(u).eq(0))return{value:n.dZero,lowerBound:n.dZero,upperBound:n.dZero};if(t(u).lt(e))return console.warn("eMath.js: The function is not monotonically increasing. (f(n) < n)"),{value:u,lowerBound:u,upperBound:u};for(let g=0;g=0;f--){let g=r.add(u.mul(f)),l=r.add(u.mul(f+1)),S=a;if(a=a.add(t(g).add(t(l)).div(2).mul(u)),$t(S,a,s,{verbose:!1,mode:"geometric"}))break}return a}function zt(t,e,r=0,i,s){return r=new n(r),e=new n(e),e.sub(r).lte(At)?ae(t,e,r,i):oe(t,e,r,s)}function Be(t,e=10,r=0,i=1e3){if(t=new n(t),e=new n(e),r=new n(r),i=new n(i),e.lt(1)||r.lt(1))return n.dNaN;let s=t.sign;if(t=t.abs(),t.gte(n.pow(e,i)))return t;let a=n.floor(n.log(t,e)),u=t.div(n.pow(e,a));return u=u.mul(n.pow(e,r)).round(),u=u.div(n.pow(e,r)),u=u.mul(n.pow(e,a)).mul(s),u}function ue(t,e,r,i=n.dInf,s,a,u=!1){t=new n(t),r=new n(r??e.level),i=new n(i);let f=i.sub(r);if(f.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",f),[n.dZero,n.dZero];if(u=(typeof e.el=="function"?e.el():e.el)??u,f.eq(1)){let E=e.cost(e.level),V=t.gte(E),q=[n.dZero,n.dZero];return u?(q[0]=V?n.dOne:n.dZero,q):(q=[V?n.dOne:n.dZero,V?E:n.dZero],q)}if(e.costBulk){let[E,V]=e.costBulk(t,e.level,f),q=t.gte(V);return[q?E:n.dZero,q&&!u?V:n.dZero]}if(u){let E=U=>e.cost(U.add(r)),V=n.min(i,Zt(E,t,s,a).value.floor()),q=n.dZero;return[V,q]}let g=Zt(E=>zt(e.cost,E,r),t,s,a).value.floor().min(r.add(f).sub(1)),l=zt(e.cost,g,r);return[g.sub(r).add(1).max(0),l]}function le(t){return t=new n(t),`${t.sign}/${t.mag}/${t.layer}`}function De(t){return`el/${le(t)}`}var It=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?new n(t.level):n.dOne}};tt([_t()],It.prototype,"id",2),tt([pt(()=>n)],It.prototype,"level",2);var fe=class Ie{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.level,this,this.currencyPointerFn())}set description(e){this.descriptionFn=typeof e=="function"?e:()=>e}get level(){return((this??{data:{level:n.dOne}}).data??{level:n.dOne}).level}set level(e){this.data.level=new n(e)}constructor(e,r,i,s){let a=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>a,this.currencyPointerFn=typeof i=="function"?i:()=>i,this.cache=new Lt(s??Ie.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??n.dOne}},Nr=dt(Nt());function he(t,e,r=n.dOne,i=n.dInf){if(t=new n(t),r=new n(r),i=new n(i),i.lt(0))return console.warn("eMath.js: Invalid target for calculateItem: ",i),[n.dZero,n.dZero];if(i.eq(1)){let u=e.cost(r);return[t.gte(u)?n.dOne:n.dZero,t.gte(u)?u:n.dZero]}let s=t.div(e.cost(r)).floor().min(i),a=e.cost(r).mul(s);return[s,a]}var ce=class{constructor(t,e,r){this.defaultAmount=n.dZero;let i=typeof e=="function"?e():e;this.dataPointerFn=typeof e=="function"?e:()=>i,this.currencyPointerFn=typeof r=="function"?r:()=>r,this.id=t.id,this.name=t.name??t.id,this.cost=t.cost,this.effect=t.effect,this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.defaultAmount=t.amount??n.dZero}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn(this.amount,this,this.currencyPointerFn())}set description(t){this.descriptionFn=typeof t=="function"?t:()=>t}get amount(){return((this??{data:{amount:n.dOne}}).data??{amount:n.dOne}).amount}set amount(t){this.data.amount=new n(t)}},St=class{constructor(t){t=t??{},this.id=t.id,this.amount=t.amount??n.dZero}};tt([_t()],St.prototype,"id",2),tt([pt(()=>n)],St.prototype,"amount",2);var pr=dt(Nt()),Et=class{constructor(){this.value=n.dZero,this.upgrades={},this.items={}}};tt([pt(()=>n)],Et.prototype,"value",2),tt([pt(()=>It)],Et.prototype,"upgrades",2),tt([pt(()=>St)],Et.prototype,"items",2);var He=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new Et,e,r,i={defaultVal:n.dZero,defaultBoost:n.dOne}){this.defaultVal=i.defaultVal,this.defaultBoost=i.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Gt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e),this.items={},r&&this.addItem(r)}onLoadData(){for(let t of Object.values(this.upgrades))this.runUpgradeEffect(t)}reset(t,e,r){let i={resetCurrency:!0,resetUpgradeLevels:!0,resetItemAmounts:!0,runUpgradeEffect:!0};if(typeof t=="object"?Object.assign(i,t):Object.assign(i,{resetCurrency:t,resetUpgradeLevels:e,runUpgradeEffect:r}),i.resetCurrency&&(this.value=this.defaultVal),i.resetUpgradeLevels)for(let s of Object.values(this.upgrades))s.level=new n(s.defaultLevel),i.runUpgradeEffect&&this.runUpgradeEffect(s);if(i.resetItemAmounts)for(let s of Object.values(this.items))s.amount=new n(s.defaultAmount),i.runUpgradeEffect&&this.runItemEffect(s)}gain(t=1e3){let e=this.boost.calculate().mul(new n(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new It(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}queryUpgrade(t){let e=Object.keys(this.upgrades);if(t instanceof RegExp){let i=t;return e.filter(a=>i.test(a)).map(a=>this.upgrades[a])}return typeof t=="string"&&(t=[t]),e.filter(i=>t.includes(i)).map(i=>this.upgrades[i])}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r=[];for(let i of t){this.pointerAddUpgrade(i);let s=new fe(i,()=>this.pointerGetUpgrade(i.id),()=>this);e&&this.runUpgradeEffect(s),this.upgrades[i.id]=s,r.push(s)}return r}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&Object.assign(r,e)}runUpgradeEffect(t){t.effect?.(t.level,t,this)}runItemEffect(t,e=n.dOne){e=new n(e),t.effect?.(t.amount,e,t,this)}calculateUpgrade(t,e=1/0,r,i){let s=this.getUpgrade(t);return s===null?(console.warn(`eMath.js: Upgrade "${t}" not found.`),[n.dZero,n.dZero]):(e=s.level.add(e),s.maxLevel!==void 0&&(e=n.min(e,s.maxLevel)),ue(this.value,s,s.level,e,r,i))}getNextCost(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i)[0];return s.cost(s.level.add(a))}getNextCostMax(t,e=1,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),n.dZero;let a=this.calculateUpgrade(t,e,r,i);return s.cost(s.level.add(a[0])).add(a[1])}buyUpgrade(t,e,r,i){let s=this.getUpgrade(t);if(s===null)return console.warn(`eMath.js: Upgrade "${t}" not found.`),!1;let[a,u]=this.calculateUpgrade(t,e,r,i);return a.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(u),s.level=s.level.add(a),this.runUpgradeEffect(s),!0)}pointerAddItem(t){let e=new St(t);return this.pointer.items[t.id]=e,e}pointerGetItem(t){return this.pointer.items[t]??null}addItem(t,e=!0){Array.isArray(t)||(t=[t]);for(let r of t){this.pointerAddItem(r);let i=new ce(r,()=>this.pointerGetItem(r.id),()=>this);e&&this.runItemEffect(i),this.items[r.id]=i}}getItem(t){return this.items[t]??null}calculateItem(t,e,r){let i=this.getItem(t);return i===null?(console.warn(`eMath.js: Item "${t}" not found.`),[n.dZero,n.dZero]):he(this.value,i,e,r)}buyItem(t,e,r){let i=this.getItem(t);if(i===null)return console.warn(`eMath.js: Item "${t}" not found.`),!1;let[s,a]=this.calculateItem(t,e,r);return s.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(a),i.amount=i.amount.add(s),this.runItemEffect(i,e),!0)}},br=dt(Nt()),Yt=class{constructor(t=0){this.value=new n(t)}};tt([pt(()=>n)],Yt.prototype,"value",2);var We=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=new n(r),t??=new Yt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Gt(this.initial):null}update(){console.warn("eMath.js: AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},Ct=class{constructor(t,e,r={},i){this.setValue=this.set.bind(this),this.getValue=this.get.bind(this),this.x=t,this.y=e,this.properties=typeof r=="function"?r(this):{...r},this.gridSymbol=i}get grid(){return Bt.getInstance(this.gridSymbol)}set(t,e){return this.properties[t]=e,e}get(t){return this.properties[t]}translate(t=0,e=0){return Bt.getInstance(this.gridSymbol).getCell(this.x+t,this.y+e)}direction(t,e=1,r){let i=this.grid;return(()=>{switch(t){case"up":return i.getCell(this.x,this.y-e);case"right":return i.getCell(this.x+e,this.y);case"down":return i.getCell(this.x,this.y+e);case"left":return i.getCell(this.x-e,this.y);case"adjacent":return i.getAdjacent(this.x,this.y,e,r);case"diagonal":return i.getDiagonal(this.x,this.y,e,r);case"encircling":return i.getEncircling(this.x,this.y,e,r);default:throw new Error("Invalid direction")}})()}up(t=1){return this.direction("up",t)}right(t=1){return this.direction("right",t)}down(t=1){return this.direction("down",t)}left(t=1){return this.direction("left",t)}};function me(t,e,r=!0){let i=r?"Size":"Coordinates";if(typeof t!="number"||typeof e!="number")throw new RangeError(`${i} must be numbers: ${t}, ${e}`);if(!Number.isInteger(t)||!Number.isInteger(e))throw new RangeError(`${i} must be integers: ${t}, ${e}`);if(t<0||e<0)throw new RangeError(`${i} must be positive: ${t}, ${e}`);if(!Number.isFinite(t)||!Number.isFinite(e))throw new RangeError(`${i} must be finite: ${t}, ${e}`);if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e))throw new RangeError(`${i} must be safe integers: ${t}, ${e}`)}var K=class Qt extends Array{constructor(e){e=Array.isArray(e)?e:[e],e=e.filter(r=>r!==void 0),super(...e),this.removeDuplicates()}removeDuplicates(){let e=[];this.forEach((r,i)=>{this.indexOf(r)!==i&&e.push(i)}),e.forEach(r=>this.splice(r,1))}translate(e=0,r=0){return new Qt(this.map(i=>i.translate(e,r)))}direction(e,r,i){return new Qt(this.flatMap(s=>s.direction(e,r,i)))}up(e){return this.direction("up",e)}right(e){return this.direction("right",e)}down(e){return this.direction("down",e)}left(e){return this.direction("left",e)}adjacent(e,r){return this.direction("adjacent",e,r)}diagonal(e,r){return this.direction("diagonal",e,r)}encircling(e,r){return this.direction("encircling",e,r)}},Bt=class Jt{constructor(e,r,i){this.cells=[],this.gridSymbol=Symbol(),this.all=this.getAll.bind(this),this.allX=this.getAllX.bind(this),this.allY=this.getAllY.bind(this),this.get=this.getCell.bind(this),this.set=this.setCell.bind(this),Jt.instances[this.gridSymbol]=this,this.starterProps=i??{},this.xSize=e,this.ySize=r??e,me(this.xSize,this.ySize,!0);for(let s=0;s{if(this.ySize!==s&&(this.ySizes))for(let a=s;a{if(this.xSize!==i){if(this.xSizei)for(let a=0;a{let t=!1,e=r=>(t||(console.warn("eMath.js: The E function is deprecated. Use the Decimal class directly."),t=!0),new n(r));return Object.getOwnPropertyNames(n).filter(r=>!Object.getOwnPropertyNames(class{}).includes(r)).forEach(r=>{e[r]=n[r]}),e})(),Je=ee;if(typeof at.exports=="object"&&typeof Mt=="object"){var Xe=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,s)&&s!==r&&Object.defineProperty(t,s,{get:()=>e[s],enumerable:!(i=Object.getOwnPropertyDescriptor(e,s))||i.enumerable});return t};at.exports=Xe(at.exports,Mt)}return at.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/main/eMath.mjs b/dist/main/eMath.mjs index 16c47bc6..36372aea 100644 --- a/dist/main/eMath.mjs +++ b/dist/main/eMath.mjs @@ -1673,25 +1673,31 @@ var Decimal = class { return D(value).reciprocate(); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value, other) { - return D(value).mod(other); + static mod(value, other, floored = false) { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value, other) { - return D(value).modulo(other); + static modulo(value, other, floored = false) { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value, other) { - return D(value).modular(other); + static modular(value, other, floored = false) { + return D(value).modular(other, floored); } /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. @@ -2141,6 +2147,31 @@ var Decimal = class { static pentate(value, height = 2, payload = FC_NN(1, 0, 1), linear = false) { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value, base = 10, linear = false) { + return D(value).penta_log(base, 100, linear); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value, degree) { + return D(value).linear_penta_root(degree); + } /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -2632,6 +2663,12 @@ var Decimal = class { } else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + if (this.layer < 0 || this.layer % 1 != 0) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -3128,12 +3165,20 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - mod(value) { - const decimal = D(value).abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + mod(value, floored = false) { + const vd = D(value); + const decimal = vd.abs(); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if (this.sign == -1 != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); if (isFinite(num_this) && isFinite(num_decimal) && num_this != 0 && num_decimal != 0) { @@ -3150,17 +3195,21 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value) { - return this.mod(value); + modulo(value, floored = false) { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value) { - return this.mod(value); + modular(value, floored = false) { + return this.mod(value, floored); } /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. @@ -4500,45 +4549,406 @@ var Decimal = class { } } } + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func, decreasing = false, iterations = 120, minX = Decimal.dLayerMax.neg(), maxX = Decimal.dLayerMax, minY = Decimal.dLayerMax.neg(), maxY = Decimal.dLayerMax) { + return function(value) { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let rangeApply = function(value2) { + return new Decimal(value2); + }; + let currentCheck = true; + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return new Decimal(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()); + }; + } + } + } + } else { + reciprocal = true; + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip().neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip().neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip().neg(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.neg(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).neg(); + }; + } + } + } + } + let searchIncreasing = positive != reciprocal != decreasing; + let comparative = searchIncreasing ? function(a, b) { + return Decimal.gt(a, b); + } : function(a, b) { + return Decimal.lt(a, b); + }; + let step_size = 1e-3; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { + break; + } + let currently_rose = comparative(new_decimal, value); + if (i > 1) { + if (previously_rose != currently_rose) { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) { + step_size /= 2; + } else { + step_size *= 2; + } + if (currently_rose != searchIncreasing && appliedResult.eq(maxX) || currently_rose == searchIncreasing && appliedResult.eq(minX)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { + break; + } + } + return rangeApply(result); + }; + } /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation - * + * * Tetration for non-integer heights does not have a single agreed-upon definition, * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. * Analytic approximation is not currently supported for bases > 10. - * + * * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height = 2, payload = FC_NN(1, 0, 1), linear = false) { payload = new Decimal(payload); const oldheight = height; - height = Math.trunc(height); + height = Math.floor(height); const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; if (fracheight !== 0) { if (payload.eq(Decimal.dOne)) { ++height; payload = Decimal.fromNumber(fracheight); } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + return this.pentate(payload.penta_log(this, void 0, linear).plus(oldheight).toNumber(), 1, linear); } } - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + if (payload.eq(prevpayload) || payload.eq(prevtwopayload) && i % 2 == height % 2) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 1e4) { + return payload; + } } - if (i > 10) { - return payload; + } else { + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, void 0, linear); + if (payload.eq(prevpayload)) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 100) { + return payload; + } } } return payload; } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + penta_log(base = 10, iterations = 100, linear = false) { + base = new Decimal(base); + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1e3) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { + break; + } + } + return Decimal.fromNumber(result); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree) { + if (degree == 1) { + return this; + } + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (degree > 0 && degree < 1) { + return this.root(degree); + } + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.lt(1)) { + return this.linear_sroot(degree); + } + return Decimal.increasingInverse(function(value) { + return Decimal.pentate(value, degree, 1, true); + })(this); + } // trig functions! /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. @@ -4876,16 +5286,64 @@ var Decimal = class { return new Decimal(Math.random()).lt(rng); } }; +/** + * Represents the number 0. + */ Decimal.dZero = FC_NN(0, 0, 0); +/** + * Represents the number 1. + */ Decimal.dOne = FC_NN(1, 0, 1); +/** + * Represents the number -1. + */ Decimal.dNegOne = FC_NN(-1, 0, 1); +/** + * Represents the number 2. + */ Decimal.dTwo = FC_NN(1, 0, 2); +/** + * Represents the number 10. + */ Decimal.dTen = FC_NN(1, 0, 10); +/** + * Represents a NaN (Not A Number) value. + */ Decimal.dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); +/** + * Represents positive infinity. + */ Decimal.dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents negative infinity. + */ Decimal.dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ Decimal.dNumberMax = FC(1, 0, Number.MAX_VALUE); +/** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ Decimal.dNumberMin = FC(1, 0, Number.MIN_VALUE); +/** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ +Decimal.dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); +/** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ +Decimal.dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); +/** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ +Decimal.dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); +/** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ +Decimal.dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); Decimal.fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); __decorateClass([ Expose() diff --git a/dist/presets/eMath.presets.js b/dist/presets/eMath.presets.js index 5fb8273c..88a1fcb3 100644 --- a/dist/presets/eMath.presets.js +++ b/dist/presets/eMath.presets.js @@ -1695,25 +1695,31 @@ var Decimal = class { return D(value).reciprocate(); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value, other) { - return D(value).mod(other); + static mod(value, other, floored = false) { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value, other) { - return D(value).modulo(other); + static modulo(value, other, floored = false) { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value, other) { - return D(value).modular(other); + static modular(value, other, floored = false) { + return D(value).modular(other, floored); } /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. @@ -2163,6 +2169,31 @@ var Decimal = class { static pentate(value, height = 2, payload = FC_NN(1, 0, 1), linear = false) { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value, base = 10, linear = false) { + return D(value).penta_log(base, 100, linear); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value, degree) { + return D(value).linear_penta_root(degree); + } /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -2654,6 +2685,12 @@ var Decimal = class { } else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + if (this.layer < 0 || this.layer % 1 != 0) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -3150,12 +3187,20 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - mod(value) { - const decimal = D(value).abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + mod(value, floored = false) { + const vd = D(value); + const decimal = vd.abs(); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if (this.sign == -1 != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); if (isFinite(num_this) && isFinite(num_decimal) && num_this != 0 && num_decimal != 0) { @@ -3172,17 +3217,21 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value) { - return this.mod(value); + modulo(value, floored = false) { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value) { - return this.mod(value); + modular(value, floored = false) { + return this.mod(value, floored); } /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. @@ -4522,45 +4571,406 @@ var Decimal = class { } } } + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func, decreasing = false, iterations = 120, minX = Decimal.dLayerMax.neg(), maxX = Decimal.dLayerMax, minY = Decimal.dLayerMax.neg(), maxY = Decimal.dLayerMax) { + return function(value) { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let rangeApply = function(value2) { + return new Decimal(value2); + }; + let currentCheck = true; + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return new Decimal(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()); + }; + } + } + } + } else { + reciprocal = true; + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip().neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip().neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip().neg(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.neg(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).neg(); + }; + } + } + } + } + let searchIncreasing = positive != reciprocal != decreasing; + let comparative = searchIncreasing ? function(a, b) { + return Decimal.gt(a, b); + } : function(a, b) { + return Decimal.lt(a, b); + }; + let step_size = 1e-3; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { + break; + } + let currently_rose = comparative(new_decimal, value); + if (i > 1) { + if (previously_rose != currently_rose) { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) { + step_size /= 2; + } else { + step_size *= 2; + } + if (currently_rose != searchIncreasing && appliedResult.eq(maxX) || currently_rose == searchIncreasing && appliedResult.eq(minX)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { + break; + } + } + return rangeApply(result); + }; + } /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation - * + * * Tetration for non-integer heights does not have a single agreed-upon definition, * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. * Analytic approximation is not currently supported for bases > 10. - * + * * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height = 2, payload = FC_NN(1, 0, 1), linear = false) { payload = new Decimal(payload); const oldheight = height; - height = Math.trunc(height); + height = Math.floor(height); const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; if (fracheight !== 0) { if (payload.eq(Decimal.dOne)) { ++height; payload = Decimal.fromNumber(fracheight); } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + return this.pentate(payload.penta_log(this, void 0, linear).plus(oldheight).toNumber(), 1, linear); } } - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + if (payload.eq(prevpayload) || payload.eq(prevtwopayload) && i % 2 == height % 2) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 1e4) { + return payload; + } } - if (i > 10) { - return payload; + } else { + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, void 0, linear); + if (payload.eq(prevpayload)) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 100) { + return payload; + } } } return payload; } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + penta_log(base = 10, iterations = 100, linear = false) { + base = new Decimal(base); + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1e3) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { + break; + } + } + return Decimal.fromNumber(result); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree) { + if (degree == 1) { + return this; + } + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (degree > 0 && degree < 1) { + return this.root(degree); + } + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.lt(1)) { + return this.linear_sroot(degree); + } + return Decimal.increasingInverse(function(value) { + return Decimal.pentate(value, degree, 1, true); + })(this); + } // trig functions! /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. @@ -4898,16 +5308,64 @@ var Decimal = class { return new Decimal(Math.random()).lt(rng); } }; +/** + * Represents the number 0. + */ Decimal.dZero = FC_NN(0, 0, 0); +/** + * Represents the number 1. + */ Decimal.dOne = FC_NN(1, 0, 1); +/** + * Represents the number -1. + */ Decimal.dNegOne = FC_NN(-1, 0, 1); +/** + * Represents the number 2. + */ Decimal.dTwo = FC_NN(1, 0, 2); +/** + * Represents the number 10. + */ Decimal.dTen = FC_NN(1, 0, 10); +/** + * Represents a NaN (Not A Number) value. + */ Decimal.dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); +/** + * Represents positive infinity. + */ Decimal.dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents negative infinity. + */ Decimal.dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ Decimal.dNumberMax = FC(1, 0, Number.MAX_VALUE); +/** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ Decimal.dNumberMin = FC(1, 0, Number.MIN_VALUE); +/** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ +Decimal.dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); +/** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ +Decimal.dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); +/** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ +Decimal.dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); +/** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ +Decimal.dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); Decimal.fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); __decorateClass([ (0, import_class_transformer.Expose)() diff --git a/dist/presets/eMath.presets.min.js b/dist/presets/eMath.presets.min.js index 69d3e715..05f7c557 100644 --- a/dist/presets/eMath.presets.min.js +++ b/dist/presets/eMath.presets.min.js @@ -1 +1 @@ -"use strict";(function(j,V){var k=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],V);else if(typeof module=="object"&&module.exports)module.exports=V();else{var H=V(),K=k?exports:j;for(var X in H)K[X]=H[X]}})(typeof self<"u"?self:exports,()=>{var j={},V={exports:j},k=Object.defineProperty,H=Object.getOwnPropertyDescriptor,K=Object.getOwnPropertyNames,X=Object.prototype.hasOwnProperty,rt=(t,e)=>{for(var r in e)k(t,r,{get:e[r],enumerable:!0})},ht=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of K(e))!X.call(t,a)&&a!==r&&k(t,a,{get:()=>e[a],enumerable:!(i=H(e,a))||i.enumerable});return t},mt=t=>ht(k({},"__esModule",{value:!0}),t),W=(t,e,r,i)=>{for(var a=i>1?void 0:i?H(e,r):e,o=t.length-1,m;o>=0;o--)(m=t[o])&&(a=(i?m(e,r,a):m(a))||a);return i&&a&&k(e,r,a),a},it={};rt(it,{emathPresets:()=>st}),V.exports=mt(it);var st={};rt(st,{GameFormatClass:()=>qt,formatOptions:()=>Ct,formatTimeOptions:()=>At,gameFormat:()=>Q,gameFormatGain:()=>lt});var L;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(L||(L={}));var ft=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(a){return!a.options||a.options.toClassOnly===!0&&a.options.toPlainOnly===!0?!0:a.options.toClassOnly===!0?i===L.CLASS_TO_CLASS||i===L.PLAIN_TO_CLASS:a.options.toPlainOnly===!0?i===L.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),a=this._exposeMetadatas.get(e),o=a&&a.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===L.CLASS_TO_CLASS||r===L.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===L.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===L.CLASS_TO_CLASS||r===L.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===L.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),a;i&&(a=Array.from(i.values()).filter(function(I){return I.propertyName!==void 0}));for(var o=[],m=0,N=this.getAncestors(r);mthis.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},Nt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},R=[[["","U","D","T","Qa","Qt","Sx","Sp","Oc","No"],["","Dc","Vg","Tg","Qag","Qtg","Sxg","Spg","Ocg","Nog"],["","Ce","De","Te","Qae","Qte","Sxe","Spe","Oce","Noe"]],[["","Mi","Mc","Na","Pc","Fm","At","Zp","Yc","Xn"],["","Me","Du","Tr","Te","Pe","He","Hp","Ot","En"],["","c","Ic","TCn","TeC","PCn","HCn","HpC","OCn","ECn"],["","Hc","DHe","THt","TeH","PHc","HHe","HpH","OHt","EHc"]]];function dt(t){let e={omega:{config:{greek:"\u03B2\u03B6\u03BB\u03C8\u03A3\u0398\u03A8\u03C9",infinity:"\u03A9"},format(n){n=new t(n);let h=t.floor(n.div(1e3)),l=t.floor(h.div(e.omega.config.greek.length)),d=e.omega.config.greek[h.toNumber()%e.omega.config.greek.length]+o(n.toNumber()%1e3);(e.omega.config.greek[h.toNumber()%e.omega.config.greek.length]===void 0||h.toNumber()>Number.MAX_SAFE_INTEGER)&&(d="\u03C9");let y=t.log(n,8e3).toNumber();if(l.equals(0))return d;if(l.gt(0)&&l.lte(3)){let T=[];for(let C=0;CNumber.MAX_SAFE_INTEGER)&&(d="\u03C9");let y=t.log(n,8e3).toNumber();if(l.equals(0))return d;if(l.gt(0)&&l.lte(2)){let T=[];for(let C=0;C118?e.elemental.beyondOg(b):e.elemental.config.element_lists[n-1][d]},beyondOg(n){let h=Math.floor(Math.log10(n)),l=["n","u","b","t","q","p","h","s","o","e"],d="";for(let b=h;b>=0;b--){let y=Math.floor(n/Math.pow(10,b))%10;d==""?d=l[y].toUpperCase():d+=l[y]}return d},abbreviationLength(n){return n==1?1:Math.pow(Math.floor(n/2)+1,2)*2},getAbbreviationAndValue(n){let h=n.log(118).toNumber(),l=Math.floor(h)+1,d=e.elemental.abbreviationLength(l),b=h-l+1,y=Math.floor(b*d),M=e.elemental.getAbbreviation(l,b),v=new t(118).pow(l+y/d-1);return[M,v]},formatElementalPart(n,h){return h.eq(1)?n:`${h.toString()} ${n}`},format(n,h=2){if(n.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(n.log10(),h);let l=n.log(118),b=l.log(118).log(118).toNumber(),y=Math.max(4-b*2,1),M=[];for(;l.gte(1)&&M.length=y)return M.map(T=>e.elemental.formatElementalPart(T[0],T[1])).join(" + ");let v=new t(118).pow(l).toFixed(M.length===1?3:h);return M.length===0?v:M.length===1?`${v} \xD7 ${e.elemental.formatElementalPart(M[0][0],M[0][1])}`:`${v} \xD7 (${M.map(T=>e.elemental.formatElementalPart(T[0],T[1])).join(" + ")})`}},old_sc:{format(n,h){n=new t(n);let l=n.log10().floor();if(l.lt(9))return l.lt(3)?n.toFixed(h):n.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(n.gte("eeee10")){let b=n.slog();return(b.gte(1e9)?"":t.dTen.pow(b.sub(b.floor())).toFixed(4))+"F"+e.old_sc.format(b.floor(),0)}let d=n.div(t.dTen.pow(l));return(l.log10().gte(9)?"":d.toFixed(4))+"e"+e.old_sc.format(l,0)}}},eng:{format(n,h=2){n=new t(n);let l=n.log10().floor();if(l.lt(9))return l.lt(3)?n.toFixed(h):n.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(n.gte("eeee10")){let b=n.slog();return(b.gte(1e9)?"":t.dTen.pow(b.sub(b.floor())).toFixed(4))+"F"+e.eng.format(b.floor(),0)}let d=n.div(new t(1e3).pow(l.div(3).floor()));return(l.log10().gte(9)?"":d.toFixed(new t(4).sub(l.sub(l.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(l.div(3).floor().mul(3),0)}}},mixed_sc:{format(n,h,l=9){n=new t(n);let d=n.log10().floor();return d.lt(303)&&d.gte(l)?g(n,h,l,"st"):g(n,h,l,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(n,h=2,l){n=new t(n);let d=n.max(1).log10().max(1).log(r.log10()).floor();if(d.lte(0))return g(n,h,l,"sc");n=t.dTen.pow(n.max(1).log10().div(r.log10().pow(d)).sub(d.gte(1)?1:0));let b=d.div(10).floor(),y=d.toNumber()%10-1;return g(n,Math.max(4,h),l,"sc")+" "+(b.gte(1)?"meta"+(b.gte(2)?"^"+g(b,0,l,"sc"):"")+"-":"")+(isNaN(y)?"nanity":e.layer.layers[y])}},standard:{tier1(n){return R[0][0][n%10]+R[0][1][Math.floor(n/10)%10]+R[0][2][Math.floor(n/100)]},tier2(n){let h=n%10,l=Math.floor(n/10)%10,d=Math.floor(n/100)%10,b="";return n<10?R[1][0][n]:(l==1&&h==0?b+="Vec":b+=R[1][1][h]+R[1][2][l],b+=R[1][3][d],b)}},inf:{format(n,h,l){n=new t(n);let d=0,b=new t(Number.MAX_VALUE),y=["","\u221E","\u03A9","\u03A8","\u028A"],M=["","","m","mm","mmm"];for(;n.gte(b);)n=n.log(b),d++;return d==0?g(n,h,l,"sc"):n.gte(3)?M[d]+y[d]+"\u03C9^"+g(n.sub(1),h,l,"sc"):n.gte(2)?M[d]+"\u03C9"+y[d]+"-"+g(b.pow(n.sub(2)),h,l,"sc"):M[d]+y[d]+"-"+g(b.pow(n.sub(1)),h,l,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(n,h=new t(1e15),l=!1,d=9){if(n=new t(n),h=new t(h).div(1e3),n.lt(h.mul(1e3)))return"";let{alphabet:b}=e.alphabet.config,y=b.length,M=n.log(1e3).sub(h.log(1e3)).floor(),v=M.add(1).log(y+1).ceil(),T="",C=(P,Y)=>{let x=P,B="";for(let G=0;G=y)return"\u03C9";B=b[U]+B,x=x.sub(1).div(y).floor()}return B};if(v.lt(d))T=C(M,v);else{let P=v.sub(d).add(1),Y=M.div(t.pow(y+1,P.sub(1))).floor();T=`${C(Y,new t(d))}(${P.gt("1e9")?P.format():P.format(0)})`}return T},format(n,h=2,l=9,d="mixed_sc",b=new t(1e15),y=!1,M){if(n=new t(n),b=new t(b).div(1e3),n.lt(b.mul(1e3)))return g(n,h,l,d);let v=e.alphabet.getAbbreviation(n,b,y,M),T=n.div(t.pow(1e3,n.log(1e3).floor()));return`${v.length>(M??9)+2?"":T.toFixed(h)+" "}${v}`}}},r=t.dTwo.pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",a="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(n){return n.toFixed(0).split("").map(h=>h==="-"?"\u208B":i[parseInt(h,10)]).join("")}function m(n){return n.toFixed(0).split("").map(h=>h==="-"?"\u208B":a[parseInt(h,10)]).join("")}function N(n,h=2,l=9,d="st"){return g(n,h,l,d)}function g(n,h=2,l=9,d="mixed_sc"){n=new t(n);let b=n.lt(0)?"-":"";if(n.mag==1/0)return b+"Infinity";if(Number.isNaN(n.mag))return b+"NaN";if(n.lt(0)&&(n=n.mul(-1)),n.eq(0))return n.toFixed(h);let y=n.log10().floor();switch(d){case"sc":case"scientific":if(n.log10().lt(Math.min(-h,0))&&h>1){let M=n.log10().ceil(),v=n.div(M.eq(-1)?new t(.1):t.dTen.pow(M)),T=M.mul(-1).max(1).log10().gte(9);return b+(T?"":v.toFixed(2))+"e"+g(M,0,l,"mixed_sc")}else if(y.lt(l)){let M=Math.max(Math.min(h-y.toNumber(),h),0);return b+(M>0?n.toFixed(M):n.toFixed(M).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(n.gte("eeee10")){let T=n.slog();return(T.gte(1e9)?"":t.dTen.pow(T.sub(T.floor())).toFixed(2))+"F"+g(T.floor(),0)}let M=n.div(t.dTen.pow(y)),v=y.log10().gte(9);return b+(v?"":M.toFixed(2))+"e"+g(y,0,l,"mixed_sc")}case"st":case"standard":{let M=n.log(1e3).floor();if(M.lt(1))return b+n.toFixed(Math.max(Math.min(h-y.toNumber(),h),0));let v=M.mul(3),T=M.log10().floor();if(T.gte(3e3))return"e"+g(y,h,l,"st");let C="";if(M.lt(4))C=["","K","M","B"][Math.round(M.toNumber())];else{let x=Math.floor(M.log(1e3).toNumber());for(x<100&&(x=Math.max(x-1,0)),M=M.sub(1).div(t.dTen.pow(x*3));M.gt(0);){let B=M.div(1e3).floor(),G=M.sub(B.mul(1e3)).floor().toNumber();G>0&&(G==1&&!x&&(C="U"),x&&(C=e.standard.tier2(x)+(C?"-"+C:"")),G>1&&(C=e.standard.tier1(G)+C)),M=B,x++}}let P=n.div(t.dTen.pow(v)),Y=h===2?t.dTwo.sub(y.sub(v)).add(1).toNumber():h;return b+(T.gte(10)?"":P.toFixed(Y)+" ")+C}default:return e[d]||console.error('Invalid format type "',d,'"'),b+e[d].format(n,h,l)}}function c(n,h,l="mixed_sc",d,b){n=new t(n),h=new t(h);let y=n.add(h),M,v=y.div(n);return v.gte(10)&&n.gte(1e100)?(v=v.log10().mul(20),M="(+"+g(v,d,b,l)+" OoMs/sec)"):M="(+"+g(h,d,b,l)+"/sec)",M}function _(n,h=2,l="s"){return n=new t(n),n.gte(86400)?g(n.div(86400).floor(),0,12,"sc")+":"+_(n.mod(86400),h,"d"):n.gte(3600)||l=="d"?(n.div(3600).gte(10)||l!="d"?"":"0")+g(n.div(3600).floor(),0,12,"sc")+":"+_(n.mod(3600),h,"h"):n.gte(60)||l=="h"?(n.div(60).gte(10)||l!="h"?"":"0")+g(n.div(60).floor(),0,12,"sc")+":"+_(n.mod(60),h,"m"):(n.gte(10)||l!="m"?"":"0")+g(n,h,12,"sc")}function I(n,h=!1,l=0,d=9,b="mixed_sc"){let y=Vt=>g(Vt,l,d,b);n=new t(n);let M=n.mul(1e3).mod(1e3).floor(),v=n.mod(60).floor(),T=n.div(60).mod(60).floor(),C=n.div(3600).mod(24).floor(),P=n.div(86400).mod(365.2425).floor(),Y=n.div(31556952).floor(),x=Y.eq(1)?" year":" years",B=P.eq(1)?" day":" days",G=C.eq(1)?" hour":" hours",U=T.eq(1)?" minute":" minutes",xt=v.eq(1)?" second":" seconds",Lt=M.eq(1)?" millisecond":" milliseconds";return`${Y.gt(0)?y(Y)+x+", ":""}${P.gt(0)?y(P)+B+", ":""}${C.gt(0)?y(C)+G+", ":""}${T.gt(0)?y(T)+U+", ":""}${v.gt(0)?y(v)+xt+",":""}${h&&M.gt(0)?" "+y(M)+Lt:""}`.replace(/,([^,]*)$/,"$1").trim()}function q(n){return n=new t(n),g(t.dOne.sub(n).mul(100))+"%"}function F(n){return n=new t(n),g(n.mul(100))+"%"}function O(n,h=2){return n=new t(n),n.gte(1)?"\xD7"+n.format(h):"/"+n.pow(-1).format(h)}function p(n,h,l=10){return t.gte(n,10)?t.pow(l,t.log(n,l).pow(h)):new t(n)}function S(n,h=0){n=new t(n);let l=(M=>M.map((v,T)=>({name:v.name,altName:v.altName,value:t.pow(1e3,new t(T).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),d="",b=n.lte(0)?0:t.min(t.log(n,1e3).sub(1),l.length-1).floor().toNumber(),y=l[b];if(b===0)switch(h){case 1:d="";break;case 2:case 0:default:d=n.format();break}switch(h){case 1:d=y.name;break;case 2:d=n.divide(y.value).format();break;case 3:d=y.altName;break;case 0:default:d=`${n.divide(y.value).format()} ${y.name}`;break}return d}function E(n,h=!1){return`${S(n,2)} ${S(n,1)}eV${h?"/c^2":""}`}let A={...e,toSubscript:o,toSuperscript:m,formatST:N,format:g,formatGain:c,formatTime:_,formatTimeLong:I,formatReduction:q,formatPercent:F,formatMult:O,expMult:p,metric:S,ev:E};return{FORMATS:e,formats:A}}var D=17,pt=9e15,bt=Math.log10(9e15),Mt=1/9e15,wt=308,yt=-324,at=5,_t=1023,It=!0,St=!1,Ft=function(){let t=[];for(let r=yt+1;r<=wt;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),Z=[2,Math.E,3,4,5,6,7,8,9,10],Tt=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],vt=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],u=function(e){return s.fromValue_noAlloc(e)},w=function(t,e,r){return s.fromComponents(t,e,r)},f=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},$=function(e,r){let i=r+1,a=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-a))*Math.pow(10,a-i);return parseFloat(o.toFixed(Math.max(i-a,0)))},tt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Et=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,a=t;return r=r+1/(12*a),a=a*i,r=r-1/(360*a),a=a*i,r=r+1/(1260*a),a=a*i,r=r-1/(1680*a),a=a*i,r=r+1/(1188*a),a=a*i,r=r-691/(360360*a),a=a*i,r=r+7/(1092*a),a=a*i,r=r-3617/(122400*a),Math.exp(r)/e},Ot=.36787944117144233,ot=.5671432904097838,et=function(t,e=1e-10,r=!0){let i,a;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ot;t<10?i=0:i=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?i=-2:i=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(a=(t*Math.exp(-i)+i*i)/(i+1),Math.abs(a-i).5?1:-1;if(Math.random()*20<1)return f(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let a=Math.pow(10,i);return Math.random()>.9&&(a=Math.trunc(a)),w(e,r,a)}static affordGeometricSeries_core(t,e,r,i){let a=e.mul(r.pow(i));return s.floor(t.div(a).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),m=o.pow(2);return o.neg().add(m.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let a=e.add(i.mul(r));return t.div(2).mul(a.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=pt)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);It?t=t.replace(",",""):St&&(t=t.replace(",","."));let a=t.split("^^^");if(a.length===2){let p=parseFloat(a[0]),S=parseFloat(a[1]),E=a[1].split(";"),A=1;if(E.length===2&&(A=parseFloat(E[1]),isFinite(A)||(A=1)),isFinite(p)&&isFinite(S)){let n=s.pentate(p,S,A,e);return this.sign=n.sign,this.layer=n.layer,this.mag=n.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let p=parseFloat(o[0]),S=parseFloat(o[1]),E=o[1].split(";"),A=1;if(E.length===2&&(A=parseFloat(E[1]),isFinite(A)||(A=1)),isFinite(p)&&isFinite(S)){let n=s.tetrate(p,S,A,e);return this.sign=n.sign,this.layer=n.layer,this.mag=n.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let m=t.split("^");if(m.length===2){let p=parseFloat(m[0]),S=parseFloat(m[1]);if(isFinite(p)&&isFinite(S)){let E=s.pow(p,S);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let N,g,c=t.split("pt");if(c.length===2){N=10;let p=!1;c[0].startsWith("-")&&(p=!0,c[0]=c[0].slice(1)),g=parseFloat(c[0]),c[1]=c[1].replace("(",""),c[1]=c[1].replace(")","");let S=parseFloat(c[1]);if(isFinite(S)||(S=1),isFinite(N)&&isFinite(g)){let E=s.tetrate(N,g,S,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),p&&(this.sign*=-1),this}}if(c=t.split("p"),c.length===2){N=10;let p=!1;c[0].startsWith("-")&&(p=!0,c[0]=c[0].slice(1)),g=parseFloat(c[0]),c[1]=c[1].replace("(",""),c[1]=c[1].replace(")","");let S=parseFloat(c[1]);if(isFinite(S)||(S=1),isFinite(N)&&isFinite(g)){let E=s.tetrate(N,g,S,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),p&&(this.sign*=-1),this}}if(c=t.split("f"),c.length===2){N=10;let p=!1;c[0].startsWith("-")&&(p=!0,c[0]=c[0].slice(1)),c[0]=c[0].replace("(",""),c[0]=c[0].replace(")","");let S=parseFloat(c[0]);if(c[1]=c[1].replace("(",""),c[1]=c[1].replace(")",""),g=parseFloat(c[1]),isFinite(S)||(S=1),isFinite(N)&&isFinite(g)){let E=s.tetrate(N,g,S,e);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),p&&(this.sign*=-1),this}}let _=t.split("e"),I=_.length-1;if(I===0){let p=parseFloat(t);if(isFinite(p))return this.fromNumber(p),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(I===1){let p=parseFloat(t);if(isFinite(p)&&p!==0)return this.fromNumber(p),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let q=t.split("e^");if(q.length===2){this.sign=1,q[0].startsWith("-")&&(this.sign=-1);let p="";for(let S=0;S=43&&E<=57||E===101)p+=q[1].charAt(S);else return this.layer=parseFloat(p),this.mag=parseFloat(q[1].substr(S+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(I<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let F=parseFloat(_[0]);if(F===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let O=parseFloat(_[_.length-1]);if(I>=2){let p=parseFloat(_[_.length-2]);isFinite(p)&&(O*=Math.sign(p),O+=tt(p))}if(!isFinite(F))this.sign=_[0]==="-"?-1:1,this.layer=I,this.mag=O;else if(I===1)this.sign=Math.sign(F),this.layer=1,this.mag=O+Math.log10(Math.abs(F));else if(this.sign=Math.sign(F),this.layer=I,I===2){let p=s.mul(w(1,2,O),u(F));return this.sign=p.sign,this.layer=p.layer,this.mag=p.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=O;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:$(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:$(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=at?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):$(this.m,t)+"e"+$(this.e,t):this.layer===1?$(this.m,t)+"e"+$(this.e,t):this.layer<=at?(this.sign===-1?"-":"")+"e".repeat(this.layer)+$(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+$(this.mag,t)}abs(){return f(this.sign===0?0:1,this.layer,this.mag)}neg(){return f(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?f(0,0,0):this.layer===0?w(this.sign,0,Math.round(this.mag)):new s(this)}floor(){return this.mag<0?this.sign===-1?f(-1,0,1):f(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?w(this.sign,0,Math.floor(this.mag)):new s(this)}ceil(){return this.mag<0?this.sign===1?f(1,0,1):f(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?w(this.sign,0,Math.ceil(this.mag)):new s(this)}trunc(){return this.mag<0?f(0,0,0):this.layer===0?w(this.sign,0,Math.trunc(this.mag)):new s(this)}add(t){let e=u(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return f(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0)return new s(e);if(e.sign===0)return new s(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return f(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let a=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(a-o>=2)return r;if(a===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>D)return r;{let m=Math.pow(10,Math.log10(r.mag)-i.mag),N=i.sign+r.sign*m;return w(Math.sign(N),1,i.mag+Math.log10(Math.abs(N)))}}if(a===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>D)return r;{let m=Math.pow(10,r.mag-Math.log10(i.mag)),N=i.sign+r.sign*m;return w(Math.sign(N),1,Math.log10(i.mag)+Math.log10(Math.abs(N)))}}if(Math.abs(r.mag-i.mag)>D)return r;{let m=Math.pow(10,r.mag-i.mag),N=i.sign+r.sign*m;return w(Math.sign(N),1,i.mag+Math.log10(Math.abs(N)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(u(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=u(t);if(this.eq(s.dInf)&&e.eq(s.dNegInf)||this.eq(s.dNegInf)&&e.eq(s.dInf))return f(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(s.dZero)||this.eq(s.dZero)&&this.mag==Number.POSITIVE_INFINITY)return f(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new s(this);if(!Number.isFinite(e.layer))return new s(e);if(this.sign===0||e.sign===0)return f(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return f(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new s(this),i=new s(e)):(r=new s(e),i=new s(this)),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return w(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return w(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return w(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let a=w(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(w(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return w(r.sign*i.sign,a.layer+1,a.sign*a.mag)}if(r.layer===2&&i.layer===2){let a=w(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(w(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return w(r.sign*i.sign,a.layer+1,a.sign*a.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=u(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?f(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?f(0,0,0):this.layer===0?w(this.sign,0,1/this.mag):w(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=u(t).abs();if(e.eq(s.dZero))return f(0,0,0);let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new s(r%i):this.sub(e).eq(this)?f(0,0,0):e.sub(this).eq(e)?new s(this):this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=u(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?new s(e):new s(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=u(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=u(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,a=r.mag;return this.layer>r.layer&&(a=tt(a)),this.layer0?w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):w(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?f(Number.NaN,Number.NaN,Number.NaN):this.layer>0?w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):w(this.sign,0,Math.log10(this.mag))}log(t){return t=u(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?w(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0?w(this.sign,0,Math.log2(this.mag)):this.layer===1?w(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?w(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0?w(this.sign,0,Math.log(this.mag)):this.layer===1?w(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?w(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):w(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=u(t),r=new s(this),i=new s(e);if(r.sign===0)return i.eq(0)?f(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return f(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let a=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?a.neg():Math.abs(i.toNumber()%2)%2===0?a:f(Number.NaN,Number.NaN,Number.NaN):a}pow10(){if(this.eq(s.dInf))return f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(s.dNegInf))return f(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return f(Number.NaN,Number.NaN,Number.NaN);let t=new s(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return w(1,0,e);if(t.sign===0)return f(1,0,1);t=f(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?w(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?w(-t.sign,t.layer+1,-t.mag):f(1,0,1)}pow_base(t){return u(t).pow(this)}root(t){let e=u(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(f(1,0,24)))return s.fromNumber(Et(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,a=12*i,o=1/a,m=e+o;if(m===e||(e=m,i=i*r,a=360*i,o=1/a,m=e-o,m===e))return s.exp(e);e=m,i=i*r,a=1260*i;let N=1/a;return e=e+N,i=i*r,a=1680*i,N=1/a,e=e-N,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?f(1,0,1):this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?w(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?w(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):w(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return w(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(f(this.sign,this.layer-1,this.mag),f(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=f(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return f(1,0,1);if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let m=s.ln(this).neg(),N=m.lambertw().div(m);if(o<1)return N;let g=m.lambertw(!1).div(m);return o>1.444667861009099&&(N=g=s.fromNumber(Math.E)),e=u(e),e.eq(g)?g:e.lt(g)?N:f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):f(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=new s(e);let i=t;t=Math.trunc(t);let a=i-t;if(this.gt(s.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(s.ln(this).neg().lambertw(!1).div(s.ln(this).neg())))&&(i>1e4||!r)){let o=Math.min(1e4,t);e.eq(s.dOne)?e=this.pow(a):this.lt(1)?e=e.pow(1-a).mul(this.pow(e).pow(a)):e=e.layeradd(a,this);for(let m=0;m1e4&&Math.ceil(i)%2==1?this.pow(e):e}a!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(a):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),a)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(a,r):this.lt(1)?e=e.pow(1-a).mul(this.pow(e).pow(a)):e=e.layeradd(a,this,r));for(let o=0;o3)return f(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=f(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=u(t);let i=s.fromDecimal(this),a=e;e=Math.trunc(e);let o=a-e;if(i.layer-t.layer>3){let m=Math.min(e,i.layer-t.layer-3);e-=m,i.layer-=m}for(let m=0;m1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,a=!1,o=!1,m=this.slog_internal(t,r).toNumber();for(let N=1;N1&&o!=c&&(a=!0),o=c,a?i/=2:i*=2,i=Math.abs(i)*(c?-1:1),m+=i,i===0)break}return s.fromNumber(m)}slog_internal(t=10,e=!1){if(t=u(t),t.lte(s.dZero)||t.eq(s.dOne))return f(Number.NaN,Number.NaN,Number.NaN);if(t.lt(s.dOne))return this.eq(s.dOne)?f(0,0,0):this.eq(s.dZero)?f(-1,0,1):f(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(s.dZero))return f(-1,0,1);if(t.lt(1.444667861009766)){let a=s.ln(t).neg(),o=a.lambertw().div(a);if(this.eq(o))return f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return f(Number.NaN,Number.NaN,Number.NaN)}let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let a=i.layer-t.layer-3;r+=a,i.layer-=a}for(let a=0;a<100;++a)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,vt)}static tetrate_critical(t,e){return s.critical_section(t,e,Tt)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let a=0,o=0;for(let N=0;Nt){let g=(t-Z[N])/(Z[N+1]-Z[N]);a=r[N][Math.floor(e)]*(1-g)+r[N+1][Math.floor(e)]*g,o=r[N][Math.ceil(e)]*(1-g)+r[N+1][Math.ceil(e)]*g;break}let m=e-Math.floor(e);return a<=0||o<=0?a*(1-m)+o*m:Math.pow(t,Math.log(a)/Math.log(t)*(1-m)+Math.log(o)/Math.log(t)*m)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let a=0;a<100;++a){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let i=u(e);if(i.gt(1)&&i.lte(1.444667861009766)){let m=s.excess_slog(this,e,r),N=m[0].toNumber(),g=m[1],c=N+t,_=s.ln(e).neg(),I=_.lambertw().div(_),q=_.lambertw(!1).div(_),F=s.dOne;g==1?F=I.mul(q).sqrt():g==2&&(F=q.mul(2));let O=i.pow(F),p=Math.floor(c),S=c-p,E=F.pow(1-S).mul(O.pow(S));return s.tetrate(i,p,E,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?s.tetrate(e,o,s.dOne,r):Number.isFinite(o)?o>=-1?s.log(s.tetrate(e,o+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,o+2,s.dOne,r),e),e):f(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=u(t),e=u(e);let i=e;if(e=e.toNumber(),e==1||e<=0)return[f(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let a=s.ln(e).neg(),o=a.lambertw().div(a),m=s.dInf;if(e>1&&(m=a.lambertw(!1).div(a)),e>1.444667861009099&&(o=m=s.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(m))return[f(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(m)){let N=m.mul(2),g=i.pow(N),c=0;if(t.gte(N)&&t.lt(g))c=0;else if(t.gte(g)){let p=g;for(c=1;p.lt(t);)if(p=i.pow(p),c=c+1,p.layer>3){let S=Math.floor(t.layer-p.layer+1);p=i.iteratedexp(S,p,r),c=c+S}p.gt(t)&&(p=p.log(e),c=c-1)}else if(t.lt(N)){let p=N;for(c=0;p.gt(t);)p=p.log(e),c=c-1}let _=0,I=0,q=.5,F=N,O=s.dZero;for(;q>1e-16;){if(I=_+q,F=N.pow(1-I).mul(g.pow(I)),O=s.iteratedexp(e,c,F),O.eq(t))return[new s(c+I),2];O.lt(t)&&(_+=q),q/=2}return O.neq_tolerance(t,1e-7)?[f(Number.NaN,Number.NaN,Number.NaN),0]:[new s(c+_),2]}if(t.lt(m)&&t.gt(o)){let N=o.mul(m).sqrt(),g=i.pow(N),c=0;if(t.lte(N)&&t.gt(g))c=0;else if(t.lte(g)){let p=g;for(c=1;p.gt(t);)p=i.pow(p),c=c+1;p.lt(t)&&(p=p.log(e),c=c-1)}else if(t.gt(N)){let p=N;for(c=0;p.lt(t);)p=p.log(e),c=c-1}let _=0,I=0,q=.5,F=N,O=s.dZero;for(;q>1e-16;){if(I=_+q,F=N.pow(1-I).mul(g.pow(I)),O=s.iteratedexp(e,c,F),O.eq(t))return[new s(c+I),1];O.gt(t)&&(_+=q),q/=2}return O.neq_tolerance(t,1e-7)?[f(Number.NaN,Number.NaN,Number.NaN),0]:[new s(c+_),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?f(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new s(this):this.mag<0?s.fromNumber(et(this.toNumber())):this.layer===0?s.fromNumber(et(this.sign*this.mag)):this.lt("eee15")?ut(this):this.ln():this.sign===1?f(Number.NaN,Number.NaN,Number.NaN):this.layer===0?s.fromNumber(et(this.sign*this.mag,1e-10,!1)):this.layer==1?ut(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return f(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return f(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eOt?this.pow(this.recip()):f(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return f(1,0,1);if(this.lt(0))return f(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new s(this):f(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,a=e.iteratedlog(10,i,!0),o=a,m=a.div(2),N=!0;for(;N;)m=r.add(a).div(2),s.iteratedexp(10,i,m,!0).tetrate(t,1,!0).gt(this)?a=m:r=m,m.eq(o)?N=!1:o=m;return s.iteratedexp(10,i,m,!0)}else{let e=1,r=w(1,10,1),i=w(1,10,1),a=w(1,10,1),o=w(1,1,-16),m=s.dZero,N=w(1,10,1),g=o.pow10().recip(),c=s.dZero,_=g,I=g,q=Math.ceil(t)%2==0,F=0,O=w(1,10,1),p=!1,S=s.dZero,E=!1;for(;e<4;){if(e==2){if(q)break;a=w(1,10,1),o=r,e=3,N=w(1,10,1),O=w(1,10,1)}for(p=!1;o.neq(a);){if(S=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))g=o.pow10().recip(),_=o.pow10().recip(),I=o.pow10().recip(),c=s.dZero,F=-1,e==3&&(O=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!q&&o.pow10().recip().lt(.4))g=o.pow10().recip(),_=o.pow10().recip(),I=o.pow10().recip(),c=s.dZero,F=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))g=o.pow10().recip(),_=s.dZero,I=g.mul(2),c=g,q?F=-1:F=0;else{for(m=o.mul(12e-17),g=o.pow10().recip(),_=o.add(m).pow10().recip(),c=g.sub(_),I=g.add(c);_.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||I.tetrate(t,1,!0).eq(g.tetrate(t,1,!0))||_.gte(g)||I.lte(g);)m=m.mul(2),_=o.add(m).pow10().recip(),c=g.sub(_),I=g.add(c);if((e==1&&I.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))&&_.tetrate(t,1,!0).gt(g.tetrate(t,1,!0))||e==3&&I.tetrate(t,1,!0).lt(g.tetrate(t,1,!0))&&_.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))&&(O=o),I.tetrate(t,1,!0).lt(g.tetrate(t,1,!0)))F=-1;else if(q)F=1;else if(e==3&&o.gt_tolerance(r,1e-8))F=0;else{for(;_.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||I.tetrate(t,1,!0).eq_tolerance(g.tetrate(t,1,!0),1e-8)||_.gte(g)||I.lte(g);)m=m.mul(2),_=o.add(m).pow10().recip(),c=g.sub(_),I=g.add(c);I.tetrate(t,1,!0).sub(g.tetrate(t,1,!0)).lt(g.tetrate(t,1,!0).sub(_.tetrate(t,1,!0)))?F=0:F=1}}if(F==-1&&(E=!0),e==1&&F==1||e==3&&F!=0)if(a.eq(w(1,10,1)))o=o.mul(2);else{let l=!1;if(p&&(F==1&&e==1||F==-1&&e==3)&&(l=!0),o=o.add(a).div(2),l)break}else if(a.eq(w(1,10,1)))a=o,o=o.div(2);else{let l=!1;if(p&&(F==1&&e==1||F==-1&&e==3)&&(l=!0),a=a.sub(N),o=o.sub(N),l)break}if(a.sub(o).div(2).abs().gt(N.mul(1.5))&&(p=!0),N=a.sub(o).div(2).abs(),o.gt("1e18")||o.eq(S))break}if(o.gt("1e18")||!E||O==w(1,10,1))break;e==1?r=O:e==3&&(i=O),e++}a=r,o=w(1,1,-18);let A=o,n=s.dZero,h=!0;for(;h;)if(a.eq(w(1,10,1))?n=o.mul(2):n=a.add(o).div(2),s.pow(10,n).recip().tetrate(t,1,!0).gt(this)?o=n:a=n,n.eq(A)?h=!1:A=n,o.gt("1e18"))return f(Number.NaN,Number.NaN,Number.NaN);if(n.eq_tolerance(r,1e-15)){if(i.eq(w(1,10,1)))return f(Number.NaN,Number.NaN,Number.NaN);for(a=w(1,10,1),o=i,A=o,n=s.dZero,h=!0;h;)if(a.eq(w(1,10,1))?n=o.mul(2):n=a.add(o).div(2),s.pow(10,n).recip().tetrate(t,1,!0).gt(this)?o=n:a=n,n.eq(A)?h=!1:A=n,o.gt("1e18"))return f(Number.NaN,Number.NaN,Number.NaN);return n.pow10().recip()}else return n.pow10().recip()}}pentate(t=2,e=f(1,0,1),r=!1){e=new s(e);let i=t;t=Math.trunc(t);let a=i-t;a!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(a)):this.eq(10)?e=e.layeradd10(a,r):e=e.layeradd(a,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):f(0,0,0)}cos(){return this.mag<0?f(1,0,1):this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):f(0,0,0)}tan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):f(0,0,0)}asin(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):f(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):f(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new s(this):this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?f(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new s(this):this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let a=this.clone();return a.gte(t)&&([0,"pow"].includes(r)&&(a=i?a.mul(t.pow(e.sub(1))).root(e):a.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(a=i?a.div(t).max(1).log(e).add(t):s.pow(e,a.sub(t)).mul(t))),a}static scale(t,e,r,i,a=!1){return new s(t).scale(e,r,i,a)}format(t=2,e=9,r="mixed_sc"){return z.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return z.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return z.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return z.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return z.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,a){return z.formatGain(new s(t),e,r,i,a)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},a="";for(let o of Object.keys(i)){let m=Math.floor(r/i[o]);r-=m*i[o],a+=o.repeat(m)}return a}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=f(0,0,0),s.dOne=f(1,0,1),s.dNegOne=f(-1,0,1),s.dTwo=f(1,0,2),s.dTen=f(1,0,10),s.dNaN=f(Number.NaN,Number.NaN,Number.NaN),s.dInf=f(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=f(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNumberMax=w(1,0,Number.MAX_VALUE),s.dNumberMin=w(1,0,Number.MIN_VALUE),s.fromStringCache=new ct(_t),W([J()],s.prototype,"sign",2),W([J()],s.prototype,"mag",2),W([J()],s.prototype,"layer",2),s=W([gt()],s);var{formats:z,FORMATS:Yt}=dt(s);s.formats=z;function Q(t,e){e=Object.assign({formatType:"mixed_sc",acc:2,max:9},e);let{formatType:r,acc:i,max:a,time:o,multi:m,formatTimeType:N}=e;if(o)switch(N){case"short":return s.formats.formatTime(t,i,r);case"long":return s.formats.formatTimeLong(t,!0,0,a,r)}return m?s.formats.formatMult(t,i):s.format(t,i,a,r)}function lt(t,e,r){let{formatType:i,acc:a,max:o}=r;return s.formatGain(t,e,i,a,o)}var qt=class{constructor(t){this.format=e=>Q(e,this.settings),this.gain=(e,r)=>lt(e,r,this.settings),this.time=e=>Q(e,{...this.settings,time:!0}),this.multi=e=>Q(e,{...this.settings,multi:!0}),this.settingsFn=typeof t=="function"?t:()=>t}get settings(){return this.settingsFn()}},Ct=[{name:"Standard",value:"standard"},{name:"Scientific",value:"scientific"},{name:"Mixed Scientific (default)",value:"mixed_sc"},{name:"Old Scientific",value:"old_sc"},{name:"Engineering",value:"eng"},{name:"Infinity",value:"inf"},{name:"Omega",value:"omega"},{name:"Omega Short",value:"omega_short"},{name:"Elemental",value:"elemental"},{name:"Layer",value:"layer"}].sort((t,e)=>t.name.localeCompare(e.name)),At=[{name:"Short (default)",value:"short"},{name:"Long",value:"long"}].sort((t,e)=>t.name.localeCompare(e.name));if(typeof V.exports=="object"&&typeof j=="object"){var Pt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,a)&&a!==r&&Object.defineProperty(t,a,{get:()=>e[a],enumerable:!(i=Object.getOwnPropertyDescriptor(e,a))||i.enumerable});return t};V.exports=Pt(V.exports,j)}return V.exports}); +"use strict";(function(H,Y){var Z=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],Y);else if(typeof module=="object"&&module.exports)module.exports=Y();else{var W=Y(),X=Z?exports:H;for(var K in W)X[K]=W[K]}})(typeof self<"u"?self:exports,()=>{var H={},Y={exports:H},Z=Object.defineProperty,W=Object.getOwnPropertyDescriptor,X=Object.getOwnPropertyNames,K=Object.prototype.hasOwnProperty,st=(t,e)=>{for(var r in e)Z(t,r,{get:e[r],enumerable:!0})},mt=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of X(e))!K.call(t,n)&&n!==r&&Z(t,n,{get:()=>e[n],enumerable:!(s=W(e,n))||s.enumerable});return t},gt=t=>mt(Z({},"__esModule",{value:!0}),t),J=(t,e,r,s)=>{for(var n=s>1?void 0:s?W(e,r):e,o=t.length-1,g;o>=0;o--)(g=t[o])&&(n=(s?g(e,r,n):g(n))||n);return s&&n&&Z(e,r,n),n},nt={};st(nt,{emathPresets:()=>at}),Y.exports=gt(nt);var at={};st(at,{GameFormatClass:()=>qt,formatOptions:()=>At,formatTimeOptions:()=>Ct,gameFormat:()=>D,gameFormatGain:()=>ht});var x;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(x||(x={}));var ct=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,s){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?s===x.CLASS_TO_CLASS||s===x.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?s===x.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(s){return s.options&&s.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),s=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return s&&o||!s&&!o?"none":s?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(s){return!s.options||s.options.toClassOnly===!0&&s.options.toPlainOnly===!0?!0:s.options.toClassOnly===!0?r===x.CLASS_TO_CLASS||r===x.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?r===x.CLASS_TO_PLAIN:!0}).map(function(s){return s.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(s){return!s.options||s.options.toClassOnly===!0&&s.options.toPlainOnly===!0?!0:s.options.toClassOnly===!0?r===x.CLASS_TO_CLASS||r===x.PLAIN_TO_CLASS:s.options.toPlainOnly===!0?r===x.CLASS_TO_PLAIN:!0}).map(function(s){return s.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var s=e.get(r),n;s&&(n=Array.from(s.values()).filter(function(y){return y.propertyName!==void 0}));for(var o=[],g=0,f=this.getAncestors(r);gthis.maxSize;){let s=this.last;this.map.delete(s.key),this.last=s.prev,this.last.next=void 0}}},bt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},R=[[["","U","D","T","Qa","Qt","Sx","Sp","Oc","No"],["","Dc","Vg","Tg","Qag","Qtg","Sxg","Spg","Ocg","Nog"],["","Ce","De","Te","Qae","Qte","Sxe","Spe","Oce","Noe"]],[["","Mi","Mc","Na","Pc","Fm","At","Zp","Yc","Xn"],["","Me","Du","Tr","Te","Pe","He","Hp","Ot","En"],["","c","Ic","TCn","TeC","PCn","HCn","HpC","OCn","ECn"],["","Hc","DHe","THt","TeH","PHc","HHe","HpH","OHt","EHc"]]];function dt(t){let e={omega:{config:{greek:"\u03B2\u03B6\u03BB\u03C8\u03A3\u0398\u03A8\u03C9",infinity:"\u03A9"},format(a){a=new t(a);let N=t.floor(a.div(1e3)),p=t.floor(N.div(e.omega.config.greek.length)),c=e.omega.config.greek[N.toNumber()%e.omega.config.greek.length]+o(a.toNumber()%1e3);(e.omega.config.greek[N.toNumber()%e.omega.config.greek.length]===void 0||N.toNumber()>Number.MAX_SAFE_INTEGER)&&(c="\u03C9");let d=t.log(a,8e3).toNumber();if(p.equals(0))return c;if(p.gt(0)&&p.lte(3)){let E=[];for(let C=0;CNumber.MAX_SAFE_INTEGER)&&(c="\u03C9");let d=t.log(a,8e3).toNumber();if(p.equals(0))return c;if(p.gt(0)&&p.lte(2)){let E=[];for(let C=0;C118?e.elemental.beyondOg(b):e.elemental.config.element_lists[a-1][c]},beyondOg(a){let N=Math.floor(Math.log10(a)),p=["n","u","b","t","q","p","h","s","o","e"],c="";for(let b=N;b>=0;b--){let d=Math.floor(a/Math.pow(10,b))%10;c==""?c=p[d].toUpperCase():c+=p[d]}return c},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let N=a.log(118).toNumber(),p=Math.floor(N)+1,c=e.elemental.abbreviationLength(p),b=N-p+1,d=Math.floor(b*c),_=e.elemental.getAbbreviation(p,b),O=new t(118).pow(p+d/c-1);return[_,O]},formatElementalPart(a,N){return N.eq(1)?a:`${N.toString()} ${a}`},format(a,N=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),N);let p=a.log(118),b=p.log(118).log(118).toNumber(),d=Math.max(4-b*2,1),_=[];for(;p.gte(1)&&_.length=d)return _.map(E=>e.elemental.formatElementalPart(E[0],E[1])).join(" + ");let O=new t(118).pow(p).toFixed(_.length===1?3:N);return _.length===0?O:_.length===1?`${O} \xD7 ${e.elemental.formatElementalPart(_[0][0],_[0][1])}`:`${O} \xD7 (${_.map(E=>e.elemental.formatElementalPart(E[0],E[1])).join(" + ")})`}},old_sc:{format(a,N){a=new t(a);let p=a.log10().floor();if(p.lt(9))return p.lt(3)?a.toFixed(N):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let b=a.slog();return(b.gte(1e9)?"":t.dTen.pow(b.sub(b.floor())).toFixed(4))+"F"+e.old_sc.format(b.floor(),0)}let c=a.div(t.dTen.pow(p));return(p.log10().gte(9)?"":c.toFixed(4))+"e"+e.old_sc.format(p,0)}}},eng:{format(a,N=2){a=new t(a);let p=a.log10().floor();if(p.lt(9))return p.lt(3)?a.toFixed(N):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let b=a.slog();return(b.gte(1e9)?"":t.dTen.pow(b.sub(b.floor())).toFixed(4))+"F"+e.eng.format(b.floor(),0)}let c=a.div(new t(1e3).pow(p.div(3).floor()));return(p.log10().gte(9)?"":c.toFixed(new t(4).sub(p.sub(p.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(p.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,N,p=9){a=new t(a);let c=a.log10().floor();return c.lt(303)&&c.gte(p)?h(a,N,p,"st"):h(a,N,p,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,N=2,p){a=new t(a);let c=a.max(1).log10().max(1).log(r.log10()).floor();if(c.lte(0))return h(a,N,p,"sc");a=t.dTen.pow(a.max(1).log10().div(r.log10().pow(c)).sub(c.gte(1)?1:0));let b=c.div(10).floor(),d=c.toNumber()%10-1;return h(a,Math.max(4,N),p,"sc")+" "+(b.gte(1)?"meta"+(b.gte(2)?"^"+h(b,0,p,"sc"):"")+"-":"")+(isNaN(d)?"nanity":e.layer.layers[d])}},standard:{tier1(a){return R[0][0][a%10]+R[0][1][Math.floor(a/10)%10]+R[0][2][Math.floor(a/100)]},tier2(a){let N=a%10,p=Math.floor(a/10)%10,c=Math.floor(a/100)%10,b="";return a<10?R[1][0][a]:(p==1&&N==0?b+="Vec":b+=R[1][1][N]+R[1][2][p],b+=R[1][3][c],b)}},inf:{format(a,N,p){a=new t(a);let c=0,b=new t(Number.MAX_VALUE),d=["","\u221E","\u03A9","\u03A8","\u028A"],_=["","","m","mm","mmm"];for(;a.gte(b);)a=a.log(b),c++;return c==0?h(a,N,p,"sc"):a.gte(3)?_[c]+d[c]+"\u03C9^"+h(a.sub(1),N,p,"sc"):a.gte(2)?_[c]+"\u03C9"+d[c]+"-"+h(b.pow(a.sub(2)),N,p,"sc"):_[c]+d[c]+"-"+h(b.pow(a.sub(1)),N,p,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,N=new t(1e15),p=!1,c=9){if(a=new t(a),N=new t(N).div(1e3),a.lt(N.mul(1e3)))return"";let{alphabet:b}=e.alphabet.config,d=b.length,_=a.log(1e3).sub(N.log(1e3)).floor(),O=_.add(1).log(d+1).ceil(),E="",C=(L,k)=>{let V=L,B="";for(let G=0;G=d)return"\u03C9";B=b[Q]+B,V=V.sub(1).div(d).floor()}return B};if(O.lt(c))E=C(_,O);else{let L=O.sub(c).add(1),k=_.div(t.pow(d+1,L.sub(1))).floor();E=`${C(k,new t(c))}(${L.gt("1e9")?L.format():L.format(0)})`}return E},format(a,N=2,p=9,c="mixed_sc",b=new t(1e15),d=!1,_){if(a=new t(a),b=new t(b).div(1e3),a.lt(b.mul(1e3)))return h(a,N,p,c);let O=e.alphabet.getAbbreviation(a,b,d,_),E=a.div(t.pow(1e3,a.log(1e3).floor()));return`${O.length>(_??9)+2?"":E.toFixed(N)+" "}${O}`}}},r=t.dTwo.pow(1024),s="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(N=>N==="-"?"\u208B":s[parseInt(N,10)]).join("")}function g(a){return a.toFixed(0).split("").map(N=>N==="-"?"\u208B":n[parseInt(N,10)]).join("")}function f(a,N=2,p=9,c="st"){return h(a,N,p,c)}function h(a,N=2,p=9,c="mixed_sc"){a=new t(a);let b=a.lt(0)?"-":"";if(a.mag==1/0)return b+"Infinity";if(Number.isNaN(a.mag))return b+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(N);let d=a.log10().floor();switch(c){case"sc":case"scientific":if(a.log10().lt(Math.min(-N,0))&&N>1){let _=a.log10().ceil(),O=a.div(_.eq(-1)?new t(.1):t.dTen.pow(_)),E=_.mul(-1).max(1).log10().gte(9);return b+(E?"":O.toFixed(2))+"e"+h(_,0,p,"mixed_sc")}else if(d.lt(p)){let _=Math.max(Math.min(N-d.toNumber(),N),0);return b+(_>0?a.toFixed(_):a.toFixed(_).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let E=a.slog();return(E.gte(1e9)?"":t.dTen.pow(E.sub(E.floor())).toFixed(2))+"F"+h(E.floor(),0)}let _=a.div(t.dTen.pow(d)),O=d.log10().gte(9);return b+(O?"":_.toFixed(2))+"e"+h(d,0,p,"mixed_sc")}case"st":case"standard":{let _=a.log(1e3).floor();if(_.lt(1))return b+a.toFixed(Math.max(Math.min(N-d.toNumber(),N),0));let O=_.mul(3),E=_.log10().floor();if(E.gte(3e3))return"e"+h(d,N,p,"st");let C="";if(_.lt(4))C=["","K","M","B"][Math.round(_.toNumber())];else{let V=Math.floor(_.log(1e3).toNumber());for(V<100&&(V=Math.max(V-1,0)),_=_.sub(1).div(t.dTen.pow(V*3));_.gt(0);){let B=_.div(1e3).floor(),G=_.sub(B.mul(1e3)).floor().toNumber();G>0&&(G==1&&!V&&(C="U"),V&&(C=e.standard.tier2(V)+(C?"-"+C:"")),G>1&&(C=e.standard.tier1(G)+C)),_=B,V++}}let L=a.div(t.dTen.pow(O)),k=N===2?t.dTwo.sub(d.sub(O)).add(1).toNumber():N;return b+(E.gte(10)?"":L.toFixed(k)+" ")+C}default:return e[c]||console.error('Invalid format type "',c,'"'),b+e[c].format(a,N,p)}}function l(a,N,p="mixed_sc",c,b){a=new t(a),N=new t(N);let d=a.add(N),_,O=d.div(a);return O.gte(10)&&a.gte(1e100)?(O=O.log10().mul(20),_="(+"+h(O,c,b,p)+" OoMs/sec)"):_="(+"+h(N,c,b,p)+"/sec)",_}function I(a,N=2,p="s"){return a=new t(a),a.gte(86400)?h(a.div(86400).floor(),0,12,"sc")+":"+I(a.mod(86400),N,"d"):a.gte(3600)||p=="d"?(a.div(3600).gte(10)||p!="d"?"":"0")+h(a.div(3600).floor(),0,12,"sc")+":"+I(a.mod(3600),N,"h"):a.gte(60)||p=="h"?(a.div(60).gte(10)||p!="h"?"":"0")+h(a.div(60).floor(),0,12,"sc")+":"+I(a.mod(60),N,"m"):(a.gte(10)||p!="m"?"":"0")+h(a,N,12,"sc")}function y(a,N=!1,p=0,c=9,b="mixed_sc"){let d=xt=>h(xt,p,c,b);a=new t(a);let _=a.mul(1e3).mod(1e3).floor(),O=a.mod(60).floor(),E=a.div(60).mod(60).floor(),C=a.div(3600).mod(24).floor(),L=a.div(86400).mod(365.2425).floor(),k=a.div(31556952).floor(),V=k.eq(1)?" year":" years",B=L.eq(1)?" day":" days",G=C.eq(1)?" hour":" hours",Q=E.eq(1)?" minute":" minutes",Lt=O.eq(1)?" second":" seconds",Vt=_.eq(1)?" millisecond":" milliseconds";return`${k.gt(0)?d(k)+V+", ":""}${L.gt(0)?d(L)+B+", ":""}${C.gt(0)?d(C)+G+", ":""}${E.gt(0)?d(E)+Q+", ":""}${O.gt(0)?d(O)+Lt+",":""}${N&&_.gt(0)?" "+d(_)+Vt:""}`.replace(/,([^,]*)$/,"$1").trim()}function q(a){return a=new t(a),h(t.dOne.sub(a).mul(100))+"%"}function F(a){return a=new t(a),h(a.mul(100))+"%"}function v(a,N=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(N):"/"+a.pow(-1).format(N)}function w(a,N,p=10){return t.gte(a,10)?t.pow(p,t.log(a,p).pow(N)):new t(a)}function S(a,N=0){a=new t(a);let p=(_=>_.map((O,E)=>({name:O.name,altName:O.altName,value:t.pow(1e3,new t(E).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"Decimal",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),c="",b=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),p.length-1).floor().toNumber(),d=p[b];if(b===0)switch(N){case 1:c="";break;case 2:case 0:default:c=a.format();break}switch(N){case 1:c=d.name;break;case 2:c=a.divide(d.value).format();break;case 3:c=d.altName;break;case 0:default:c=`${a.divide(d.value).format()} ${d.name}`;break}return c}function T(a,N=!1){return`${S(a,2)} ${S(a,1)}eV${N?"/c^2":""}`}let A={...e,toSubscript:o,toSuperscript:g,formatST:f,format:h,formatGain:l,formatTime:I,formatTimeLong:y,formatReduction:q,formatPercent:F,formatMult:v,expMult:w,metric:S,ev:T};return{FORMATS:e,formats:A}}var et=17,P=9e15,wt=Math.log10(9e15),z=1/9e15,Mt=308,_t=-324,lt=5,It=1023,yt=!0,St=!1,Ft=function(){let t=[];for(let r=_t+1;r<=Mt;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),U=[2,Math.E,3,4,5,6,7,8,9,10],Tt=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],Et=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],u=function(e){return i.fromValue_noAlloc(e)},M=function(t,e,r){return i.fromComponents(t,e,r)},m=function(e,r,s){return i.fromComponents_noNormalize(e,r,s)},$=function(e,r){let s=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,s-n))*Math.pow(10,n-s);return parseFloat(o.toFixed(Math.max(s-n,0)))},rt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},vt=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let s=t*t,n=t;return r=r+1/(12*n),n=n*s,r=r-1/(360*n),n=n*s,r=r+1/(1260*n),n=n*s,r=r-1/(1680*n),n=n*s,r=r+1/(1188*n),n=n*s,r=r-691/(360360*n),n=n*s,r=r+7/(1092*n),n=n*s,r=r-3617/(122400*n),Math.exp(r)/e},Ot=.36787944117144233,ut=.5671432904097838,it=function(t,e=1e-10,r=!0){let s,n;if(!Number.isFinite(t))return t;if(r){if(t===0)return t;if(t===1)return ut;t<10?s=0:s=Math.log(t)-Math.log(Math.log(t))}else{if(t===0)return-1/0;t<=-.1?s=-2:s=Math.log(-t)-Math.log(-Math.log(-t))}for(let o=0;o<100;++o){if(n=(t*Math.exp(-s)+s*s)/(s+1),Math.abs(n-s).5?1:-1;if(Math.random()*20<1)return m(e,0,1);let r=Math.floor(Math.random()*(t+1)),s=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(s=Math.trunc(s));let n=Math.pow(10,s);return Math.random()>.9&&(n=Math.trunc(n)),M(e,r,n)}static affordGeometricSeries_core(t,e,r,s){let n=e.mul(r.pow(s));return i.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,s){return e.mul(r.pow(s)).mul(i.sub(1,r.pow(t))).div(i.sub(1,r))}static affordArithmeticSeries_core(t,e,r,s){let o=e.add(s.mul(r)).sub(r.div(2)),g=o.pow(2);return o.neg().add(g.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,s){let n=e.add(s.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(this.layer===0&&this.mag=P)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,s=i.fromStringCache.get(r);if(s!==void 0)return this.fromDecimal(s);yt?t=t.replace(",",""):St&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let w=parseFloat(n[0]),S=parseFloat(n[1]),T=n[1].split(";"),A=1;if(T.length===2&&(A=parseFloat(T[1]),isFinite(A)||(A=1)),isFinite(w)&&isFinite(S)){let a=i.pentate(w,S,A,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let w=parseFloat(o[0]),S=parseFloat(o[1]),T=o[1].split(";"),A=1;if(T.length===2&&(A=parseFloat(T[1]),isFinite(A)||(A=1)),isFinite(w)&&isFinite(S)){let a=i.tetrate(w,S,A,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}}let g=t.split("^");if(g.length===2){let w=parseFloat(g[0]),S=parseFloat(g[1]);if(isFinite(w)&&isFinite(S)){let T=i.pow(w,S);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}}t=t.trim().toLowerCase();let f,h,l=t.split("pt");if(l.length===2){f=10;let w=!1;l[0].startsWith("-")&&(w=!0,l[0]=l[0].slice(1)),h=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let S=parseFloat(l[1]);if(isFinite(S)||(S=1),isFinite(f)&&isFinite(h)){let T=i.tetrate(f,h,S,e);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),w&&(this.sign*=-1),this}}if(l=t.split("p"),l.length===2){f=10;let w=!1;l[0].startsWith("-")&&(w=!0,l[0]=l[0].slice(1)),h=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let S=parseFloat(l[1]);if(isFinite(S)||(S=1),isFinite(f)&&isFinite(h)){let T=i.tetrate(f,h,S,e);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),w&&(this.sign*=-1),this}}if(l=t.split("f"),l.length===2){f=10;let w=!1;l[0].startsWith("-")&&(w=!0,l[0]=l[0].slice(1)),l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let S=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),h=parseFloat(l[1]),isFinite(S)||(S=1),isFinite(f)&&isFinite(h)){let T=i.tetrate(f,h,S,e);return this.sign=T.sign,this.layer=T.layer,this.mag=T.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),w&&(this.sign*=-1),this}}let I=t.split("e"),y=I.length-1;if(y===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),i.fromStringCache.size>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}else if(y===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}let q=t.split("e^");if(q.length===2){this.sign=1,q[0].startsWith("-")&&(this.sign=-1);let w="";for(let S=0;S=43&&T<=57||T===101)w+=q[1].charAt(S);else{if(this.layer=parseFloat(w),this.mag=parseFloat(q[1].substr(S+1)),this.layer<0||this.layer%1!=0){let A=i.tetrate(10,this.layer,this.mag,e);this.sign=A.sign,this.layer=A.layer,this.mag=A.mag}return this.normalize(),i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}}}if(y<1)return this.sign=0,this.layer=0,this.mag=0,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this;let F=parseFloat(I[0]);if(F===0)return this.sign=0,this.layer=0,this.mag=0,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this;let v=parseFloat(I[I.length-1]);if(y>=2){let w=parseFloat(I[I.length-2]);isFinite(w)&&(v*=Math.sign(w),v+=rt(w))}if(!isFinite(F))this.sign=I[0]==="-"?-1:1,this.layer=y,this.mag=v;else if(y===1)this.sign=Math.sign(F),this.layer=1,this.mag=v+Math.log10(Math.abs(F));else if(this.sign=Math.sign(F),this.layer=y,y===2){let w=i.mul(M(1,2,v),u(F));return this.sign=w.sign,this.layer=w.layer,this.mag=w.mag,i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}else this.mag=v;return this.normalize(),i.fromStringCache.maxSize>=1&&i.fromStringCache.set(r,i.fromDecimal(this)),this}fromValue(t){return t instanceof i?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:$(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:$(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=lt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):$(this.m,t)+"e"+$(this.e,t):this.layer===1?$(this.m,t)+"e"+$(this.e,t):this.layer<=lt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+$(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+$(this.mag,t)}abs(){return m(this.sign===0?0:1,this.layer,this.mag)}neg(){return m(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?m(0,0,0):this.layer===0?M(this.sign,0,Math.round(this.mag)):new i(this)}floor(){return this.mag<0?this.sign===-1?m(-1,0,1):m(0,0,0):this.sign===-1?this.neg().ceil().neg():this.layer===0?M(this.sign,0,Math.floor(this.mag)):new i(this)}ceil(){return this.mag<0?this.sign===1?m(1,0,1):m(0,0,0):this.sign===-1?this.neg().floor().neg():this.layer===0?M(this.sign,0,Math.ceil(this.mag)):new i(this)}trunc(){return this.mag<0?m(0,0,0):this.layer===0?M(this.sign,0,Math.trunc(this.mag)):new i(this)}add(t){let e=u(t);if(this.eq(i.dInf)&&e.eq(i.dNegInf)||this.eq(i.dNegInf)&&e.eq(i.dInf))return m(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new i(this);if(!Number.isFinite(e.layer))return new i(e);if(this.sign===0)return new i(e);if(e.sign===0)return new i(this);if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return m(0,0,0);let r,s;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(i.cmpabs(this,e)>0?(r=new i(this),s=new i(e)):(r=new i(e),s=new i(this)),r.layer===0&&s.layer===0)return i.fromNumber(r.sign*r.mag+s.sign*s.mag);let n=r.layer*Math.sign(r.mag),o=s.layer*Math.sign(s.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(s.mag-Math.log10(r.mag))>et)return r;{let g=Math.pow(10,Math.log10(r.mag)-s.mag),f=s.sign+r.sign*g;return M(Math.sign(f),1,s.mag+Math.log10(Math.abs(f)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(s.mag))>et)return r;{let g=Math.pow(10,r.mag-Math.log10(s.mag)),f=s.sign+r.sign*g;return M(Math.sign(f),1,Math.log10(s.mag)+Math.log10(Math.abs(f)))}}if(Math.abs(r.mag-s.mag)>et)return r;{let g=Math.pow(10,r.mag-s.mag),f=s.sign+r.sign*g;return M(Math.sign(f),1,s.mag+Math.log10(Math.abs(f)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(u(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=u(t);if(this.eq(i.dInf)&&e.eq(i.dNegInf)||this.eq(i.dNegInf)&&e.eq(i.dInf))return m(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.mag==Number.POSITIVE_INFINITY&&e.eq(i.dZero)||this.eq(i.dZero)&&this.mag==Number.POSITIVE_INFINITY)return m(Number.NaN,Number.NaN,Number.NaN);if(!Number.isFinite(this.layer))return new i(this);if(!Number.isFinite(e.layer))return new i(e);if(this.sign===0||e.sign===0)return m(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return m(this.sign*e.sign,0,1);let r,s;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=new i(this),s=new i(e)):(r=new i(e),s=new i(this)),r.layer===0&&s.layer===0)return i.fromNumber(r.sign*s.sign*r.mag*s.mag);if(r.layer>=3||r.layer-s.layer>=2)return M(r.sign*s.sign,r.layer,r.mag);if(r.layer===1&&s.layer===0)return M(r.sign*s.sign,1,r.mag+Math.log10(s.mag));if(r.layer===1&&s.layer===1)return M(r.sign*s.sign,1,r.mag+s.mag);if(r.layer===2&&s.layer===1){let n=M(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(M(Math.sign(s.mag),s.layer-1,Math.abs(s.mag)));return M(r.sign*s.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&s.layer===2){let n=M(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(M(Math.sign(s.mag),s.layer-1,Math.abs(s.mag)));return M(r.sign*s.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=u(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?m(Number.NaN,Number.NaN,Number.NaN):this.mag===Number.POSITIVE_INFINITY?m(0,0,0):this.layer===0?M(this.sign,0,1/this.mag):M(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t,e=!1){let r=u(t),s=r.abs();if(this.eq(i.dZero)||s.eq(i.dZero))return m(0,0,0);if(e){let g=this.abs().mod(s);return this.sign==-1!=(r.sign==-1)&&(g=r.abs().sub(g)),g.mul(r.sign)}let n=this.toNumber(),o=s.toNumber();return isFinite(n)&&isFinite(o)&&n!=0&&o!=0?new i(n%o):this.sub(s).eq(this)?m(0,0,0):s.sub(this).eq(s)?new i(this):this.sign==-1?this.abs().mod(s).neg():this.sub(this.div(s).floor().mul(s))}modulo(t,e=!1){return this.mod(t,e)}modular(t,e=!1){return this.mod(t,e)}cmp(t){let e=u(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,s=e.mag>0?e.layer:-e.layer;return r>s?1:re.mag?1:this.mag0?new i(e):new i(this)}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=u(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=u(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let s=this.mag,n=r.mag;return this.layer>r.layer&&(n=rt(n)),this.layer0?M(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):M(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?m(Number.NaN,Number.NaN,Number.NaN):this.layer>0?M(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):M(this.sign,0,Math.log10(this.mag))}log(t){return t=u(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?m(Number.NaN,Number.NaN,Number.NaN):this.layer===0&&t.layer===0?M(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):i.div(this.log10(),t.log10())}log2(){return this.sign<=0?m(Number.NaN,Number.NaN,Number.NaN):this.layer===0?M(this.sign,0,Math.log2(this.mag)):this.layer===1?M(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?M(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):M(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?m(Number.NaN,Number.NaN,Number.NaN):this.layer===0?M(this.sign,0,Math.log(this.mag)):this.layer===1?M(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?M(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):M(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=u(t),r=new i(this),s=new i(e);if(r.sign===0)return s.eq(0)?m(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(s.sign===0)return m(1,0,1);if(s.sign===1&&s.layer===0&&s.mag===1)return r;let n=r.absLog10().mul(s).pow10();return this.sign===-1?Math.abs(s.toNumber()%2)%2===1?n.neg():Math.abs(s.toNumber()%2)%2===0?n:m(Number.NaN,Number.NaN,Number.NaN):n}pow10(){if(this.eq(i.dInf))return m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.eq(i.dNegInf))return m(0,0,0);if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return m(Number.NaN,Number.NaN,Number.NaN);let t=new i(this);if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return M(1,0,e);if(t.sign===0)return m(1,0,1);t=m(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?M(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?M(-t.sign,t.layer+1,-t.mag):m(1,0,1)}pow_base(t){return u(t).pow(this)}root(t){let e=u(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?i.exp(i.mul(this,i.ln(this).sub(1))):i.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(m(1,0,24)))return i.fromNumber(vt(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,s=t,n=12*s,o=1/n,g=e+o;if(g===e||(e=g,s=s*r,n=360*s,o=1/n,g=e-o,g===e))return i.exp(e);e=g,s=s*r,n=1260*s;let f=1/n;return e=e+f,s=s*r,n=1680*s,f=1/n,e=e-f,i.exp(e)}else return this.layer===1?i.exp(i.mul(this,i.ln(this).sub(1))):i.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?m(1,0,1):this.layer===0&&this.mag<=709.7?i.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?M(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?M(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):M(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return i.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return M(1,2,Math.log10(this.mag)-.3010299956639812);{let t=i.div(m(this.sign,this.layer-1,this.mag),m(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=m(1,0,1),r=!1){if(t===1)return i.pow(this,e);if(t===0)return new i(e);if(this.eq(i.dOne))return m(1,0,1);if(this.eq(-1))return i.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){let g=i.ln(this).neg(),f=g.lambertw().div(g);if(o<1)return f;let h=g.lambertw(!1).div(g);return o>1.444667861009099&&(f=h=i.fromNumber(Math.E)),e=u(e),e.eq(h)?h:e.lt(h)?f:m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}else return o>1.444667861009766?m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY):m(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(i.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),i.fromNumber(o)}if(t<0)return i.iteratedlog(e,this,-t,r);e=new i(e);let s=t;t=Math.trunc(t);let n=s-t;if(this.gt(i.dZero)&&(this.lt(1)||this.lte(1.444667861009766)&&e.lte(i.ln(this).neg().lambertw(!1).div(i.ln(this).neg())))&&(s>1e4||!r)){let o=Math.min(1e4,t);e.eq(i.dOne)?e=this.pow(n):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this);for(let g=0;g1e4&&Math.ceil(s)%2==1?this.pow(e):e}n!==0&&(e.eq(i.dOne)?this.gt(10)||r?e=this.pow(n):(e=i.fromNumber(i.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):this.lt(1)?e=e.pow(1-n).mul(this.pow(e).pow(n)):e=e.layeradd(n,this,r));for(let o=0;o3)return m(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=m(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return i.tetrate(t,-e,this,r);t=u(t);let s=i.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(s.layer-t.layer>3){let g=Math.min(e,s.layer-t.layer-3);e-=g,s.layer-=g}for(let g=0;g1e4)return s}return o>0&&o<1&&(t.eq(10)?s=s.layeradd10(-o,r):s=s.layeradd(-o,t,r)),s}slog(t=10,e=100,r=!1){let s=.001,n=!1,o=!1,g=this.slog_internal(t,r).toNumber();for(let f=1;f1&&o!=l&&(n=!0),o=l,n?s/=2:s*=2,s=Math.abs(s)*(l?-1:1),g+=s,s===0)break}return i.fromNumber(g)}slog_internal(t=10,e=!1){if(t=u(t),t.lte(i.dZero)||t.eq(i.dOne))return m(Number.NaN,Number.NaN,Number.NaN);if(t.lt(i.dOne))return this.eq(i.dOne)?m(0,0,0):this.eq(i.dZero)?m(-1,0,1):m(Number.NaN,Number.NaN,Number.NaN);if(this.mag<0||this.eq(i.dZero))return m(-1,0,1);if(t.lt(1.444667861009766)){let n=i.ln(t).neg(),o=n.lambertw().div(n);if(this.eq(o))return m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(o))return m(Number.NaN,Number.NaN,Number.NaN)}let r=0,s=i.fromDecimal(this);if(s.layer-t.layer>3){let n=s.layer-t.layer-3;r+=n,s.layer-=n}for(let n=0;n<100;++n)if(s.lt(i.dZero))s=i.pow(t,s),r-=1;else{if(s.lte(i.dOne))return e?i.fromNumber(r+s.toNumber()-1):i.fromNumber(r+i.slog_critical(t.toNumber(),s.toNumber()));r+=1,s=i.log(s,t)}return i.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:i.critical_section(t,e,Et)}static tetrate_critical(t,e){return i.critical_section(t,e,Tt)}static critical_section(t,e,r,s=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let f=0;ft){let h=(t-U[f])/(U[f+1]-U[f]);n=r[f][Math.floor(e)]*(1-h)+r[f+1][Math.floor(e)]*h,o=r[f][Math.ceil(e)]*(1-h)+r[f+1][Math.ceil(e)]*h;break}let g=e-Math.floor(e);return n<=0||o<=0?n*(1-g)+o*g:Math.pow(t,Math.log(n)/Math.log(t)*(1-g)+Math.log(o)/Math.log(t)*g)}layeradd10(t,e=!1){t=i.fromValue_noAlloc(t).toNumber();let r=i.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let s=Math.trunc(t);t-=s,r.layer+=s}if(t<=-1){let s=Math.trunc(t);if(t-=s,r.layer+=s,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let s=u(e);if(s.gt(1)&&s.lte(1.444667861009766)){let g=i.excess_slog(this,e,r),f=g[0].toNumber(),h=g[1],l=f+t,I=i.ln(e).neg(),y=I.lambertw().div(I),q=I.lambertw(!1).div(I),F=i.dOne;h==1?F=y.mul(q).sqrt():h==2&&(F=q.mul(2));let v=s.pow(F),w=Math.floor(l),S=l-w,T=F.pow(1-S).mul(v.pow(S));return i.tetrate(s,w,T,r)}let o=this.slog(e,100,r).toNumber()+t;return o>=0?i.tetrate(e,o,i.dOne,r):Number.isFinite(o)?o>=-1?i.log(i.tetrate(e,o+1,i.dOne,r),e):i.log(i.log(i.tetrate(e,o+2,i.dOne,r),e),e):m(Number.NaN,Number.NaN,Number.NaN)}static excess_slog(t,e,r=!1){t=u(t),e=u(e);let s=e;if(e=e.toNumber(),e==1||e<=0)return[m(Number.NaN,Number.NaN,Number.NaN),0];if(e>1.444667861009766)return[t.slog(e,100,r),0];let n=i.ln(e).neg(),o=n.lambertw().div(n),g=i.dInf;if(e>1&&(g=n.lambertw(!1).div(n)),e>1.444667861009099&&(o=g=i.fromNumber(Math.E)),t.lt(o))return[t.slog(e,100,r),0];if(t.eq(o))return[m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),0];if(t.eq(g))return[m(1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),2];if(t.gt(g)){let f=g.mul(2),h=s.pow(f),l=0;if(t.gte(f)&&t.lt(h))l=0;else if(t.gte(h)){let w=h;for(l=1;w.lt(t);)if(w=s.pow(w),l=l+1,w.layer>3){let S=Math.floor(t.layer-w.layer+1);w=s.iteratedexp(S,w,r),l=l+S}w.gt(t)&&(w=w.log(e),l=l-1)}else if(t.lt(f)){let w=f;for(l=0;w.gt(t);)w=w.log(e),l=l-1}let I=0,y=0,q=.5,F=f,v=i.dZero;for(;q>1e-16;){if(y=I+q,F=f.pow(1-y).mul(h.pow(y)),v=i.iteratedexp(e,l,F),v.eq(t))return[new i(l+y),2];v.lt(t)&&(I+=q),q/=2}return v.neq_tolerance(t,1e-7)?[m(Number.NaN,Number.NaN,Number.NaN),0]:[new i(l+I),2]}if(t.lt(g)&&t.gt(o)){let f=o.mul(g).sqrt(),h=s.pow(f),l=0;if(t.lte(f)&&t.gt(h))l=0;else if(t.lte(h)){let w=h;for(l=1;w.gt(t);)w=s.pow(w),l=l+1;w.lt(t)&&(w=w.log(e),l=l-1)}else if(t.gt(f)){let w=f;for(l=0;w.lt(t);)w=w.log(e),l=l-1}let I=0,y=0,q=.5,F=f,v=i.dZero;for(;q>1e-16;){if(y=I+q,F=f.pow(1-y).mul(h.pow(y)),v=i.iteratedexp(e,l,F),v.eq(t))return[new i(l+y),1];v.gt(t)&&(I+=q),q/=2}return v.neq_tolerance(t,1e-7)?[m(Number.NaN,Number.NaN,Number.NaN),0]:[new i(l+I),1]}throw new Error("Unhandled behavior in excess_slog")}lambertw(t=!0){return this.lt(-.3678794411710499)?m(Number.NaN,Number.NaN,Number.NaN):t?this.abs().lt("1e-300")?new i(this):this.mag<0?i.fromNumber(it(this.toNumber())):this.layer===0?i.fromNumber(it(this.sign*this.mag)):this.lt("eee15")?ft(this):this.ln():this.sign===1?m(Number.NaN,Number.NaN,Number.NaN):this.layer===0?i.fromNumber(it(this.sign*this.mag,1e-10,!1)):this.layer==1?ft(this,1e-10,!1):this.neg().recip().lambertw().neg()}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(i.dInf))return m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(!this.isFinite())return m(Number.NaN,Number.NaN,Number.NaN);if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return i.fromNumber(t).add(2).pow(this.recip());if(t<=0)return m(Number.NaN,Number.NaN,Number.NaN);if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eOt?this.pow(this.recip()):m(Number.NaN,Number.NaN,Number.NaN)}if(this.eq(1))return m(1,0,1);if(this.lt(0))return m(Number.NaN,Number.NaN,Number.NaN);if(this.lte("1ee-16"))return t%2==1?new i(this):m(Number.NaN,Number.NaN,Number.NaN);if(this.gt(1)){let e=i.dTen;this.gte(i.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=i.dZero,s=e.layer,n=e.iteratedlog(10,s,!0),o=n,g=n.div(2),f=!0;for(;f;)g=r.add(n).div(2),i.iteratedexp(10,s,g,!0).tetrate(t,1,!0).gt(this)?n=g:r=g,g.eq(o)?f=!1:o=g;return i.iteratedexp(10,s,g,!0)}else{let e=1,r=M(1,10,1),s=M(1,10,1),n=M(1,10,1),o=M(1,1,-16),g=i.dZero,f=M(1,10,1),h=o.pow10().recip(),l=i.dZero,I=h,y=h,q=Math.ceil(t)%2==0,F=0,v=M(1,10,1),w=!1,S=i.dZero,T=!1;for(;e<4;){if(e==2){if(q)break;n=M(1,10,1),o=r,e=3,f=M(1,10,1),v=M(1,10,1)}for(w=!1;o.neq(n);){if(S=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))h=o.pow10().recip(),I=o.pow10().recip(),y=o.pow10().recip(),l=i.dZero,F=-1,e==3&&(v=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!q&&o.pow10().recip().lt(.4))h=o.pow10().recip(),I=o.pow10().recip(),y=o.pow10().recip(),l=i.dZero,F=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))h=o.pow10().recip(),I=i.dZero,y=h.mul(2),l=h,q?F=-1:F=0;else{for(g=o.mul(12e-17),h=o.pow10().recip(),I=o.add(g).pow10().recip(),l=h.sub(I),y=h.add(l);I.tetrate(t,1,!0).eq(h.tetrate(t,1,!0))||y.tetrate(t,1,!0).eq(h.tetrate(t,1,!0))||I.gte(h)||y.lte(h);)g=g.mul(2),I=o.add(g).pow10().recip(),l=h.sub(I),y=h.add(l);if((e==1&&y.tetrate(t,1,!0).gt(h.tetrate(t,1,!0))&&I.tetrate(t,1,!0).gt(h.tetrate(t,1,!0))||e==3&&y.tetrate(t,1,!0).lt(h.tetrate(t,1,!0))&&I.tetrate(t,1,!0).lt(h.tetrate(t,1,!0)))&&(v=o),y.tetrate(t,1,!0).lt(h.tetrate(t,1,!0)))F=-1;else if(q)F=1;else if(e==3&&o.gt_tolerance(r,1e-8))F=0;else{for(;I.tetrate(t,1,!0).eq_tolerance(h.tetrate(t,1,!0),1e-8)||y.tetrate(t,1,!0).eq_tolerance(h.tetrate(t,1,!0),1e-8)||I.gte(h)||y.lte(h);)g=g.mul(2),I=o.add(g).pow10().recip(),l=h.sub(I),y=h.add(l);y.tetrate(t,1,!0).sub(h.tetrate(t,1,!0)).lt(h.tetrate(t,1,!0).sub(I.tetrate(t,1,!0)))?F=0:F=1}}if(F==-1&&(T=!0),e==1&&F==1||e==3&&F!=0)if(n.eq(M(1,10,1)))o=o.mul(2);else{let p=!1;if(w&&(F==1&&e==1||F==-1&&e==3)&&(p=!0),o=o.add(n).div(2),p)break}else if(n.eq(M(1,10,1)))n=o,o=o.div(2);else{let p=!1;if(w&&(F==1&&e==1||F==-1&&e==3)&&(p=!0),n=n.sub(f),o=o.sub(f),p)break}if(n.sub(o).div(2).abs().gt(f.mul(1.5))&&(w=!0),f=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(S))break}if(o.gt("1e18")||!T||v==M(1,10,1))break;e==1?r=v:e==3&&(s=v),e++}n=r,o=M(1,1,-18);let A=o,a=i.dZero,N=!0;for(;N;)if(n.eq(M(1,10,1))?a=o.mul(2):a=n.add(o).div(2),i.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(A)?N=!1:A=a,o.gt("1e18"))return m(Number.NaN,Number.NaN,Number.NaN);if(a.eq_tolerance(r,1e-15)){if(s.eq(M(1,10,1)))return m(Number.NaN,Number.NaN,Number.NaN);for(n=M(1,10,1),o=s,A=o,a=i.dZero,N=!0;N;)if(n.eq(M(1,10,1))?a=o.mul(2):a=n.add(o).div(2),i.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(A)?N=!1:A=a,o.gt("1e18"))return m(Number.NaN,Number.NaN,Number.NaN);return a.pow10().recip()}else return a.pow10().recip()}}static increasingInverse(t,e=!1,r=120,s=i.dLayerMax.neg(),n=i.dLayerMax,o=i.dLayerMax.neg(),g=i.dLayerMax){return function(f){if(f=new i(f),s=new i(s),n=new i(n),o=new i(o),g=new i(g),f.isNan()||n.lt(s)||f.lt(o)||f.gt(g))return m(Number.NaN,Number.NaN,Number.NaN);let h=function(c){return new i(c)},l=!0;if(n.lt(0))l=!1;else if(s.gt(0))l=!0;else{let c=t(i.dZero);if(c.eq(f))return m(0,0,0);l=f.gt(c),e&&(l=!l)}let I=l,y;if(l){if(n.lt(z))l=!0;else if(s.gt(z))l=!1;else{let c=t(new i(z));l=f.lt(c),e&&(l=!l)}if(l){y=!0;let c=i.pow(10,P).recip();if(n.lt(c))l=!1;else if(s.gt(c))l=!0;else{let b=t(new i(c));l=f.gt(b),e&&(l=!l)}if(l)h=function(b){return i.pow(10,b).recip()};else{let b=i.tetrate(10,P);if(n.lt(b))l=!1;else if(s.gt(b))l=!0;else{let d=t(new i(b));l=f.gt(d),e&&(l=!l)}l?h=function(d){return i.tetrate(10,new i(d).toNumber()).recip()}:h=function(d){return new i(d).gt(Math.log10(Number.MAX_VALUE))?i.dZero:i.tetrate(10,i.pow(10,d).toNumber()).recip()}}}else{if(y=!1,n.lt(P))l=!0;else if(s.gt(P))l=!1;else{let c=t(new i(P));l=f.lt(c),e&&(l=!l)}if(l)h=function(c){return new i(c)};else{let c=i.pow(10,P);if(n.lt(c))l=!0;else if(s.gt(c))l=!1;else{let b=t(new i(c));l=f.lt(b),e&&(l=!l)}if(l)h=function(b){return i.pow(10,b)};else{let b=i.tetrate(10,P);if(n.lt(b))l=!0;else if(s.gt(b))l=!1;else{let d=t(new i(b));l=f.lt(d),e&&(l=!l)}l?h=function(d){return i.tetrate(10,new i(d).toNumber())}:h=function(d){return new i(d).gt(Math.log10(Number.MAX_VALUE))?i.dInf:i.tetrate(10,i.pow(10,d).toNumber())}}}}}else{if(y=!0,n.lt(-z))l=!1;else if(s.gt(-z))l=!0;else{let c=t(new i(-z));l=f.gt(c),e&&(l=!l)}if(l){let c=i.pow(10,P).recip().neg();if(n.lt(c))l=!0;else if(s.gt(c))l=!1;else{let b=t(new i(c));l=f.lt(b),e&&(l=!l)}if(l)h=function(b){return i.pow(10,b).recip().neg()};else{let b=i.tetrate(10,P).neg();if(n.lt(b))l=!0;else if(s.gt(b))l=!1;else{let d=t(new i(b));l=f.lt(d),e&&(l=!l)}l?h=function(d){return i.tetrate(10,new i(d).toNumber()).recip().neg()}:h=function(d){return new i(d).gt(Math.log10(Number.MAX_VALUE))?i.dZero:i.tetrate(10,i.pow(10,d).toNumber()).recip().neg()}}}else{if(y=!1,n.lt(-P))l=!1;else if(s.gt(-P))l=!0;else{let c=t(new i(-P));l=f.gt(c),e&&(l=!l)}if(l)h=function(c){return i.neg(c)};else{let c=i.pow(10,P).neg();if(n.lt(c))l=!1;else if(s.gt(c))l=!0;else{let b=t(new i(c));l=f.gt(b),e&&(l=!l)}if(l)h=function(b){return i.pow(10,b).neg()};else{let b=i.tetrate(10,P).neg();if(n.lt(b))l=!1;else if(s.gt(b))l=!0;else{let d=t(new i(b));l=f.gt(d),e&&(l=!l)}l?h=function(d){return i.tetrate(10,new i(d).toNumber()).neg()}:h=function(d){return new i(d).gt(Math.log10(Number.MAX_VALUE))?i.dNegInf:i.tetrate(10,i.pow(10,d).toNumber()).neg()}}}}}let q=I!=y!=e,F=q?function(c,b){return i.gt(c,b)}:function(c,b){return i.lt(c,b)},v=.001,w=!1,S=!1,T=1,A=i.dOne,a=0,N=!1;for(var p=1;p1&&S!=b&&(w=!0),S=b,w?v/=2:v*=2,b!=q&&A.eq(n)||b==q&&A.eq(s))return m(Number.NaN,Number.NaN,Number.NaN);if(v=Math.abs(v)*(b?-1:1),T+=v,v===0||a==T)break}return h(T)}}pentate(t=2,e=m(1,0,1),r=!1){e=new i(e);let s=t;t=Math.floor(t);let n=s-t,o=i.dZero,g=i.dZero;if(n!==0)if(e.eq(i.dOne))++t,e=i.fromNumber(n);else return this.pentate(e.penta_log(this,void 0,r).plus(s).toNumber(),1,r);if(t>0)for(let f=0;f1e4)return e}else for(let f=0;f<-t;++f){if(o=e,e=e.slog(this,void 0,r),e.eq(o)||!isFinite(e.layer)||!isFinite(e.mag))return e.normalize();if(f>100)return e}return e}penta_log(t=10,e=100,r=!1){if(t=new i(t),t.lte(1))return m(Number.NaN,Number.NaN,Number.NaN);if(this.eq(1))return m(0,0,0);if(this.eq(i.dInf))return m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);let s=new i(1),n=0,o=1;if(this.lt(-1)){if(this.lte(-2))return m(Number.NaN,Number.NaN,Number.NaN);let f=t.tetrate(this.toNumber(),1,r);if(this.eq(f))return m(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);if(this.gt(f))return m(Number.NaN,Number.NaN,Number.NaN)}if(this.gt(1)){for(;s.lt(this);)if(n++,s=i.tetrate(t,s.toNumber(),1,r),n>1e3)return m(Number.NaN,Number.NaN,Number.NaN)}else for(;s.gt(this);)if(n--,s=i.slog(s,t,r),n>100)return m(Number.NaN,Number.NaN,Number.NaN);for(var g=1;g0&&t<1?this.root(t):this.eq(1)?m(1,0,1):this.lt(0)?m(Number.NaN,Number.NaN,Number.NaN):this.lt(1)?this.linear_sroot(t):i.increasingInverse(function(e){return i.pentate(e,t,1,!0)})(this):m(Number.NaN,Number.NaN,Number.NaN)}sin(){return this.mag<0?new i(this):this.layer===0?i.fromNumber(Math.sin(this.sign*this.mag)):m(0,0,0)}cos(){return this.mag<0?m(1,0,1):this.layer===0?i.fromNumber(Math.cos(this.sign*this.mag)):m(0,0,0)}tan(){return this.mag<0?new i(this):this.layer===0?i.fromNumber(Math.tan(this.sign*this.mag)):m(0,0,0)}asin(){return this.mag<0?new i(this):this.layer===0?i.fromNumber(Math.asin(this.sign*this.mag)):m(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?i.fromNumber(Math.acos(this.toNumber())):this.layer===0?i.fromNumber(Math.acos(this.sign*this.mag)):m(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?new i(this):this.layer===0?i.fromNumber(Math.atan(this.sign*this.mag)):i.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return i.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return i.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?m(Number.NaN,Number.NaN,Number.NaN):i.ln(this.add(1).div(i.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?new i(this):this.root(i.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,s){return new i(t).add(new i(e).minus(new i(t)).times(new i(r)).times(new i(s)))}clone(){return this}static clone(t){return i.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let s=this.clone();return s.gte(t)&&([0,"pow"].includes(r)&&(s=s.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(s=s.sub(t).div(e).add(t))),s}static softcap(t,e,r,s){return new i(t).softcap(e,r,s)}scale(t,e,r,s=!1){t=new i(t),e=new i(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=s?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=s?n.div(t).max(1).log(e).add(t):i.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,s,n=!1){return new i(t).scale(e,r,s,n)}format(t=2,e=9,r="mixed_sc"){return j.format(this.clone(),t,e,r)}static format(t,e=2,r=9,s="mixed_sc"){return j.format(new i(t),e,r,s)}formatST(t=2,e=9,r="st"){return j.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,s="st"){return j.format(new i(t),e,r,s)}formatGain(t,e="mixed_sc",r,s){return j.formatGain(this.clone(),t,e,r,s)}static formatGain(t,e,r="mixed_sc",s,n){return j.formatGain(new i(t),e,r,s,n)}toRoman(t=5e3){t=new i(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),s={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(s)){let g=Math.floor(r/s[o]);r-=g*s[o],n+=o.repeat(g)}return n}static toRoman(t,e){return new i(t).toRoman(e)}static random(t=0,e=1){return t=new i(t),e=new i(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new i(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new i(Math.random()).lt(t)}};i.dZero=m(0,0,0),i.dOne=m(1,0,1),i.dNegOne=m(-1,0,1),i.dTwo=m(1,0,2),i.dTen=m(1,0,10),i.dNaN=m(Number.NaN,Number.NaN,Number.NaN),i.dInf=m(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),i.dNegInf=m(-1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),i.dNumberMax=M(1,0,Number.MAX_VALUE),i.dNumberMin=M(1,0,Number.MIN_VALUE),i.dLayerSafeMax=M(1,Number.MAX_SAFE_INTEGER,P-1),i.dLayerSafeMin=M(1,Number.MAX_SAFE_INTEGER,-(P-1)),i.dLayerMax=M(1,Number.MAX_VALUE,P-1),i.dLayerMin=M(1,Number.MAX_VALUE,-(P-1)),i.fromStringCache=new pt(It),J([tt()],i.prototype,"sign",2),J([tt()],i.prototype,"mag",2),J([tt()],i.prototype,"layer",2),i=J([Nt()],i);var{formats:j,FORMATS:Yt}=dt(i);i.formats=j;function D(t,e){e=Object.assign({formatType:"mixed_sc",acc:2,max:9},e);let{formatType:r,acc:s,max:n,time:o,multi:g,formatTimeType:f}=e;if(o)switch(f){case"short":return i.formats.formatTime(t,s,r);case"long":return i.formats.formatTimeLong(t,!0,0,n,r)}return g?i.formats.formatMult(t,s):i.format(t,s,n,r)}function ht(t,e,r){let{formatType:s,acc:n,max:o}=r;return i.formatGain(t,e,s,n,o)}var qt=class{constructor(t){this.format=e=>D(e,this.settings),this.gain=(e,r)=>ht(e,r,this.settings),this.time=e=>D(e,{...this.settings,time:!0}),this.multi=e=>D(e,{...this.settings,multi:!0}),this.settingsFn=typeof t=="function"?t:()=>t}get settings(){return this.settingsFn()}},At=[{name:"Standard",value:"standard"},{name:"Scientific",value:"scientific"},{name:"Mixed Scientific (default)",value:"mixed_sc"},{name:"Old Scientific",value:"old_sc"},{name:"Engineering",value:"eng"},{name:"Infinity",value:"inf"},{name:"Omega",value:"omega"},{name:"Omega Short",value:"omega_short"},{name:"Elemental",value:"elemental"},{name:"Layer",value:"layer"}].sort((t,e)=>t.name.localeCompare(e.name)),Ct=[{name:"Short (default)",value:"short"},{name:"Long",value:"long"}].sort((t,e)=>t.name.localeCompare(e.name));if(typeof Y.exports=="object"&&typeof H=="object"){var Pt=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(s=Object.getOwnPropertyDescriptor(e,n))||s.enumerable});return t};Y.exports=Pt(Y.exports,H)}return Y.exports}); diff --git a/dist/presets/eMath.presets.mjs b/dist/presets/eMath.presets.mjs index 2323ca15..1226d3d6 100644 --- a/dist/presets/eMath.presets.mjs +++ b/dist/presets/eMath.presets.mjs @@ -1655,25 +1655,31 @@ var Decimal = class { return D(value).reciprocate(); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value, other) { - return D(value).mod(other); + static mod(value, other, floored = false) { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value, other) { - return D(value).modulo(other); + static modulo(value, other, floored = false) { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value, other) { - return D(value).modular(other); + static modular(value, other, floored = false) { + return D(value).modular(other, floored); } /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. @@ -2123,6 +2129,31 @@ var Decimal = class { static pentate(value, height = 2, payload = FC_NN(1, 0, 1), linear = false) { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value, base = 10, linear = false) { + return D(value).penta_log(base, 100, linear); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value, degree) { + return D(value).linear_penta_root(degree); + } /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -2614,6 +2645,12 @@ var Decimal = class { } else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + if (this.layer < 0 || this.layer % 1 != 0) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -3110,12 +3147,20 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - mod(value) { - const decimal = D(value).abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + mod(value, floored = false) { + const vd = D(value); + const decimal = vd.abs(); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if (this.sign == -1 != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); if (isFinite(num_this) && isFinite(num_decimal) && num_this != 0 && num_decimal != 0) { @@ -3132,17 +3177,21 @@ var Decimal = class { } /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value) { - return this.mod(value); + modulo(value, floored = false) { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value) { - return this.mod(value); + modular(value, floored = false) { + return this.mod(value, floored); } /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. @@ -4482,45 +4531,406 @@ var Decimal = class { } } } + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func, decreasing = false, iterations = 120, minX = Decimal.dLayerMax.neg(), maxX = Decimal.dLayerMax, minY = Decimal.dLayerMax.neg(), maxY = Decimal.dLayerMax) { + return function(value) { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let rangeApply = function(value2) { + return new Decimal(value2); + }; + let currentCheck = true; + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return new Decimal(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()); + }; + } + } + } + } else { + reciprocal = true; + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).recip().neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = true; + else if (minX.gt(limit2)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).recip().neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).recip().neg(); + }; + } + } else { + reciprocal = false; + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.neg(value2); + }; + else { + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.pow(10, value2).neg(); + }; + else { + let limit2 = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit2)) currentCheck = false; + else if (minX.gt(limit2)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit2)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) rangeApply = function(value2) { + return Decimal.tetrate(10, new Decimal(value2).toNumber()).neg(); + }; + else rangeApply = function(value2) { + return new Decimal(value2).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value2).toNumber()).neg(); + }; + } + } + } + } + let searchIncreasing = positive != reciprocal != decreasing; + let comparative = searchIncreasing ? function(a, b) { + return Decimal.gt(a, b); + } : function(a, b) { + return Decimal.lt(a, b); + }; + let step_size = 1e-3; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { + break; + } + let currently_rose = comparative(new_decimal, value); + if (i > 1) { + if (previously_rose != currently_rose) { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) { + step_size /= 2; + } else { + step_size *= 2; + } + if (currently_rose != searchIncreasing && appliedResult.eq(maxX) || currently_rose == searchIncreasing && appliedResult.eq(minX)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { + break; + } + } + return rangeApply(result); + }; + } /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation - * + * * Tetration for non-integer heights does not have a single agreed-upon definition, * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. * Analytic approximation is not currently supported for bases > 10. - * + * * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height = 2, payload = FC_NN(1, 0, 1), linear = false) { payload = new Decimal(payload); const oldheight = height; - height = Math.trunc(height); + height = Math.floor(height); const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; if (fracheight !== 0) { if (payload.eq(Decimal.dOne)) { ++height; payload = Decimal.fromNumber(fracheight); } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + return this.pentate(payload.penta_log(this, void 0, linear).plus(oldheight).toNumber(), 1, linear); } } - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + if (payload.eq(prevpayload) || payload.eq(prevtwopayload) && i % 2 == height % 2) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 1e4) { + return payload; + } } - if (i > 10) { - return payload; + } else { + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, void 0, linear); + if (payload.eq(prevpayload)) return payload.normalize(); + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + if (i > 100) { + return payload; + } } } return payload; } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + penta_log(base = 10, iterations = 100, linear = false) { + base = new Decimal(base); + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1e3) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { + break; + } + } + return Decimal.fromNumber(result); + } + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree) { + if (degree == 1) { + return this; + } + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (degree > 0 && degree < 1) { + return this.root(degree); + } + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.lt(1)) { + return this.linear_sroot(degree); + } + return Decimal.increasingInverse(function(value) { + return Decimal.pentate(value, degree, 1, true); + })(this); + } // trig functions! /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. @@ -4858,16 +5268,64 @@ var Decimal = class { return new Decimal(Math.random()).lt(rng); } }; +/** + * Represents the number 0. + */ Decimal.dZero = FC_NN(0, 0, 0); +/** + * Represents the number 1. + */ Decimal.dOne = FC_NN(1, 0, 1); +/** + * Represents the number -1. + */ Decimal.dNegOne = FC_NN(-1, 0, 1); +/** + * Represents the number 2. + */ Decimal.dTwo = FC_NN(1, 0, 2); +/** + * Represents the number 10. + */ Decimal.dTen = FC_NN(1, 0, 10); +/** + * Represents a NaN (Not A Number) value. + */ Decimal.dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); +/** + * Represents positive infinity. + */ Decimal.dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents negative infinity. + */ Decimal.dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); +/** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ Decimal.dNumberMax = FC(1, 0, Number.MAX_VALUE); +/** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ Decimal.dNumberMin = FC(1, 0, Number.MIN_VALUE); +/** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ +Decimal.dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); +/** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ +Decimal.dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); +/** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ +Decimal.dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); +/** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ +Decimal.dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); Decimal.fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); __decorateClass([ Expose() diff --git a/dist/types/E/e.d.ts b/dist/types/E/e.d.ts index 3cf68535..8e22c870 100644 --- a/dist/types/E/e.d.ts +++ b/dist/types/E/e.d.ts @@ -8,16 +8,64 @@ export type DecimalSource = Decimal | number | string; * The value of the Decimal is sign * 10^10^10...^mag, with (layer) 10s. If the layer is not 0, then negative mag means it's the reciprocal of the corresponding number with positive mag. */ declare class Decimal { + /** + * Represents the number 0. + */ static readonly dZero: Decimal; + /** + * Represents the number 1. + */ static readonly dOne: Decimal; + /** + * Represents the number -1. + */ static readonly dNegOne: Decimal; + /** + * Represents the number 2. + */ static readonly dTwo: Decimal; + /** + * Represents the number 10. + */ static readonly dTen: Decimal; + /** + * Represents a NaN (Not A Number) value. + */ static readonly dNaN: Decimal; + /** + * Represents positive infinity. + */ static readonly dInf: Decimal; + /** + * Represents negative infinity. + */ static readonly dNegInf: Decimal; + /** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ static readonly dNumberMax: Decimal; + /** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ static readonly dNumberMin: Decimal; + /** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ + static readonly dLayerSafeMax: Decimal; + /** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ + static readonly dLayerSafeMin: Decimal; + /** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ + static readonly dLayerMax: Decimal; + /** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ + static readonly dLayerMin: Decimal; private static fromStringCache; sign: number; mag: number; @@ -170,20 +218,26 @@ declare class Decimal { */ static reciprocate(value: DecimalSource): Decimal; /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static mod(value: DecimalSource, other: DecimalSource): Decimal; + static mod(value: DecimalSource, other: DecimalSource, floored?: boolean): Decimal; /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modulo(value: DecimalSource, other: DecimalSource): Decimal; + static modulo(value: DecimalSource, other: DecimalSource, floored?: boolean): Decimal; /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - static modular(value: DecimalSource, other: DecimalSource): Decimal; + static modular(value: DecimalSource, other: DecimalSource, floored?: boolean): Decimal; /** * Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'. */ @@ -514,6 +568,27 @@ declare class Decimal { * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ static pentate(value: DecimalSource, height?: number, payload?: DecimalSource, linear?: boolean): Decimal; + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + static penta_log(value: DecimalSource, base?: DecimalSource, linear?: boolean): Decimal; + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + static linear_penta_root(value: DecimalSource, degree: number): Decimal; /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -771,19 +846,25 @@ declare class Decimal { reciprocate(): Decimal; /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - mod(value: DecimalSource): Decimal; + mod(value: DecimalSource, floored?: boolean): Decimal; /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modulo(value: DecimalSource): Decimal; + modulo(value: DecimalSource, floored?: boolean): Decimal; /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - modular(value: DecimalSource): Decimal; + modular(value: DecimalSource, floored?: boolean): Decimal; /** * Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'. */ @@ -1121,6 +1202,25 @@ declare class Decimal { * This only matters for non-integer degrees. */ linear_sroot(degree: number): Decimal; + /** + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + static increasingInverse(func: (((value: DecimalSource) => Decimal) | ((value: Decimal) => Decimal)), decreasing?: boolean, iterations?: number, minX?: DecimalSource, maxX?: DecimalSource, minY?: DecimalSource, maxY?: DecimalSource): (value: DecimalSource) => Decimal; /** * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! * https://en.wikipedia.org/wiki/Pentation @@ -1133,6 +1233,27 @@ declare class Decimal { * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. */ pentate(height?: number, payload?: DecimalSource, linear?: boolean): Decimal; + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + penta_log(base?: DecimalSource, iterations?: number, linear?: boolean): Decimal; + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + linear_penta_root(degree: number): Decimal; /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ diff --git a/dist/types/classes/numericalAnalysis.d.ts b/dist/types/classes/numericalAnalysis.d.ts index 0c2891e7..5b0a7bff 100644 --- a/dist/types/classes/numericalAnalysis.d.ts +++ b/dist/types/classes/numericalAnalysis.d.ts @@ -57,6 +57,7 @@ interface EqualsToleranceConfig { declare function equalsTolerance(a: DecimalSource, b: DecimalSource, tolerance: DecimalSource, config?: Partial): boolean; /** * Approximates the inverse of a function at `n` using the bisection / binary search method. + * @deprecated Use {@link Decimal.increasingInverse} instead. * @param f - The function to approximate the inverse of. It must be monotonically increasing and satisfy `f(n) >= n` for all `n >= 0`. * @param n - The value to approximate the inverse at. * @param mode - The mode/mean method to use. See {@link MeanMode} diff --git a/src/E/e.ts b/src/E/e.ts index 0a749286..6a9027bf 100644 --- a/src/E/e.ts +++ b/src/E/e.ts @@ -397,16 +397,64 @@ export type DecimalSource = Decimal | number | string; */ @Exclude() class Decimal { + /** + * Represents the number 0. + */ public static readonly dZero = FC_NN(0, 0, 0); + /** + * Represents the number 1. + */ public static readonly dOne = FC_NN(1, 0, 1); + /** + * Represents the number -1. + */ public static readonly dNegOne = FC_NN(-1, 0, 1); + /** + * Represents the number 2. + */ public static readonly dTwo = FC_NN(1, 0, 2); + /** + * Represents the number 10. + */ public static readonly dTen = FC_NN(1, 0, 10); + /** + * Represents a NaN (Not A Number) value. + */ public static readonly dNaN = FC_NN(Number.NaN, Number.NaN, Number.NaN); + /** + * Represents positive infinity. + */ public static readonly dInf = FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + /** + * Represents negative infinity. + */ public static readonly dNegInf = FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + /** + * Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308. + */ public static readonly dNumberMax = FC(1, 0, Number.MAX_VALUE); + /** + * Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324. + */ public static readonly dNumberMin = FC(1, 0, Number.MIN_VALUE); + /** + * Represents the largest Decimal where adding 1 to the layer is a safe operation + * (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). + * Approximately 10^^(9.007 * 10^15). + */ + public static readonly dLayerSafeMax = FC(1, Number.MAX_SAFE_INTEGER, EXP_LIMIT - 1); + /** + * Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)). + */ + public static readonly dLayerSafeMin = FC(1, Number.MAX_SAFE_INTEGER, -(EXP_LIMIT - 1)); + /** + * Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308). + */ + public static readonly dLayerMax = FC(1, Number.MAX_VALUE, EXP_LIMIT - 1); + /** + * Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)). + */ + public static readonly dLayerMin = FC(1, Number.MAX_VALUE, -(EXP_LIMIT - 1)); private static fromStringCache = new LRUCache(DEFAULT_FROM_STRING_CACHE_SIZE); @@ -756,27 +804,33 @@ class Decimal { } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - public static mod (value: DecimalSource, other: DecimalSource): Decimal { - return D(value).mod(other); + public static mod(value: DecimalSource, other: DecimalSource, floored : boolean = false): Decimal { + return D(value).mod(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - public static modulo (value: DecimalSource, other: DecimalSource): Decimal { - return D(value).modulo(other); + public static modulo(value: DecimalSource, other: DecimalSource, floored : boolean = false): Decimal { + return D(value).modulo(other, floored); } /** - * Returns the remainder of 'value' divided by 'other': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - public static modular (value: DecimalSource, other: DecimalSource): Decimal { - return D(value).modular(other); + public static modular(value: DecimalSource, other: DecimalSource, floored : boolean = false): Decimal { + return D(value).modular(other, floored); } /** @@ -1335,6 +1389,33 @@ class Decimal { return D(value).pentate(height, payload, linear); } + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + public static penta_log(value: DecimalSource, base : DecimalSource = 10, linear = false): Decimal { + return D(value).penta_log(base, 100, linear); + } + + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + public static linear_penta_root(value: DecimalSource, degree: number): Decimal { + return D(value).linear_penta_root(degree); + } + /** * The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi. */ @@ -1985,6 +2066,13 @@ class Decimal { else { this.layer = parseFloat(layerstring); this.mag = parseFloat(newparts[1].substr(i + 1)); + // Handle invalid cases like (e^-8)1 and (e^10.5)1 by just calling tetrate + if (this.layer < 0 || (this.layer % 1 != 0)) { + const result = Decimal.tetrate(10, this.layer, this.mag, linearhyper4); + this.sign = result.sign; + this.layer = result.layer; + this.mag = result.mag; + } this.normalize(); if (Decimal.fromStringCache.maxSize >= 1) { Decimal.fromStringCache.set(originalValue, Decimal.fromDecimal(this)); @@ -2598,13 +2686,21 @@ class Decimal { /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ // Taken from OmegaNum.js, with a couple touch-ups - public mod (value: DecimalSource): Decimal { - const decimal = D(value).abs(); + public mod(value: DecimalSource, floored : boolean = false): Decimal { + const vd = D(value); + const decimal = vd.abs(); - if (decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dZero) || decimal.eq(Decimal.dZero)) return FC_NN(0, 0, 0); + if (floored) { + let absmod = this.abs().mod(decimal); + if ((this.sign == -1) != (vd.sign == -1)) absmod = vd.abs().sub(absmod); + return absmod.mul(vd.sign); + } const num_this = this.toNumber(); const num_decimal = decimal.toNumber(); // Special case: To avoid precision issues, if both numbers are valid JS numbers, just call % on those @@ -2612,11 +2708,11 @@ class Decimal { return new Decimal(num_this % num_decimal); } if (this.sub(decimal).eq(this)) { - // decimal is too small to register to this + // decimal is too small to register to this return FC_NN(0, 0, 0); } if (decimal.sub(this).eq(decimal)) { - // this is too small to register to decimal + // this is too small to register to decimal return new Decimal(this); } if (this.sign == -1) return this.abs().mod(decimal).neg(); @@ -2625,18 +2721,22 @@ class Decimal { /** * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - public modulo (value: DecimalSource) : Decimal { - return this.mod(value); + public modulo(value: DecimalSource, floored : boolean = false) : Decimal { + return this.mod(value, floored); } /** - * Returns the remainder of this / value: for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. - * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%). + * Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. + * Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... + * unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. + * These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers. */ - public modular (value: DecimalSource) : Decimal { - return this.mod(value); + public modular(value: DecimalSource, floored : boolean = false) : Decimal { + return this.mod(value, floored); } /** @@ -4226,50 +4326,449 @@ class Decimal { } /** - * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! - * https://en.wikipedia.org/wiki/Pentation - * - * Tetration for non-integer heights does not have a single agreed-upon definition, - * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. - * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. - * Analytic approximation is not currently supported for bases > 10. - * - * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. - */ - public pentate (height = 2, payload: DecimalSource = FC_NN(1, 0, 1), linear = false): Decimal { - payload = new Decimal(payload); - const oldheight = height; - height = Math.trunc(height); - const fracheight = oldheight - height; - - // I have no idea if this is a meaningful approximation for pentation to continuous heights, but it is monotonic and continuous. - if (fracheight !== 0) { - if (payload.eq(Decimal.dOne)) { - ++height; - payload = Decimal.fromNumber(fracheight); - } else { - if (this.eq(10)) { - payload = payload.layeradd10(fracheight, linear); - } else { - payload = payload.layeradd(fracheight, this, linear); - } + * This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), + * and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. + * The resulting function will call the original many times, so it may be noticably slower than the original. + * + * This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. + * Its resulting function may output erroneous results if the original function was not strictly increasing. + * If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. + * If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented) + * + * @param func The Decimal => Decimal function to create an inverse function of. + * @param decreasing This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing. + * @param iterations The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows. + * @param minX The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxX The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + * @param minY If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not. + * @param maxY If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not. + */ + public static increasingInverse( + func : (((value : DecimalSource) => Decimal) | ((value : Decimal) => Decimal)), + decreasing = false, + iterations = 120, + minX : DecimalSource = Decimal.dLayerMax.neg(), + maxX : DecimalSource = Decimal.dLayerMax, + minY : DecimalSource = Decimal.dLayerMax.neg(), + maxY : DecimalSource = Decimal.dLayerMax, + ) { + return function(value : DecimalSource) : Decimal { + value = new Decimal(value); + minX = new Decimal(minX); + maxX = new Decimal(maxX); + minY = new Decimal(minY); + maxY = new Decimal(maxY); + + if (value.isNan() || maxX.lt(minX) || value.lt(minY) || value.gt(maxY)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + + // Before actually doing the search, let's determine what range we're looking at. First-class function shenanigans incoming. + let rangeApply = function(value : DecimalSource){return new Decimal(value);} + let currentCheck = true; // Checking whether the inverse is positive + if (maxX.lt(0)) currentCheck = false; + else if (minX.gt(0)) currentCheck = true; + else { + let valCheck = func(Decimal.dZero); + if (valCheck.eq(value)) return FC_NN(0, 0, 0); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + let positive = currentCheck; + let reciprocal; + if (currentCheck) { + // Checking whether the inverse is below 1/9e15 + if (maxX.lt(FIRST_NEG_LAYER)) currentCheck = true; + else if (minX.gt(FIRST_NEG_LAYER)) currentCheck = false; + else { + let valCheck = func(new Decimal(FIRST_NEG_LAYER)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + reciprocal = true; + // Checking whether the inverse is above 1/e9e15 + let limit = Decimal.pow(10, EXP_LIMIT).recip(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between 1/e9e15 and 1/9e15, search through layer -1 numbers. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.pow(10, value).recip();} + else { + // Checking whether the inverse is above 1/10^^9e15 + let limit = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; } + // If the inverse is between 1/10^^9e15 and 1/e9e15, search through reciprocals of negative layers themselves. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.tetrate(10, new Decimal(value).toNumber()).recip();} + // If the inverse is below 1/10^^9e15, search through reciprocals of exponents of layers. + else rangeApply = function(value : DecimalSource){return (new Decimal(value).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value).toNumber()).recip())} + } } - - for (let i = 0; i < height; ++i) { - payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); - // bail if we're NaN - if (!isFinite(payload.layer) || !isFinite(payload.mag)) { - return payload.normalize(); + else { + reciprocal = false + // Checking whether the inverse is below 9e15 + if (maxX.lt(EXP_LIMIT)) currentCheck = true; + else if (minX.gt(EXP_LIMIT)) currentCheck = false; + else { + let valCheck = func(new Decimal(EXP_LIMIT)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between 1/9e15 and 9e15, search through direct (layer 0) numbers. + if (currentCheck) rangeApply = function(value : DecimalSource){return new Decimal(value);} + else { + // Checking whether the inverse is below e9e15 + let limit = Decimal.pow(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; } - // give up after 10 iterations if nothing is happening - if (i > 10) { - return payload; + // If the inverse is between 9e15 and e9e15, search through layer 1 numbers. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.pow(10, value);} + else { + // Checking whether the inverse is below 10^^9e15 + let limit = Decimal.tetrate(10, EXP_LIMIT); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between e9e15 and 10^^9e15, search through layers themselves. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.tetrate(10, new Decimal(value).toNumber());} + // If the inverse is above 10^^9e15, search through exponents of layers. + else rangeApply = function(value : DecimalSource){return (new Decimal(value).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dInf : Decimal.tetrate(10, Decimal.pow(10, value).toNumber()))} } + } + } + } + else { + reciprocal = true + // Checking whether the inverse is above -1/9e15 + if (maxX.lt(-FIRST_NEG_LAYER)) currentCheck = false; + else if (minX.gt(-FIRST_NEG_LAYER)) currentCheck = true; + else { + let valCheck = func(new Decimal(-FIRST_NEG_LAYER)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + if (currentCheck) { + // Checking whether the inverse is below -1/e9e15 + let limit = Decimal.pow(10, EXP_LIMIT).recip().neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between -1/e9e15 and -1/9e15, search through negatives of layer -1 numbers. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.pow(10, value).recip().neg();} + else { + // Checking whether the inverse is below -1/10^^9e15 + let limit = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = true; + else if (minX.gt(limit)) currentCheck = false; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.lt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between -1/10^^9e15 and -1/e9e15, search through reciprocals of negative layers themselves. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.tetrate(10, new Decimal(value).toNumber()).recip().neg();} + // If the inverse is above -1/10^^9e15, search through exponents of reciprocals of negative layers. + else rangeApply = function(value : DecimalSource){return (new Decimal(value).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dZero : Decimal.tetrate(10, Decimal.pow(10, value).toNumber()).recip().neg())} + } } - - return payload; + else { + reciprocal = false; + // Checking whether the inverse is above -9e15 + if (maxX.lt(-EXP_LIMIT)) currentCheck = false; + else if (minX.gt(-EXP_LIMIT)) currentCheck = true; + else { + let valCheck = func(new Decimal(-EXP_LIMIT)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between -1/9e15 and -9e15, search through negatives of direct (layer 0) numbers. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.neg(value);} + else { + // Checking whether the inverse is above -e9e15 + let limit = Decimal.pow(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between -9e15 and -e9e15, search through negatives of layer 1 numbers. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.pow(10, value).neg();} + else { + // Checking whether the inverse is above -10^^9e15 + let limit = Decimal.tetrate(10, EXP_LIMIT).neg(); + if (maxX.lt(limit)) currentCheck = false; + else if (minX.gt(limit)) currentCheck = true; + else { + let valCheck = func(new Decimal(limit)); + currentCheck = value.gt(valCheck); + if (decreasing) currentCheck = !currentCheck; + } + // If the inverse is between e9e15 and 10^^9e15, search through negatives of layers themselves. + if (currentCheck) rangeApply = function(value : DecimalSource){return Decimal.tetrate(10, new Decimal(value).toNumber()).neg();} + // If the inverse is below -10^^9e15, search through negatives of exponents of layers. + else rangeApply = function(value : DecimalSource){return (new Decimal(value).gt(Math.log10(Number.MAX_VALUE)) ? Decimal.dNegInf : Decimal.tetrate(10, Decimal.pow(10, value).toNumber()).neg())} + } + } + } + } + let searchIncreasing = ((positive != reciprocal) != decreasing); + let comparative = searchIncreasing ? (function(a : DecimalSource, b : DecimalSource){return Decimal.gt(a, b)}) : (function(a : DecimalSource, b : DecimalSource){return Decimal.lt(a, b)}); + + let step_size = 0.001; + let has_changed_directions_once = false; + let previously_rose = false; + let result = 1; + let appliedResult = Decimal.dOne; + let oldresult = 0; + let critical = false; + for (var i = 1; i < iterations; ++i) + { + critical = false; + oldresult = result; + appliedResult = rangeApply(result); + //Under no circumstances should we be calling func on something outside its domain. + if (appliedResult.gt(maxX)) { + appliedResult = maxX; + critical = true; + } + if (appliedResult.lt(minX)) { + appliedResult = minX; + critical = true; + } + let new_decimal = func(appliedResult); + if (new_decimal.eq(value) && !critical) { break; } + let currently_rose = comparative(new_decimal, value); + if (i > 1) + { + if (previously_rose != currently_rose) + { + has_changed_directions_once = true; + } + } + previously_rose = currently_rose; + if (has_changed_directions_once) + { + step_size /= 2; + } + else + { + step_size *= 2; + } + // If the inverse is trying to increase when it's already at maxX, or it's trying to decrease when it's already at minX, it's going outside the domain, so return NaN. + if ((currently_rose != searchIncreasing && appliedResult.eq(maxX)) || (currently_rose == searchIncreasing && appliedResult.eq(minX))) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + if (step_size === 0 || oldresult == result) { break; } + } + return rangeApply(result); + } + } + + /** + * Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! + * https://en.wikipedia.org/wiki/Pentation + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + public pentate(height = 2, payload: DecimalSource = FC_NN(1, 0, 1), linear = false): Decimal { + payload = new Decimal(payload); + const oldheight = height; + height = Math.floor(height); + const fracheight = oldheight - height; + let prevpayload = Decimal.dZero; + let prevtwopayload = Decimal.dZero; + + // Linear approximation. I have no idea if this is a meaningful approximation for pentation to continuous heights, but it is monotonic and continuous. + if (fracheight !== 0) { + if (payload.eq(Decimal.dOne)) { + ++height; + payload = Decimal.fromNumber(fracheight); + } else { + // Despite calling penta_log, this is safe, as penta_log only calls pentation with payload 1. + return this.pentate(payload.penta_log(this, undefined, linear).plus(oldheight).toNumber(), 1, linear); + } + } + + if (height > 0) { + for (let i = 0; i < height; ) { + prevtwopayload = prevpayload; + prevpayload = payload; + payload = this.tetrate(payload.toNumber(), Decimal.dOne, linear); + ++i; + // Under the linear approximation of pentation, if p is between 0 and 1, x^^^p == x^^p (which just equals x^p if tetration is also using the linear approximation) + // ...and once both the base and payload are between 0 and 1, they'll both stay that way. + if (this.gt(0) && this.lte(1) && payload.gt(0) && payload.lte(1)) return this.tetrate(height - i, payload, linear); + // End early if it's settled on a limit. Bases close to 0 alternate between two possible values. + if (payload.eq(prevpayload) || (payload.eq(prevtwopayload) && (i % 2 == height % 2))) return payload.normalize(); + //bail if we're NaN + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + //give up after 10000 iterations if nothing is happening + if (i > 10000) { + return payload; + } + } + } + else { + // Repeated slog is sloooow, but that's what negative pentation height means. Since it's just calling slog repeatedly anyway (without any layer shortcuts), I see no reason to make this its own function (whereas iteratedlog makes sense to be its own function even though it's negative height tetrate). + for (let i = 0; i < -height; ++i) { + prevpayload = payload; + payload = payload.slog(this, undefined, linear); + // End early if it's settled on a limit + if (payload.eq(prevpayload)) return payload.normalize(); + //bail if we're NaN + if (!isFinite(payload.layer) || !isFinite(payload.mag)) { + return payload.normalize(); + } + //give up after 100 iterations if nothing is happening + if (i > 100) { + return payload; + } + } + } + + return payload; + } + + /** + * Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'. + * + * Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function. + * + * Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth. + * + * Tetration for non-integer heights does not have a single agreed-upon definition, + * so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. + * If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. + * Analytic approximation is not currently supported for bases > 10. + * + * For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation. + */ + // INCREDIBLY slow on numbers <= -1. Probably don't call it on those. + // If you're here looking to port penta_log to OmegaNum, ExpantaNum, or something similar, then know that this implementation isn't sufficient for that purpose. The pentation functions here run loops without shortcuts, because in break_eternity the numbers don't get large enough to need those shortcuts. + public penta_log(base: DecimalSource = 10, iterations = 100, linear = false) { + base = new Decimal(base); + // Bases below 1 oscillate, so the logarithm doesn't make sense + if (base.lte(1)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + if (this.eq(1)) return FC_NN(0, 0, 0); + if (this.eq(Decimal.dInf)) return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + let value = new Decimal(1); + let result = 0; + let step_size = 1; + + // There's some x between -1 and -2, depending on the base, where base^^x == x. This x is base^^^(-Infinity), and we shouldn't bother with numbers less than that limit. + if (this.lt(-1)) { + if (this.lte(-2)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + let limitcheck = base.tetrate(this.toNumber(), 1, linear); + if (this.eq(limitcheck)) return FC_NN(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + if (this.gt(limitcheck)) return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + + // pentate runs through each tetration iteration anyway, so while we're narrowing down on the nearest integer it's faster to just check them one-by-one than to run through pentate every time + if (this.gt(1)) { + while (value.lt(this)) { + result++; + value = Decimal.tetrate(base, value.toNumber(), 1, linear); + if (result > 1000) { + // Probably reached a limit by this point. + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } } + else { + while (value.gt(this)) { + result--; + value = Decimal.slog(value, base, linear); + if (result > 100) { + // Probably reached the limit by this point. + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + } + } + for (var i = 1; i < iterations; ++i) { + let new_decimal = base.pentate(result, Decimal.dOne, linear); + if (new_decimal.eq(this)) break; + let currently_rose = new_decimal.gt(this); + step_size = Math.abs(step_size) * (currently_rose ? -1 : 1); + result += step_size; + step_size /= 2; + if (step_size === 0) { break; } + } + return Decimal.fromNumber(result); + } + + /** + * Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'? + * + * Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. + */ + public linear_penta_root(degree: number) : Decimal { + //1st-degree super root just returns its input + if (degree == 1) { + return this; + } + //TODO: degree < 0 (A pretty useless case, seeing as it runs into the same issues as linear_sroot's degrees between -1 and 0 for degrees between -2 and 0, and for degrees below -2 it'll only have a value for negative numbers between -1 and... some limit between -1 and -2.) + if (degree < 0) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + if (this.eq(Decimal.dInf)) { + return FC_NN(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + } + if (!this.isFinite()) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + //Using linear approximation, x^^^n = x^n if 0 < n < 1 + if (degree > 0 && degree < 1) { + return this.root(degree); + } + //Special case: any super-root of 1 is 1 + if (this.eq(1)) { + return FC_NN(1, 0, 1); + } + //TODO: base < 0 (It'll probably be NaN anyway) + if (this.lt(0)) { + return FC_NN(Number.NaN, Number.NaN, Number.NaN); + } + /* If 'this' is below 1, then the result is going to be below 1, meaning the original number was a tetration tower where all entries are below 1... + ...and in the linear approximation, tetration with a height between 0 and 1 reduces to exponentiation of that height. + Therefore, penta_root and sroot will return the same value. */ + if (this.lt(1)) { + return this.linear_sroot(degree) + } + + // Unlike with super-root, I'm not sure how to get a good upper bound here, so let's just call increasingInverse. + return (Decimal.increasingInverse(function(value : Decimal){return Decimal.pentate(value, degree, 1, true)}))(this); + } + // trig functions! /** diff --git a/src/classes/numericalAnalysis.ts b/src/classes/numericalAnalysis.ts index 2e45a0d7..4fd6a383 100644 --- a/src/classes/numericalAnalysis.ts +++ b/src/classes/numericalAnalysis.ts @@ -149,6 +149,7 @@ function equalsTolerance( /** * Approximates the inverse of a function at `n` using the bisection / binary search method. + * @deprecated Use {@link Decimal.increasingInverse} instead. * @param f - The function to approximate the inverse of. It must be monotonically increasing and satisfy `f(n) >= n` for all `n >= 0`. * @param n - The value to approximate the inverse at. * @param mode - The mode/mean method to use. See {@link MeanMode}