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