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