forked from MikeMcl/bignumber.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbignumber.min.js
2 lines (2 loc) · 17.5 KB
/
bignumber.min.js
1
2
/* bignumber.js v7.2.1 https://github.com/MikeMcl/bignumber.js/LICENCE */
!function(e){"use strict";var r,L=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,B=Math.ceil,U=Math.floor,x="[BigNumber Error] ",I=x+"Number primitive has more than 15 significant digits: ",T=1e14,C=14,M=9007199254740991,G=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],F=1e7,k=1e9;function q(e){var r=0|e;return 0<e||e===r?r:r-1}function $(e){for(var r,n,t=1,i=e.length,o=e[0]+"";t<i;){for(r=e[t++]+"",n=C-r.length;n--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function z(e,r){var n,t,i=e.c,o=r.c,s=e.s,f=r.s,u=e.e,c=r.e;if(!s||!f)return null;if(n=i&&!i[0],t=o&&!o[0],n||t)return n?t?0:-f:s;if(s!=f)return s;if(n=s<0,t=u==c,!i||!o)return t?0:!i^n?1:-1;if(!t)return c<u^n?1:-1;for(f=(u=i.length)<(c=o.length)?u:c,s=0;s<f;s++)if(i[s]!=o[s])return i[s]>o[s]^n?1:-1;return u==c?0:c<u^n?1:-1}function j(e,r,n,t){if(e<r||n<e||e!==(e<0?B(e):U(e)))throw Error(x+(t||"Argument")+("number"==typeof e?e<r||n<e?" out of range: ":" not an integer: ":" not a primitive number: ")+e)}function H(e){return"[object Array]"==Object.prototype.toString.call(e)}function V(e){var r=e.c.length-1;return q(e.e/C)==r&&e.c[r]%2!=0}function W(e,r){return(1<e.length?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function X(e,r,n){var t,i;if(r<0){for(i=n+".";++r;i+=n);e=i+e}else if(++r>(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else r<t&&(e=e.slice(0,r)+"."+e.slice(r));return e}(r=function e(r){var v,a,h,n,c,s,f,u,l,g,t=_.prototype={constructor:_,toString:null,valueOf:null},w=new _(1),O=20,N=4,p=-7,i=21,d=-1e7,m=1e7,y=!1,o=1,E=0,b={decimalSeparator:".",groupSeparator:",",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:" ",fractionGroupSize:0},A="0123456789abcdefghijklmnopqrstuvwxyz";function _(e,r){var n,t,i,o,s,f,u,c,l=this;if(!(l instanceof _))return new _(e,r);if(null==r){if(e instanceof _)return l.s=e.s,l.e=e.e,void(l.c=(e=e.c)?e.slice():e);if((f="number"==typeof e)&&0*e==0){if(l.s=1/e<0?(e=-e,-1):1,e===~~e){for(o=0,s=e;10<=s;s/=10,o++);return l.e=o,void(l.c=[e])}c=e+""}else{if(!L.test(c=e+""))return h(l,c,f);l.s=45==c.charCodeAt(0)?(c=c.slice(1),-1):1}-1<(o=c.indexOf("."))&&(c=c.replace(".","")),0<(s=c.search(/e/i))?(o<0&&(o=s),o+=+c.slice(s+1),c=c.substring(0,s)):o<0&&(o=c.length)}else{if(j(r,2,A.length,"Base"),c=e+"",10==r)return D(l=new _(e instanceof _?e:c),O+l.e+1,N);if(f="number"==typeof e){if(0*e!=0)return h(l,c,f,r);if(l.s=1/e<0?(c=c.slice(1),-1):1,_.DEBUG&&15<c.replace(/^0\.0*|\./,"").length)throw Error(I+e);f=!1}else l.s=45===c.charCodeAt(0)?(c=c.slice(1),-1):1;for(n=A.slice(0,r),o=s=0,u=c.length;s<u;s++)if(n.indexOf(t=c.charAt(s))<0){if("."==t){if(o<s){o=u;continue}}else if(!i&&(c==c.toUpperCase()&&(c=c.toLowerCase())||c==c.toLowerCase()&&(c=c.toUpperCase()))){i=!0,s=-1,o=0;continue}return h(l,e+"",f,r)}-1<(o=(c=a(c,r,10,l.s)).indexOf("."))?c=c.replace(".",""):o=c.length}for(s=0;48===c.charCodeAt(s);s++);for(u=c.length;48===c.charCodeAt(--u););if(c=c.slice(s,++u)){if(u-=s,f&&_.DEBUG&&15<u&&(M<e||e!==U(e)))throw Error(I+l.s*e);if(m<(o=o-s-1))l.c=l.e=null;else if(o<d)l.c=[l.e=0];else{if(l.e=o,l.c=[],s=(o+1)%C,o<0&&(s+=C),s<u){for(s&&l.c.push(+c.slice(0,s)),u-=C;s<u;)l.c.push(+c.slice(s,s+=C));c=c.slice(s),s=C-c.length}else s-=u;for(;s--;c+="0");l.c.push(+c)}}else l.c=[l.e=0]}function R(e,r,n,t){var i,o,s,f,u;if(null==n?n=N:j(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==r)u=$(e.c),u=1==t||2==t&&s<=p?W(u,s):X(u,s,"0");else if(o=(e=D(new _(e),r,n)).e,f=(u=$(e.c)).length,1==t||2==t&&(r<=o||o<=p)){for(;f<r;u+="0",f++);u=W(u,o)}else if(r-=s,u=X(u,o,"0"),f<o+1){if(0<--r)for(u+=".";r--;u+="0");}else if(0<(r+=o-f))for(o+1==f&&(u+=".");r--;u+="0");return e.s<0&&i?"-"+u:u}function S(e,r){var n,t,i=0;for(H(e[0])&&(e=e[0]),n=new _(e[0]);++i<e.length;){if(!(t=new _(e[i])).s){n=t;break}r.call(n,t)&&(n=t)}return n}function P(e,r,n){for(var t=1,i=r.length;!r[--i];r.pop());for(i=r[0];10<=i;i/=10,t++);return(n=t+n*C-1)>m?e.c=e.e=null:e.c=n<d?[e.e=0]:(e.e=n,r),e}function D(e,r,n,t){var i,o,s,f,u,c,l,a=e.c,h=G;if(a){e:{for(i=1,f=a[0];10<=f;f/=10,i++);if((o=r-i)<0)o+=C,s=r,l=(u=a[c=0])/h[i-s-1]%10|0;else if((c=B((o+1)/C))>=a.length){if(!t)break e;for(;a.length<=c;a.push(0));u=l=0,s=(o%=C)-C+(i=1)}else{for(u=f=a[c],i=1;10<=f;f/=10,i++);l=(s=(o%=C)-C+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[c+1]||(s<0?u:u%h[i-s-1]),t=n<4?(l||t)&&(0==n||n==(e.s<0?3:2)):5<l||5==l&&(4==n||t||6==n&&(0<o?0<s?u/h[i-s]:0:a[c-1])%10&1||n==(e.s<0?8:7)),r<1||!a[0])return a.length=0,t?(r-=e.e+1,a[0]=h[(C-r%C)%C],e.e=-r||0):a[0]=e.e=0,e;if(0==o?(a.length=c,f=1,c--):(a.length=c+1,f=h[C-o],a[c]=0<s?U(u/h[i-s]%h[s])*f:0),t)for(;;){if(0==c){for(o=1,s=a[0];10<=s;s/=10,o++);for(s=a[0]+=f,f=1;10<=s;s/=10,f++);o!=f&&(e.e++,a[0]==T&&(a[0]=1));break}if(a[c]+=f,a[c]!=T)break;a[c--]=0,f=1}for(o=a.length;0===a[--o];a.pop());}e.e>m?e.c=e.e=null:e.e<d&&(e.c=[e.e=0])}return e}return _.clone=e,_.ROUND_UP=0,_.ROUND_DOWN=1,_.ROUND_CEIL=2,_.ROUND_FLOOR=3,_.ROUND_HALF_UP=4,_.ROUND_HALF_DOWN=5,_.ROUND_HALF_EVEN=6,_.ROUND_HALF_CEIL=7,_.ROUND_HALF_FLOOR=8,_.EUCLID=9,_.config=_.set=function(e){var r,n;if(null!=e){if("object"!=typeof e)throw Error(x+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(j(n=e[r],0,k,r),O=n),e.hasOwnProperty(r="ROUNDING_MODE")&&(j(n=e[r],0,8,r),N=n),e.hasOwnProperty(r="EXPONENTIAL_AT")&&(H(n=e[r])?(j(n[0],-k,0,r),j(n[1],0,k,r),p=n[0],i=n[1]):(j(n,-k,k,r),p=-(i=n<0?-n:n))),e.hasOwnProperty(r="RANGE"))if(H(n=e[r]))j(n[0],-k,-1,r),j(n[1],1,k,r),d=n[0],m=n[1];else{if(j(n,-k,k,r),!n)throw Error(x+r+" cannot be zero: "+n);d=-(m=n<0?-n:n)}if(e.hasOwnProperty(r="CRYPTO")){if((n=e[r])!==!!n)throw Error(x+r+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw y=!n,Error(x+"crypto unavailable");y=n}else y=n}if(e.hasOwnProperty(r="MODULO_MODE")&&(j(n=e[r],0,9,r),o=n),e.hasOwnProperty(r="POW_PRECISION")&&(j(n=e[r],0,k,r),E=n),e.hasOwnProperty(r="FORMAT")){if("object"!=typeof(n=e[r]))throw Error(x+r+" not an object: "+n);b=n}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(n=e[r])||/^.$|\./.test(n)||function(e){for(var r=0;r<e.length;r++)if(0<=e.slice(r+1).indexOf(e.charAt(r)))return!0;return!1}(n))throw Error(x+r+" invalid: "+n);A=n}}return{DECIMAL_PLACES:O,ROUNDING_MODE:N,EXPONENTIAL_AT:[p,i],RANGE:[d,m],CRYPTO:y,MODULO_MODE:o,POW_PRECISION:E,FORMAT:b,ALPHABET:A}},_.isBigNumber=function(e){return e instanceof _||e&&!0===e._isBigNumber||!1},_.maximum=_.max=function(){return S(arguments,t.lt)},_.minimum=_.min=function(){return S(arguments,t.gt)},_.random=(n=9007199254740992,c=Math.random()*n&2097151?function(){return U(Math.random()*n)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,n,t,i,o,s=0,f=[],u=new _(w);if(null==e?e=O:j(e,0,k),i=B(e/C),y)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));s<i;)9e15<=(o=131072*r[s]+(r[s+1]>>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw y=!1,Error(x+"crypto unavailable");for(r=crypto.randomBytes(i*=7);s<i;)9e15<=(o=281474976710656*(31&r[s])+1099511627776*r[s+1]+4294967296*r[s+2]+16777216*r[s+3]+(r[s+4]<<16)+(r[s+5]<<8)+r[s+6])?crypto.randomBytes(7).copy(r,s):(f.push(o%1e14),s+=7);s=i/7}if(!y)for(;s<i;)(o=c())<9e15&&(f[s++]=o%1e14);for(i=f[--s],e%=C,i&&e&&(o=G[C-e],f[s]=U(i/o)*o);0===f[s];f.pop(),s--);if(s<0)f=[t=0];else{for(t=-1;0===f[0];f.splice(0,1),t-=C);for(s=1,o=f[0];10<=o;o/=10,s++);s<C&&(t-=C-s)}return u.e=t,u.c=f,u}),a=function(){var d="0123456789";function m(e,r,n,t){for(var i,o,s=[0],f=0,u=e.length;f<u;){for(o=s.length;o--;s[o]*=r);for(s[0]+=t.indexOf(e.charAt(f++)),i=0;i<s.length;i++)s[i]>n-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,c,l,a,h,g=e.indexOf("."),p=O,w=N;for(0<=g&&(u=E,E=0,e=e.replace(".",""),l=(h=new _(r)).pow(e.length-g),E=u,h.c=m(X($(l.c),l.e,"0"),10,n,d),h.e=h.c.length),f=u=(a=m(e,r,n,i?(o=A,d):(o=d,A))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(g<0?--f:(l.c=a,l.e=f,l.s=t,a=(l=v(l,h,p,w,n)).c,c=l.r,f=l.e),g=a[s=f+p+1],u=n/2,c=c||s<0||null!=a[s+1],c=w<4?(null!=g||c)&&(0==w||w==(l.s<0?3:2)):u<g||g==u&&(4==w||c||6==w&&1&a[s-1]||w==(l.s<0?8:7)),s<1||!a[0])e=c?X(o.charAt(1),-p,o.charAt(0)):o.charAt(0);else{if(a.length=s,c)for(--n;++a[--s]>n;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(g=0,e="";g<=u;e+=o.charAt(a[g++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function R(e,r,n){var t,i,o,s,f=0,u=e.length,c=r%F,l=r/F|0;for(e=e.slice();u--;)f=((i=c*(o=e[u]%F)+(t=l*o+(s=e[u]/F|0)*c)%F*F+f)/n|0)+(t/F|0)+l*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function S(e,r,n,t){var i,o;if(n!=t)o=t<n?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function P(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n]<r[n]?1:0,e[n]=i*t+e[n]-r[n];for(;!e[0]&&1<e.length;e.splice(0,1));}return function(e,r,n,t,i){var o,s,f,u,c,l,a,h,g,p,w,d,m,v,O,N,y,E=e.s==r.s?1:-1,b=e.c,A=r.c;if(!(b&&b[0]&&A&&A[0]))return new _(e.s&&r.s&&(b?!A||b[0]!=A[0]:A)?b&&0==b[0]||!A?0*E:E/0:NaN);for(g=(h=new _(E)).c=[],E=n+(s=e.e-r.e)+1,i||(i=T,s=q(e.e/C)-q(r.e/C),E=E/C|0),f=0;A[f]==(b[f]||0);f++);if(A[f]>(b[f]||0)&&s--,E<0)g.push(1),u=!0;else{for(v=b.length,N=A.length,E+=2,1<(c=U(i/(A[f=0]+1)))&&(A=R(A,c,i),b=R(b,c,i),N=A.length,v=b.length),m=N,w=(p=b.slice(0,N)).length;w<N;p[w++]=0);y=A.slice(),y=[0].concat(y),O=A[0],A[1]>=i/2&&O++;do{if(c=0,(o=S(A,p,N,w))<0){if(d=p[0],N!=w&&(d=d*i+(p[1]||0)),1<(c=U(d/O)))for(i<=c&&(c=i-1),a=(l=R(A,c,i)).length,w=p.length;1==S(l,p,a,w);)c--,P(l,N<a?y:A,a,i),a=l.length,o=1;else 0==c&&(o=c=1),a=(l=A.slice()).length;if(a<w&&(l=[0].concat(l)),P(p,l,w,i),w=p.length,-1==o)for(;S(A,p,N,w)<1;)c++,P(p,N<w?y:A,w,i),w=p.length}else 0===o&&(c++,p=[0]);g[f++]=c,p[0]?p[w++]=b[m]||0:(p=[b[m]],w=1)}while((m++<v||null!=p[0])&&E--);u=null!=p[0],g[0]||g.splice(0,1)}if(i==T){for(f=1,E=g[0];10<=E;E/=10,f++);D(h,n+(h.e=f+s*C-1)+1,t,u)}else h.e=s,h.r=+u;return h}}(),s=/^(-?)0([xbo])(\w[\w.]*$)/i,f=/^([^.]+)\.$/,u=/^\.([^.]+)$/,l=/^-?(Infinity|NaN)$/,g=/^\s*\+([\w.])|^\s+|\s+$/g,h=function(e,r,n,i){var o,t=n?r:r.replace(g,"$1");if(l.test(t))e.s=isNaN(t)?null:t<0?-1:1,e.c=e.e=null;else{if(!n&&(t=t.replace(s,function(e,r,n,t){return o="x"==(n=n.toLowerCase())?16:"b"==n?2:8,i&&i!=o?e:r+t}),i&&(o=i,t=t.replace(f,"$1").replace(u,"0.$1")),r!=t))return new _(t,o);if(_.DEBUG)throw Error(x+"Not a"+(i?" base "+i:"")+" number: "+r);e.c=e.e=e.s=null}},t.absoluteValue=t.abs=function(){var e=new _(this);return e.s<0&&(e.s=1),e},t.comparedTo=function(e,r){return z(this,new _(e,r))},t.decimalPlaces=t.dp=function(e,r){var n,t,i;if(null!=e)return j(e,0,k),null==r?r=N:j(r,0,8),D(new _(this),e+this.e+1,r);if(!(n=this.c))return null;if(t=((i=n.length-1)-q(this.e/C))*C,i=n[i])for(;i%10==0;i/=10,t--);return t<0&&(t=0),t},t.dividedBy=t.div=function(e,r){return v(this,new _(e,r),O,N)},t.dividedToIntegerBy=t.idiv=function(e,r){return v(this,new _(e,r),0,1)},t.exponentiatedBy=t.pow=function(e,r){var n,t,i,o,s,f,u,c=this;if((e=new _(e)).c&&!e.isInteger())throw Error(x+"Exponent not an integer: "+e);if(null!=r&&(r=new _(r)),o=14<e.e,!c.c||!c.c[0]||1==c.c[0]&&!c.e&&1==c.c.length||!e.c||!e.c[0])return u=new _(Math.pow(+c.valueOf(),o?2-V(e):+e)),r?u.mod(r):u;if(s=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new _(NaN);(t=!s&&c.isInteger()&&r.isInteger())&&(c=c.mod(r))}else{if(9<e.e&&(0<c.e||c.e<-1||(0==c.e?1<c.c[0]||o&&24e7<=c.c[1]:c.c[0]<8e13||o&&c.c[0]<=9999975e7)))return i=c.s<0&&V(e)?-0:0,-1<c.e&&(i=1/i),new _(s?1/i:i);E&&(i=B(E/C+2))}for(f=o?(n=new _(.5),V(e)):e%2,s&&(e.s=1),u=new _(w);;){if(f){if(!(u=u.times(c)).c)break;i?u.c.length>i&&(u.c.length=i):t&&(u=u.mod(r))}if(o){if(D(e=e.times(n),e.e+1,1),!e.c[0])break;o=14<e.e,f=V(e)}else{if(!(e=U(e/2)))break;f=e%2}c=c.times(c),i?c.c&&c.c.length>i&&(c.c.length=i):t&&(c=c.mod(r))}return t?u:(s&&(u=w.div(u)),r?u.mod(r):i?D(u,E,N,void 0):u)},t.integerValue=function(e){var r=new _(this);return null==e?e=N:j(e,0,8),D(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new _(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0<z(this,new _(e,r))},t.isGreaterThanOrEqualTo=t.gte=function(e,r){return 1===(r=z(this,new _(e,r)))||0===r},t.isInteger=function(){return!!this.c&&q(this.e/C)>this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new _(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new _(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0<this.s},t.isZero=function(){return!!this.c&&0==this.c[0]},t.minus=function(e,r){var n,t,i,o,s=this,f=s.s;if(r=(e=new _(e,r)).s,!f||!r)return new _(NaN);if(f!=r)return e.s=-r,s.plus(e);var u=s.e/C,c=e.e/C,l=s.c,a=e.c;if(!u||!c){if(!l||!a)return l?(e.s=-r,e):new _(a?s:NaN);if(!l[0]||!a[0])return a[0]?(e.s=-r,e):new _(l[0]?s:3==N?-0:0)}if(u=q(u),c=q(c),l=l.slice(),f=u-c){for((i=(o=f<0)?(f=-f,l):(c=u,a)).reverse(),r=f;r--;i.push(0));i.reverse()}else for(t=(o=(f=l.length)<(r=a.length))?f:r,f=r=0;r<t;r++)if(l[r]!=a[r]){o=l[r]<a[r];break}if(o&&(i=l,l=a,a=i,e.s=-e.s),0<(r=(t=a.length)-(n=l.length)))for(;r--;l[n++]=0);for(r=T-1;f<t;){if(l[--t]<a[t]){for(n=t;n&&!l[--n];l[n]=r);--l[n],l[t]+=T}l[t]-=a[t]}for(;0==l[0];l.splice(0,1),--c);return l[0]?P(e,l,c):(e.s=3==N?-1:1,e.c=[e.e=0],e)},t.modulo=t.mod=function(e,r){var n,t,i=this;return e=new _(e,r),!i.c||!e.s||e.c&&!e.c[0]?new _(NaN):!e.c||i.c&&!i.c[0]?new _(i):(9==o?(t=e.s,e.s=1,n=v(i,e,0,3),e.s=t,n.s*=t):n=v(i,e,0,o),(e=i.minus(n.times(e))).c[0]||1!=o||(e.s=i.s),e)},t.multipliedBy=t.times=function(e,r){var n,t,i,o,s,f,u,c,l,a,h,g,p,w,d,m=this,v=m.c,O=(e=new _(e,r)).c;if(!(v&&O&&v[0]&&O[0]))return!m.s||!e.s||v&&!v[0]&&!O||O&&!O[0]&&!v?e.c=e.e=e.s=null:(e.s*=m.s,v&&O?(e.c=[0],e.e=0):e.c=e.e=null),e;for(t=q(m.e/C)+q(e.e/C),e.s*=m.s,(u=v.length)<(a=O.length)&&(p=v,v=O,O=p,i=u,u=a,a=i),i=u+a,p=[];i--;p.push(0));for(w=T,d=F,i=a;0<=--i;){for(n=0,h=O[i]%d,g=O[i]/d|0,o=i+(s=u);i<o;)n=((c=h*(c=v[--s]%d)+(f=g*c+(l=v[s]/d|0)*h)%d*d+p[o]+n)/w|0)+(f/d|0)+g*l,p[o--]=c%w;p[o]=n}return n?++t:p.splice(0,1),P(e,p,t)},t.negated=function(){var e=new _(this);return e.s=-e.s||null,e},t.plus=function(e,r){var n,t=this,i=t.s;if(r=(e=new _(e,r)).s,!i||!r)return new _(NaN);if(i!=r)return e.s=-r,t.minus(e);var o=t.e/C,s=e.e/C,f=t.c,u=e.c;if(!o||!s){if(!f||!u)return new _(i/0);if(!f[0]||!u[0])return u[0]?e:new _(f[0]?t:0*i)}if(o=q(o),s=q(s),f=f.slice(),i=o-s){for((n=0<i?(s=o,u):(i=-i,f)).reverse();i--;n.push(0));n.reverse()}for((i=f.length)-(r=u.length)<0&&(n=u,u=f,f=n,r=i),i=0;r;)i=(f[--r]=f[r]+u[r]+i)/T|0,f[r]=T===f[r]?0:f[r]%T;return i&&(f=[i].concat(f),++s),P(e,f,s)},t.precision=t.sd=function(e,r){var n,t,i;if(null!=e&&e!==!!e)return j(e,1,k),null==r?r=N:j(r,0,8),D(new _(this),e,r);if(!(n=this.c))return null;if(t=(i=n.length-1)*C+1,i=n[i]){for(;i%10==0;i/=10,t--);for(i=n[0];10<=i;i/=10,t++);}return e&&this.e+1>t&&(t=this.e+1),t},t.shiftedBy=function(e){return j(e,-M,M),this.times("1e"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,c=O+4,l=new _("0.5");if(1!==f||!s||!s[0])return new _(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+o))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+="0"),f=Math.sqrt(r),u=q((u+1)/2)-(u<0||u%2),new _(r=f==1/0?"1e"+u:(r=f.toExponential()).slice(0,r.indexOf("e")+1)+u)):new _(f+"")).c[0])for((f=(u=n.e)+c)<3&&(f=0);;)if(i=n,n=l.times(i.plus(v(o,i,c,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.e<u&&--f,"9999"!=(r=r.slice(f-3,f+1))&&(t||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(D(n,n.e+O+2,1),e=!n.times(n).eq(o));break}if(!t&&(D(i,i.e+O+2,0),i.times(i).eq(o))){n=i;break}c+=4,f+=4,t=1}return D(n,n.e+O+1,N,e)},t.toExponential=function(e,r){return null!=e&&(j(e,0,k),e++),R(this,e,r,1)},t.toFixed=function(e,r){return null!=e&&(j(e,0,k),e=e+this.e+1),R(this,e,r)},t.toFormat=function(e,r){var n=this.toFixed(e,r);if(this.c){var t,i=n.split("."),o=+b.groupSize,s=+b.secondaryGroupSize,f=b.groupSeparator,u=i[0],c=i[1],l=this.s<0,a=l?u.slice(1):u,h=a.length;if(s&&(t=o,o=s,h-=s=t),0<o&&0<h){for(t=h%o||o,u=a.substr(0,t);t<h;t+=o)u+=f+a.substr(t,o);0<s&&(u+=f+a.slice(t)),l&&(u="-"+u)}n=c?u+b.decimalSeparator+((s=+b.fractionGroupSize)?c.replace(new RegExp("\\d{"+s+"}\\B","g"),"$&"+b.fractionGroupSeparator):c):u}return n},t.toFraction=function(e){var r,n,t,i,o,s,f,u,c,l,a,h,g=this,p=g.c;if(null!=e&&(!(u=new _(e)).isInteger()&&(u.c||1!==u.s)||u.lt(w)))throw Error(x+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+e);if(!p)return g.toString();for(n=new _(w),l=t=new _(w),i=c=new _(w),h=$(p),s=n.e=h.length-g.e-1,n.c[0]=G[(f=s%C)<0?C+f:f],e=!e||0<u.comparedTo(n)?0<s?n:l:u,f=m,m=1/0,u=new _(h),c.c[0]=0;a=v(u,n,0,1),1!=(o=t.plus(a.times(i))).comparedTo(e);)t=i,i=o,l=c.plus(a.times(o=l)),c=o,n=u.minus(a.times(o=n)),u=o;return o=v(e.minus(t),i,0,1),c=c.plus(o.times(l)),t=t.plus(o.times(i)),c.s=l.s=g.s,r=v(l,i,s*=2,N).minus(g).abs().comparedTo(v(c,t,s,N).minus(g).abs())<1?[l.toString(),i.toString()]:[c.toString(),t.toString()],m=f,r},t.toNumber=function(){return+this},t.toPrecision=function(e,r){return null!=e&&j(e,1,k),R(this,e,r,2)},t.toString=function(e){var r,n=this.s,t=this.e;return null===t?n?(r="Infinity",n<0&&(r="-"+r)):r="NaN":(r=$(this.c),r=null==e?t<=p||i<=t?W(r,t):X(r,t,"0"):(j(e,2,A.length,"Base"),a(X(r,t,"0"),10,e,n,!0)),n<0&&this.c[0]&&(r="-"+r)),r},t.valueOf=t.toJSON=function(){var e,r=this.e;return null===r?this.toString():(e=$(this.c),e=r<=p||i<=r?W(e,r):X(e,r,"0"),this.s<0?"-"+e:e)},t._isBigNumber=!0,null!=r&&_.set(r),_}()).default=r.BigNumber=r,"function"==typeof define&&define.amd?define(function(){return r}):"undefined"!=typeof module&&module.exports?module.exports=r:(e||(e="undefined"!=typeof self&&self?self:window),e.BigNumber=r)}(this);