From 97088f637f32a588e64d689ebbf57bdebe94004c Mon Sep 17 00:00:00 2001 From: MathCookie17 Date: Mon, 19 Feb 2024 15:00:48 -0500 Subject: [PATCH] Negative infinity fix My previous attempt at normalizing infinities did not work correctly for negative infinities. Hopefully this one does... --- break_eternity.cjs.js | 24 ++++++++++++++++-------- break_eternity.esm.js | 24 ++++++++++++++++-------- break_eternity.js | 24 ++++++++++++++++-------- break_eternity.min.js | 2 +- src/index.ts | 27 +++++++++++++++++---------- 5 files changed, 66 insertions(+), 35 deletions(-) diff --git a/break_eternity.cjs.js b/break_eternity.cjs.js index 6dabc2d..a49f322 100644 --- a/break_eternity.cjs.js +++ b/break_eternity.cjs.js @@ -491,11 +491,11 @@ var Decimal = /*#__PURE__*/function () { Any 0 is totally zero (0, 0, 0) and any NaN is totally NaN (NaN, NaN, NaN). Anything layer 0 has mag 0 OR mag > 1/9e15 and < 9e15. Anything layer 1 or higher has abs(mag) >= 15.954 and < 9e15. - Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, Infinity, Infinity). + Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, -Infinity, -Infinity). We will assume in calculations that all Decimals are either erroneous or satisfy these criteria. (Otherwise: Garbage in, garbage out.) */ //Any 0 is totally 0 - if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0) { + if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0 && Number.isFinite(this.layer)) { this.sign = 0; this.mag = 0; this.layer = 0; @@ -507,9 +507,14 @@ var Decimal = /*#__PURE__*/function () { this.sign = -this.sign; } //Handle infinities - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { - this.mag = Number.POSITIVE_INFINITY; - this.layer = Number.POSITIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { + if (this.sign == 1) { + this.mag = Number.POSITIVE_INFINITY; + this.layer = Number.POSITIVE_INFINITY; + } else if (this.sign == -1) { + this.mag = Number.NEGATIVE_INFINITY; + this.layer = Number.NEGATIVE_INFINITY; + } return this; } //Handle shifting from layer 0 to negative layers. @@ -930,8 +935,11 @@ var Decimal = /*#__PURE__*/function () { }, { key: "toNumber", value: function toNumber() { - if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY) { - return this.sign > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY && this.sign === 1) { + return Number.POSITIVE_INFINITY; + } + if (this.mag === Number.NEGATIVE_INFINITY && this.layer === Number.NEGATIVE_INFINITY && this.sign === -1) { + return Number.NEGATIVE_INFINITY; } if (!Number.isFinite(this.layer)) { return Number.NaN; @@ -980,7 +988,7 @@ var Decimal = /*#__PURE__*/function () { if (isNaN(this.layer) || isNaN(this.sign) || isNaN(this.mag)) { return "NaN"; } - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { return this.sign === 1 ? "Infinity" : "-Infinity"; } if (this.layer === 0) { diff --git a/break_eternity.esm.js b/break_eternity.esm.js index 8a55b1c..fe56416 100644 --- a/break_eternity.esm.js +++ b/break_eternity.esm.js @@ -489,11 +489,11 @@ var Decimal = /*#__PURE__*/function () { Any 0 is totally zero (0, 0, 0) and any NaN is totally NaN (NaN, NaN, NaN). Anything layer 0 has mag 0 OR mag > 1/9e15 and < 9e15. Anything layer 1 or higher has abs(mag) >= 15.954 and < 9e15. - Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, Infinity, Infinity). + Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, -Infinity, -Infinity). We will assume in calculations that all Decimals are either erroneous or satisfy these criteria. (Otherwise: Garbage in, garbage out.) */ //Any 0 is totally 0 - if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0) { + if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0 && Number.isFinite(this.layer)) { this.sign = 0; this.mag = 0; this.layer = 0; @@ -505,9 +505,14 @@ var Decimal = /*#__PURE__*/function () { this.sign = -this.sign; } //Handle infinities - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { - this.mag = Number.POSITIVE_INFINITY; - this.layer = Number.POSITIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { + if (this.sign == 1) { + this.mag = Number.POSITIVE_INFINITY; + this.layer = Number.POSITIVE_INFINITY; + } else if (this.sign == -1) { + this.mag = Number.NEGATIVE_INFINITY; + this.layer = Number.NEGATIVE_INFINITY; + } return this; } //Handle shifting from layer 0 to negative layers. @@ -928,8 +933,11 @@ var Decimal = /*#__PURE__*/function () { }, { key: "toNumber", value: function toNumber() { - if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY) { - return this.sign > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY && this.sign === 1) { + return Number.POSITIVE_INFINITY; + } + if (this.mag === Number.NEGATIVE_INFINITY && this.layer === Number.NEGATIVE_INFINITY && this.sign === -1) { + return Number.NEGATIVE_INFINITY; } if (!Number.isFinite(this.layer)) { return Number.NaN; @@ -978,7 +986,7 @@ var Decimal = /*#__PURE__*/function () { if (isNaN(this.layer) || isNaN(this.sign) || isNaN(this.mag)) { return "NaN"; } - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { return this.sign === 1 ? "Infinity" : "-Infinity"; } if (this.layer === 0) { diff --git a/break_eternity.js b/break_eternity.js index 1c10829..6aa091a 100644 --- a/break_eternity.js +++ b/break_eternity.js @@ -495,11 +495,11 @@ Any 0 is totally zero (0, 0, 0) and any NaN is totally NaN (NaN, NaN, NaN). Anything layer 0 has mag 0 OR mag > 1/9e15 and < 9e15. Anything layer 1 or higher has abs(mag) >= 15.954 and < 9e15. - Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, Infinity, Infinity). + Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, -Infinity, -Infinity). We will assume in calculations that all Decimals are either erroneous or satisfy these criteria. (Otherwise: Garbage in, garbage out.) */ //Any 0 is totally 0 - if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0) { + if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0 && Number.isFinite(this.layer)) { this.sign = 0; this.mag = 0; this.layer = 0; @@ -511,9 +511,14 @@ this.sign = -this.sign; } //Handle infinities - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { - this.mag = Number.POSITIVE_INFINITY; - this.layer = Number.POSITIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { + if (this.sign == 1) { + this.mag = Number.POSITIVE_INFINITY; + this.layer = Number.POSITIVE_INFINITY; + } else if (this.sign == -1) { + this.mag = Number.NEGATIVE_INFINITY; + this.layer = Number.NEGATIVE_INFINITY; + } return this; } //Handle shifting from layer 0 to negative layers. @@ -934,8 +939,11 @@ }, { key: "toNumber", value: function toNumber() { - if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY) { - return this.sign > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY && this.sign === 1) { + return Number.POSITIVE_INFINITY; + } + if (this.mag === Number.NEGATIVE_INFINITY && this.layer === Number.NEGATIVE_INFINITY && this.sign === -1) { + return Number.NEGATIVE_INFINITY; } if (!Number.isFinite(this.layer)) { return Number.NaN; @@ -984,7 +992,7 @@ if (isNaN(this.layer) || isNaN(this.sign) || isNaN(this.mag)) { return "NaN"; } - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { return this.sign === 1 ? "Infinity" : "-Infinity"; } if (this.layer === 0) { diff --git a/break_eternity.min.js b/break_eternity.min.js index b0bd507..0c04d5f 100644 --- a/break_eternity.min.js +++ b/break_eternity.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Decimal=e()}(this,(function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var i=0;ithis.maxSize;){var r=this.last;this.map.delete(r.key),this.last=r.prev,this.last.next=void 0}}}}]),e}(),n=i((function e(i,r){t(this,e),this.next=void 0,this.prev=void 0,this.key=i,this.value=r})),a=Math.log10(9e15),s=function(){for(var t=[],e=-323;e<=308;e++)t.push(Number("1e"+e));return function(e){return t[e+323]}}(),u=[2,Math.E,3,4,5,6,7,8,9,10],o=[[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]],h=[[-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]],l=function(t){return p.fromValue_noAlloc(t)},m=function(t,e,i){return p.fromComponents(t,e,i)},g=function(t,e,i){return p.fromComponents_noNormalize(t,e,i)},f=function(t,e){var i=e+1,r=Math.ceil(Math.log10(Math.abs(t))),n=Math.round(t*Math.pow(10,i-r))*Math.pow(10,r-i);return parseFloat(n.toFixed(Math.max(i-r,0)))},c=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},y=.5671432904097838,v=function(t){var e,i,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10;if(!Number.isFinite(t))return t;if(0===t)return t;if(1===t)return y;e=t<10?0:Math.log(t)-Math.log(Math.log(t));for(var n=0;n<100;++n){if(i=(t*Math.exp(-e)+e*e)/(e+1),Math.abs(i-e)1&&void 0!==arguments[1]?arguments[1]:1e-10;if(!Number.isFinite(t.mag))return t;if(t.eq(p.dZero))return t;if(t.eq(p.dOne))return p.fromNumber(y);e=p.ln(t);for(var s=0;s<100;++s){if(i=e.neg().exp(),r=e.sub(t.mul(i)),n=e.sub(r.div(e.add(1).sub(e.add(2).mul(r).div(p.mul(2,e).add(2))))),p.abs(n.sub(e)).lt(p.abs(n).mul(a)))return n;e=n}throw Error("Iteration failed to converge: ".concat(t.toString()))}var p=function(){function e(i){t(this,e),this.sign=0,this.mag=0,this.layer=0,i instanceof e?this.fromDecimal(i):"number"==typeof i?this.fromNumber(i):"string"==typeof i&&this.fromString(i)}return i(e,[{key:"m",get:function(){if(0===this.sign)return 0;if(0===this.layer){var t,e=Math.floor(Math.log10(this.mag));return t=5e-324===this.mag?5:this.mag/s(e),this.sign*t}if(1===this.layer){var i=this.mag-Math.floor(this.mag);return this.sign*Math.pow(10,i)}return this.sign},set:function(t){this.layer<=2?this.fromMantissaExponent(t,this.e):(this.sign=Math.sign(t),0===this.sign&&(this.layer=0,this.exponent=0))}},{key:"e",get:function(){return 0===this.sign?0:0===this.layer?Math.floor(Math.log10(this.mag)):1===this.layer?Math.floor(this.mag):2===this.layer?Math.floor(Math.sign(this.mag)*Math.pow(10,Math.abs(this.mag))):this.mag*Number.POSITIVE_INFINITY},set:function(t){this.fromMantissaExponent(this.m,t)}},{key:"s",get:function(){return this.sign},set:function(t){0===t?(this.sign=0,this.layer=0,this.mag=0):this.sign=t}},{key:"mantissa",get:function(){return this.m},set:function(t){this.m=t}},{key:"exponent",get:function(){return this.e},set:function(t){this.e=t}},{key:"normalize",value:function(){if(0===this.sign||0===this.mag&&0===this.layer||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0)return this.sign=0,this.mag=0,this.layer=0,this;if(0===this.layer&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY)return this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY,this;if(0===this.layer&&this.mag<1/9e15)return this.layer+=1,this.mag=Math.log10(this.mag),this;var t=Math.abs(this.mag),e=Math.sign(this.mag);if(t>=9e15)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,0===this.layer?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 0===this.layer&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):0===this.mag&&(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}},{key:"fromComponents",value:function(t,e,i){return this.sign=t,this.layer=e,this.mag=i,this.normalize(),this}},{key:"fromComponents_noNormalize",value:function(t,e,i){return this.sign=t,this.layer=e,this.mag=i,this}},{key:"fromMantissaExponent",value:function(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}},{key:"fromMantissaExponent_noNormalize",value:function(t,e){return this.fromMantissaExponent(t,e),this}},{key:"fromDecimal",value:function(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}},{key:"fromNumber",value:function(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}},{key:"fromString",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=t,n=e.fromStringCache.get(r);if(void 0!==n)return this.fromDecimal(n);var a=(t=t.replace(",","")).split("^^^");if(2===a.length){var s=parseFloat(a[0]),u=parseFloat(a[1]),o=a[1].split(";"),h=1;if(2===o.length&&(h=parseFloat(o[1]),isFinite(h)||(h=1)),isFinite(s)&&isFinite(u)){var g=e.pentate(s,u,h,i);return this.sign=g.sign,this.layer=g.layer,this.mag=g.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var f=t.split("^^");if(2===f.length){var y=parseFloat(f[0]),v=parseFloat(f[1]),d=f[1].split(";"),p=1;if(2===d.length&&(p=parseFloat(d[1]),isFinite(p)||(p=1)),isFinite(y)&&isFinite(v)){var N=e.tetrate(y,v,p,i);return this.sign=N.sign,this.layer=N.layer,this.mag=N.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var k,b,M=t.split("^");if(2===M.length){var I=parseFloat(M[0]),_=parseFloat(M[1]);if(isFinite(I)&&isFinite(_)){var F=e.pow(I,_);return this.sign=F.sign,this.layer=F.layer,this.mag=F.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var w=(t=t.trim().toLowerCase()).split("pt");if(2===w.length){k=10,b=parseFloat(w[0]),w[1]=w[1].replace("(",""),w[1]=w[1].replace(")","");var S=parseFloat(w[1]);if(isFinite(S)||(S=1),isFinite(k)&&isFinite(b)){var q=e.tetrate(k,b,S,i);return this.sign=q.sign,this.layer=q.layer,this.mag=q.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}if(2===(w=t.split("p")).length){k=10,b=parseFloat(w[0]),w[1]=w[1].replace("(",""),w[1]=w[1].replace(")","");var x=parseFloat(w[1]);if(isFinite(x)||(x=1),isFinite(k)&&isFinite(b)){var E=e.tetrate(k,b,x,i);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}if(2===(w=t.split("f")).length){k=10,w[0]=w[0].replace("(",""),w[0]=w[0].replace(")","");var T=parseFloat(w[0]);if(w[1]=w[1].replace("(",""),w[1]=w[1].replace(")",""),b=parseFloat(w[1]),isFinite(T)||(T=1),isFinite(k)&&isFinite(b)){var O=e.tetrate(k,b,T,i);return this.sign=O.sign,this.layer=O.layer,this.mag=O.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var C=t.split("e"),z=C.length-1;if(0===z){var V=parseFloat(t);if(isFinite(V))return this.fromNumber(V),e.fromStringCache.size>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}else if(1===z){var P=parseFloat(t);if(isFinite(P)&&0!==P)return this.fromNumber(P),e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}var D=t.split("e^");if(2===D.length){this.sign=1,"-"==D[0].charAt(0)&&(this.sign=-1);for(var Z="",A=0;A=43&&Y<=57||101===Y))return this.layer=parseFloat(Z),this.mag=parseFloat(D[1].substr(A+1)),this.normalize(),e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this;Z+=D[1].charAt(A)}}if(z<1)return this.sign=0,this.layer=0,this.mag=0,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this;var G=parseFloat(C[0]);if(0===G)return this.sign=0,this.layer=0,this.mag=0,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this;var L=parseFloat(C[C.length-1]);if(z>=2){var j=parseFloat(C[C.length-2]);isFinite(j)&&(L*=Math.sign(j),L+=c(j))}if(isFinite(G))if(1===z)this.sign=Math.sign(G),this.layer=1,this.mag=L+Math.log10(Math.abs(G));else{if(this.sign=Math.sign(G),this.layer=z,2===z){var W=e.mul(m(1,2,L),l(G));return this.sign=W.sign,this.layer=W.layer,this.mag=W.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}this.mag=L}else this.sign="-"===C[0]?-1:1,this.layer=z,this.mag=L;return this.normalize(),e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}},{key:"fromValue",value:function(t){return t instanceof e?this.fromDecimal(t):"number"==typeof t?this.fromNumber(t):"string"==typeof t?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}},{key:"toNumber",value:function(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?0===this.layer?this.sign*this.mag:1===this.layer?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}},{key:"mantissaWithDecimalPlaces",value:function(t){return isNaN(this.m)?Number.NaN:0===this.m?0:f(this.m,t)}},{key:"magnitudeWithDecimalPlaces",value:function(t){return isNaN(this.mag)?Number.NaN:0===this.mag?0:f(this.mag,t)}},{key:"toString",value:function(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY?1===this.sign?"Infinity":"-Infinity":0===this.layer?this.mag<1e21&&this.mag>1e-7||0===this.mag?(this.sign*this.mag).toString():this.m+"e"+this.e:1===this.layer?this.m+"e"+this.e:this.layer<=5?(-1===this.sign?"-":"")+"e".repeat(this.layer)+this.mag:(-1===this.sign?"-":"")+"(e^"+this.layer+")"+this.mag}},{key:"toExponential",value:function(t){return 0===this.layer?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}},{key:"toFixed",value:function(t){return 0===this.layer?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}},{key:"toPrecision",value:function(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}},{key:"valueOf",value:function(){return this.toString()}},{key:"toJSON",value:function(){return this.toString()}},{key:"toStringWithDecimalPlaces",value:function(t){return 0===this.layer?this.mag<1e21&&this.mag>1e-7||0===this.mag?(this.sign*this.mag).toFixed(t):f(this.m,t)+"e"+f(this.e,t):1===this.layer?f(this.m,t)+"e"+f(this.e,t):this.layer<=5?(-1===this.sign?"-":"")+"e".repeat(this.layer)+f(this.mag,t):(-1===this.sign?"-":"")+"(e^"+this.layer+")"+f(this.mag,t)}},{key:"abs",value:function(){return g(0===this.sign?0:1,this.layer,this.mag)}},{key:"neg",value:function(){return g(-this.sign,this.layer,this.mag)}},{key:"negate",value:function(){return this.neg()}},{key:"negated",value:function(){return this.neg()}},{key:"sgn",value:function(){return this.sign}},{key:"round",value:function(){return this.mag<0?e.dZero:0===this.layer?m(this.sign,0,Math.round(this.mag)):this}},{key:"floor",value:function(){return this.mag<0?-1===this.sign?e.dNegOne:e.dZero:-1===this.sign?this.neg().ceil().neg():0===this.layer?m(this.sign,0,Math.floor(this.mag)):this}},{key:"ceil",value:function(){return this.mag<0?1===this.sign?e.dOne:e.dZero:-1===this.sign?this.neg().floor().neg():0===this.layer?m(this.sign,0,Math.ceil(this.mag)):this}},{key:"trunc",value:function(){return this.mag<0?e.dZero:0===this.layer?m(this.sign,0,Math.trunc(this.mag)):this}},{key:"add",value:function(t){var i,r,n=l(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(n.layer))return n;if(0===this.sign)return n;if(0===n.sign)return this;if(this.sign===-n.sign&&this.layer===n.layer&&this.mag===n.mag)return g(0,0,0);if(this.layer>=2||n.layer>=2)return this.maxabs(n);if(e.cmpabs(this,n)>0?(i=this,r=n):(i=n,r=this),0===i.layer&&0===r.layer)return e.fromNumber(i.sign*i.mag+r.sign*r.mag);var a=i.layer*Math.sign(i.mag),s=r.layer*Math.sign(r.mag);if(a-s>=2)return i;if(0===a&&-1===s){if(Math.abs(r.mag-Math.log10(i.mag))>17)return i;var u=Math.pow(10,Math.log10(i.mag)-r.mag),o=r.sign+i.sign*u;return m(Math.sign(o),1,r.mag+Math.log10(Math.abs(o)))}if(1===a&&0===s){if(Math.abs(i.mag-Math.log10(r.mag))>17)return i;var h=Math.pow(10,i.mag-Math.log10(r.mag)),f=r.sign+i.sign*h;return m(Math.sign(f),1,Math.log10(r.mag)+Math.log10(Math.abs(f)))}if(Math.abs(i.mag-r.mag)>17)return i;var c=Math.pow(10,i.mag-r.mag),y=r.sign+i.sign*c;return m(Math.sign(y),1,r.mag+Math.log10(Math.abs(y)))}},{key:"plus",value:function(t){return this.add(t)}},{key:"sub",value:function(t){return this.add(l(t).neg())}},{key:"subtract",value:function(t){return this.sub(t)}},{key:"minus",value:function(t){return this.sub(t)}},{key:"mul",value:function(t){var i,r,n=l(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(n.layer))return n;if(0===this.sign||0===n.sign)return g(0,0,0);if(this.layer===n.layer&&this.mag===-n.mag)return g(this.sign*n.sign,0,1);if(this.layer>n.layer||this.layer==n.layer&&Math.abs(this.mag)>Math.abs(n.mag)?(i=this,r=n):(i=n,r=this),0===i.layer&&0===r.layer)return e.fromNumber(i.sign*r.sign*i.mag*r.mag);if(i.layer>=3||i.layer-r.layer>=2)return m(i.sign*r.sign,i.layer,i.mag);if(1===i.layer&&0===r.layer)return m(i.sign*r.sign,1,i.mag+Math.log10(r.mag));if(1===i.layer&&1===r.layer)return m(i.sign*r.sign,1,i.mag+r.mag);if(2===i.layer&&1===r.layer){var a=m(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)).add(m(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)));return m(i.sign*r.sign,a.layer+1,a.sign*a.mag)}if(2===i.layer&&2===r.layer){var s=m(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)).add(m(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)));return m(i.sign*r.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}},{key:"multiply",value:function(t){return this.mul(t)}},{key:"times",value:function(t){return this.mul(t)}},{key:"div",value:function(t){var e=l(t);return this.mul(e.recip())}},{key:"divide",value:function(t){return this.div(t)}},{key:"divideBy",value:function(t){return this.div(t)}},{key:"dividedBy",value:function(t){return this.div(t)}},{key:"recip",value:function(){return 0===this.mag?e.dNaN:0===this.layer?m(this.sign,0,1/this.mag):m(this.sign,this.layer,-this.mag)}},{key:"reciprocal",value:function(){return this.recip()}},{key:"reciprocate",value:function(){return this.recip()}},{key:"mod",value:function(t){var i=l(t).abs();if(i.eq(e.dZero))return e.dZero;var r=this.toNumber(),n=i.toNumber();return isFinite(r)&&isFinite(n)&&0!=r&&0!=n?new e(r%n):this.sub(i).eq(this)?e.dZero:i.sub(this).eq(i)?this:-1==this.sign?this.abs().mod(i).neg():this.sub(this.div(i).floor().mul(i))}},{key:"modulo",value:function(t){return this.mod(t)}},{key:"modular",value:function(t){return this.mod(t)}},{key:"cmp",value:function(t){var e=l(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,r=e.mag>0?e.layer:-e.layer;return i>r?1:ie.mag?1:this.mag0?e:this}},{key:"clamp",value:function(t,e){return this.max(t).min(e)}},{key:"clampMin",value:function(t){return this.max(t)}},{key:"clampMax",value:function(t){return this.min(t)}},{key:"cmp_tolerance",value:function(t,e){var i=l(t);return this.eq_tolerance(i,e)?0:this.cmp(i)}},{key:"compare_tolerance",value:function(t,e){return this.cmp_tolerance(t,e)}},{key:"eq_tolerance",value:function(t,e){var i=l(t);if(null==e&&(e=1e-7),this.sign!==i.sign)return!1;if(Math.abs(this.layer-i.layer)>1)return!1;var r=this.mag,n=i.mag;return this.layer>i.layer&&(n=c(n)),this.layer0?m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):m(1,0,Math.log10(this.mag))}},{key:"log10",value:function(){return this.sign<=0?e.dNaN:this.layer>0?m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):m(this.sign,0,Math.log10(this.mag))}},{key:"log",value:function(t){return t=l(t),this.sign<=0||t.sign<=0||1===t.sign&&0===t.layer&&1===t.mag?e.dNaN:0===this.layer&&0===t.layer?m(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):e.div(this.log10(),t.log10())}},{key:"log2",value:function(){return this.sign<=0?e.dNaN:0===this.layer?m(this.sign,0,Math.log2(this.mag)):1===this.layer?m(Math.sign(this.mag),0,3.321928094887362*Math.abs(this.mag)):2===this.layer?m(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}},{key:"ln",value:function(){return this.sign<=0?e.dNaN:0===this.layer?m(this.sign,0,Math.log(this.mag)):1===this.layer?m(Math.sign(this.mag),0,2.302585092994046*Math.abs(this.mag)):2===this.layer?m(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}},{key:"logarithm",value:function(t){return this.log(t)}},{key:"pow",value:function(t){var i=this,r=l(t);if(0===i.sign)return r.eq(0)?g(1,0,1):i;if(1===i.sign&&0===i.layer&&1===i.mag)return i;if(0===r.sign)return g(1,0,1);if(1===r.sign&&0===r.layer&&1===r.mag)return i;var n=i.absLog10().mul(r).pow10();return-1===this.sign?Math.abs(r.toNumber()%2)%2==1?n.neg():Math.abs(r.toNumber()%2)%2==0?n:e.dNaN:n}},{key:"pow10",value:function(){if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return e.dNaN;var t=this;if(0===t.layer){var i=Math.pow(10,t.sign*t.mag);if(Number.isFinite(i)&&Math.abs(i)>=.1)return m(1,0,i);if(0===t.sign)return e.dOne;t=g(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):e.dOne}},{key:"pow_base",value:function(t){return l(t).pow(this)}},{key:"root",value:function(t){var e=l(t);return this.pow(e.recip())}},{key:"factorial",value:function(){return this.mag<0||0===this.layer?this.add(1).gamma():1===this.layer?e.exp(e.mul(this,e.ln(this).sub(1))):e.exp(this)}},{key:"gamma",value:function(){if(this.mag<0)return this.recip();if(0===this.layer){if(this.lt(g(1,0,24)))return e.fromNumber(function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;for(var e=1;t<10;)e*=t,++t;var i=.9189385332046727;i+=((t-=1)+.5)*Math.log(t),i-=t;var r=t*t,n=t;return i+=1/(12*n),i+=1/(360*(n*=r)),i+=1/(1260*(n*=r)),i+=1/(1680*(n*=r)),i+=1/(1188*(n*=r)),i+=691/(360360*(n*=r)),i+=7/(1092*(n*=r)),i+=3617/(122400*(n*=r)),Math.exp(i)/e}(this.sign*this.mag));var t=this.mag-1,i=.9189385332046727;i+=(t+.5)*Math.log(t);var r=t*t,n=t,a=12*n,s=1/a,u=(i-=t)+s;if(u===i)return e.exp(i);if((u=(i=u)-(s=1/(a=360*(n*=r))))===i)return e.exp(i);i=u;var o=1/(a=1260*(n*=r));return i+=o,i-=o=1/(a=1680*(n*=r)),e.exp(i)}return 1===this.layer?e.exp(e.mul(this,e.ln(this).sub(1))):e.exp(this)}},{key:"lngamma",value:function(){return this.gamma().ln()}},{key:"exp",value:function(){return this.mag<0?e.dOne:0===this.layer&&this.mag<=709.7?e.fromNumber(Math.exp(this.sign*this.mag)):0===this.layer?m(1,1,this.sign*Math.log10(Math.E)*this.mag):1===this.layer?m(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):m(1,this.layer+1,this.sign*this.mag)}},{key:"sqr",value:function(){return this.pow(2)}},{key:"sqrt",value:function(){if(0===this.layer)return e.fromNumber(Math.sqrt(this.sign*this.mag));if(1===this.layer)return m(1,2,Math.log10(this.mag)-.3010299956639812);var t=e.div(g(this.sign,this.layer-1,this.mag),g(1,0,2));return t.layer+=1,t.normalize(),t}},{key:"cube",value:function(){return this.pow(3)}},{key:"cbrt",value:function(){return this.pow(1/3)}},{key:"tetrate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g(1,0,1),r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(1===t)return e.pow(this,i);if(0===t)return new e(i);if(this.eq(e.dOne))return e.dOne;if(this.eq(-1))return e.pow(this,i);if(t===Number.POSITIVE_INFINITY){var n=this.toNumber();if(n<=1.444667861009766&&n>=.06598803584531254){if(n>1.444667861009099)return e.fromNumber(Math.E);var a=e.ln(this).neg();return a.lambertw().div(a)}return n>1.444667861009766?e.fromNumber(Number.POSITIVE_INFINITY):e.dNaN}if(this.eq(e.dZero)){var s=Math.abs((t+1)%2);return s>1&&(s=2-s),e.fromNumber(s)}if(t<0)return e.iteratedlog(i,this,-t,r);i=l(i);var u=t,o=u-(t=Math.trunc(t));if(this.gt(e.dZero)&&this.lte(1.444667861009766)&&(u>1e4||!r)){t=Math.min(1e4,t);for(var h=0;h1e4){var f=this.pow(i);return u<=1e4||Math.ceil(u)%2==0?i.mul(1-o).add(f.mul(o)):i.mul(o).add(f.mul(1-o))}return i}0!==o&&(i.eq(e.dOne)?this.gt(10)||r?i=this.pow(o):(i=e.fromNumber(e.tetrate_critical(this.toNumber(),o)),this.lt(2)&&(i=i.sub(1).mul(this.minus(1)).plus(1))):i=this.eq(10)?i.layeradd10(o,r):i.layeradd(o,this,r));for(var c=0;c3)return g(i.sign,i.layer+(t-c-1),i.mag);if(c>1e4)return i}return i}},{key:"iteratedexp",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g(1,0,1),i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.tetrate(t,e,i)}},{key:"iteratedlog",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(i<0)return e.tetrate(t,-i,this,r);t=l(t);var n=e.fromDecimal(this),a=i,s=a-(i=Math.trunc(i));if(n.layer-t.layer>3){var u=Math.min(i,n.layer-t.layer-3);i-=u,n.layer-=u}for(var o=0;o1e4)return n}return s>0&&s<1&&(n=t.eq(10)?n.layeradd10(-s,r):n.layeradd(-s,t,r)),n}},{key:"slog",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=.001,a=!1,s=!1,u=this.slog_internal(t,r).toNumber(),o=1;o1&&s!=l&&(a=!0),s=l,a?n/=2:n*=2,u+=n=Math.abs(n)*(l?-1:1),0===n)break}return e.fromNumber(u)}},{key:"slog_internal",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if((t=l(t)).lte(e.dZero))return e.dNaN;if(t.eq(e.dOne))return e.dNaN;if(t.lt(e.dOne))return this.eq(e.dOne)?e.dZero:this.eq(e.dZero)?e.dNegOne:e.dNaN;if(this.mag<0||this.eq(e.dZero))return e.dNegOne;var r=0,n=e.fromDecimal(this);if(n.layer-t.layer>3){var a=n.layer-t.layer-3;r+=a,n.layer-=a}for(var s=0;s<100;++s)if(n.lt(e.dZero))n=e.pow(t,n),r-=1;else{if(n.lte(e.dOne))return i?e.fromNumber(r+n.toNumber()-1):e.fromNumber(r+e.slog_critical(t.toNumber(),n.toNumber()));r+=1,n=e.log(n,t)}return e.fromNumber(r)}},{key:"layeradd10",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];t=e.fromValue_noAlloc(t).toNumber();var r=e.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):-1===r.sign&&0==r.layer&&(r.sign=1,r.mag=-r.mag);var n=Math.trunc(t);t-=n,r.layer+=n}if(t<=-1){var a=Math.trunc(t);if(t-=a,r.layer+=a,r.layer<0)for(var s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return 0===r.sign&&(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 0===r.sign&&(r.sign=1,0===r.mag&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),0!==t?r.layeradd(t,10,i):r}},{key:"layeradd",value:function(t,i){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=this.slog(i).toNumber(),a=n+t;return a>=0?e.tetrate(i,a,e.dOne,r):Number.isFinite(a)?a>=-1?e.log(e.tetrate(i,a+1,e.dOne,r),i):e.log(e.log(e.tetrate(i,a+2,e.dOne,r),i),i):e.dNaN}},{key:"lambertw",value:function(){if(this.lt(-.3678794411710499))throw Error("lambertw is unimplemented for results less than -1, sorry!");if(this.mag<0)return e.fromNumber(v(this.toNumber()));if(0===this.layer)return e.fromNumber(v(this.sign*this.mag));if(1===this.layer)return d(this);if(2===this.layer)return d(this);if(this.layer>=3)return g(this.sign,this.layer-1,this.mag);throw"Unhandled behavior in lambertw()"}},{key:"ssqrt",value:function(){return this.linear_sroot(2)}},{key:"linear_sroot",value:function(t){if(1==t)return this;if(this.eq(e.dInf))return e.dInf;if(!this.isFinite())return e.dNaN;if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return e.fromNumber(t).add(2).pow(this.recip());if(t<=0)return e.dNaN;if(t==Number.POSITIVE_INFINITY){var i=this.toNumber();return i.36787944117144233?this.pow(this.recip()):e.dNaN}if(this.eq(1))return e.dOne;if(this.lt(0))return e.dNaN;if(this.lte("1ee-16"))return t%2==1?this:e.dNaN;if(this.gt(1)){var r=e.dTen;this.gte(e.tetrate(10,t,1,!0))&&(r=this.iteratedlog(10,t-1,!0)),t<=1&&(r=this.root(t));for(var n=e.dZero,a=r.layer,s=r.iteratedlog(10,a,!0),u=s,o=s.div(2),h=!0;h;)o=n.add(s).div(2),e.iteratedexp(10,a,o,!0).tetrate(t,1,!0).gt(this)?s=o:n=o,o.eq(u)?h=!1:u=o;return e.iteratedexp(10,a,o,!0)}for(var l=1,g=m(1,10,1),f=m(1,10,1),c=m(1,10,1),y=m(1,1,-16),v=e.dZero,d=m(1,10,1),p=y.pow10().recip(),N=e.dZero,k=p,b=p,M=Math.ceil(t)%2==0,I=0,_=m(1,10,1),F=!1,w=e.dZero,S=!1;l<4;){if(2==l){if(M)break;c=m(1,10,1),y=g,l=3,d=m(1,10,1),_=m(1,10,1)}for(F=!1;y.neq(c);){if(w=y,y.pow10().recip().tetrate(t,1,!0).eq(1)&&y.pow10().recip().lt(.4))p=y.pow10().recip(),k=y.pow10().recip(),b=y.pow10().recip(),N=e.dZero,I=-1,3==l&&(_=y);else if(y.pow10().recip().tetrate(t,1,!0).eq(y.pow10().recip())&&!M&&y.pow10().recip().lt(.4))p=y.pow10().recip(),k=y.pow10().recip(),b=y.pow10().recip(),N=e.dZero,I=0;else if(y.pow10().recip().tetrate(t,1,!0).eq(y.pow10().recip().mul(2).tetrate(t,1,!0)))p=y.pow10().recip(),k=e.dZero,b=p.mul(2),N=p,I=M?-1:0;else{for(v=y.mul(12e-17),p=y.pow10().recip(),k=y.add(v).pow10().recip(),N=p.sub(k),b=p.add(N);k.tetrate(t,1,!0).eq(p.tetrate(t,1,!0))||b.tetrate(t,1,!0).eq(p.tetrate(t,1,!0))||k.gte(p)||b.lte(p);)v=v.mul(2),k=y.add(v).pow10().recip(),N=p.sub(k),b=p.add(N);if((1==l&&b.tetrate(t,1,!0).gt(p.tetrate(t,1,!0))&&k.tetrate(t,1,!0).gt(p.tetrate(t,1,!0))||3==l&&b.tetrate(t,1,!0).lt(p.tetrate(t,1,!0))&&k.tetrate(t,1,!0).lt(p.tetrate(t,1,!0)))&&(_=y),b.tetrate(t,1,!0).lt(p.tetrate(t,1,!0)))I=-1;else if(M)I=1;else if(3==l&&y.gt_tolerance(g,1e-8))I=0;else{for(;k.tetrate(t,1,!0).eq_tolerance(p.tetrate(t,1,!0),1e-8)||b.tetrate(t,1,!0).eq_tolerance(p.tetrate(t,1,!0),1e-8)||k.gte(p)||b.lte(p);)v=v.mul(2),k=y.add(v).pow10().recip(),N=p.sub(k),b=p.add(N);I=b.tetrate(t,1,!0).sub(p.tetrate(t,1,!0)).lt(p.tetrate(t,1,!0).sub(k.tetrate(t,1,!0)))?0:1}}if(-1==I&&(S=!0),1==l&&1==I||3==l&&0!=I)if(c.eq(m(1,10,1)))y=y.mul(2);else{var q=!1;if(F&&(1==I&&1==l||-1==I&&3==l)&&(q=!0),y=y.add(c).div(2),q)break}else if(c.eq(m(1,10,1)))c=y,y=y.div(2);else{var x=!1;if(F&&(1==I&&1==l||-1==I&&3==l)&&(x=!0),c=c.sub(d),y=y.sub(d),x)break}if(c.sub(y).div(2).abs().gt(d.mul(1.5))&&(F=!0),d=c.sub(y).div(2).abs(),y.gt("1e18"))break;if(y.eq(w))break}if(y.gt("1e18"))break;if(!S)break;if(_==m(1,10,1))break;1==l?g=_:3==l&&(f=_),l++}c=g;for(var E=y=m(1,1,-18),T=e.dZero,O=!0;O;)if(T=c.eq(m(1,10,1))?y.mul(2):c.add(y).div(2),e.pow(10,T).recip().tetrate(t,1,!0).gt(this)?y=T:c=T,T.eq(E)?O=!1:E=T,y.gt("1e18"))return e.dNaN;if(T.eq_tolerance(g,1e-15)){if(f.eq(m(1,10,1)))return e.dNaN;for(c=m(1,10,1),E=y=f,T=e.dZero,O=!0;O;)if(T=c.eq(m(1,10,1))?y.mul(2):c.add(y).div(2),e.pow(10,T).recip().tetrate(t,1,!0).gt(this)?y=T:c=T,T.eq(E)?O=!1:E=T,y.gt("1e18"))return e.dNaN;return T.pow10().recip()}return T.pow10().recip()}},{key:"pentate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g(1,0,1),r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];i=l(i);var n=t,a=n-(t=Math.trunc(t));0!==a&&(i.eq(e.dOne)?(++t,i=e.fromNumber(a)):i=this.eq(10)?i.layeradd10(a,r):i.layeradd(a,this,r));for(var s=0;s10)return i}return i}},{key:"sin",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.sin(this.sign*this.mag)):g(0,0,0)}},{key:"cos",value:function(){return this.mag<0?e.dOne:0===this.layer?e.fromNumber(Math.cos(this.sign*this.mag)):g(0,0,0)}},{key:"tan",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.tan(this.sign*this.mag)):g(0,0,0)}},{key:"asin",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.asin(this.sign*this.mag)):g(Number.NaN,Number.NaN,Number.NaN)}},{key:"acos",value:function(){return this.mag<0?e.fromNumber(Math.acos(this.toNumber())):0===this.layer?e.fromNumber(Math.acos(this.sign*this.mag)):g(Number.NaN,Number.NaN,Number.NaN)}},{key:"atan",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.atan(this.sign*this.mag)):e.fromNumber(Math.atan(Infinity*this.sign))}},{key:"sinh",value:function(){return this.exp().sub(this.negate().exp()).div(2)}},{key:"cosh",value:function(){return this.exp().add(this.negate().exp()).div(2)}},{key:"tanh",value:function(){return this.sinh().div(this.cosh())}},{key:"asinh",value:function(){return e.ln(this.add(this.sqr().add(1).sqrt()))}},{key:"acosh",value:function(){return e.ln(this.add(this.sqr().sub(1).sqrt()))}},{key:"atanh",value:function(){return this.abs().gte(1)?g(Number.NaN,Number.NaN,Number.NaN):e.ln(this.add(1).div(e.fromNumber(1).sub(this))).div(2)}},{key:"ascensionPenalty",value:function(t){return 0===t?this:this.root(e.pow(10,t))}},{key:"egg",value:function(){return this.add(9)}},{key:"lessThanOrEqualTo",value:function(t){return this.cmp(t)<1}},{key:"lessThan",value:function(t){return this.cmp(t)<0}},{key:"greaterThanOrEqualTo",value:function(t){return this.cmp(t)>-1}},{key:"greaterThan",value:function(t){return this.cmp(t)>0}}],[{key:"fromComponents",value:function(t,i,r){return(new e).fromComponents(t,i,r)}},{key:"fromComponents_noNormalize",value:function(t,i,r){return(new e).fromComponents_noNormalize(t,i,r)}},{key:"fromMantissaExponent",value:function(t,i){return(new e).fromMantissaExponent(t,i)}},{key:"fromMantissaExponent_noNormalize",value:function(t,i){return(new e).fromMantissaExponent_noNormalize(t,i)}},{key:"fromDecimal",value:function(t){return(new e).fromDecimal(t)}},{key:"fromNumber",value:function(t){return(new e).fromNumber(t)}},{key:"fromString",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return(new e).fromString(t,i)}},{key:"fromValue",value:function(t){return(new e).fromValue(t)}},{key:"fromValue_noAlloc",value:function(t){if(t instanceof e)return t;if("string"==typeof t){var i=e.fromStringCache.get(t);return void 0!==i?i:e.fromString(t)}return"number"==typeof t?e.fromNumber(t):e.dZero}},{key:"abs",value:function(t){return l(t).abs()}},{key:"neg",value:function(t){return l(t).neg()}},{key:"negate",value:function(t){return l(t).neg()}},{key:"negated",value:function(t){return l(t).neg()}},{key:"sign",value:function(t){return l(t).sign}},{key:"sgn",value:function(t){return l(t).sign}},{key:"round",value:function(t){return l(t).round()}},{key:"floor",value:function(t){return l(t).floor()}},{key:"ceil",value:function(t){return l(t).ceil()}},{key:"trunc",value:function(t){return l(t).trunc()}},{key:"add",value:function(t,e){return l(t).add(e)}},{key:"plus",value:function(t,e){return l(t).add(e)}},{key:"sub",value:function(t,e){return l(t).sub(e)}},{key:"subtract",value:function(t,e){return l(t).sub(e)}},{key:"minus",value:function(t,e){return l(t).sub(e)}},{key:"mul",value:function(t,e){return l(t).mul(e)}},{key:"multiply",value:function(t,e){return l(t).mul(e)}},{key:"times",value:function(t,e){return l(t).mul(e)}},{key:"div",value:function(t,e){return l(t).div(e)}},{key:"divide",value:function(t,e){return l(t).div(e)}},{key:"recip",value:function(t){return l(t).recip()}},{key:"reciprocal",value:function(t){return l(t).recip()}},{key:"reciprocate",value:function(t){return l(t).reciprocate()}},{key:"mod",value:function(t,e){return l(t).mod(e)}},{key:"modulo",value:function(t,e){return l(t).modulo(e)}},{key:"modular",value:function(t,e){return l(t).modular(e)}},{key:"cmp",value:function(t,e){return l(t).cmp(e)}},{key:"cmpabs",value:function(t,e){return l(t).cmpabs(e)}},{key:"compare",value:function(t,e){return l(t).cmp(e)}},{key:"isNaN",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return t=l(t),isNaN(t.sign)||isNaN(t.layer)||isNaN(t.mag)}))},{key:"isFinite",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return t=l(t),isFinite(t.sign)&&isFinite(t.layer)&&isFinite(t.mag)}))},{key:"eq",value:function(t,e){return l(t).eq(e)}},{key:"equals",value:function(t,e){return l(t).eq(e)}},{key:"neq",value:function(t,e){return l(t).neq(e)}},{key:"notEquals",value:function(t,e){return l(t).notEquals(e)}},{key:"lt",value:function(t,e){return l(t).lt(e)}},{key:"lte",value:function(t,e){return l(t).lte(e)}},{key:"gt",value:function(t,e){return l(t).gt(e)}},{key:"gte",value:function(t,e){return l(t).gte(e)}},{key:"max",value:function(t,e){return l(t).max(e)}},{key:"min",value:function(t,e){return l(t).min(e)}},{key:"minabs",value:function(t,e){return l(t).minabs(e)}},{key:"maxabs",value:function(t,e){return l(t).maxabs(e)}},{key:"clamp",value:function(t,e,i){return l(t).clamp(e,i)}},{key:"clampMin",value:function(t,e){return l(t).clampMin(e)}},{key:"clampMax",value:function(t,e){return l(t).clampMax(e)}},{key:"cmp_tolerance",value:function(t,e,i){return l(t).cmp_tolerance(e,i)}},{key:"compare_tolerance",value:function(t,e,i){return l(t).cmp_tolerance(e,i)}},{key:"eq_tolerance",value:function(t,e,i){return l(t).eq_tolerance(e,i)}},{key:"equals_tolerance",value:function(t,e,i){return l(t).eq_tolerance(e,i)}},{key:"neq_tolerance",value:function(t,e,i){return l(t).neq_tolerance(e,i)}},{key:"notEquals_tolerance",value:function(t,e,i){return l(t).notEquals_tolerance(e,i)}},{key:"lt_tolerance",value:function(t,e,i){return l(t).lt_tolerance(e,i)}},{key:"lte_tolerance",value:function(t,e,i){return l(t).lte_tolerance(e,i)}},{key:"gt_tolerance",value:function(t,e,i){return l(t).gt_tolerance(e,i)}},{key:"gte_tolerance",value:function(t,e,i){return l(t).gte_tolerance(e,i)}},{key:"pLog10",value:function(t){return l(t).pLog10()}},{key:"absLog10",value:function(t){return l(t).absLog10()}},{key:"log10",value:function(t){return l(t).log10()}},{key:"log",value:function(t,e){return l(t).log(e)}},{key:"log2",value:function(t){return l(t).log2()}},{key:"ln",value:function(t){return l(t).ln()}},{key:"logarithm",value:function(t,e){return l(t).logarithm(e)}},{key:"pow",value:function(t,e){return l(t).pow(e)}},{key:"pow10",value:function(t){return l(t).pow10()}},{key:"root",value:function(t,e){return l(t).root(e)}},{key:"factorial",value:function(t,e){return l(t).factorial()}},{key:"gamma",value:function(t,e){return l(t).gamma()}},{key:"lngamma",value:function(t,e){return l(t).lngamma()}},{key:"exp",value:function(t){return l(t).exp()}},{key:"sqr",value:function(t){return l(t).sqr()}},{key:"sqrt",value:function(t){return l(t).sqrt()}},{key:"cube",value:function(t){return l(t).cube()}},{key:"cbrt",value:function(t){return l(t).cbrt()}},{key:"tetrate",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g(1,0,1),r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).tetrate(e,i,r)}},{key:"iteratedexp",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g(1,0,1),r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).iteratedexp(e,i,r)}},{key:"iteratedlog",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).iteratedlog(e,i,r)}},{key:"layeradd10",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return l(t).layeradd10(e,i)}},{key:"layeradd",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).layeradd(e,i,r)}},{key:"slog",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return l(t).slog(e,100,i)}},{key:"lambertw",value:function(t){return l(t).lambertw()}},{key:"ssqrt",value:function(t){return l(t).ssqrt()}},{key:"linear_sroot",value:function(t,e){return l(t).linear_sroot(e)}},{key:"pentate",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g(1,0,1),r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).pentate(e,i,r)}},{key:"sin",value:function(t){return l(t).sin()}},{key:"cos",value:function(t){return l(t).cos()}},{key:"tan",value:function(t){return l(t).tan()}},{key:"asin",value:function(t){return l(t).asin()}},{key:"acos",value:function(t){return l(t).acos()}},{key:"atan",value:function(t){return l(t).atan()}},{key:"sinh",value:function(t){return l(t).sinh()}},{key:"cosh",value:function(t){return l(t).cosh()}},{key:"tanh",value:function(t){return l(t).tanh()}},{key:"asinh",value:function(t){return l(t).asinh()}},{key:"acosh",value:function(t){return l(t).acosh()}},{key:"atanh",value:function(t){return l(t).atanh()}},{key:"affordGeometricSeries",value:function(t,e,i,r){return this.affordGeometricSeries_core(l(t),l(e),l(i),r)}},{key:"sumGeometricSeries",value:function(t,e,i,r){return this.sumGeometricSeries_core(t,l(e),l(i),r)}},{key:"affordArithmeticSeries",value:function(t,e,i,r){return this.affordArithmeticSeries_core(l(t),l(e),l(i),l(r))}},{key:"sumArithmeticSeries",value:function(t,e,i,r){return this.sumArithmeticSeries_core(l(t),l(e),l(i),l(r))}},{key:"efficiencyOfPurchase",value:function(t,e,i){return this.efficiencyOfPurchase_core(l(t),l(e),l(i))}},{key:"randomDecimalForTesting",value:function(t){if(20*Math.random()<1)return g(0,0,0);var e=Math.random()>.5?1:-1;if(20*Math.random()<1)return g(e,0,1);var i=Math.floor(Math.random()*(t+1)),r=0===i?616*Math.random()-308:16*Math.random();Math.random()>.9&&(r=Math.trunc(r));var n=Math.pow(10,r);return Math.random()>.9&&(n=Math.trunc(n)),m(e,i,n)}},{key:"affordGeometricSeries_core",value:function(t,i,r,n){var a=i.mul(r.pow(n));return e.floor(t.div(a).mul(r.sub(1)).add(1).log10().div(r.log10()))}},{key:"sumGeometricSeries_core",value:function(t,i,r,n){return i.mul(r.pow(n)).mul(e.sub(1,r.pow(t))).div(e.sub(1,r))}},{key:"affordArithmeticSeries_core",value:function(t,e,i,r){var n=e.add(r.mul(i)).sub(i.div(2)),a=n.pow(2);return n.neg().add(a.add(i.mul(t).mul(2)).sqrt()).div(i).floor()}},{key:"sumArithmeticSeries_core",value:function(t,e,i,r){var n=e.add(r.mul(i));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(i)))}},{key:"efficiencyOfPurchase_core",value:function(t,e,i){return t.div(e).add(t.div(i))}},{key:"slog_critical",value:function(t,i){return t>10?i-1:e.critical_section(t,i,h)}},{key:"tetrate_critical",value:function(t,i){return e.critical_section(t,i,o)}},{key:"critical_section",value:function(t,e,i){(e*=10)<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);for(var r=0,n=0,a=0;at){var s=(t-u[a])/(u[a+1]-u[a]);r=i[a][Math.floor(e)]*(1-s)+i[a+1][Math.floor(e)]*s,n=i[a][Math.ceil(e)]*(1-s)+i[a+1][Math.ceil(e)]*s;break}}var o=e-Math.floor(e);return r<=0||n<=0?r*(1-o)+n*o:Math.pow(t,Math.log(r)/Math.log(t)*(1-o)+Math.log(n)/Math.log(t)*o)}}]),e}();return p.dZero=g(0,0,0),p.dOne=g(1,0,1),p.dNegOne=g(-1,0,1),p.dTwo=g(1,0,2),p.dTen=g(1,0,10),p.dNaN=g(Number.NaN,Number.NaN,Number.NaN),p.dInf=g(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),p.dNegInf=g(-1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),p.dNumberMax=m(1,0,Number.MAX_VALUE),p.dNumberMin=m(1,0,Number.MIN_VALUE),p.fromStringCache=new r(1023),l=p.fromValue_noAlloc,m=p.fromComponents,g=p.fromComponents_noNormalize,p.fromMantissaExponent,p.fromMantissaExponent_noNormalize,p})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Decimal=e()}(this,(function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var i=0;ithis.maxSize;){var r=this.last;this.map.delete(r.key),this.last=r.prev,this.last.next=void 0}}}}]),e}(),n=i((function e(i,r){t(this,e),this.next=void 0,this.prev=void 0,this.key=i,this.value=r})),a=Math.log10(9e15),s=function(){for(var t=[],e=-323;e<=308;e++)t.push(Number("1e"+e));return function(e){return t[e+323]}}(),u=[2,Math.E,3,4,5,6,7,8,9,10],o=[[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]],h=[[-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]],l=function(t){return N.fromValue_noAlloc(t)},m=function(t,e,i){return N.fromComponents(t,e,i)},g=function(t,e,i){return N.fromComponents_noNormalize(t,e,i)},f=function(t,e){var i=e+1,r=Math.ceil(Math.log10(Math.abs(t))),n=Math.round(t*Math.pow(10,i-r))*Math.pow(10,r-i);return parseFloat(n.toFixed(Math.max(i-r,0)))},c=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},y=.5671432904097838,v=function(t){var e,i,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10;if(!Number.isFinite(t))return t;if(0===t)return t;if(1===t)return y;e=t<10?0:Math.log(t)-Math.log(Math.log(t));for(var n=0;n<100;++n){if(i=(t*Math.exp(-e)+e*e)/(e+1),Math.abs(i-e)1&&void 0!==arguments[1]?arguments[1]:1e-10;if(!Number.isFinite(t.mag))return t;if(t.eq(N.dZero))return t;if(t.eq(N.dOne))return N.fromNumber(y);e=N.ln(t);for(var s=0;s<100;++s){if(i=e.neg().exp(),r=e.sub(t.mul(i)),n=e.sub(r.div(e.add(1).sub(e.add(2).mul(r).div(N.mul(2,e).add(2))))),N.abs(n.sub(e)).lt(N.abs(n).mul(a)))return n;e=n}throw Error("Iteration failed to converge: ".concat(t.toString()))}var N=function(){function e(i){t(this,e),this.sign=0,this.mag=0,this.layer=0,i instanceof e?this.fromDecimal(i):"number"==typeof i?this.fromNumber(i):"string"==typeof i&&this.fromString(i)}return i(e,[{key:"m",get:function(){if(0===this.sign)return 0;if(0===this.layer){var t,e=Math.floor(Math.log10(this.mag));return t=5e-324===this.mag?5:this.mag/s(e),this.sign*t}if(1===this.layer){var i=this.mag-Math.floor(this.mag);return this.sign*Math.pow(10,i)}return this.sign},set:function(t){this.layer<=2?this.fromMantissaExponent(t,this.e):(this.sign=Math.sign(t),0===this.sign&&(this.layer=0,this.exponent=0))}},{key:"e",get:function(){return 0===this.sign?0:0===this.layer?Math.floor(Math.log10(this.mag)):1===this.layer?Math.floor(this.mag):2===this.layer?Math.floor(Math.sign(this.mag)*Math.pow(10,Math.abs(this.mag))):this.mag*Number.POSITIVE_INFINITY},set:function(t){this.fromMantissaExponent(this.m,t)}},{key:"s",get:function(){return this.sign},set:function(t){0===t?(this.sign=0,this.layer=0,this.mag=0):this.sign=t}},{key:"mantissa",get:function(){return this.m},set:function(t){this.m=t}},{key:"exponent",get:function(){return this.e},set:function(t){this.e=t}},{key:"normalize",value:function(){if(0===this.sign||0===this.mag&&0===this.layer||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(0===this.layer&&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 1==this.sign?(this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY):-1==this.sign&&(this.mag=Number.NEGATIVE_INFINITY,this.layer=Number.NEGATIVE_INFINITY),this;if(0===this.layer&&this.mag<1/9e15)return this.layer+=1,this.mag=Math.log10(this.mag),this;var t=Math.abs(this.mag),e=Math.sign(this.mag);if(t>=9e15)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,0===this.layer?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 0===this.layer&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):0===this.mag&&(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}},{key:"fromComponents",value:function(t,e,i){return this.sign=t,this.layer=e,this.mag=i,this.normalize(),this}},{key:"fromComponents_noNormalize",value:function(t,e,i){return this.sign=t,this.layer=e,this.mag=i,this}},{key:"fromMantissaExponent",value:function(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}},{key:"fromMantissaExponent_noNormalize",value:function(t,e){return this.fromMantissaExponent(t,e),this}},{key:"fromDecimal",value:function(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}},{key:"fromNumber",value:function(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}},{key:"fromString",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=t,n=e.fromStringCache.get(r);if(void 0!==n)return this.fromDecimal(n);var a=(t=t.replace(",","")).split("^^^");if(2===a.length){var s=parseFloat(a[0]),u=parseFloat(a[1]),o=a[1].split(";"),h=1;if(2===o.length&&(h=parseFloat(o[1]),isFinite(h)||(h=1)),isFinite(s)&&isFinite(u)){var g=e.pentate(s,u,h,i);return this.sign=g.sign,this.layer=g.layer,this.mag=g.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var f=t.split("^^");if(2===f.length){var y=parseFloat(f[0]),v=parseFloat(f[1]),d=f[1].split(";"),N=1;if(2===d.length&&(N=parseFloat(d[1]),isFinite(N)||(N=1)),isFinite(y)&&isFinite(v)){var p=e.tetrate(y,v,N,i);return this.sign=p.sign,this.layer=p.layer,this.mag=p.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var b,k,M=t.split("^");if(2===M.length){var I=parseFloat(M[0]),_=parseFloat(M[1]);if(isFinite(I)&&isFinite(_)){var F=e.pow(I,_);return this.sign=F.sign,this.layer=F.layer,this.mag=F.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var w=(t=t.trim().toLowerCase()).split("pt");if(2===w.length){b=10,k=parseFloat(w[0]),w[1]=w[1].replace("(",""),w[1]=w[1].replace(")","");var S=parseFloat(w[1]);if(isFinite(S)||(S=1),isFinite(b)&&isFinite(k)){var q=e.tetrate(b,k,S,i);return this.sign=q.sign,this.layer=q.layer,this.mag=q.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}if(2===(w=t.split("p")).length){b=10,k=parseFloat(w[0]),w[1]=w[1].replace("(",""),w[1]=w[1].replace(")","");var x=parseFloat(w[1]);if(isFinite(x)||(x=1),isFinite(b)&&isFinite(k)){var E=e.tetrate(b,k,x,i);return this.sign=E.sign,this.layer=E.layer,this.mag=E.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}if(2===(w=t.split("f")).length){b=10,w[0]=w[0].replace("(",""),w[0]=w[0].replace(")","");var T=parseFloat(w[0]);if(w[1]=w[1].replace("(",""),w[1]=w[1].replace(")",""),k=parseFloat(w[1]),isFinite(T)||(T=1),isFinite(b)&&isFinite(k)){var O=e.tetrate(b,k,T,i);return this.sign=O.sign,this.layer=O.layer,this.mag=O.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}}var C=t.split("e"),z=C.length-1;if(0===z){var V=parseFloat(t);if(isFinite(V))return this.fromNumber(V),e.fromStringCache.size>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}else if(1===z){var A=parseFloat(t);if(isFinite(A)&&0!==A)return this.fromNumber(A),e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}var P=t.split("e^");if(2===P.length){this.sign=1,"-"==P[0].charAt(0)&&(this.sign=-1);for(var Y="",D=0;D=43&&Z<=57||101===Z))return this.layer=parseFloat(Y),this.mag=parseFloat(P[1].substr(D+1)),this.normalize(),e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this;Y+=P[1].charAt(D)}}if(z<1)return this.sign=0,this.layer=0,this.mag=0,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this;var G=parseFloat(C[0]);if(0===G)return this.sign=0,this.layer=0,this.mag=0,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this;var L=parseFloat(C[C.length-1]);if(z>=2){var j=parseFloat(C[C.length-2]);isFinite(j)&&(L*=Math.sign(j),L+=c(j))}if(isFinite(G))if(1===z)this.sign=Math.sign(G),this.layer=1,this.mag=L+Math.log10(Math.abs(G));else{if(this.sign=Math.sign(G),this.layer=z,2===z){var W=e.mul(m(1,2,L),l(G));return this.sign=W.sign,this.layer=W.layer,this.mag=W.mag,e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}this.mag=L}else this.sign="-"===C[0]?-1:1,this.layer=z,this.mag=L;return this.normalize(),e.fromStringCache.maxSize>=1&&e.fromStringCache.set(r,e.fromDecimal(this)),this}},{key:"fromValue",value:function(t){return t instanceof e?this.fromDecimal(t):"number"==typeof t?this.fromNumber(t):"string"==typeof t?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}},{key:"toNumber",value:function(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&1===this.sign?Number.POSITIVE_INFINITY:this.mag===Number.NEGATIVE_INFINITY&&this.layer===Number.NEGATIVE_INFINITY&&-1===this.sign?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?0===this.layer?this.sign*this.mag:1===this.layer?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}},{key:"mantissaWithDecimalPlaces",value:function(t){return isNaN(this.m)?Number.NaN:0===this.m?0:f(this.m,t)}},{key:"magnitudeWithDecimalPlaces",value:function(t){return isNaN(this.mag)?Number.NaN:0===this.mag?0:f(this.mag,t)}},{key:"toString",value:function(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY?1===this.sign?"Infinity":"-Infinity":0===this.layer?this.mag<1e21&&this.mag>1e-7||0===this.mag?(this.sign*this.mag).toString():this.m+"e"+this.e:1===this.layer?this.m+"e"+this.e:this.layer<=5?(-1===this.sign?"-":"")+"e".repeat(this.layer)+this.mag:(-1===this.sign?"-":"")+"(e^"+this.layer+")"+this.mag}},{key:"toExponential",value:function(t){return 0===this.layer?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}},{key:"toFixed",value:function(t){return 0===this.layer?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}},{key:"toPrecision",value:function(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}},{key:"valueOf",value:function(){return this.toString()}},{key:"toJSON",value:function(){return this.toString()}},{key:"toStringWithDecimalPlaces",value:function(t){return 0===this.layer?this.mag<1e21&&this.mag>1e-7||0===this.mag?(this.sign*this.mag).toFixed(t):f(this.m,t)+"e"+f(this.e,t):1===this.layer?f(this.m,t)+"e"+f(this.e,t):this.layer<=5?(-1===this.sign?"-":"")+"e".repeat(this.layer)+f(this.mag,t):(-1===this.sign?"-":"")+"(e^"+this.layer+")"+f(this.mag,t)}},{key:"abs",value:function(){return g(0===this.sign?0:1,this.layer,this.mag)}},{key:"neg",value:function(){return g(-this.sign,this.layer,this.mag)}},{key:"negate",value:function(){return this.neg()}},{key:"negated",value:function(){return this.neg()}},{key:"sgn",value:function(){return this.sign}},{key:"round",value:function(){return this.mag<0?e.dZero:0===this.layer?m(this.sign,0,Math.round(this.mag)):this}},{key:"floor",value:function(){return this.mag<0?-1===this.sign?e.dNegOne:e.dZero:-1===this.sign?this.neg().ceil().neg():0===this.layer?m(this.sign,0,Math.floor(this.mag)):this}},{key:"ceil",value:function(){return this.mag<0?1===this.sign?e.dOne:e.dZero:-1===this.sign?this.neg().floor().neg():0===this.layer?m(this.sign,0,Math.ceil(this.mag)):this}},{key:"trunc",value:function(){return this.mag<0?e.dZero:0===this.layer?m(this.sign,0,Math.trunc(this.mag)):this}},{key:"add",value:function(t){var i,r,n=l(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(n.layer))return n;if(0===this.sign)return n;if(0===n.sign)return this;if(this.sign===-n.sign&&this.layer===n.layer&&this.mag===n.mag)return g(0,0,0);if(this.layer>=2||n.layer>=2)return this.maxabs(n);if(e.cmpabs(this,n)>0?(i=this,r=n):(i=n,r=this),0===i.layer&&0===r.layer)return e.fromNumber(i.sign*i.mag+r.sign*r.mag);var a=i.layer*Math.sign(i.mag),s=r.layer*Math.sign(r.mag);if(a-s>=2)return i;if(0===a&&-1===s){if(Math.abs(r.mag-Math.log10(i.mag))>17)return i;var u=Math.pow(10,Math.log10(i.mag)-r.mag),o=r.sign+i.sign*u;return m(Math.sign(o),1,r.mag+Math.log10(Math.abs(o)))}if(1===a&&0===s){if(Math.abs(i.mag-Math.log10(r.mag))>17)return i;var h=Math.pow(10,i.mag-Math.log10(r.mag)),f=r.sign+i.sign*h;return m(Math.sign(f),1,Math.log10(r.mag)+Math.log10(Math.abs(f)))}if(Math.abs(i.mag-r.mag)>17)return i;var c=Math.pow(10,i.mag-r.mag),y=r.sign+i.sign*c;return m(Math.sign(y),1,r.mag+Math.log10(Math.abs(y)))}},{key:"plus",value:function(t){return this.add(t)}},{key:"sub",value:function(t){return this.add(l(t).neg())}},{key:"subtract",value:function(t){return this.sub(t)}},{key:"minus",value:function(t){return this.sub(t)}},{key:"mul",value:function(t){var i,r,n=l(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(n.layer))return n;if(0===this.sign||0===n.sign)return g(0,0,0);if(this.layer===n.layer&&this.mag===-n.mag)return g(this.sign*n.sign,0,1);if(this.layer>n.layer||this.layer==n.layer&&Math.abs(this.mag)>Math.abs(n.mag)?(i=this,r=n):(i=n,r=this),0===i.layer&&0===r.layer)return e.fromNumber(i.sign*r.sign*i.mag*r.mag);if(i.layer>=3||i.layer-r.layer>=2)return m(i.sign*r.sign,i.layer,i.mag);if(1===i.layer&&0===r.layer)return m(i.sign*r.sign,1,i.mag+Math.log10(r.mag));if(1===i.layer&&1===r.layer)return m(i.sign*r.sign,1,i.mag+r.mag);if(2===i.layer&&1===r.layer){var a=m(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)).add(m(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)));return m(i.sign*r.sign,a.layer+1,a.sign*a.mag)}if(2===i.layer&&2===r.layer){var s=m(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)).add(m(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)));return m(i.sign*r.sign,s.layer+1,s.sign*s.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}},{key:"multiply",value:function(t){return this.mul(t)}},{key:"times",value:function(t){return this.mul(t)}},{key:"div",value:function(t){var e=l(t);return this.mul(e.recip())}},{key:"divide",value:function(t){return this.div(t)}},{key:"divideBy",value:function(t){return this.div(t)}},{key:"dividedBy",value:function(t){return this.div(t)}},{key:"recip",value:function(){return 0===this.mag?e.dNaN:0===this.layer?m(this.sign,0,1/this.mag):m(this.sign,this.layer,-this.mag)}},{key:"reciprocal",value:function(){return this.recip()}},{key:"reciprocate",value:function(){return this.recip()}},{key:"mod",value:function(t){var i=l(t).abs();if(i.eq(e.dZero))return e.dZero;var r=this.toNumber(),n=i.toNumber();return isFinite(r)&&isFinite(n)&&0!=r&&0!=n?new e(r%n):this.sub(i).eq(this)?e.dZero:i.sub(this).eq(i)?this:-1==this.sign?this.abs().mod(i).neg():this.sub(this.div(i).floor().mul(i))}},{key:"modulo",value:function(t){return this.mod(t)}},{key:"modular",value:function(t){return this.mod(t)}},{key:"cmp",value:function(t){var e=l(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,r=e.mag>0?e.layer:-e.layer;return i>r?1:ie.mag?1:this.mag0?e:this}},{key:"clamp",value:function(t,e){return this.max(t).min(e)}},{key:"clampMin",value:function(t){return this.max(t)}},{key:"clampMax",value:function(t){return this.min(t)}},{key:"cmp_tolerance",value:function(t,e){var i=l(t);return this.eq_tolerance(i,e)?0:this.cmp(i)}},{key:"compare_tolerance",value:function(t,e){return this.cmp_tolerance(t,e)}},{key:"eq_tolerance",value:function(t,e){var i=l(t);if(null==e&&(e=1e-7),this.sign!==i.sign)return!1;if(Math.abs(this.layer-i.layer)>1)return!1;var r=this.mag,n=i.mag;return this.layer>i.layer&&(n=c(n)),this.layer0?m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):m(1,0,Math.log10(this.mag))}},{key:"log10",value:function(){return this.sign<=0?e.dNaN:this.layer>0?m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):m(this.sign,0,Math.log10(this.mag))}},{key:"log",value:function(t){return t=l(t),this.sign<=0||t.sign<=0||1===t.sign&&0===t.layer&&1===t.mag?e.dNaN:0===this.layer&&0===t.layer?m(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):e.div(this.log10(),t.log10())}},{key:"log2",value:function(){return this.sign<=0?e.dNaN:0===this.layer?m(this.sign,0,Math.log2(this.mag)):1===this.layer?m(Math.sign(this.mag),0,3.321928094887362*Math.abs(this.mag)):2===this.layer?m(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}},{key:"ln",value:function(){return this.sign<=0?e.dNaN:0===this.layer?m(this.sign,0,Math.log(this.mag)):1===this.layer?m(Math.sign(this.mag),0,2.302585092994046*Math.abs(this.mag)):2===this.layer?m(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):m(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}},{key:"logarithm",value:function(t){return this.log(t)}},{key:"pow",value:function(t){var i=this,r=l(t);if(0===i.sign)return r.eq(0)?g(1,0,1):i;if(1===i.sign&&0===i.layer&&1===i.mag)return i;if(0===r.sign)return g(1,0,1);if(1===r.sign&&0===r.layer&&1===r.mag)return i;var n=i.absLog10().mul(r).pow10();return-1===this.sign?Math.abs(r.toNumber()%2)%2==1?n.neg():Math.abs(r.toNumber()%2)%2==0?n:e.dNaN:n}},{key:"pow10",value:function(){if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return e.dNaN;var t=this;if(0===t.layer){var i=Math.pow(10,t.sign*t.mag);if(Number.isFinite(i)&&Math.abs(i)>=.1)return m(1,0,i);if(0===t.sign)return e.dOne;t=g(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):e.dOne}},{key:"pow_base",value:function(t){return l(t).pow(this)}},{key:"root",value:function(t){var e=l(t);return this.pow(e.recip())}},{key:"factorial",value:function(){return this.mag<0||0===this.layer?this.add(1).gamma():1===this.layer?e.exp(e.mul(this,e.ln(this).sub(1))):e.exp(this)}},{key:"gamma",value:function(){if(this.mag<0)return this.recip();if(0===this.layer){if(this.lt(g(1,0,24)))return e.fromNumber(function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;for(var e=1;t<10;)e*=t,++t;var i=.9189385332046727;i+=((t-=1)+.5)*Math.log(t),i-=t;var r=t*t,n=t;return i+=1/(12*n),i+=1/(360*(n*=r)),i+=1/(1260*(n*=r)),i+=1/(1680*(n*=r)),i+=1/(1188*(n*=r)),i+=691/(360360*(n*=r)),i+=7/(1092*(n*=r)),i+=3617/(122400*(n*=r)),Math.exp(i)/e}(this.sign*this.mag));var t=this.mag-1,i=.9189385332046727;i+=(t+.5)*Math.log(t);var r=t*t,n=t,a=12*n,s=1/a,u=(i-=t)+s;if(u===i)return e.exp(i);if((u=(i=u)-(s=1/(a=360*(n*=r))))===i)return e.exp(i);i=u;var o=1/(a=1260*(n*=r));return i+=o,i-=o=1/(a=1680*(n*=r)),e.exp(i)}return 1===this.layer?e.exp(e.mul(this,e.ln(this).sub(1))):e.exp(this)}},{key:"lngamma",value:function(){return this.gamma().ln()}},{key:"exp",value:function(){return this.mag<0?e.dOne:0===this.layer&&this.mag<=709.7?e.fromNumber(Math.exp(this.sign*this.mag)):0===this.layer?m(1,1,this.sign*Math.log10(Math.E)*this.mag):1===this.layer?m(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):m(1,this.layer+1,this.sign*this.mag)}},{key:"sqr",value:function(){return this.pow(2)}},{key:"sqrt",value:function(){if(0===this.layer)return e.fromNumber(Math.sqrt(this.sign*this.mag));if(1===this.layer)return m(1,2,Math.log10(this.mag)-.3010299956639812);var t=e.div(g(this.sign,this.layer-1,this.mag),g(1,0,2));return t.layer+=1,t.normalize(),t}},{key:"cube",value:function(){return this.pow(3)}},{key:"cbrt",value:function(){return this.pow(1/3)}},{key:"tetrate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g(1,0,1),r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(1===t)return e.pow(this,i);if(0===t)return new e(i);if(this.eq(e.dOne))return e.dOne;if(this.eq(-1))return e.pow(this,i);if(t===Number.POSITIVE_INFINITY){var n=this.toNumber();if(n<=1.444667861009766&&n>=.06598803584531254){if(n>1.444667861009099)return e.fromNumber(Math.E);var a=e.ln(this).neg();return a.lambertw().div(a)}return n>1.444667861009766?e.fromNumber(Number.POSITIVE_INFINITY):e.dNaN}if(this.eq(e.dZero)){var s=Math.abs((t+1)%2);return s>1&&(s=2-s),e.fromNumber(s)}if(t<0)return e.iteratedlog(i,this,-t,r);i=l(i);var u=t,o=u-(t=Math.trunc(t));if(this.gt(e.dZero)&&this.lte(1.444667861009766)&&(u>1e4||!r)){t=Math.min(1e4,t);for(var h=0;h1e4){var f=this.pow(i);return u<=1e4||Math.ceil(u)%2==0?i.mul(1-o).add(f.mul(o)):i.mul(o).add(f.mul(1-o))}return i}0!==o&&(i.eq(e.dOne)?this.gt(10)||r?i=this.pow(o):(i=e.fromNumber(e.tetrate_critical(this.toNumber(),o)),this.lt(2)&&(i=i.sub(1).mul(this.minus(1)).plus(1))):i=this.eq(10)?i.layeradd10(o,r):i.layeradd(o,this,r));for(var c=0;c3)return g(i.sign,i.layer+(t-c-1),i.mag);if(c>1e4)return i}return i}},{key:"iteratedexp",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g(1,0,1),i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this.tetrate(t,e,i)}},{key:"iteratedlog",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(i<0)return e.tetrate(t,-i,this,r);t=l(t);var n=e.fromDecimal(this),a=i,s=a-(i=Math.trunc(i));if(n.layer-t.layer>3){var u=Math.min(i,n.layer-t.layer-3);i-=u,n.layer-=u}for(var o=0;o1e4)return n}return s>0&&s<1&&(n=t.eq(10)?n.layeradd10(-s,r):n.layeradd(-s,t,r)),n}},{key:"slog",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=.001,a=!1,s=!1,u=this.slog_internal(t,r).toNumber(),o=1;o1&&s!=l&&(a=!0),s=l,a?n/=2:n*=2,u+=n=Math.abs(n)*(l?-1:1),0===n)break}return e.fromNumber(u)}},{key:"slog_internal",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if((t=l(t)).lte(e.dZero))return e.dNaN;if(t.eq(e.dOne))return e.dNaN;if(t.lt(e.dOne))return this.eq(e.dOne)?e.dZero:this.eq(e.dZero)?e.dNegOne:e.dNaN;if(this.mag<0||this.eq(e.dZero))return e.dNegOne;var r=0,n=e.fromDecimal(this);if(n.layer-t.layer>3){var a=n.layer-t.layer-3;r+=a,n.layer-=a}for(var s=0;s<100;++s)if(n.lt(e.dZero))n=e.pow(t,n),r-=1;else{if(n.lte(e.dOne))return i?e.fromNumber(r+n.toNumber()-1):e.fromNumber(r+e.slog_critical(t.toNumber(),n.toNumber()));r+=1,n=e.log(n,t)}return e.fromNumber(r)}},{key:"layeradd10",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];t=e.fromValue_noAlloc(t).toNumber();var r=e.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):-1===r.sign&&0==r.layer&&(r.sign=1,r.mag=-r.mag);var n=Math.trunc(t);t-=n,r.layer+=n}if(t<=-1){var a=Math.trunc(t);if(t-=a,r.layer+=a,r.layer<0)for(var s=0;s<100;++s){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return 0===r.sign&&(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 0===r.sign&&(r.sign=1,0===r.mag&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),0!==t?r.layeradd(t,10,i):r}},{key:"layeradd",value:function(t,i){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=this.slog(i).toNumber(),a=n+t;return a>=0?e.tetrate(i,a,e.dOne,r):Number.isFinite(a)?a>=-1?e.log(e.tetrate(i,a+1,e.dOne,r),i):e.log(e.log(e.tetrate(i,a+2,e.dOne,r),i),i):e.dNaN}},{key:"lambertw",value:function(){if(this.lt(-.3678794411710499))throw Error("lambertw is unimplemented for results less than -1, sorry!");if(this.mag<0)return e.fromNumber(v(this.toNumber()));if(0===this.layer)return e.fromNumber(v(this.sign*this.mag));if(1===this.layer)return d(this);if(2===this.layer)return d(this);if(this.layer>=3)return g(this.sign,this.layer-1,this.mag);throw"Unhandled behavior in lambertw()"}},{key:"ssqrt",value:function(){return this.linear_sroot(2)}},{key:"linear_sroot",value:function(t){if(1==t)return this;if(this.eq(e.dInf))return e.dInf;if(!this.isFinite())return e.dNaN;if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return e.fromNumber(t).add(2).pow(this.recip());if(t<=0)return e.dNaN;if(t==Number.POSITIVE_INFINITY){var i=this.toNumber();return i.36787944117144233?this.pow(this.recip()):e.dNaN}if(this.eq(1))return e.dOne;if(this.lt(0))return e.dNaN;if(this.lte("1ee-16"))return t%2==1?this:e.dNaN;if(this.gt(1)){var r=e.dTen;this.gte(e.tetrate(10,t,1,!0))&&(r=this.iteratedlog(10,t-1,!0)),t<=1&&(r=this.root(t));for(var n=e.dZero,a=r.layer,s=r.iteratedlog(10,a,!0),u=s,o=s.div(2),h=!0;h;)o=n.add(s).div(2),e.iteratedexp(10,a,o,!0).tetrate(t,1,!0).gt(this)?s=o:n=o,o.eq(u)?h=!1:u=o;return e.iteratedexp(10,a,o,!0)}for(var l=1,g=m(1,10,1),f=m(1,10,1),c=m(1,10,1),y=m(1,1,-16),v=e.dZero,d=m(1,10,1),N=y.pow10().recip(),p=e.dZero,b=N,k=N,M=Math.ceil(t)%2==0,I=0,_=m(1,10,1),F=!1,w=e.dZero,S=!1;l<4;){if(2==l){if(M)break;c=m(1,10,1),y=g,l=3,d=m(1,10,1),_=m(1,10,1)}for(F=!1;y.neq(c);){if(w=y,y.pow10().recip().tetrate(t,1,!0).eq(1)&&y.pow10().recip().lt(.4))N=y.pow10().recip(),b=y.pow10().recip(),k=y.pow10().recip(),p=e.dZero,I=-1,3==l&&(_=y);else if(y.pow10().recip().tetrate(t,1,!0).eq(y.pow10().recip())&&!M&&y.pow10().recip().lt(.4))N=y.pow10().recip(),b=y.pow10().recip(),k=y.pow10().recip(),p=e.dZero,I=0;else if(y.pow10().recip().tetrate(t,1,!0).eq(y.pow10().recip().mul(2).tetrate(t,1,!0)))N=y.pow10().recip(),b=e.dZero,k=N.mul(2),p=N,I=M?-1:0;else{for(v=y.mul(12e-17),N=y.pow10().recip(),b=y.add(v).pow10().recip(),p=N.sub(b),k=N.add(p);b.tetrate(t,1,!0).eq(N.tetrate(t,1,!0))||k.tetrate(t,1,!0).eq(N.tetrate(t,1,!0))||b.gte(N)||k.lte(N);)v=v.mul(2),b=y.add(v).pow10().recip(),p=N.sub(b),k=N.add(p);if((1==l&&k.tetrate(t,1,!0).gt(N.tetrate(t,1,!0))&&b.tetrate(t,1,!0).gt(N.tetrate(t,1,!0))||3==l&&k.tetrate(t,1,!0).lt(N.tetrate(t,1,!0))&&b.tetrate(t,1,!0).lt(N.tetrate(t,1,!0)))&&(_=y),k.tetrate(t,1,!0).lt(N.tetrate(t,1,!0)))I=-1;else if(M)I=1;else if(3==l&&y.gt_tolerance(g,1e-8))I=0;else{for(;b.tetrate(t,1,!0).eq_tolerance(N.tetrate(t,1,!0),1e-8)||k.tetrate(t,1,!0).eq_tolerance(N.tetrate(t,1,!0),1e-8)||b.gte(N)||k.lte(N);)v=v.mul(2),b=y.add(v).pow10().recip(),p=N.sub(b),k=N.add(p);I=k.tetrate(t,1,!0).sub(N.tetrate(t,1,!0)).lt(N.tetrate(t,1,!0).sub(b.tetrate(t,1,!0)))?0:1}}if(-1==I&&(S=!0),1==l&&1==I||3==l&&0!=I)if(c.eq(m(1,10,1)))y=y.mul(2);else{var q=!1;if(F&&(1==I&&1==l||-1==I&&3==l)&&(q=!0),y=y.add(c).div(2),q)break}else if(c.eq(m(1,10,1)))c=y,y=y.div(2);else{var x=!1;if(F&&(1==I&&1==l||-1==I&&3==l)&&(x=!0),c=c.sub(d),y=y.sub(d),x)break}if(c.sub(y).div(2).abs().gt(d.mul(1.5))&&(F=!0),d=c.sub(y).div(2).abs(),y.gt("1e18"))break;if(y.eq(w))break}if(y.gt("1e18"))break;if(!S)break;if(_==m(1,10,1))break;1==l?g=_:3==l&&(f=_),l++}c=g;for(var E=y=m(1,1,-18),T=e.dZero,O=!0;O;)if(T=c.eq(m(1,10,1))?y.mul(2):c.add(y).div(2),e.pow(10,T).recip().tetrate(t,1,!0).gt(this)?y=T:c=T,T.eq(E)?O=!1:E=T,y.gt("1e18"))return e.dNaN;if(T.eq_tolerance(g,1e-15)){if(f.eq(m(1,10,1)))return e.dNaN;for(c=m(1,10,1),E=y=f,T=e.dZero,O=!0;O;)if(T=c.eq(m(1,10,1))?y.mul(2):c.add(y).div(2),e.pow(10,T).recip().tetrate(t,1,!0).gt(this)?y=T:c=T,T.eq(E)?O=!1:E=T,y.gt("1e18"))return e.dNaN;return T.pow10().recip()}return T.pow10().recip()}},{key:"pentate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:g(1,0,1),r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];i=l(i);var n=t,a=n-(t=Math.trunc(t));0!==a&&(i.eq(e.dOne)?(++t,i=e.fromNumber(a)):i=this.eq(10)?i.layeradd10(a,r):i.layeradd(a,this,r));for(var s=0;s10)return i}return i}},{key:"sin",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.sin(this.sign*this.mag)):g(0,0,0)}},{key:"cos",value:function(){return this.mag<0?e.dOne:0===this.layer?e.fromNumber(Math.cos(this.sign*this.mag)):g(0,0,0)}},{key:"tan",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.tan(this.sign*this.mag)):g(0,0,0)}},{key:"asin",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.asin(this.sign*this.mag)):g(Number.NaN,Number.NaN,Number.NaN)}},{key:"acos",value:function(){return this.mag<0?e.fromNumber(Math.acos(this.toNumber())):0===this.layer?e.fromNumber(Math.acos(this.sign*this.mag)):g(Number.NaN,Number.NaN,Number.NaN)}},{key:"atan",value:function(){return this.mag<0?this:0===this.layer?e.fromNumber(Math.atan(this.sign*this.mag)):e.fromNumber(Math.atan(Infinity*this.sign))}},{key:"sinh",value:function(){return this.exp().sub(this.negate().exp()).div(2)}},{key:"cosh",value:function(){return this.exp().add(this.negate().exp()).div(2)}},{key:"tanh",value:function(){return this.sinh().div(this.cosh())}},{key:"asinh",value:function(){return e.ln(this.add(this.sqr().add(1).sqrt()))}},{key:"acosh",value:function(){return e.ln(this.add(this.sqr().sub(1).sqrt()))}},{key:"atanh",value:function(){return this.abs().gte(1)?g(Number.NaN,Number.NaN,Number.NaN):e.ln(this.add(1).div(e.fromNumber(1).sub(this))).div(2)}},{key:"ascensionPenalty",value:function(t){return 0===t?this:this.root(e.pow(10,t))}},{key:"egg",value:function(){return this.add(9)}},{key:"lessThanOrEqualTo",value:function(t){return this.cmp(t)<1}},{key:"lessThan",value:function(t){return this.cmp(t)<0}},{key:"greaterThanOrEqualTo",value:function(t){return this.cmp(t)>-1}},{key:"greaterThan",value:function(t){return this.cmp(t)>0}}],[{key:"fromComponents",value:function(t,i,r){return(new e).fromComponents(t,i,r)}},{key:"fromComponents_noNormalize",value:function(t,i,r){return(new e).fromComponents_noNormalize(t,i,r)}},{key:"fromMantissaExponent",value:function(t,i){return(new e).fromMantissaExponent(t,i)}},{key:"fromMantissaExponent_noNormalize",value:function(t,i){return(new e).fromMantissaExponent_noNormalize(t,i)}},{key:"fromDecimal",value:function(t){return(new e).fromDecimal(t)}},{key:"fromNumber",value:function(t){return(new e).fromNumber(t)}},{key:"fromString",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return(new e).fromString(t,i)}},{key:"fromValue",value:function(t){return(new e).fromValue(t)}},{key:"fromValue_noAlloc",value:function(t){if(t instanceof e)return t;if("string"==typeof t){var i=e.fromStringCache.get(t);return void 0!==i?i:e.fromString(t)}return"number"==typeof t?e.fromNumber(t):e.dZero}},{key:"abs",value:function(t){return l(t).abs()}},{key:"neg",value:function(t){return l(t).neg()}},{key:"negate",value:function(t){return l(t).neg()}},{key:"negated",value:function(t){return l(t).neg()}},{key:"sign",value:function(t){return l(t).sign}},{key:"sgn",value:function(t){return l(t).sign}},{key:"round",value:function(t){return l(t).round()}},{key:"floor",value:function(t){return l(t).floor()}},{key:"ceil",value:function(t){return l(t).ceil()}},{key:"trunc",value:function(t){return l(t).trunc()}},{key:"add",value:function(t,e){return l(t).add(e)}},{key:"plus",value:function(t,e){return l(t).add(e)}},{key:"sub",value:function(t,e){return l(t).sub(e)}},{key:"subtract",value:function(t,e){return l(t).sub(e)}},{key:"minus",value:function(t,e){return l(t).sub(e)}},{key:"mul",value:function(t,e){return l(t).mul(e)}},{key:"multiply",value:function(t,e){return l(t).mul(e)}},{key:"times",value:function(t,e){return l(t).mul(e)}},{key:"div",value:function(t,e){return l(t).div(e)}},{key:"divide",value:function(t,e){return l(t).div(e)}},{key:"recip",value:function(t){return l(t).recip()}},{key:"reciprocal",value:function(t){return l(t).recip()}},{key:"reciprocate",value:function(t){return l(t).reciprocate()}},{key:"mod",value:function(t,e){return l(t).mod(e)}},{key:"modulo",value:function(t,e){return l(t).modulo(e)}},{key:"modular",value:function(t,e){return l(t).modular(e)}},{key:"cmp",value:function(t,e){return l(t).cmp(e)}},{key:"cmpabs",value:function(t,e){return l(t).cmpabs(e)}},{key:"compare",value:function(t,e){return l(t).cmp(e)}},{key:"isNaN",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return t=l(t),isNaN(t.sign)||isNaN(t.layer)||isNaN(t.mag)}))},{key:"isFinite",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return t=l(t),isFinite(t.sign)&&isFinite(t.layer)&&isFinite(t.mag)}))},{key:"eq",value:function(t,e){return l(t).eq(e)}},{key:"equals",value:function(t,e){return l(t).eq(e)}},{key:"neq",value:function(t,e){return l(t).neq(e)}},{key:"notEquals",value:function(t,e){return l(t).notEquals(e)}},{key:"lt",value:function(t,e){return l(t).lt(e)}},{key:"lte",value:function(t,e){return l(t).lte(e)}},{key:"gt",value:function(t,e){return l(t).gt(e)}},{key:"gte",value:function(t,e){return l(t).gte(e)}},{key:"max",value:function(t,e){return l(t).max(e)}},{key:"min",value:function(t,e){return l(t).min(e)}},{key:"minabs",value:function(t,e){return l(t).minabs(e)}},{key:"maxabs",value:function(t,e){return l(t).maxabs(e)}},{key:"clamp",value:function(t,e,i){return l(t).clamp(e,i)}},{key:"clampMin",value:function(t,e){return l(t).clampMin(e)}},{key:"clampMax",value:function(t,e){return l(t).clampMax(e)}},{key:"cmp_tolerance",value:function(t,e,i){return l(t).cmp_tolerance(e,i)}},{key:"compare_tolerance",value:function(t,e,i){return l(t).cmp_tolerance(e,i)}},{key:"eq_tolerance",value:function(t,e,i){return l(t).eq_tolerance(e,i)}},{key:"equals_tolerance",value:function(t,e,i){return l(t).eq_tolerance(e,i)}},{key:"neq_tolerance",value:function(t,e,i){return l(t).neq_tolerance(e,i)}},{key:"notEquals_tolerance",value:function(t,e,i){return l(t).notEquals_tolerance(e,i)}},{key:"lt_tolerance",value:function(t,e,i){return l(t).lt_tolerance(e,i)}},{key:"lte_tolerance",value:function(t,e,i){return l(t).lte_tolerance(e,i)}},{key:"gt_tolerance",value:function(t,e,i){return l(t).gt_tolerance(e,i)}},{key:"gte_tolerance",value:function(t,e,i){return l(t).gte_tolerance(e,i)}},{key:"pLog10",value:function(t){return l(t).pLog10()}},{key:"absLog10",value:function(t){return l(t).absLog10()}},{key:"log10",value:function(t){return l(t).log10()}},{key:"log",value:function(t,e){return l(t).log(e)}},{key:"log2",value:function(t){return l(t).log2()}},{key:"ln",value:function(t){return l(t).ln()}},{key:"logarithm",value:function(t,e){return l(t).logarithm(e)}},{key:"pow",value:function(t,e){return l(t).pow(e)}},{key:"pow10",value:function(t){return l(t).pow10()}},{key:"root",value:function(t,e){return l(t).root(e)}},{key:"factorial",value:function(t,e){return l(t).factorial()}},{key:"gamma",value:function(t,e){return l(t).gamma()}},{key:"lngamma",value:function(t,e){return l(t).lngamma()}},{key:"exp",value:function(t){return l(t).exp()}},{key:"sqr",value:function(t){return l(t).sqr()}},{key:"sqrt",value:function(t){return l(t).sqrt()}},{key:"cube",value:function(t){return l(t).cube()}},{key:"cbrt",value:function(t){return l(t).cbrt()}},{key:"tetrate",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g(1,0,1),r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).tetrate(e,i,r)}},{key:"iteratedexp",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g(1,0,1),r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).iteratedexp(e,i,r)}},{key:"iteratedlog",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).iteratedlog(e,i,r)}},{key:"layeradd10",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return l(t).layeradd10(e,i)}},{key:"layeradd",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).layeradd(e,i,r)}},{key:"slog",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return l(t).slog(e,100,i)}},{key:"lambertw",value:function(t){return l(t).lambertw()}},{key:"ssqrt",value:function(t){return l(t).ssqrt()}},{key:"linear_sroot",value:function(t,e){return l(t).linear_sroot(e)}},{key:"pentate",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g(1,0,1),r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return l(t).pentate(e,i,r)}},{key:"sin",value:function(t){return l(t).sin()}},{key:"cos",value:function(t){return l(t).cos()}},{key:"tan",value:function(t){return l(t).tan()}},{key:"asin",value:function(t){return l(t).asin()}},{key:"acos",value:function(t){return l(t).acos()}},{key:"atan",value:function(t){return l(t).atan()}},{key:"sinh",value:function(t){return l(t).sinh()}},{key:"cosh",value:function(t){return l(t).cosh()}},{key:"tanh",value:function(t){return l(t).tanh()}},{key:"asinh",value:function(t){return l(t).asinh()}},{key:"acosh",value:function(t){return l(t).acosh()}},{key:"atanh",value:function(t){return l(t).atanh()}},{key:"affordGeometricSeries",value:function(t,e,i,r){return this.affordGeometricSeries_core(l(t),l(e),l(i),r)}},{key:"sumGeometricSeries",value:function(t,e,i,r){return this.sumGeometricSeries_core(t,l(e),l(i),r)}},{key:"affordArithmeticSeries",value:function(t,e,i,r){return this.affordArithmeticSeries_core(l(t),l(e),l(i),l(r))}},{key:"sumArithmeticSeries",value:function(t,e,i,r){return this.sumArithmeticSeries_core(l(t),l(e),l(i),l(r))}},{key:"efficiencyOfPurchase",value:function(t,e,i){return this.efficiencyOfPurchase_core(l(t),l(e),l(i))}},{key:"randomDecimalForTesting",value:function(t){if(20*Math.random()<1)return g(0,0,0);var e=Math.random()>.5?1:-1;if(20*Math.random()<1)return g(e,0,1);var i=Math.floor(Math.random()*(t+1)),r=0===i?616*Math.random()-308:16*Math.random();Math.random()>.9&&(r=Math.trunc(r));var n=Math.pow(10,r);return Math.random()>.9&&(n=Math.trunc(n)),m(e,i,n)}},{key:"affordGeometricSeries_core",value:function(t,i,r,n){var a=i.mul(r.pow(n));return e.floor(t.div(a).mul(r.sub(1)).add(1).log10().div(r.log10()))}},{key:"sumGeometricSeries_core",value:function(t,i,r,n){return i.mul(r.pow(n)).mul(e.sub(1,r.pow(t))).div(e.sub(1,r))}},{key:"affordArithmeticSeries_core",value:function(t,e,i,r){var n=e.add(r.mul(i)).sub(i.div(2)),a=n.pow(2);return n.neg().add(a.add(i.mul(t).mul(2)).sqrt()).div(i).floor()}},{key:"sumArithmeticSeries_core",value:function(t,e,i,r){var n=e.add(r.mul(i));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(i)))}},{key:"efficiencyOfPurchase_core",value:function(t,e,i){return t.div(e).add(t.div(i))}},{key:"slog_critical",value:function(t,i){return t>10?i-1:e.critical_section(t,i,h)}},{key:"tetrate_critical",value:function(t,i){return e.critical_section(t,i,o)}},{key:"critical_section",value:function(t,e,i){(e*=10)<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);for(var r=0,n=0,a=0;at){var s=(t-u[a])/(u[a+1]-u[a]);r=i[a][Math.floor(e)]*(1-s)+i[a+1][Math.floor(e)]*s,n=i[a][Math.ceil(e)]*(1-s)+i[a+1][Math.ceil(e)]*s;break}}var o=e-Math.floor(e);return r<=0||n<=0?r*(1-o)+n*o:Math.pow(t,Math.log(r)/Math.log(t)*(1-o)+Math.log(n)/Math.log(t)*o)}}]),e}();return N.dZero=g(0,0,0),N.dOne=g(1,0,1),N.dNegOne=g(-1,0,1),N.dTwo=g(1,0,2),N.dTen=g(1,0,10),N.dNaN=g(Number.NaN,Number.NaN,Number.NaN),N.dInf=g(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),N.dNegInf=g(-1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),N.dNumberMax=m(1,0,Number.MAX_VALUE),N.dNumberMin=m(1,0,Number.MIN_VALUE),N.fromStringCache=new r(1023),l=N.fromValue_noAlloc,m=N.fromComponents,g=N.fromComponents_noNormalize,N.fromMantissaExponent,N.fromMantissaExponent_noNormalize,N})); diff --git a/src/index.ts b/src/index.ts index 191c714..31a9e1b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1552,12 +1552,12 @@ export default class Decimal { Any 0 is totally zero (0, 0, 0) and any NaN is totally NaN (NaN, NaN, NaN). Anything layer 0 has mag 0 OR mag > 1/9e15 and < 9e15. Anything layer 1 or higher has abs(mag) >= 15.954 and < 9e15. - Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, Infinity, Infinity). + Any positive infinity is (1, Infinity, Infinity) and any negative infinity is (-1, -Infinity, -Infinity). We will assume in calculations that all Decimals are either erroneous or satisfy these criteria. (Otherwise: Garbage in, garbage out.) */ //Any 0 is totally 0 - if (this.sign === 0 || (this.mag === 0 && this.layer === 0) || (this.mag === Number.NEGATIVE_INFINITY && this.layer > 0)) { + if (this.sign === 0 || (this.mag === 0 && this.layer === 0) || (this.mag === Number.NEGATIVE_INFINITY && this.layer > 0 && Number.isFinite(this.layer))) { this.sign = 0; this.mag = 0; this.layer = 0; @@ -1571,9 +1571,15 @@ export default class Decimal { } //Handle infinities - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { - this.mag = Number.POSITIVE_INFINITY; - this.layer = Number.POSITIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { + if (this.sign == 1) { + this.mag = Number.POSITIVE_INFINITY; + this.layer = Number.POSITIVE_INFINITY; + } + else if (this.sign == -1) { + this.mag = Number.NEGATIVE_INFINITY + this.layer = Number.NEGATIVE_INFINITY; + } return this; } @@ -2009,10 +2015,11 @@ export default class Decimal { * Returns the numeric value of the Decimal it's called on. Will return Infinity (or -Infinity for negatives) for Decimals that are larger than Number.MAX_VALUE. */ public toNumber(): number { - if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY) { - return this.sign > 0 - ? Number.POSITIVE_INFINITY - : Number.NEGATIVE_INFINITY; + if (this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY && this.sign === 1) { + return Number.POSITIVE_INFINITY; + } + if (this.mag === Number.NEGATIVE_INFINITY && this.layer === Number.NEGATIVE_INFINITY && this.sign === -1) { + return Number.NEGATIVE_INFINITY; } if (!Number.isFinite(this.layer)) { return Number.NaN; @@ -2066,7 +2073,7 @@ export default class Decimal { if (isNaN(this.layer) || isNaN(this.sign) || isNaN(this.mag)) { return "NaN"; } - if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY) { + if (this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) { return this.sign === 1 ? "Infinity" : "-Infinity"; }