You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MikeMcl_decimal.js/decimal.min.js

2 lines
20 KiB

/*! decimal.js v2.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */
(function(n){"use strict";function p(n,t,i,r){return(!r&&i>3&&n[t]==4||(r||i<4)&&n[t]==9)&&n[t+1]==9&&n[t+2]==9&&n[t+3]==9&&(r!=null||n[t+4]==9)||r==null&&(n[t]==5||!n[t])&&!n[t+1]&&!n[t+2]&&!n[t+3]&&!n[t+4]}function v(n,t,i){var r=n.constructor;return t==null||((o=t<0||t>8)||t!==0&&(r.errors?parseInt:parseFloat)(t)!=t)&&!f(r,"rounding mode",t,i,0)?r.rounding:t|0}function y(n,t,i,r){var u=n.constructor;return!(o=t<(r||0)||t>=d+1)&&(t===0||(u.errors?parseInt:parseFloat)(t)==t)||f(u,"argument",t,i,0)}function e(n,t,r,u,f,e){var b=n.constructor,k=n.e-t.e,v=n.s==t.s?1:-1,h=n.c,s=t.c;if(!h||!h[0]||!s||!s[0])return new b(!n.s||!t.s||(h?s&&h[0]==s[0]:!s)?NaN:h&&h[0]==0||!s?v*0:v/0);for(var p,w,l,d,y,it=s.slice(),g=y=s.length,rt=h.length,o=h.slice(0,y),c=o.length,nt=new b(v),tt=nt.c=[],a=v=0;s[a]==(h[a]||0);a++);if(s[a]>(h[a]||0)&&(k--,v=1),nt.e=k,r==null?(r=b.precision,u=b.rounding):f&&(r+=k+1),e=e||10,r>=0){for(v+=r;c++<y;o.push(0));it.unshift(a=0);do{for(w=0;w<e;w++){if(y!=(c=o.length))p=y>c?1:-1;else for(l=-1,p=0;++l<y;)if(s[l]!=o[l]){p=s[l]>o[l]?1:-1;break}if(p<0){for(d=c==y?s:it;c;){if(o[--c]<d[c]){for(l=c;l&&!o[--l];o[l]=e-1);--o[l];o[c]+=e}o[c]-=d[c]}for(;!o[0];o.shift());}else break}tt[a++]=p?w:++w;o[0]&&p?o[c]=h[g]||0:o=[h[g]]}while((g++<rt||o[0]!=null)&&v--);!tt[0]&&a>1&&tt.shift();a<=r&&(r=null)}return i(nt,r,u,o[0]!=null,e)}function g(n,t){var h,l,b,c,r,o,s,a=0,k=0,v=0,f=n.constructor,y=f.ONE,d=f.rounding,w=f.precision;if(!n.c||!n.c[0]||n.e>17)return new f(n.c?n.c[0]?n.s<0?0:1/0:y:n.s?n.s<0?0:n:NaN);for(t==null?(u=!1,r=w):r=t,s=new f(.03125);n.e>-2;)n=n.times(s),v+=5;for(l=Math.log(Math.pow(2,v))/Math.LN10*2+5|0,r+=l,h=c=o=new f(y),f.precision=r;;){if(c=i(c.times(n),r,1),h=h.times(++k),s=o.plus(e(c,h,r,1)),s.c.slice(0,r).join("")===o.c.slice(0,r).join("")){for(b=v;b--;)o=i(o.times(o),r,1);if(t==null)if(a<3&&p(o.c,r-l,d,a))f.precision=r+=10,h=c=s=new f(y),k=0,a++;else return i(o,f.precision=w,d,u=!0);else return f.precision=w,o}o=s}}function w(n,t,r,u){var o=n.constructor,e=(n=new o(n)).e,f=n.c;if(!f)return n.toString();for(f.length>++t&&i(n,t,r),e=u?t:t+n.e-e;f.length<e;f.push(0));return e=n.e,u==1||u==2&&(t<=e||e<=o.toExpNeg)?(n.s<0&&f[0]?"-":"")+(f.length>1?f[0]+"."+f.slice(1).join(""):f[0])+(e<0?"e":"e+")+e:n.toString()}function f(n,t,i,u,f){if(n.errors){var e=new Error((u||["new Decimal","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFraction","pow","random","log","sqrt","toNearest","divToInt"][r?r<0?-r:r:1/r<0?1:0])+"() "+(["number type has more than 15 significant digits","LN10 out of digits"][t]||t+([o?" out of range":" not an integer"," not a boolean or binary digit"][f]||""))+": "+i);e.name="Decimal Error";o=r=0;throw e;}}function it(n,t,i){var r=new n(n.ONE);for(u=!1;;){if(i&1&&(r=r.times(t)),i>>=1,!i)break;t=t.times(t)}return u=!0,r}function c(n,t){var b,v,y,ut,o,a,k,nt,tt,it=1,d=10,r=n,l=r.c,s=r.constructor,g=s.ONE,rt=s.rounding,w=s.precision;if(r.s<0||!l||!l[0]||!r.e&&l[0]==1&&l.length==1)return new s(l&&!l[0]?-1/0:r.s!=1?NaN:l?0:r);if(t==null?(u=!1,o=w):o=t,s.precision=o+=d,Math.abs(v=r.e)<15e14){while(l[0]<7&&l[0]!=1||l[0]==1&&l[1]>3)r=r.times(n),l=r.c,it++;v=r.e;l[0]>1?(it==1?r=new s("0."+l.join("")):r.e=-1,v++):r=new s("1."+l.slice(1).join(""))}else return r=new s(r),r.e=0,o+2>h.length&&f(s,1,o+2,"ln"),r=c(r,o-d).plus(new s(h.slice(0,o+2)).times(v+"")),s.precision=w,t==null?i(r,w,rt,u=!0):r;for(nt=r,a=y=r=e(r.minus(g),r.plus(g),o,1),tt=i(r.times(r),o,1),b=3;;){if(y=i(y.times(tt),o,1),k=a.plus(e(y,new s(b),o,1)),k.c.slice(0,o).join("")===a.c.slice(0,o).join(""))if(a=a.times(2),v!==0&&(o+2>h.length&&f(s,1,o+2,"ln"),a=a.plus(new s(h.slice(0,o+2)).times(v+""))),a=e(a,new s(it),o,1),t==null)if(p(a.c,o-d,rt,ut))s.precision=o+=d,k=y=r=e(nt.minus(g),nt.plus(g),o,1),tt=i(r.times(r),o,1),b=ut=1;else return i(a,s.precision=w,rt,u=!0);else return s.precision=w,a;a=k;b+=2}}function i(n,t,i,r,f){var o,h,s,e,c=n.constructor;if(t!=o){if(!(e=n.c))return n;if(s=n.s<0,h=(f=f||10)/2,o=e[t],r=r||t<0||e[t+1]!=null,r=i<4?(o!=null||r)&&(i==0||i==2&&!s||i==3&&s):o>h||o==h&&(i==4||r||i==6&&e[t-1]&1||i==7&&!s||i==8&&s),t<1||!e[0])return e.length=0,r?(t=t-n.e-1,e[0]=1,n.e=-t||0):e[0]=n.e=0,n;if(e.length>t&&(e.length=t),t--,r){for(o=t;e[o]==null;e[o--]=0);for(--f;++e[t]>f;)e[t]=0,t--||(++n.e,e.unshift(1))}for(t=e.length;!e[--t];e.pop());}return u&&(n.e>c.maxE?n.c=n.e=null:n.e<c.minE&&(n.c=[n.e=0])),n}var b,s,l,nt,tt=Object.prototype.toString,o,r=0,u=!0,k="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_",t={},a=9e15,d=1e9,rt=3e3,h="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";t.absoluteValue=t.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),i(n)};t.ceil=function(){return i(new this.constructor(this),this.e+1,2)};t.comparedTo=t.cmp=function(n,t){var u,c=this,f=c.c,s=(r=-r,n=new c.constructor(n,t),n.c),i=c.s,h=n.s,e=c.e,o=n.e;if(!i||!h)return null;if(u=f&&!f[0],t=s&&!s[0],u||t)return u?t?0:-h:i;if(i!=h)return i;if(u=i<0,!f||!s)return e==o?0:!f^u?1:-1;if(e!=o)return e>o^u?1:-1;for(i=-1,h=(e=f.length)<(o=s.length)?e:o;++i<h;)if(f[i]!=s[i])return f[i]>s[i]^u?1:-1;return e==o?0:e>o^u?1:-1};t.decimalPlaces=t.dp=function(){var n=this;return n.c?Math.max(n.c.length-n.e-1,0):null};t.dividedBy=t.div=function(n,t){return r=2,e(this,new this.constructor(n,t))};t.dividedToIntegerBy=t.divToInt=function(n,t){var f=this,u=f.constructor;return r=18,i(e(f,new u(n,t),0,1,1),u.precision,u.rounding)};t.equals=t.eq=function(n,t){return r=3,this.cmp(n,t)===0};t.exponential=t.exp=function(){return g(this)};t.floor=function(){return i(new this.constructor(this),this.e+1,3)};t.greaterThan=t.gt=function(n,t){return r=4,this.cmp(n,t)>0};t.greaterThanOrEqualTo=t.gte=function(n,t){return r=5,t=this.cmp(n,t),t==1||t===0};t.isFinite=function(){return!!this.c};t.isInteger=t.isInt=function(){return!!this.c&&this.e>this.c.length-2};t.isNaN=function(){return!this.s};t.isNegative=t.isNeg=function(){return this.s<0};t.isZero=function(){return!!this.c&&this.c[0]==0};t.lessThan=t.lt=function(n,t){return r=6,this.cmp(n,t)<0};t.lessThanOrEqualTo=t.lte=function(n,t){return r=7,t=this.cmp(n,t),t==-1||t===0};t.logarithm=t.log=function(n,t){var b,o,w,d,tt,g,s,a,v,y=this,l=y.constructor,k=l.precision,nt=l.rounding,it=5;if(n==null)n=new l(10),b=!0;else{if(r=15,n=new l(n,t),o=n.c,n.s<0||!o||!o[0]||!n.e&&o[0]==1&&o.length==1)return new l(NaN);b=n.eq(10)}if(o=y.c,y.s<0||!o||!o[0]||!y.e&&o[0]==1&&o.length==1)return new l(o&&!o[0]?-1/0:y.s!=1?NaN:o?0:1/0);if(tt=b&&(o[0]!=1||o.length>1)||(n.c[n.c.length-1]&1)!=(o[o.length-1]&1)||0&&n.eq(2)&&y.toString(2).replace(/[^1]+/g,"")!="1",u=!1,s=k+it,a=s+10,g=c(y,s),b?(a>h.length&&f(l,1,a,"log"),w=new l(h.slice(0,a))):w=c(n,s),v=e(g,w,s,1),p(v.c,d=k,nt))do if(s+=10,g=c(y,s),b?(a=s+10,a>h.length&&f(l,1,a,"log"),w=new l(h.slice(0,a))):w=c(n,s),v=e(g,w,s,1),!tt){for(o=v.c;o[++d]==9;);d==k+it+10&&(v=i(v,k+1,0));break}while(p(v.c,d+=10,nt));return u=!0,i(v,k,nt)};t.minus=function(n,t){var c,o,l,y,h=this,a=h.constructor,s=h.s;if(r=8,n=new a(n,t),t=n.s,!s||!t)return new a(NaN);if(s!=t)return n.s=-t,h.plus(n);var f=h.c,b=h.e,e=n.c,v=n.e,p=a.precision,w=a.rounding;if(!b||!v){if(!f||!e)return f?(n.s=-t,n):new a(e?h:NaN);if(!f[0]||!e[0])return h=e[0]?(n.s=-t,n):new a(f[0]?h:w==3?-0:0),u?i(h,p,w):h}if(f=f.slice(),o=f.length,s=b-v){for((y=s<0)?(s=-s,c=f,o=e.length):(v=b,c=e),p>o&&(o=p),s>(o+=2)&&(s=o,c.length=1),c.reverse(),t=s;t--;c.push(0));c.reverse()}else for((y=o<(l=e.length))&&(l=o),s=t=0;t<l;t++)if(f[t]!=e[t]){y=f[t]<e[t];break}if(y&&(c=f,f=e,e=c,n.s=-n.s),(t=-((l=f.length)-e.length))>0)for(;t--;f[l++]=0);for(t=e.length;t>s;){if(f[--t]<e[t]){for(o=t;o&&!f[--o];f[o]=9);--f[o];f[t]+=10}f[t]-=e[t]}for(;f[--l]==0;f.pop());for(;f[0]==0;f.shift(),--v);return f[0]||(f=[v=0],n.s=w==3?-1:1),n.c=f,n.e=v,u?i(n,p,w):n};t.modulo=t.mod=function(n,t){var h,o,f=this,s=f.constructor,c=s.modulo;return(r=9,n=new s(n,t),t=n.s,h=!f.c||!t||n.c&&!n.c[0],h||!n.c||f.c&&!f.c[0])?h?new s(NaN):i(new s(f),s.precision,s.rounding):(u=!1,c==9?(n.s=1,o=e(f,n,0,3,1),n.s=t,o.s*=t):o=e(f,n,0,c,1),o=o.times(n),u=!0,f.minus(o))};t.naturalLogarithm=t.ln=function(){return c(this)};t.negated=t.neg=function(){var n=new this.constructor(this);return n.s=-n.s||null,i(n)};t.plus=function(n,t){var h,s=this,c=s.constructor,f=s.s;if(r=10,n=new c(n,t),t=n.s,!f||!t)return new c(NaN);if(f!=t)return n.s=-t,s.minus(n);var v=s.e,e=s.c,l=n.e,o=n.c,a=c.precision,y=c.rounding;if(!v||!l){if(!e||!o)return new c(f/0);if(!e[0]||!o[0])return s=o[0]?n:new c(e[0]?s:f*0),u?i(s,a,y):s}if(e=e.slice(),f=v-l){for(f<0?(f=-f,h=e,t=o.length):(l=v,h=o,t=e.length),a>t&&(t=a),f>++t&&(f=t,h.length=1),h.reverse();f--;h.push(0));h.reverse()}for(e.length-o.length<0&&(h=o,o=e,e=h),f=o.length,t=0;f;e[f]%=10)t=(e[--f]=e[f]+o[f]+t)/10|0;for(t&&(e.unshift(t),++l),f=e.length;e[--f]==0;e.pop());return n.c=e,n.e=l,u?i(n,a,y):n};t.precision=t.sd=function(n){var t=this;return n!=null&&n!==!!n&&n!==1&&n!==0&&f(t.constructor,"argument",n,"precision",1),t.c?n?Math.max(t.e+1,t.c.length):t.c.length:null};t.round=function(){var n=this,t=n.constructor;return i(new t(n),n.e+1,t.rounding)};t.squareRoot=t.sqrt=function(){var l,t,r,a,o,s=this,n=s.c,h=s.s,f=s.e,c=s.constructor,v=new c(.5);if(h!==1||!n||!n[0])return new c(!h||h<0&&(!n||n[0])?NaN:n?s:1/0);for(u=!1,h=Math.sqrt(+s),h==0||h==1/0?(l=n.join(""),(l.length+f)%2==0&&(l+="0"),r=new c(Math.sqrt(l)+""),r.c||(r.c=[1]),r.e=Math.floor((f+1)/2)-(f<0||f%2)):r=new c(h.toString()),t=(f=c.precision)+3;;)if(o=r,r=v.times(o.plus(e(s,o,t+2,1))),o.c.slice(0,t).join("")===r.c.slice(0,t).join(""))if(n=r.c,n[t-3]!=9&&(a||n[t-3]!=4)||n[t-2]!=9||n[t-1]!=9||n[t]!=9){if((!n[t-3]||n[t-3]==5)&&!n[t-2]&&!n[t-1]&&!n[t]&&(n.length>f+1&&(n.length=f+1),!r.times(r).eq(s))){while(n.length<f)n.push(0);n[f]++}break}else{if(!a&&(o=i(o,f+1,0),o.times(o).eq(s))){r=o;break}t+=4;a=1}return u=!0,i(r,f,c.rounding)};t.times=function(n,t){var e,l=this,a=l.constructor,o=l.c,s=(r=11,n=new a(n,t),n.c),h=l.e,f=n.e,c=l.s;if(t=n.s,n.s=c==t?1:-1,!h&&(!o||!o[0])||!f&&(!s||!s[0]))return new a(!c||!t||o&&!o[0]&&!s||s&&!s[0]&&!o?NaN:!o||!s?n.s/0:n.s*0);for(n.e=h+f,c=o.length,t=s.length,c<t&&(e=o,o=s,s=e,f=c,c=t,t=f),f=c+t,e=[];f--;e.push(0));for(h=t-1;h>-1;h--){for(t=0,f=c+h;f>h;t=t/10|0)t=e[f]+s[h]*o[f-h-1]+t,e[f--]=t%10|0;t&&(e[f]=(e[f]+t)%10)}for(t&&++n.e,e[0]||e.shift(),f=e.length;!e[--f];e.pop());return n.c=e,u?i(n,a.precision,a.rounding):n};t.toDecimalPlaces=t.toDP=function(n,t){var r=this;return r=new r.constructor(r),n==null||!y(r,n,"toDP")?r:i(r,(n|0)+r.e+1,v(r,t,"toDP"))};t.toExponential=function(n,t){var i=this;return w(i,n!=null&&y(i,n,"toExponential")||!i.c?n|0:i.c.length-1,n!=null&&v(i,t,"toExponential"),1)};t.toFixed=function(n,t){var i,r=this,u=r.constructor,f=u.toExpNeg,e=u.toExpPos;return n!=null&&(n=y(r,n,i="toFixed",-d)?r.e+(n|0):null,t=v(r,t,i)),u.toExpNeg=-(u.toExpPos=1/0),n==null?i=r.toString():(i=w(r,n,t),r.s<0&&r.c&&(r.c[0]?i.indexOf("-")<0&&(i="-"+i):i=i.replace("-",""))),u.toExpNeg=f,u.toExpPos=e,i};t.toFormat=function(n,t,i){var r=this.toFixed(t).split(".");return r[0].replace(/\B(?=(\d{3})+$)/g,n==null?",":n+"")+(r[1]?"."+(i?r[1].replace(/\d{5}\B/g,"$&"+i):r[1]):"")};t.toFraction=function(n){var h,i,p,k,s,c,w,a=this,t=a.constructor,l=h=new t(t.ONE),v=c=new t(0),b=a.c,y=new t(t.ONE),d=t.precision;if(!b)return a.toString();for(p=y.e=b.length-a.e-1,(n==null||(!(r=12,s=new t(n)).s||(o=s.cmp(l)<0||!s.c)||t.errors&&s.e<s.c.length-1)&&!f(t,"max denominator",n,"toFraction",0)||(n=s).cmp(y)>0)&&(n=p>0?y:l),u=!1,s=new t(b.join("")),t.precision=b.length;;){if(w=e(s,y,0,1,1),i=h.plus(w.times(v)),i.cmp(n)==1)break;h=v;v=i;l=c.plus(w.times(i=l));c=i;y=s.minus(w.times(i=y));s=i}return i=e(n.minus(h),v,0,1,1),c=c.plus(i.times(l)),h=h.plus(i.times(v)),c.s=l.s=a.s,p*=2,k=e(l,v,p,1,1).minus(a).abs().cmp(e(c,h,p,1,1).minus(a).abs())<1?[l.toString(),v.toString()]:[c.toString(),h.toString()],u=!0,t.precision=d,k};t.toNearest=function(n,t){var f=this,o=f.constructor;return f=new o(f),n==null?(n=new o(o.ONE),t=o.rounding):(r=17,n=new o(n),t=v(f,t,"toNearest")),n.c?f.c&&(u=!1,t<4&&(t=[4,5,7,8][t]),n.c[0]==1&&n.c.length==1?(f.e-=n.e,i(f,f.e+1,t),f.c[0]&&(f.e+=n.e)):n.c[0]?f=e(f,n,0,t,1).times(n):f.c=[f.e=0],u=!0,i(f)):f.s&&(n.s&&(n.s=f.s),f=n),f};t.toNumber=function(){var n=this;return+n||(n|0)*n.s};t.toPower=t.pow=function(n,t){var b,h,y,e,f=this,o=f.constructor,a=f.s,v=+(r=13,n=new o(n,t)),l=v<0?-v:v,s=o.precision,w=o.rounding;if(!f.c||!n.c||(y=!f.c[0])||!n.c[0])return new o(Math.pow(y?a*0:+f,v));if(f=new o(f),b=f.c.length,!f.e&&f.c[0]==f.s&&b==1)return f;if(t=n.c.length-1,n.e||n.c[0]!=n.s||t)if(y=n.e>=t,!y&&a<0)e=new o(NaN);else{if(y&&b*l<rt){if(e=it(o,f,l),n.s<0)return o.ONE.div(e)}else{if(a=a<0&&n.c[Math.max(n.e,t)]&1?-1:1,t=Math.pow(+f,v),h=t==0||!isFinite(t)?Math.floor(v*(Math.log("0."+f.c.join(""))/Math.LN10+f.e+1)):new o(t+"").e,h>o.maxE+1||h<o.minE-1)return new o(h>0?a/0:0);if(u=!1,o.rounding=f.s=1,l=Math.min(12,(h+"").length),e=g(n.times(c(f,s+l)),s),e=i(e,s+5,1),p(e.c,s,w)){for(h=s+10,e=i(g(n.times(c(f,h+l)),h),h+5,1),l=s;e.c[++l]==9;);l==s+15&&(e=i(e,s+1,0))}e.s=a;u=!0;o.rounding=w}e=i(e,s,w)}else e=i(f,s,w);return e};t.toPrecision=function(n,t){return n!=null&&y(this,n,"toPrecision",1)?w(this,--n|0,v(this,t,"toPrecision"),2):this.toString()};t.toSignificantDigits=t.toSD=function(n,t){var r=this,u=r.constructor;return r=new u(r),n==null||!y(r,n,"toSD",1)?i(r,u.precision,u.rounding):i(r,n|0,v(r,t,"toSD"))};t.toString=function(n){var e,t,s,r=this,u=r.constructor,i=r.e;if(i===null)t=r.s?"Infinity":"NaN";else{if(n===e&&(i<=u.toExpNeg||i>=u.toExpPos))return w(r,r.c.length-1,u.rounding,1);if(t=r.c.join(""),i<0){for(;++i;t="0"+t);t="0."+t}else if(s=t.length,i>0)if(++i>s)for(i-=s;i--;t+="0");else i<s&&(t=t.slice(0,i)+"."+t.slice(i));else if(e=t.charAt(0),s>1)t=e+"."+t.slice(1);else if(e=="0")return e;if(n!=null)if((o=!(n>=2&&n<65))||n!=(n|0)&&u.errors)f(u,"base",n,"toString",0);else if(t=b(u,t,n|0,10,r.s),t=="0")return t}return r.s<0?"-"+t:t};t.truncated=t.trunc=function(){return i(new this.constructor(this),this.e+1,1)};t.valueOf=t.toJSON=function(){return this.toString()};b=function(){function n(n,t,i){for(var u,r=[0],f,e=0,o=n.length;e<o;){for(f=r.length;f--;r[f]*=t);for(r[u=0]+=k.indexOf(n.charAt(e++));u<r.length;u++)r[u]>i-1&&(r[u+1]==null&&(r[u+1]=0),r[u+1]+=r[u]/i|0,r[u]%=i)}return r.reverse()}return function(t,i,r,u,f){var o,s,l,h=i.indexOf("."),c=new t(u);for(u<37&&(i=i.toLowerCase()),h<0?(o=new t(c),l=[1]):(o=it(t,c,i.length-h-1),l=n(o.toFixed(),10,r),i=i.replace(".","")),c.c=l,c.e=l.length,s=n(i,u,r),o.c=s,o.e=s.length,o.s=f,o=e(o,c,t.precision,t.rounding,0,r),s=o.c,h=s.length;h--;)s[h]=k.charAt(s[h]);return o.s=1,o.toFixed()}}();l=function(){function c(n){var i,e,t,u=this,h="config",c=u.errors?parseInt:parseFloat;return n==e||typeof n!="object"&&!f(u,"object expected",n,h)?u:((t=n[i="precision"])!=e&&((o=t<1||t>d)||c(t)!=t?f(u,i,t,h,0):u[i]=t|0),(t=n[i="rounding"])!=e&&((o=t<0||t>8)||c(t)!=t?f(u,i,t,h,0):u[i]=t|0),(t=n[i="toExpNeg"])!=e&&((o=t<-a||t>0)||c(t)!=t?f(u,i,t,h,0):u[i]=Math.floor(t)),(t=n[i="toExpPos"])!=e&&((o=t<0||t>a)||c(t)!=t?f(u,i,t,h,0):u[i]=Math.floor(t)),(t=n[i="minE"])!=e&&((o=t<-a||t>0)||c(t)!=t?f(u,i,t,h,0):u[i]=Math.floor(t)),(t=n[i="maxE"])!=e&&((o=t<0||t>a)||c(t)!=t?f(u,i,t,h,0):u[i]=Math.floor(t)),(t=n[i="errors"])!=e&&(t===!!t||t===1||t===0?(o=r=0,u[i]=!!t):f(u,i,t,h,1)),(t=n[i="crypto"])!=e&&(t===!!t||t===1||t===0?u[i]=!!(t&&s&&typeof s=="object"):f(u,i,t,h,1)),(t=n[i="modulo"])!=e&&((o=t<0||t>9)||c(t)!=t?f(u,i,t,h,0):u[i]=t|0),u)}function l(n){return new this(n).exp()}function v(n){return new this(n).ln()}function p(n,t){return new this(n).log(t)}function e(n,t,i){var r,u,f=0;for(tt.call(t[0])=="[object Array]"&&(t=t[0]),r=new n(t[0]);++f<t.length;)if(u=new n(t[f]),u.s)r[i](u)&&(r=u);else{r=u;break}return r}function w(){return e(this,arguments,"lt")}function g(){return e(this,arguments,"gt")}function it(n,t){return new this(n).pow(t)}function ut(n){return new this(n).sqrt()}function h(n){function u(n,t){var e=this;if(!(e instanceof u))return f(u,"Decimal called without new",n),new u(n,t);if(n instanceof u){if(t==null){r=0;e.constructor=n.constructor;e.s=n.s;e.e=n.e;e.c=(n=n.c)?n.slice():n;return}if(t==10)return i(new u(n),u.precision,u.rounding);n+=""}return nt(e.constructor=u,e,n,t)}return u.precision=20,u.rounding=4,u.modulo=1,u.toExpNeg=-7,u.toExpPos=21,u.minE=-a,u.maxE=a,u.errors=!0,u.crypto=!1,u.prototype=t,u.ONE=new u(1),u.ROUND_UP=0,u.ROUND_DOWN=1,u.ROUND_CEIL=2,u.ROUND_FLOOR=3,u.ROUND_HALF_UP=4,u.ROUND_HALF_DOWN=5,u.ROUND_HALF_EVEN=6,u.ROUND_HALF_CEIL=7,u.ROUND_HALF_FLOOR=8,u.EUCLID=9,u.config=c,u.constructor=h,u.exp=l,u.ln=v,u.log=p,u.max=w,u.min=g,u.pow=it,u.sqrt=ut,u.random=rt,n!=null&&u.config(n),u}var nt=function(){var n=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,t=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")};return function(e,s,h,c){var w,a,l,v,y,p;if(typeof h!="string"&&(h=(v=typeof h=="number"||tt.call(h)=="[object Number]")&&h===0&&1/h<0?"-0":h+""),y=h,c==a&&n.test(h))s.s=h.charAt(0)=="-"?(h=h.slice(1),-1):1;else{if(c==10)return i(new e(h),e.precision,e.rounding);if(h=t.call(h).replace(/^\+(?!-)/,""),s.s=h.charAt(0)=="-"?(h=h.replace(/^-(?!-)/,""),-1):1,c!=a?c!=(c|0)&&e.errors||(o=!(c>=2&&c<65))?(f(e,"base",c,0,0),p=n.test(h)):(w="["+k.slice(0,c=c|0)+"]+",h=h.replace(/\.$/,"").replace(/^\./,"0."),(p=new RegExp("^"+w+"(?:\\."+w+")?$",c<37?"i":"").test(h))?(v&&(h.replace(/^0\.0*|\./,"").length>15&&f(e,0,y),v=!v),h=b(e,h,10,c,s.s)):h!="Infinity"&&h!="NaN"&&(f(e,"not a base "+c+" number",y),h="NaN")):p=n.test(h),!p)return s.c=s.e=null,h!="Infinity"&&(h!="NaN"&&f(e,"not a number",y),s.s=null),r=0,s}for((a=h.indexOf("."))>-1&&(h=h.replace(".","")),(l=h.search(/e/i))>0?(a<0&&(a=l),a+=+h.slice(l+1),h=h.substring(0,l)):a<0&&(a=h.length),l=0;h.charAt(l)=="0";l++);if(l==(c=h.length))s.c=[s.e=0];else{for(v&&c>15&&h.slice(l).length>15&&f(e,0,y);h.charAt(--c)=="0";);for(s.e=a-l-1,s.c=[],a=0;l<=c;s.c[a++]=+h.charAt(l++));u&&(s.e>e.maxE?s.c=s.e=null:s.e<e.minE&&(s.c=[s.e=0]))}r=0}}(),rt=function(){function u(n){var t=Math.random();return n?(t*n|0)+"":(1+t+"").slice(2,-2)}function t(i){var r;return i?(r=s.getRandomValues(new n.Uint8Array(1))[0],r>(256/i|0)*i-1?t(i):r%i+""):(r=s.getRandomValues(new n.Uint32Array(1))[0],r>=4e9?t(i):(r+1e9+"").slice(1))}function i(n){var r,t,u=s.randomBytes;return n?(t=u(1)[0],t>(256/n|0)*n-1?i(n):t%n+""):(r=u(8),r[0]=67,r[1]=r[1]&15|48,t=r.readDoubleBE(0),t>9003599627370495?i(n):(t-0xc72815b398000+"").slice(2))}return function(n,e){var w,a,o,b,k,d,p,h,c=this,l=new c(0),v=u;if(d=n==a||!(r=14,n=new c(n)).c&&!f(c,"limit must be finite",n,"random"))n=new c(c.ONE);else if(!n.c[0])return l;c.crypto&&(s.getRandomValues?v=t:s.randomBytes&&(v=i));a=n.e;k=(w=n.c).length;do{o=0;h=v(w[0]+1)+v();do b=w[o],p=h.charAt(o++);while(b==p)}while(p>b||o>k||p=="");for(o=0;h.charAt(o)=="0";o++,a--);for(d?e=c.precision:e!=null&&y(n,e,"random",1)?e|=0:e=a+1,e+=o;h.length<e;)h+=v();for(;h.charAt(--e)=="0";);if(++e>0)for(l.c=[];o<e;l.c.push(+h.charAt(o++)));else l.c=[a=0];return l.e=a,l.s=n.s,l}}();return h()}();typeof module!="undefined"&&module&&module.exports?(module.exports=l,typeof require=="function"&&(s=require("crypto"))):(s=n.crypto,typeof define=="function"&&define.amd?define(function(){return l}):(nt=n.Decimal,l.noConflict=function(){return n.Decimal=nt,l},n.Decimal=l))})(this)