Build 576754stable
Module 737291
13,058 characters · in 85008.d388a51f5c983dbf.jsDependencies
Source Raw
function(t){!function(r){"use strict";var e,n={precision:20,rounding:4,toExpNeg:-7,toExpPos:21,LN10:"2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286"},i=!0,s="[DecimalError] ",o=s+"Invalid argument: ",f=s+"Exponent out of range: ",h=Math.floor,u=Math.pow,c=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,a=h(1286742750677284.5),l={};function d(t,r){var e,n,s,o,f,h,u,c,a=t.constructor,l=a.precision;if(!t.s||!r.s)return r.s||(r=new a(t)),i?A(r,l):r;if(u=t.d,c=r.d,f=t.e,s=r.e,u=u.slice(),o=f-s){for(o<0?(n=u,o=-o,h=c.length):(n=c,s=f,h=u.length),o>(h=(f=Math.ceil(l/7))>h?f+1:h+1)&&(o=h,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for((h=u.length)-(o=c.length)<0&&(o=h,n=c,c=u,u=n),e=0;o;)e=(u[--o]=u[o]+c[o]+e)/1e7|0,u[o]%=1e7;for(e&&(u.unshift(e),++s),h=u.length;0==u[--h];)u.pop();return r.d=u,r.e=s,i?A(r,l):r}function p(t,r,e){if(t!==~~t||t<r||t>e)throw Error(o+t)}function g(t){var r,e,n,i=t.length-1,s="",o=t[0];if(i>0){for(s+=o,r=1;r<i;r++)(e=7-(n=t[r]+"").length)&&(s+=y(e)),s+=n;(e=7-(n=(o=t[r])+"").length)&&(s+=y(e))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}l.absoluteValue=l.abs=function(){var t=new this.constructor(this);return t.s&&(t.s=1),t},l.comparedTo=l.cmp=function(t){var r,e,n,i;if(t=new this.constructor(t),this.s!==t.s)return this.s||-t.s;if(this.e!==t.e)return this.e>t.e^this.s<0?1:-1;for(r=0,e=(n=this.d.length)<(i=t.d.length)?n:i;r<e;++r)if(this.d[r]!==t.d[r])return this.d[r]>t.d[r]^this.s<0?1:-1;return n===i?0:n>i^this.s<0?1:-1},l.decimalPlaces=l.dp=function(){var t=this.d.length-1,r=(t-this.e)*7;if(t=this.d[t])for(;t%10==0;t/=10)r--;return r<0?0:r},l.dividedBy=l.div=function(t){return x(this,new this.constructor(t))},l.dividedToIntegerBy=l.idiv=function(t){var r=this.constructor;return A(x(this,new r(t),0,1),r.precision)},l.equals=l.eq=function(t){return!this.cmp(t)},l.exponent=function(){return v(this)},l.greaterThan=l.gt=function(t){return this.cmp(t)>0},l.greaterThanOrEqualTo=l.gte=function(t){return this.cmp(t)>=0},l.isInteger=l.isint=function(){return this.e>this.d.length-2},l.isNegative=l.isneg=function(){return this.s<0},l.isPositive=l.ispos=function(){return this.s>0},l.isZero=function(){return 0===this.s},l.lessThan=l.lt=function(t){return 0>this.cmp(t)},l.lessThanOrEqualTo=l.lte=function(t){return 1>this.cmp(t)},l.logarithm=l.log=function(t){var r,n=this.constructor,o=n.precision,f=o+5;if(void 0===t)t=new n(10);else if((t=new n(t)).s<1||t.eq(e))throw Error(s+"NaN");if(this.s<1)throw Error(s+(this.s?"NaN":"-Infinity"));return this.eq(e)?new n(0):(i=!1,r=x(_(this,f),_(t,f),f),i=!0,A(r,o))},l.minus=l.sub=function(t){return t=new this.constructor(t),this.s==t.s?E(this,t):d(this,(t.s=-t.s,t))},l.modulo=l.mod=function(t){var r,e=this.constructor,n=e.precision;if(!(t=new e(t)).s)throw Error(s+"NaN");return this.s?(i=!1,r=x(this,t,0,1).times(t),i=!0,this.minus(r)):A(new e(this),n)},l.naturalExponential=l.exp=function(){return b(this)},l.naturalLogarithm=l.ln=function(){return _(this)},l.negated=l.neg=function(){var t=new this.constructor(this);return t.s=-t.s||0,t},l.plus=l.add=function(t){return t=new this.constructor(t),this.s==t.s?d(this,t):E(this,(t.s=-t.s,t))},l.precision=l.sd=function(t){var r,e,n;if(void 0!==t&&!!t!==t&&1!==t&&0!==t)throw Error(o+t);if(r=v(this)+1,e=7*(n=this.d.length-1)+1,n=this.d[n]){for(;n%10==0;n/=10)e--;for(n=this.d[0];n>=10;n/=10)e++}return t&&r>e?r:e},l.squareRoot=l.sqrt=function(){var t,r,e,n,o,f,u,c=this.constructor;if(this.s<1){if(!this.s)return new c(0);throw Error(s+"NaN")}for(t=v(this),i=!1,0==(o=Math.sqrt(+this))||o==1/0?(((r=g(this.d)).length+t)%2==0&&(r+="0"),o=Math.sqrt(r),t=h((t+1)/2)-(t<0||t%2),n=new c(r=o==1/0?"1e"+t:(r=o.toExponential()).slice(0,r.indexOf("e")+1)+t)):n=new c(o.toString()),o=u=(e=c.precision)+3;;)if(n=(f=n).plus(x(this,f,u+2)).times(.5),g(f.d).slice(0,u)===(r=g(n.d)).slice(0,u)){if(r=r.slice(u-3,u+1),o==u&&"4999"==r){if(A(f,e+1,0),f.times(f).eq(this)){n=f;break}}else if("9999"!=r)break;u+=4}return i=!0,A(n,e)},l.times=l.mul=function(t){var r,e,n,s,o,f,h,u,c,a=this.constructor,l=this.d,d=(t=new a(t)).d;if(!this.s||!t.s)return new a(0);for(t.s*=this.s,e=this.e+t.e,(u=l.length)<(c=d.length)&&(o=l,l=d,d=o,f=u,u=c,c=f),o=[],n=f=u+c;n--;)o.push(0);for(n=c;--n>=0;){for(r=0,s=u+n;s>n;)h=o[s]+d[n]*l[s-n-1]+r,o[s--]=h%1e7|0,r=h/1e7|0;o[s]=(o[s]+r)%1e7|0}for(;!o[--f];)o.pop();return r?++e:o.shift(),t.d=o,t.e=e,i?A(t,a.precision):t},l.toDecimalPlaces=l.todp=function(t,r){var e=this,n=e.constructor;return(e=new n(e),void 0===t)?e:(p(t,0,1e9),void 0===r?r=n.rounding:p(r,0,8),A(e,t+v(e)+1,r))},l.toExponential=function(t,r){var e,n=this,i=n.constructor;return void 0===t?e=N(n,!0):(p(t,0,1e9),void 0===r?r=i.rounding:p(r,0,8),e=N(n=A(new i(n),t+1,r),!0,t+1)),e},l.toFixed=function(t,r){var e,n,i=this.constructor;return void 0===t?N(this):(p(t,0,1e9),void 0===r?r=i.rounding:p(r,0,8),e=N((n=A(new i(this),t+v(this)+1,r)).abs(),!1,t+v(n)+1),this.isneg()&&!this.isZero()?"-"+e:e)},l.toInteger=l.toint=function(){var t=this.constructor;return A(new t(this),v(this)+1,t.rounding)},l.toNumber=function(){return+this},l.toPower=l.pow=function(t){var r,n,o,f,u,c,a=this,l=a.constructor,d=+(t=new l(t));if(!t.s)return new l(e);if(!(a=new l(a)).s){if(t.s<1)throw Error(s+"Infinity");return a}if(a.eq(e))return a;if(o=l.precision,t.eq(e))return A(a,o);if(c=(r=t.e)>=(n=t.d.length-1),u=a.s,c){if((n=d<0?-d:d)<=0x1fffffffffffff){for(f=new l(e),r=Math.ceil(o/7+4),i=!1;n%2&&L((f=f.times(a)).d,r),0!==(n=h(n/2));)L((a=a.times(a)).d,r);return i=!0,t.s<0?new l(e).div(f):A(f,o)}}else if(u<0)throw Error(s+"NaN");return u=u<0&&1&t.d[Math.max(r,n)]?-1:1,a.s=1,i=!1,f=t.times(_(a,o+12)),i=!0,(f=b(f)).s=u,f},l.toPrecision=function(t,r){var e,n,i=this,s=i.constructor;return void 0===t?(e=v(i),n=N(i,e<=s.toExpNeg||e>=s.toExpPos)):(p(t,1,1e9),void 0===r?r=s.rounding:p(r,0,8),e=v(i=A(new s(i),t,r)),n=N(i,t<=e||e<=s.toExpNeg,t)),n},l.toSignificantDigits=l.tosd=function(t,r){var e=this.constructor;return void 0===t?(t=e.precision,r=e.rounding):(p(t,1,1e9),void 0===r?r=e.rounding:p(r,0,8)),A(new e(this),t,r)},l.toString=l.valueOf=l.val=l.toJSON=function(){var t=v(this),r=this.constructor;return N(this,t<=r.toExpNeg||t>=r.toExpPos)};var x=function(){function t(t,r){var e,n=0,i=t.length;for(t=t.slice();i--;)e=t[i]*r+n,t[i]=e%1e7|0,n=e/1e7|0;return n&&t.unshift(n),t}function r(t,r,e,n){var i,s;if(e!=n)s=e>n?1:-1;else for(i=s=0;i<e;i++)if(t[i]!=r[i]){s=t[i]>r[i]?1:-1;break}return s}function e(t,r,e){for(var n=0;e--;)t[e]-=n,n=+(t[e]<r[e]),t[e]=1e7*n+t[e]-r[e];for(;!t[0]&&t.length>1;)t.shift()}return function(n,i,o,f){var h,u,c,a,l,d,p,g,x,b,w,y,_,m,E,N,L,O,U=n.constructor,B=n.s==i.s?1:-1,C=n.d,D=i.d;if(!n.s)return new U(n);if(!i.s)throw Error(s+"Division by zero");for(c=0,u=n.e-i.e,L=D.length,E=C.length,g=(p=new U(B)).d=[];D[c]==(C[c]||0);)++c;if(D[c]>(C[c]||0)&&--u,(y=null==o?o=U.precision:f?o+(v(n)-v(i))+1:o)<0)return new U(0);if(y=y/7+2|0,c=0,1==L)for(a=0,D=D[0],y++;(c<E||a)&&y--;c++)_=1e7*a+(C[c]||0),g[c]=_/D|0,a=_%D|0;else{for((a=1e7/(D[0]+1)|0)>1&&(D=t(D,a),C=t(C,a),L=D.length,E=C.length),m=L,b=(x=C.slice(0,L)).length;b<L;)x[b++]=0;(O=D.slice()).unshift(0),N=D[0],D[1]>=1e7/2&&++N;do a=0,(h=r(D,x,L,b))<0?(w=x[0],L!=b&&(w=1e7*w+(x[1]||0)),(a=w/N|0)>1?(a>=1e7&&(a=1e7-1),d=(l=t(D,a)).length,b=x.length,1==(h=r(l,x,d,b))&&(a--,e(l,L<d?O:D,d))):(0==a&&(h=a=1),l=D.slice()),(d=l.length)<b&&l.unshift(0),e(x,l,b),-1==h&&(b=x.length,(h=r(D,x,L,b))<1&&(a++,e(x,L<b?O:D,b))),b=x.length):0===h&&(a++,x=[0]),g[c++]=a,h&&x[0]?x[b++]=C[m]||0:(x=[C[m]],b=1);while((m++<E||void 0!==x[0])&&y--)}return g[0]||g.shift(),p.e=u,A(p,f?o+v(p)+1:o)}}();function b(t,r){var n,s,o,h,c,a=0,l=0,d=t.constructor,p=d.precision;if(v(t)>16)throw Error(f+v(t));if(!t.s)return new d(e);for(null==r?(i=!1,c=p):c=r,h=new d(.03125);t.abs().gte(.1);)t=t.times(h),l+=5;for(c+=Math.log(u(2,l))/Math.LN10*2+5|0,n=s=o=new d(e),d.precision=c;;){if(s=A(s.times(t),c),n=n.times(++a),g((h=o.plus(x(s,n,c))).d).slice(0,c)===g(o.d).slice(0,c)){for(;l--;)o=A(o.times(o),c);return d.precision=p,null==r?(i=!0,A(o,p)):o}o=h}}function v(t){for(var r=7*t.e,e=t.d[0];e>=10;e/=10)r++;return r}function w(t,r,e){if(r>t.LN10.sd())throw i=!0,e&&(t.precision=e),Error(s+"LN10 precision limit exceeded");return A(new t(t.LN10),r)}function y(t){for(var r="";t--;)r+="0";return r}function _(t,r){var n,o,f,h,u,c,a,l,d,p=1,b=t,y=b.d,m=b.constructor,E=m.precision;if(b.s<1)throw Error(s+(b.s?"NaN":"-Infinity"));if(b.eq(e))return new m(0);if(null==r?(i=!1,l=E):l=r,b.eq(10))return null==r&&(i=!0),w(m,l);if(m.precision=l+=10,o=(n=g(y)).charAt(0),!(15e14>Math.abs(h=v(b))))return a=w(m,l+2,E).times(h+""),b=_(new m(o+"."+n.slice(1)),l-10).plus(a),m.precision=E,null==r?(i=!0,A(b,E)):b;for(;o<7&&1!=o||1==o&&n.charAt(1)>3;)o=(n=g((b=b.times(t)).d)).charAt(0),p++;for(h=v(b),o>1?(b=new m("0."+n),h++):b=new m(o+"."+n.slice(1)),c=u=b=x(b.minus(e),b.plus(e),l),d=A(b.times(b),l),f=3;;){if(u=A(u.times(d),l),g((a=c.plus(x(u,new m(f),l))).d).slice(0,l)===g(c.d).slice(0,l))return c=c.times(2),0!==h&&(c=c.plus(w(m,l+2,E).times(h+""))),c=x(c,new m(p),l),m.precision=E,null==r?(i=!0,A(c,E)):c;c=a,f+=2}}function m(t,r){var e,n,s;for((e=r.indexOf("."))>-1&&(r=r.replace(".","")),(n=r.search(/e/i))>0?(e<0&&(e=n),e+=+r.slice(n+1),r=r.substring(0,n)):e<0&&(e=r.length),n=0;48===r.charCodeAt(n);)++n;for(s=r.length;48===r.charCodeAt(s-1);)--s;if(r=r.slice(n,s)){if(s-=n,t.e=h((e=e-n-1)/7),t.d=[],n=(e+1)%7,e<0&&(n+=7),n<s){for(n&&t.d.push(+r.slice(0,n)),s-=7;n<s;)t.d.push(+r.slice(n,n+=7));n=7-(r=r.slice(n)).length}else n-=s;for(;n--;)r+="0";if(t.d.push(+r),i&&(t.e>a||t.e<-a))throw Error(f+e)}else t.s=0,t.e=0,t.d=[0];return t}function A(t,r,e){var n,s,o,c,l,d,p,g,x=t.d;for(c=1,o=x[0];o>=10;o/=10)c++;if((n=r-c)<0)n+=7,s=r,p=x[g=0];else{if((g=Math.ceil((n+1)/7))>=(o=x.length))return t;for(c=1,p=o=x[g];o>=10;o/=10)c++;n%=7,s=n-7+c}if(void 0!==e&&(l=p/(o=u(10,c-s-1))%10|0,d=r<0||void 0!==x[g+1]||p%o,d=e<4?(l||d)&&(0==e||e==(t.s<0?3:2)):l>5||5==l&&(4==e||d||6==e&&(n>0?s>0?p/u(10,c-s):0:x[g-1])%10&1||e==(t.s<0?8:7))),r<1||!x[0])return d?(o=v(t),x.length=1,r=r-o-1,x[0]=u(10,(7-r%7)%7),t.e=h(-r/7)||0):(x.length=1,x[0]=t.e=t.s=0),t;if(0==n?(x.length=g,o=1,g--):(x.length=g+1,o=u(10,7-n),x[g]=s>0?(p/u(10,c-s)%u(10,s)|0)*o:0),d)for(;;)if(0==g){1e7==(x[0]+=o)&&(x[0]=1,++t.e);break}else{if(x[g]+=o,1e7!=x[g])break;x[g--]=0,o=1}for(n=x.length;0===x[--n];)x.pop();if(i&&(t.e>a||t.e<-a))throw Error(f+v(t));return t}function E(t,r){var e,n,s,o,f,h,u,c,a,l,d=t.constructor,p=d.precision;if(!t.s||!r.s)return r.s?r.s=-r.s:r=new d(t),i?A(r,p):r;if(u=t.d,l=r.d,n=r.e,c=t.e,u=u.slice(),f=c-n){for((a=f<0)?(e=u,f=-f,h=l.length):(e=l,n=c,h=u.length),f>(s=Math.max(Math.ceil(p/7),h)+2)&&(f=s,e.length=1),e.reverse(),s=f;s--;)e.push(0);e.reverse()}else{for((a=(s=u.length)<(h=l.length))&&(h=s),s=0;s<h;s++)if(u[s]!=l[s]){a=u[s]<l[s];break}f=0}for(a&&(e=u,u=l,l=e,r.s=-r.s),h=u.length,s=l.length-h;s>0;--s)u[h++]=0;for(s=l.length;s>f;){if(u[--s]<l[s]){for(o=s;o&&0===u[--o];)u[o]=1e7-1;--u[o],u[s]+=1e7}u[s]-=l[s]}for(;0===u[--h];)u.pop();for(;0===u[0];u.shift())--n;return u[0]?(r.d=u,r.e=n,i?A(r,p):r):new d(0)}function N(t,r,e){var n,i=v(t),s=g(t.d),o=s.length;return r?(e&&(n=e-o)>0?s=s.charAt(0)+"."+s.slice(1)+y(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(i<0?"e":"e+")+i):i<0?(s="0."+y(-i-1)+s,e&&(n=e-o)>0&&(s+=y(n))):i>=o?(s+=y(i+1-o),e&&(n=e-i-1)>0&&(s=s+"."+y(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),e&&(n=e-o)>0&&(i+1===o&&(s+="."),s+=y(n))),t.s<0?"-"+s:s}function L(t,r){if(t.length>r)return t.length=r,!0}function O(t){if(!t||"object"!=typeof t)throw Error(s+"Object expected");var r,e,n,i=["precision",1,1e9,"rounding",0,8,"toExpNeg",-1/0,0,"toExpPos",0,1/0];for(r=0;r<i.length;r+=3)if(void 0!==(n=t[e=i[r]]))if(h(n)===n&&n>=i[r+1]&&n<=i[r+2])this[e]=n;else throw Error(o+e+": "+n);if(void 0!==(n=t[e="LN10"]))if(n==Math.LN10)this[e]=new this(n);else throw Error(o+e+": "+n);return this}(n=function t(r){var e,n,i;function s(t){if(!(this instanceof s))return new s(t);if(this.constructor=s,t instanceof s){this.s=t.s,this.e=t.e,this.d=(t=t.d)?t.slice():t;return}if("number"==typeof t){if(0*t!=0)throw Error(o+t);if(t>0)this.s=1;else if(t<0)t=-t,this.s=-1;else{this.s=0,this.e=0,this.d=[0];return}if(t===~~t&&t<1e7){this.e=0,this.d=[t];return}return m(this,t.toString())}if("string"!=typeof t)throw Error(o+t);if(45===t.charCodeAt(0)?(t=t.slice(1),this.s=-1):this.s=1,c.test(t))m(this,t);else throw Error(o+t)}if(s.prototype=l,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.clone=t,s.config=s.set=O,void 0===r&&(r={}),r)for(e=0,i=["precision","rounding","toExpNeg","toExpPos","LN10"];e<i.length;)r.hasOwnProperty(n=i[e++])||(r[n]=this[n]);return s.config(r),s}(n)).default=n.Decimal=n,e=new n(1),"function"==typeof define&&define.amd?define(function(){return n}):t.exports?t.exports=n:(r||(r="u">typeof self&&self&&self.self==self?self:Function("return this")()),r.Decimal=n)}(this)}