-
Notifications
You must be signed in to change notification settings - Fork 0
/
decimal.min.mjs
1 lines (1 loc) · 34.9 KB
/
decimal.min.mjs
1
var inexact,quadrant,EXP_LIMIT=9e15,MAX_DIGITS=1e9,NUMERALS="0123456789abcdef",LN10="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",PI="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",DEFAULTS={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-EXP_LIMIT,maxE:EXP_LIMIT,crypto:!1},external=!0,decimalError="[DecimalError] ",invalidArgument=decimalError+"Invalid argument: ",precisionLimitExceeded=decimalError+"Precision limit exceeded",cryptoUnavailable=decimalError+"crypto unavailable",tag="[object Decimal]",mathfloor=Math.floor,mathpow=Math.pow,isBinary=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,isHex=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,isOctal=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,isDecimal=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,BASE=1e7,LOG_BASE=7,MAX_SAFE_INTEGER=9007199254740991,LN10_PRECISION=LN10.length-1,PI_PRECISION=PI.length-1,P={toStringTag:tag};function digitsToString(n){var i,e,t,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,i=1;i<r;i++)t=n[i]+"",(e=LOG_BASE-t.length)&&(s+=getZeroString(e)),s+=t;o=n[i],(e=LOG_BASE-(t=o+"").length)&&(s+=getZeroString(e))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}function checkInt32(n,i,e){if(n!==~~n||n<i||n>e)throw Error(invalidArgument+n)}function checkRoundingDigits(n,i,e,t){var r,s,o,a;for(s=n[0];s>=10;s/=10)--i;return--i<0?(i+=LOG_BASE,r=0):(r=Math.ceil((i+1)/LOG_BASE),i%=LOG_BASE),s=mathpow(10,LOG_BASE-i),a=n[r]%s|0,null==t?i<3?(0==i?a=a/100|0:1==i&&(a=a/10|0),o=e<4&&99999==a||e>3&&49999==a||5e4==a||0==a):o=(e<4&&a+1==s||e>3&&a+1==s/2)&&(n[r+1]/s/100|0)==mathpow(10,i-2)-1||(a==s/2||0==a)&&0==(n[r+1]/s/100|0):i<4?(0==i?a=a/1e3|0:1==i?a=a/100|0:2==i&&(a=a/10|0),o=(t||e<4)&&9999==a||!t&&e>3&&4999==a):o=((t||e<4)&&a+1==s||!t&&e>3&&a+1==s/2)&&(n[r+1]/s/1e3|0)==mathpow(10,i-3)-1,o}function convertBase(n,i,e){for(var t,r,s=[0],o=0,a=n.length;o<a;){for(r=s.length;r--;)s[r]*=i;for(s[0]+=NUMERALS.indexOf(n.charAt(o++)),t=0;t<s.length;t++)s[t]>e-1&&(void 0===s[t+1]&&(s[t+1]=0),s[t+1]+=s[t]/e|0,s[t]%=e)}return s.reverse()}function cosine(n,i){var e,t,r;if(i.isZero())return i;(t=i.d.length)<32?r=(1/tinyPow(4,e=Math.ceil(t/3))).toString():(e=16,r="2.3283064365386962890625e-10"),n.precision+=e,i=taylorSeries(n,1,i.times(r),new n(1));for(var s=e;s--;){var o=i.times(i);i=o.times(o).minus(o).times(8).plus(1)}return n.precision-=e,i}P.absoluteValue=P.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),finalise(n)},P.ceil=function(){return finalise(new this.constructor(this),this.e+1,2)},P.clampedTo=P.clamp=function(n,i){var e=this,t=e.constructor;if(n=new t(n),i=new t(i),!n.s||!i.s)return new t(NaN);if(n.gt(i))throw Error(invalidArgument+i);return e.cmp(n)<0?n:e.cmp(i)>0?i:new t(e)},P.comparedTo=P.cmp=function(n){var i,e,t,r,s=this,o=s.d,a=(n=new s.constructor(n)).d,u=s.s,c=n.s;if(!o||!a)return u&&c?u!==c?u:o===a?0:!o^u<0?1:-1:NaN;if(!o[0]||!a[0])return o[0]?u:a[0]?-c:0;if(u!==c)return u;if(s.e!==n.e)return s.e>n.e^u<0?1:-1;for(i=0,e=(t=o.length)<(r=a.length)?t:r;i<e;++i)if(o[i]!==a[i])return o[i]>a[i]^u<0?1:-1;return t===r?0:t>r^u<0?1:-1},P.cosine=P.cos=function(){var n,i,e=this,t=e.constructor;return e.d?e.d[0]?(n=t.precision,i=t.rounding,t.precision=n+Math.max(e.e,e.sd())+LOG_BASE,t.rounding=1,e=cosine(t,toLessThanHalfPi(t,e)),t.precision=n,t.rounding=i,finalise(2==quadrant||3==quadrant?e.neg():e,n,i,!0)):new t(1):new t(NaN)},P.cubeRoot=P.cbrt=function(){var n,i,e,t,r,s,o,a,u,c,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(external=!1,(s=l.s*mathpow(l.s*l,1/3))&&Math.abs(s)!=1/0?t=new f(s.toString()):(e=digitsToString(l.d),(s=((n=l.e)-e.length+1)%3)&&(e+=1==s||-2==s?"0":"00"),s=mathpow(e,1/3),n=mathfloor((n+1)/3)-(n%3==(n<0?-1:2)),(t=new f(e=s==1/0?"5e"+n:(e=s.toExponential()).slice(0,e.indexOf("e")+1)+n)).s=l.s),o=(n=f.precision)+3;;)if(c=(u=(a=t).times(a).times(a)).plus(l),t=divide(c.plus(l).times(a),c.plus(u),o+2,1),digitsToString(a.d).slice(0,o)===(e=digitsToString(t.d)).slice(0,o)){if("9999"!=(e=e.slice(o-3,o+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(finalise(t,n+1,1),i=!t.times(t).times(t).eq(l));break}if(!r&&(finalise(a,n+1,0),a.times(a).times(a).eq(l))){t=a;break}o+=4,r=1}return external=!0,finalise(t,n,f.rounding,i)},P.decimalPlaces=P.dp=function(){var n,i=this.d,e=NaN;if(i){if(e=((n=i.length-1)-mathfloor(this.e/LOG_BASE))*LOG_BASE,n=i[n])for(;n%10==0;n/=10)e--;e<0&&(e=0)}return e},P.dividedBy=P.div=function(n){return divide(this,new this.constructor(n))},P.dividedToIntegerBy=P.divToInt=function(n){var i=this.constructor;return finalise(divide(this,new i(n),0,1,1),i.precision,i.rounding)},P.equals=P.eq=function(n){return 0===this.cmp(n)},P.floor=function(){return finalise(new this.constructor(this),this.e+1,3)},P.greaterThan=P.gt=function(n){return this.cmp(n)>0},P.greaterThanOrEqualTo=P.gte=function(n){var i=this.cmp(n);return 1==i||0===i},P.hyperbolicCosine=P.cosh=function(){var n,i,e,t,r,s=this,o=s.constructor,a=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return a;e=o.precision,t=o.rounding,o.precision=e+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?i=(1/tinyPow(4,n=Math.ceil(r/3))).toString():(n=16,i="2.3283064365386962890625e-10"),s=taylorSeries(o,1,s.times(i),new o(1),!0);for(var u,c=n,l=new o(8);c--;)u=s.times(s),s=a.minus(u.times(l.minus(u.times(l))));return finalise(s,o.precision=e,o.rounding=t,!0)},P.hyperbolicSine=P.sinh=function(){var n,i,e,t,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(i=s.precision,e=s.rounding,s.precision=i+Math.max(r.e,r.sd())+4,s.rounding=1,(t=r.d.length)<3)r=taylorSeries(s,2,r,r,!0);else{n=(n=1.4*Math.sqrt(t))>16?16:0|n,r=taylorSeries(s,2,r=r.times(1/tinyPow(5,n)),r,!0);for(var o,a=new s(5),u=new s(16),c=new s(20);n--;)o=r.times(r),r=r.times(a.plus(o.times(u.times(o).plus(c))))}return s.precision=i,s.rounding=e,finalise(r,i,e,!0)},P.hyperbolicTangent=P.tanh=function(){var n,i,e=this,t=e.constructor;return e.isFinite()?e.isZero()?new t(e):(n=t.precision,i=t.rounding,t.precision=n+7,t.rounding=1,divide(e.sinh(),e.cosh(),t.precision=n,t.rounding=i)):new t(e.s)},P.inverseCosine=P.acos=function(){var n,i=this,e=i.constructor,t=i.abs().cmp(1),r=e.precision,s=e.rounding;return-1!==t?0===t?i.isNeg()?getPi(e,r,s):new e(0):new e(NaN):i.isZero()?getPi(e,r+4,s).times(.5):(e.precision=r+6,e.rounding=1,i=i.asin(),n=getPi(e,r+4,s).times(.5),e.precision=r,e.rounding=s,n.minus(i))},P.inverseHyperbolicCosine=P.acosh=function(){var n,i,e=this,t=e.constructor;return e.lte(1)?new t(e.eq(1)?0:NaN):e.isFinite()?(n=t.precision,i=t.rounding,t.precision=n+Math.max(Math.abs(e.e),e.sd())+4,t.rounding=1,external=!1,e=e.times(e).minus(1).sqrt().plus(e),external=!0,t.precision=n,t.rounding=i,e.ln()):new t(e)},P.inverseHyperbolicSine=P.asinh=function(){var n,i,e=this,t=e.constructor;return!e.isFinite()||e.isZero()?new t(e):(n=t.precision,i=t.rounding,t.precision=n+2*Math.max(Math.abs(e.e),e.sd())+6,t.rounding=1,external=!1,e=e.times(e).plus(1).sqrt().plus(e),external=!0,t.precision=n,t.rounding=i,e.ln())},P.inverseHyperbolicTangent=P.atanh=function(){var n,i,e,t,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=s.precision,i=s.rounding,t=r.sd(),Math.max(t,n)<2*-r.e-1?finalise(new s(r),n,i,!0):(s.precision=e=t-r.e,r=divide(r.plus(1),new s(1).minus(r),e+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=i,r.times(.5))):new s(NaN)},P.inverseSine=P.asin=function(){var n,i,e,t,r=this,s=r.constructor;return r.isZero()?new s(r):(i=r.abs().cmp(1),e=s.precision,t=s.rounding,-1!==i?0===i?((n=getPi(s,e+4,t).times(.5)).s=r.s,n):new s(NaN):(s.precision=e+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=e,s.rounding=t,r.times(2)))},P.inverseTangent=P.atan=function(){var n,i,e,t,r,s,o,a,u,c=this,l=c.constructor,f=l.precision,d=l.rounding;if(c.isFinite()){if(c.isZero())return new l(c);if(c.abs().eq(1)&&f+4<=PI_PRECISION)return(o=getPi(l,f+4,d).times(.25)).s=c.s,o}else{if(!c.s)return new l(NaN);if(f+4<=PI_PRECISION)return(o=getPi(l,f+4,d).times(.5)).s=c.s,o}for(l.precision=a=f+10,l.rounding=1,n=e=Math.min(28,a/LOG_BASE+2|0);n;--n)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(external=!1,i=Math.ceil(a/LOG_BASE),t=1,u=c.times(c),o=new l(c),r=c;-1!==n;)if(r=r.times(u),s=o.minus(r.div(t+=2)),r=r.times(u),void 0!==(o=s.plus(r.div(t+=2))).d[i])for(n=i;o.d[n]===s.d[n]&&n--;);return e&&(o=o.times(2<<e-1)),external=!0,finalise(o,l.precision=f,l.rounding=d,!0)},P.isFinite=function(){return!!this.d},P.isInteger=P.isInt=function(){return!!this.d&&mathfloor(this.e/LOG_BASE)>this.d.length-2},P.isNaN=function(){return!this.s},P.isNegative=P.isNeg=function(){return this.s<0},P.isPositive=P.isPos=function(){return this.s>0},P.isZero=function(){return!!this.d&&0===this.d[0]},P.lessThan=P.lt=function(n){return this.cmp(n)<0},P.lessThanOrEqualTo=P.lte=function(n){return this.cmp(n)<1},P.logarithm=P.log=function(n){var i,e,t,r,s,o,a,u,c=this.constructor,l=c.precision,f=c.rounding;if(null==n)n=new c(10),i=!0;else{if(e=(n=new c(n)).d,n.s<0||!e||!e[0]||n.eq(1))return new c(NaN);i=n.eq(10)}if(e=this.d,this.s<0||!e||!e[0]||this.eq(1))return new c(e&&!e[0]?-1/0:1!=this.s?NaN:e?0:1/0);if(i)if(e.length>1)s=!0;else{for(r=e[0];r%10==0;)r/=10;s=1!==r}if(external=!1,o=naturalLogarithm(this,a=l+5),t=i?getLn10(c,a+10):naturalLogarithm(n,a),checkRoundingDigits((u=divide(o,t,a,1)).d,r=l,f))do{if(o=naturalLogarithm(this,a+=10),t=i?getLn10(c,a+10):naturalLogarithm(n,a),u=divide(o,t,a,1),!s){+digitsToString(u.d).slice(r+1,r+15)+1==1e14&&(u=finalise(u,l+1,0));break}}while(checkRoundingDigits(u.d,r+=10,f));return external=!0,finalise(u,l,f)},P.minus=P.sub=function(n){var i,e,t,r,s,o,a,u,c,l,f,d,h=this,g=h.constructor;if(n=new g(n),!h.d||!n.d)return h.s&&n.s?h.d?n.s=-n.s:n=new g(n.d||h.s!==n.s?h:NaN):n=new g(NaN),n;if(h.s!=n.s)return n.s=-n.s,h.plus(n);if(c=h.d,d=n.d,a=g.precision,u=g.rounding,!c[0]||!d[0]){if(d[0])n.s=-n.s;else{if(!c[0])return new g(3===u?-0:0);n=new g(h)}return external?finalise(n,a,u):n}if(e=mathfloor(n.e/LOG_BASE),l=mathfloor(h.e/LOG_BASE),c=c.slice(),s=l-e){for((f=s<0)?(i=c,s=-s,o=d.length):(i=d,e=l,o=c.length),s>(t=Math.max(Math.ceil(a/LOG_BASE),o)+2)&&(s=t,i.length=1),i.reverse(),t=s;t--;)i.push(0);i.reverse()}else{for((f=(t=c.length)<(o=d.length))&&(o=t),t=0;t<o;t++)if(c[t]!=d[t]){f=c[t]<d[t];break}s=0}for(f&&(i=c,c=d,d=i,n.s=-n.s),o=c.length,t=d.length-o;t>0;--t)c[o++]=0;for(t=d.length;t>s;){if(c[--t]<d[t]){for(r=t;r&&0===c[--r];)c[r]=BASE-1;--c[r],c[t]+=BASE}c[t]-=d[t]}for(;0===c[--o];)c.pop();for(;0===c[0];c.shift())--e;return c[0]?(n.d=c,n.e=getBase10Exponent(c,e),external?finalise(n,a,u):n):new g(3===u?-0:0)},P.modulo=P.mod=function(n){var i,e=this,t=e.constructor;return n=new t(n),!e.d||!n.s||n.d&&!n.d[0]?new t(NaN):!n.d||e.d&&!e.d[0]?finalise(new t(e),t.precision,t.rounding):(external=!1,9==t.modulo?(i=divide(e,n.abs(),0,3,1)).s*=n.s:i=divide(e,n,0,t.modulo,1),i=i.times(n),external=!0,e.minus(i))},P.naturalExponential=P.exp=function(){return naturalExponential(this)},P.naturalLogarithm=P.ln=function(){return naturalLogarithm(this)},P.negated=P.neg=function(){var n=new this.constructor(this);return n.s=-n.s,finalise(n)},P.plus=P.add=function(n){var i,e,t,r,s,o,a,u,c,l,f=this,d=f.constructor;if(n=new d(n),!f.d||!n.d)return f.s&&n.s?f.d||(n=new d(n.d||f.s===n.s?f:NaN)):n=new d(NaN),n;if(f.s!=n.s)return n.s=-n.s,f.minus(n);if(c=f.d,l=n.d,a=d.precision,u=d.rounding,!c[0]||!l[0])return l[0]||(n=new d(f)),external?finalise(n,a,u):n;if(s=mathfloor(f.e/LOG_BASE),t=mathfloor(n.e/LOG_BASE),c=c.slice(),r=s-t){for(r<0?(e=c,r=-r,o=l.length):(e=l,t=s,o=c.length),r>(o=(s=Math.ceil(a/LOG_BASE))>o?s+1:o+1)&&(r=o,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for((o=c.length)-(r=l.length)<0&&(r=o,e=l,l=c,c=e),i=0;r;)i=(c[--r]=c[r]+l[r]+i)/BASE|0,c[r]%=BASE;for(i&&(c.unshift(i),++t),o=c.length;0==c[--o];)c.pop();return n.d=c,n.e=getBase10Exponent(c,t),external?finalise(n,a,u):n},P.precision=P.sd=function(n){var i,e=this;if(void 0!==n&&n!==!!n&&1!==n&&0!==n)throw Error(invalidArgument+n);return e.d?(i=getPrecision(e.d),n&&e.e+1>i&&(i=e.e+1)):i=NaN,i},P.round=function(){var n=this,i=n.constructor;return finalise(new i(n),n.e+1,i.rounding)},P.sine=P.sin=function(){var n,i,e=this,t=e.constructor;return e.isFinite()?e.isZero()?new t(e):(n=t.precision,i=t.rounding,t.precision=n+Math.max(e.e,e.sd())+LOG_BASE,t.rounding=1,e=sine(t,toLessThanHalfPi(t,e)),t.precision=n,t.rounding=i,finalise(quadrant>2?e.neg():e,n,i,!0)):new t(NaN)},P.squareRoot=P.sqrt=function(){var n,i,e,t,r,s,o=this,a=o.d,u=o.e,c=o.s,l=o.constructor;if(1!==c||!a||!a[0])return new l(!c||c<0&&(!a||a[0])?NaN:a?o:1/0);for(external=!1,0==(c=Math.sqrt(+o))||c==1/0?(((i=digitsToString(a)).length+u)%2==0&&(i+="0"),c=Math.sqrt(i),u=mathfloor((u+1)/2)-(u<0||u%2),t=new l(i=c==1/0?"5e"+u:(i=c.toExponential()).slice(0,i.indexOf("e")+1)+u)):t=new l(c.toString()),e=(u=l.precision)+3;;)if(t=(s=t).plus(divide(o,s,e+2,1)).times(.5),digitsToString(s.d).slice(0,e)===(i=digitsToString(t.d)).slice(0,e)){if("9999"!=(i=i.slice(e-3,e+1))&&(r||"4999"!=i)){+i&&(+i.slice(1)||"5"!=i.charAt(0))||(finalise(t,u+1,1),n=!t.times(t).eq(o));break}if(!r&&(finalise(s,u+1,0),s.times(s).eq(o))){t=s;break}e+=4,r=1}return external=!0,finalise(t,u,l.rounding,n)},P.tangent=P.tan=function(){var n,i,e=this,t=e.constructor;return e.isFinite()?e.isZero()?new t(e):(n=t.precision,i=t.rounding,t.precision=n+10,t.rounding=1,(e=e.sin()).s=1,e=divide(e,new t(1).minus(e.times(e)).sqrt(),n+10,0),t.precision=n,t.rounding=i,finalise(2==quadrant||4==quadrant?e.neg():e,n,i,!0)):new t(NaN)},P.times=P.mul=function(n){var i,e,t,r,s,o,a,u,c,l=this,f=l.constructor,d=l.d,h=(n=new f(n)).d;if(n.s*=l.s,!(d&&d[0]&&h&&h[0]))return new f(!n.s||d&&!d[0]&&!h||h&&!h[0]&&!d?NaN:d&&h?0*n.s:n.s/0);for(e=mathfloor(l.e/LOG_BASE)+mathfloor(n.e/LOG_BASE),(u=d.length)<(c=h.length)&&(s=d,d=h,h=s,o=u,u=c,c=o),s=[],t=o=u+c;t--;)s.push(0);for(t=c;--t>=0;){for(i=0,r=u+t;r>t;)a=s[r]+h[t]*d[r-t-1]+i,s[r--]=a%BASE|0,i=a/BASE|0;s[r]=(s[r]+i)%BASE|0}for(;!s[--o];)s.pop();return i?++e:s.shift(),n.d=s,n.e=getBase10Exponent(s,e),external?finalise(n,f.precision,f.rounding):n},P.toBinary=function(n,i){return toStringBinary(this,2,n,i)},P.toDecimalPlaces=P.toDP=function(n,i){var e=this,t=e.constructor;return e=new t(e),void 0===n?e:(checkInt32(n,0,MAX_DIGITS),void 0===i?i=t.rounding:checkInt32(i,0,8),finalise(e,n+e.e+1,i))},P.toExponential=function(n,i){var e,t=this,r=t.constructor;return void 0===n?e=finiteToString(t,!0):(checkInt32(n,0,MAX_DIGITS),void 0===i?i=r.rounding:checkInt32(i,0,8),e=finiteToString(t=finalise(new r(t),n+1,i),!0,n+1)),t.isNeg()&&!t.isZero()?"-"+e:e},P.toFixed=function(n,i){var e,t,r=this,s=r.constructor;return void 0===n?e=finiteToString(r):(checkInt32(n,0,MAX_DIGITS),void 0===i?i=s.rounding:checkInt32(i,0,8),e=finiteToString(t=finalise(new s(r),n+r.e+1,i),!1,n+t.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e},P.toFraction=function(n){var i,e,t,r,s,o,a,u,c,l,f,d,h=this,g=h.d,m=h.constructor;if(!g)return new m(h);if(c=e=new m(1),t=u=new m(0),o=(s=(i=new m(t)).e=getPrecision(g)-h.e-1)%LOG_BASE,i.d[0]=mathpow(10,o<0?LOG_BASE+o:o),null==n)n=s>0?i:c;else{if(!(a=new m(n)).isInt()||a.lt(c))throw Error(invalidArgument+a);n=a.gt(i)?s>0?i:c:a}for(external=!1,a=new m(digitsToString(g)),l=m.precision,m.precision=s=g.length*LOG_BASE*2;f=divide(a,i,0,1,1),1!=(r=e.plus(f.times(t))).cmp(n);)e=t,t=r,r=c,c=u.plus(f.times(r)),u=r,r=i,i=a.minus(f.times(r)),a=r;return r=divide(n.minus(e),t,0,1,1),u=u.plus(r.times(c)),e=e.plus(r.times(t)),u.s=c.s=h.s,d=divide(c,t,s,1).minus(h).abs().cmp(divide(u,e,s,1).minus(h).abs())<1?[c,t]:[u,e],m.precision=l,external=!0,d},P.toHexadecimal=P.toHex=function(n,i){return toStringBinary(this,16,n,i)},P.toNearest=function(n,i){var e=this,t=e.constructor;if(e=new t(e),null==n){if(!e.d)return e;n=new t(1),i=t.rounding}else{if(n=new t(n),void 0===i?i=t.rounding:checkInt32(i,0,8),!e.d)return n.s?e:n;if(!n.d)return n.s&&(n.s=e.s),n}return n.d[0]?(external=!1,e=divide(e,n,0,i,1).times(n),external=!0,finalise(e)):(n.s=e.s,e=n),e},P.toNumber=function(){return+this},P.toOctal=function(n,i){return toStringBinary(this,8,n,i)},P.toPower=P.pow=function(n){var i,e,t,r,s,o,a=this,u=a.constructor,c=+(n=new u(n));if(!(a.d&&n.d&&a.d[0]&&n.d[0]))return new u(mathpow(+a,c));if((a=new u(a)).eq(1))return a;if(t=u.precision,s=u.rounding,n.eq(1))return finalise(a,t,s);if((i=mathfloor(n.e/LOG_BASE))>=n.d.length-1&&(e=c<0?-c:c)<=MAX_SAFE_INTEGER)return r=intPow(u,a,e,t),n.s<0?new u(1).div(r):finalise(r,t,s);if((o=a.s)<0){if(i<n.d.length-1)return new u(NaN);if(0==(1&n.d[i])&&(o=1),0==a.e&&1==a.d[0]&&1==a.d.length)return a.s=o,a}return(i=0!=(e=mathpow(+a,c))&&isFinite(e)?new u(e+"").e:mathfloor(c*(Math.log("0."+digitsToString(a.d))/Math.LN10+a.e+1)))>u.maxE+1||i<u.minE-1?new u(i>0?o/0:0):(external=!1,u.rounding=a.s=1,e=Math.min(12,(i+"").length),(r=naturalExponential(n.times(naturalLogarithm(a,t+e)),t)).d&&checkRoundingDigits((r=finalise(r,t+5,1)).d,t,s)&&(i=t+10,+digitsToString((r=finalise(naturalExponential(n.times(naturalLogarithm(a,i+e)),i),i+5,1)).d).slice(t+1,t+15)+1==1e14&&(r=finalise(r,t+1,0))),r.s=o,external=!0,u.rounding=s,finalise(r,t,s))},P.toPrecision=function(n,i){var e,t=this,r=t.constructor;return void 0===n?e=finiteToString(t,t.e<=r.toExpNeg||t.e>=r.toExpPos):(checkInt32(n,1,MAX_DIGITS),void 0===i?i=r.rounding:checkInt32(i,0,8),e=finiteToString(t=finalise(new r(t),n,i),n<=t.e||t.e<=r.toExpNeg,n)),t.isNeg()&&!t.isZero()?"-"+e:e},P.toSignificantDigits=P.toSD=function(n,i){var e=this.constructor;return void 0===n?(n=e.precision,i=e.rounding):(checkInt32(n,1,MAX_DIGITS),void 0===i?i=e.rounding:checkInt32(i,0,8)),finalise(new e(this),n,i)},P.toString=function(){var n=this,i=n.constructor,e=finiteToString(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()&&!n.isZero()?"-"+e:e},P.truncated=P.trunc=function(){return finalise(new this.constructor(this),this.e+1,1)},P.valueOf=P.toJSON=function(){var n=this,i=n.constructor,e=finiteToString(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()?"-"+e:e};var divide=function(){function n(n,i,e){var t,r=0,s=n.length;for(n=n.slice();s--;)t=n[s]*i+r,n[s]=t%e|0,r=t/e|0;return r&&n.unshift(r),n}function i(n,i,e,t){var r,s;if(e!=t)s=e>t?1:-1;else for(r=s=0;r<e;r++)if(n[r]!=i[r]){s=n[r]>i[r]?1:-1;break}return s}function e(n,i,e,t){for(var r=0;e--;)n[e]-=r,r=n[e]<i[e]?1:0,n[e]=r*t+n[e]-i[e];for(;!n[0]&&n.length>1;)n.shift()}return function(t,r,s,o,a,u){var c,l,f,d,h,g,m,p,w,v,P,E,S,N,x,A,L,O,_,B,I=t.constructor,T=t.s==r.s?1:-1,b=t.d,y=r.d;if(!(b&&b[0]&&y&&y[0]))return new I(t.s&&r.s&&(b?!y||b[0]!=y[0]:y)?b&&0==b[0]||!y?0*T:T/0:NaN);for(u?(h=1,l=t.e-r.e):(u=BASE,h=LOG_BASE,l=mathfloor(t.e/h)-mathfloor(r.e/h)),_=y.length,L=b.length,v=(w=new I(T)).d=[],f=0;y[f]==(b[f]||0);f++);if(y[f]>(b[f]||0)&&l--,null==s?(N=s=I.precision,o=I.rounding):N=a?s+(t.e-r.e)+1:s,N<0)v.push(1),g=!0;else{if(N=N/h+2|0,f=0,1==_){for(d=0,y=y[0],N++;(f<L||d)&&N--;f++)x=d*u+(b[f]||0),v[f]=x/y|0,d=x%y|0;g=d||f<L}else{for((d=u/(y[0]+1)|0)>1&&(y=n(y,d,u),b=n(b,d,u),_=y.length,L=b.length),A=_,E=(P=b.slice(0,_)).length;E<_;)P[E++]=0;(B=y.slice()).unshift(0),O=y[0],y[1]>=u/2&&++O;do{d=0,(c=i(y,P,_,E))<0?(S=P[0],_!=E&&(S=S*u+(P[1]||0)),(d=S/O|0)>1?(d>=u&&(d=u-1),1==(c=i(m=n(y,d,u),P,p=m.length,E=P.length))&&(d--,e(m,_<p?B:y,p,u))):(0==d&&(c=d=1),m=y.slice()),(p=m.length)<E&&m.unshift(0),e(P,m,E,u),-1==c&&(c=i(y,P,_,E=P.length))<1&&(d++,e(P,_<E?B:y,E,u)),E=P.length):0===c&&(d++,P=[0]),v[f++]=d,c&&P[0]?P[E++]=b[A]||0:(P=[b[A]],E=1)}while((A++<L||void 0!==P[0])&&N--);g=void 0!==P[0]}v[0]||v.shift()}if(1==h)w.e=l,inexact=g;else{for(f=1,d=v[0];d>=10;d/=10)f++;w.e=f+l*h-1,finalise(w,a?s+w.e+1:s,o,g)}return w}}();function finalise(n,i,e,t){var r,s,o,a,u,c,l,f,d,h=n.constructor;n:if(null!=i){if(!(f=n.d))return n;for(r=1,a=f[0];a>=10;a/=10)r++;if((s=i-r)<0)s+=LOG_BASE,o=i,u=(l=f[d=0])/mathpow(10,r-o-1)%10|0;else if((d=Math.ceil((s+1)/LOG_BASE))>=(a=f.length)){if(!t)break n;for(;a++<=d;)f.push(0);l=u=0,r=1,o=(s%=LOG_BASE)-LOG_BASE+1}else{for(l=a=f[d],r=1;a>=10;a/=10)r++;u=(o=(s%=LOG_BASE)-LOG_BASE+r)<0?0:l/mathpow(10,r-o-1)%10|0}if(t=t||i<0||void 0!==f[d+1]||(o<0?l:l%mathpow(10,r-o-1)),c=e<4?(u||t)&&(0==e||e==(n.s<0?3:2)):u>5||5==u&&(4==e||t||6==e&&(s>0?o>0?l/mathpow(10,r-o):0:f[d-1])%10&1||e==(n.s<0?8:7)),i<1||!f[0])return f.length=0,c?(i-=n.e+1,f[0]=mathpow(10,(LOG_BASE-i%LOG_BASE)%LOG_BASE),n.e=-i||0):f[0]=n.e=0,n;if(0==s?(f.length=d,a=1,d--):(f.length=d+1,a=mathpow(10,LOG_BASE-s),f[d]=o>0?(l/mathpow(10,r-o)%mathpow(10,o)|0)*a:0),c)for(;;){if(0==d){for(s=1,o=f[0];o>=10;o/=10)s++;for(o=f[0]+=a,a=1;o>=10;o/=10)a++;s!=a&&(n.e++,f[0]==BASE&&(f[0]=1));break}if(f[d]+=a,f[d]!=BASE)break;f[d--]=0,a=1}for(s=f.length;0===f[--s];)f.pop()}return external&&(n.e>h.maxE?(n.d=null,n.e=NaN):n.e<h.minE&&(n.e=0,n.d=[0])),n}function finiteToString(n,i,e){if(!n.isFinite())return nonFiniteToString(n);var t,r=n.e,s=digitsToString(n.d),o=s.length;return i?(e&&(t=e-o)>0?s=s.charAt(0)+"."+s.slice(1)+getZeroString(t):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):r<0?(s="0."+getZeroString(-r-1)+s,e&&(t=e-o)>0&&(s+=getZeroString(t))):r>=o?(s+=getZeroString(r+1-o),e&&(t=e-r-1)>0&&(s=s+"."+getZeroString(t))):((t=r+1)<o&&(s=s.slice(0,t)+"."+s.slice(t)),e&&(t=e-o)>0&&(r+1===o&&(s+="."),s+=getZeroString(t))),s}function getBase10Exponent(n,i){var e=n[0];for(i*=LOG_BASE;e>=10;e/=10)i++;return i}function getLn10(n,i,e){if(i>LN10_PRECISION)throw external=!0,e&&(n.precision=e),Error(precisionLimitExceeded);return finalise(new n(LN10),i,1,!0)}function getPi(n,i,e){if(i>PI_PRECISION)throw Error(precisionLimitExceeded);return finalise(new n(PI),i,e,!0)}function getPrecision(n){var i=n.length-1,e=i*LOG_BASE+1;if(i=n[i]){for(;i%10==0;i/=10)e--;for(i=n[0];i>=10;i/=10)e++}return e}function getZeroString(n){for(var i="";n--;)i+="0";return i}function intPow(n,i,e,t){var r,s=new n(1),o=Math.ceil(t/LOG_BASE+4);for(external=!1;;){if(e%2&&truncate((s=s.times(i)).d,o)&&(r=!0),0===(e=mathfloor(e/2))){e=s.d.length-1,r&&0===s.d[e]&&++s.d[e];break}truncate((i=i.times(i)).d,o)}return external=!0,s}function isOdd(n){return 1&n.d[n.d.length-1]}function maxOrMin(n,i,e){for(var t,r=new n(i[0]),s=0;++s<i.length;){if(!(t=new n(i[s])).s){r=t;break}r[e](t)&&(r=t)}return r}function naturalExponential(n,i){var e,t,r,s,o,a,u,c=0,l=0,f=0,d=n.constructor,h=d.rounding,g=d.precision;if(!n.d||!n.d[0]||n.e>17)return new d(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==i?(external=!1,u=g):u=i,a=new d(.03125);n.e>-2;)n=n.times(a),f+=5;for(u+=t=Math.log(mathpow(2,f))/Math.LN10*2+5|0,e=s=o=new d(1),d.precision=u;;){if(s=finalise(s.times(n),u,1),e=e.times(++l),digitsToString((a=o.plus(divide(s,e,u,1))).d).slice(0,u)===digitsToString(o.d).slice(0,u)){for(r=f;r--;)o=finalise(o.times(o),u,1);if(null!=i)return d.precision=g,o;if(!(c<3&&checkRoundingDigits(o.d,u-t,h,c)))return finalise(o,d.precision=g,h,external=!0);d.precision=u+=10,e=s=a=new d(1),l=0,c++}o=a}}function naturalLogarithm(n,i){var e,t,r,s,o,a,u,c,l,f,d,h=1,g=n,m=g.d,p=g.constructor,w=p.rounding,v=p.precision;if(g.s<0||!m||!m[0]||!g.e&&1==m[0]&&1==m.length)return new p(m&&!m[0]?-1/0:1!=g.s?NaN:m?0:g);if(null==i?(external=!1,l=v):l=i,p.precision=l+=10,t=(e=digitsToString(m)).charAt(0),!(Math.abs(s=g.e)<15e14))return c=getLn10(p,l+2,v).times(s+""),g=naturalLogarithm(new p(t+"."+e.slice(1)),l-10).plus(c),p.precision=v,null==i?finalise(g,v,w,external=!0):g;for(;t<7&&1!=t||1==t&&e.charAt(1)>3;)t=(e=digitsToString((g=g.times(n)).d)).charAt(0),h++;for(s=g.e,t>1?(g=new p("0."+e),s++):g=new p(t+"."+e.slice(1)),f=g,u=o=g=divide(g.minus(1),g.plus(1),l,1),d=finalise(g.times(g),l,1),r=3;;){if(o=finalise(o.times(d),l,1),digitsToString((c=u.plus(divide(o,new p(r),l,1))).d).slice(0,l)===digitsToString(u.d).slice(0,l)){if(u=u.times(2),0!==s&&(u=u.plus(getLn10(p,l+2,v).times(s+""))),u=divide(u,new p(h),l,1),null!=i)return p.precision=v,u;if(!checkRoundingDigits(u.d,l-10,w,a))return finalise(u,p.precision=v,w,external=!0);p.precision=l+=10,c=o=g=divide(f.minus(1),f.plus(1),l,1),d=finalise(g.times(g),l,1),r=a=1}u=c,r+=2}}function nonFiniteToString(n){return String(n.s*n.s/0)}function parseDecimal(n,i){var e,t,r;for((e=i.indexOf("."))>-1&&(i=i.replace(".","")),(t=i.search(/e/i))>0?(e<0&&(e=t),e+=+i.slice(t+1),i=i.substring(0,t)):e<0&&(e=i.length),t=0;48===i.charCodeAt(t);t++);for(r=i.length;48===i.charCodeAt(r-1);--r);if(i=i.slice(t,r)){if(r-=t,n.e=e=e-t-1,n.d=[],t=(e+1)%LOG_BASE,e<0&&(t+=LOG_BASE),t<r){for(t&&n.d.push(+i.slice(0,t)),r-=LOG_BASE;t<r;)n.d.push(+i.slice(t,t+=LOG_BASE));i=i.slice(t),t=LOG_BASE-i.length}else t-=r;for(;t--;)i+="0";n.d.push(+i),external&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function parseOther(n,i){var e,t,r,s,o,a,u,c,l;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),isDecimal.test(i))return parseDecimal(n,i)}else if("Infinity"===i||"NaN"===i)return+i||(n.s=NaN),n.e=NaN,n.d=null,n;if(isHex.test(i))e=16,i=i.toLowerCase();else if(isBinary.test(i))e=2;else{if(!isOctal.test(i))throw Error(invalidArgument+i);e=8}for((s=i.search(/p/i))>0?(u=+i.slice(s+1),i=i.substring(2,s)):i=i.slice(2),o=(s=i.indexOf("."))>=0,t=n.constructor,o&&(s=(a=(i=i.replace(".","")).length)-s,r=intPow(t,new t(e),s,2*s)),s=l=(c=convertBase(i,e,BASE)).length-1;0===c[s];--s)c.pop();return s<0?new t(0*n.s):(n.e=getBase10Exponent(c,l),n.d=c,external=!1,o&&(n=divide(n,r,4*a)),u&&(n=n.times(Math.abs(u)<54?mathpow(2,u):Decimal.pow(2,u))),external=!0,n)}function sine(n,i){var e,t=i.d.length;if(t<3)return i.isZero()?i:taylorSeries(n,2,i,i);e=(e=1.4*Math.sqrt(t))>16?16:0|e,i=taylorSeries(n,2,i=i.times(1/tinyPow(5,e)),i);for(var r,s=new n(5),o=new n(16),a=new n(20);e--;)r=i.times(i),i=i.times(s.plus(r.times(o.times(r).minus(a))));return i}function taylorSeries(n,i,e,t,r){var s,o,a,u,c=n.precision,l=Math.ceil(c/LOG_BASE);for(external=!1,u=e.times(e),a=new n(t);;){if(o=divide(a.times(u),new n(i++*i++),c,1),a=r?t.plus(o):t.minus(o),t=divide(o.times(u),new n(i++*i++),c,1),void 0!==(o=a.plus(t)).d[l]){for(s=l;o.d[s]===a.d[s]&&s--;);if(-1==s)break}s=a,a=t,t=o,o=s,0}return external=!0,o.d.length=l+1,o}function tinyPow(n,i){for(var e=n;--i;)e*=n;return e}function toLessThanHalfPi(n,i){var e,t=i.s<0,r=getPi(n,n.precision,1),s=r.times(.5);if((i=i.abs()).lte(s))return quadrant=t?4:1,i;if((e=i.divToInt(r)).isZero())quadrant=t?3:2;else{if((i=i.minus(e.times(r))).lte(s))return quadrant=isOdd(e)?t?2:3:t?4:1,i;quadrant=isOdd(e)?t?1:4:t?3:2}return i.minus(r).abs()}function toStringBinary(n,i,e,t){var r,s,o,a,u,c,l,f,d,h=n.constructor,g=void 0!==e;if(g?(checkInt32(e,1,MAX_DIGITS),void 0===t?t=h.rounding:checkInt32(t,0,8)):(e=h.precision,t=h.rounding),n.isFinite()){for(g?(r=2,16==i?e=4*e-3:8==i&&(e=3*e-2)):r=i,(o=(l=finiteToString(n)).indexOf("."))>=0&&(l=l.replace(".",""),(d=new h(1)).e=l.length-o,d.d=convertBase(finiteToString(d),10,r),d.e=d.d.length),s=u=(f=convertBase(l,10,r)).length;0==f[--u];)f.pop();if(f[0]){if(o<0?s--:((n=new h(n)).d=f,n.e=s,f=(n=divide(n,d,e,t,0,r)).d,s=n.e,c=inexact),o=f[e],a=r/2,c=c||void 0!==f[e+1],c=t<4?(void 0!==o||c)&&(0===t||t===(n.s<0?3:2)):o>a||o===a&&(4===t||c||6===t&&1&f[e-1]||t===(n.s<0?8:7)),f.length=e,c)for(;++f[--e]>r-1;)f[e]=0,e||(++s,f.unshift(1));for(u=f.length;!f[u-1];--u);for(o=0,l="";o<u;o++)l+=NUMERALS.charAt(f[o]);if(g){if(u>1)if(16==i||8==i){for(o=16==i?4:3,--u;u%o;u++)l+="0";for(u=(f=convertBase(l,r,i)).length;!f[u-1];--u);for(o=1,l="1.";o<u;o++)l+=NUMERALS.charAt(f[o])}else l=l.charAt(0)+"."+l.slice(1);l=l+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)l="0"+l;l="0."+l}else if(++s>u)for(s-=u;s--;)l+="0";else s<u&&(l=l.slice(0,s)+"."+l.slice(s))}else l=g?"0p+0":"0";l=(16==i?"0x":2==i?"0b":8==i?"0o":"")+l}else l=nonFiniteToString(n);return n.s<0?"-"+l:l}function truncate(n,i){if(n.length>i)return n.length=i,!0}function abs(n){return new this(n).abs()}function acos(n){return new this(n).acos()}function acosh(n){return new this(n).acosh()}function add(n,i){return new this(n).plus(i)}function asin(n){return new this(n).asin()}function asinh(n){return new this(n).asinh()}function atan(n){return new this(n).atan()}function atanh(n){return new this(n).atanh()}function atan2(n,i){n=new this(n),i=new this(i);var e,t=this.precision,r=this.rounding,s=t+4;return n.s&&i.s?n.d||i.d?!i.d||n.isZero()?(e=i.s<0?getPi(this,t,r):new this(0)).s=n.s:!n.d||i.isZero()?(e=getPi(this,s,1).times(.5)).s=n.s:i.s<0?(this.precision=s,this.rounding=1,e=this.atan(divide(n,i,s,1)),i=getPi(this,s,1),this.precision=t,this.rounding=r,e=n.s<0?e.minus(i):e.plus(i)):e=this.atan(divide(n,i,s,1)):(e=getPi(this,s,1).times(i.s>0?.25:.75)).s=n.s:e=new this(NaN),e}function cbrt(n){return new this(n).cbrt()}function ceil(n){return finalise(n=new this(n),n.e+1,2)}function clamp(n,i,e){return new this(n).clamp(i,e)}function config(n){if(!n||"object"!=typeof n)throw Error(decimalError+"Object expected");var i,e,t,r=!0===n.defaults,s=["precision",1,MAX_DIGITS,"rounding",0,8,"toExpNeg",-EXP_LIMIT,0,"toExpPos",0,EXP_LIMIT,"maxE",0,EXP_LIMIT,"minE",-EXP_LIMIT,0,"modulo",0,9];for(i=0;i<s.length;i+=3)if(e=s[i],r&&(this[e]=DEFAULTS[e]),void 0!==(t=n[e])){if(!(mathfloor(t)===t&&t>=s[i+1]&&t<=s[i+2]))throw Error(invalidArgument+e+": "+t);this[e]=t}if(e="crypto",r&&(this[e]=DEFAULTS[e]),void 0!==(t=n[e])){if(!0!==t&&!1!==t&&0!==t&&1!==t)throw Error(invalidArgument+e+": "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(cryptoUnavailable);this[e]=!0}else this[e]=!1}return this}function cos(n){return new this(n).cos()}function cosh(n){return new this(n).cosh()}function clone(n){var i,e,t;function r(n){var i,e,t,s=this;if(!(s instanceof r))return new r(n);if(s.constructor=r,isDecimalInstance(n))return s.s=n.s,void(external?!n.d||n.e>r.maxE?(s.e=NaN,s.d=null):n.e<r.minE?(s.e=0,s.d=[0]):(s.e=n.e,s.d=n.d.slice()):(s.e=n.e,s.d=n.d?n.d.slice():n.d));if("number"===(t=typeof n)){if(0===n)return s.s=1/n<0?-1:1,s.e=0,void(s.d=[0]);if(n<0?(n=-n,s.s=-1):s.s=1,n===~~n&&n<1e7){for(i=0,e=n;e>=10;e/=10)i++;return void(external?i>r.maxE?(s.e=NaN,s.d=null):i<r.minE?(s.e=0,s.d=[0]):(s.e=i,s.d=[n]):(s.e=i,s.d=[n]))}return 0*n!=0?(n||(s.s=NaN),s.e=NaN,void(s.d=null)):parseDecimal(s,n.toString())}if("string"!==t)throw Error(invalidArgument+n);return 45===(e=n.charCodeAt(0))?(n=n.slice(1),s.s=-1):(43===e&&(n=n.slice(1)),s.s=1),isDecimal.test(n)?parseDecimal(s,n):parseOther(s,n)}if(r.prototype=P,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=config,r.clone=clone,r.isDecimal=isDecimalInstance,r.abs=abs,r.acos=acos,r.acosh=acosh,r.add=add,r.asin=asin,r.asinh=asinh,r.atan=atan,r.atanh=atanh,r.atan2=atan2,r.cbrt=cbrt,r.ceil=ceil,r.clamp=clamp,r.cos=cos,r.cosh=cosh,r.div=div,r.exp=exp,r.floor=floor,r.hypot=hypot,r.ln=ln,r.log=log,r.log10=log10,r.log2=log2,r.max=max,r.min=min,r.mod=mod,r.mul=mul,r.pow=pow,r.random=random,r.round=round,r.sign=sign,r.sin=sin,r.sinh=sinh,r.sqrt=sqrt,r.sub=sub,r.sum=sum,r.tan=tan,r.tanh=tanh,r.trunc=trunc,void 0===n&&(n={}),n&&!0!==n.defaults)for(t=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<t.length;)n.hasOwnProperty(e=t[i++])||(n[e]=this[e]);return r.config(n),r}function div(n,i){return new this(n).div(i)}function exp(n){return new this(n).exp()}function floor(n){return finalise(n=new this(n),n.e+1,3)}function hypot(){var n,i,e=new this(0);for(external=!1,n=0;n<arguments.length;)if((i=new this(arguments[n++])).d)e.d&&(e=e.plus(i.times(i)));else{if(i.s)return external=!0,new this(1/0);e=i}return external=!0,e.sqrt()}function isDecimalInstance(n){return n instanceof Decimal||n&&n.toStringTag===tag||!1}function ln(n){return new this(n).ln()}function log(n,i){return new this(n).log(i)}function log2(n){return new this(n).log(2)}function log10(n){return new this(n).log(10)}function max(){return maxOrMin(this,arguments,"lt")}function min(){return maxOrMin(this,arguments,"gt")}function mod(n,i){return new this(n).mod(i)}function mul(n,i){return new this(n).mul(i)}function pow(n,i){return new this(n).pow(i)}function random(n){var i,e,t,r,s=0,o=new this(1),a=[];if(void 0===n?n=this.precision:checkInt32(n,1,MAX_DIGITS),t=Math.ceil(n/LOG_BASE),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(t));s<t;)(r=i[s])>=429e7?i[s]=crypto.getRandomValues(new Uint32Array(1))[0]:a[s++]=r%1e7;else{if(!crypto.randomBytes)throw Error(cryptoUnavailable);for(i=crypto.randomBytes(t*=4);s<t;)(r=i[s]+(i[s+1]<<8)+(i[s+2]<<16)+((127&i[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(i,s):(a.push(r%1e7),s+=4);s=t/4}else for(;s<t;)a[s++]=1e7*Math.random()|0;for(t=a[--s],n%=LOG_BASE,t&&n&&(r=mathpow(10,LOG_BASE-n),a[s]=(t/r|0)*r);0===a[s];s--)a.pop();if(s<0)e=0,a=[0];else{for(e=-1;0===a[0];e-=LOG_BASE)a.shift();for(t=1,r=a[0];r>=10;r/=10)t++;t<LOG_BASE&&(e-=LOG_BASE-t)}return o.e=e,o.d=a,o}function round(n){return finalise(n=new this(n),n.e+1,this.rounding)}function sign(n){return(n=new this(n)).d?n.d[0]?n.s:0*n.s:n.s||NaN}function sin(n){return new this(n).sin()}function sinh(n){return new this(n).sinh()}function sqrt(n){return new this(n).sqrt()}function sub(n,i){return new this(n).sub(i)}function sum(){var n=0,i=arguments,e=new this(i[n]);for(external=!1;e.s&&++n<i.length;)e=e.plus(i[n]);return external=!0,finalise(e,this.precision,this.rounding)}function tan(n){return new this(n).tan()}function tanh(n){return new this(n).tanh()}function trunc(n){return finalise(n=new this(n),n.e+1,1)}P[Symbol.for("nodejs.util.inspect.custom")]=P.toString,P[Symbol.toStringTag]="Decimal";export var Decimal=P.constructor=clone(DEFAULTS);LN10=new Decimal(LN10),PI=new Decimal(PI);export default Decimal;