forked from frozeman/bignumber.js-nolookahead
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbignumber.min.js
1 lines (1 loc) · 16.7 KB
/
bignumber.min.js
1
!function(e){"use strict";var n,C,M,T=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,B=Math.ceil,q=Math.floor,P=" not a boolean or binary digit",k="rounding mode",$="number type has more than 15 significant digits",G="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_",z=1e14,j=14,o=9007199254740991,H=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],V=1e7,W=1e9;function J(e){var n=0|e;return 0<e||e===n?n:n-1}function X(e){for(var n,t,r=1,i=e.length,o=e[0]+"";r<i;){for(n=e[r++]+"",t=j-n.length;t--;n="0"+n);o+=n}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function Y(e,n){var t,r,i=e.c,o=n.c,s=e.s,u=n.s,f=e.e,l=n.e;if(!s||!u)return null;if(t=i&&!i[0],r=o&&!o[0],t||r)return t?r?0:-u:s;if(s!=u)return s;if(t=s<0,r=f==l,!i||!o)return r?0:!i^t?1:-1;if(!r)return l<f^t?1:-1;for(u=(f=i.length)<(l=o.length)?f:l,s=0;s<u;s++)if(i[s]!=o[s])return i[s]>o[s]^t?1:-1;return f==l?0:l<f^t?1:-1}function Z(e,n,t){return(e=te(e))>=n&&e<=t}function K(e){return"[object Array]"==Object.prototype.toString.call(e)}function Q(e,n,t){for(var r,i,o=[0],s=0,u=e.length;s<u;){for(i=o.length;i--;o[i]*=n);for(o[r=0]+=G.indexOf(e.charAt(s++));r<o.length;r++)o[r]>t-1&&(null==o[r+1]&&(o[r+1]=0),o[r+1]+=o[r]/t|0,o[r]%=t)}return o.reverse()}function ee(e,n){return(1<e.length?e.charAt(0)+"."+e.slice(1):e)+(n<0?"e":"e+")+n}function ne(e,n){var t,r;if(n<0){for(r="0.";++n;r+="0");e=r+e}else if(++n>(t=e.length)){for(r="0",n-=t;--n;r+="0");e+=r}else n<t&&(e=e.slice(0,n)+"."+e.slice(n));return e}function te(e){return(e=parseFloat(e))<0?B(e):q(e)}if(n=function e(n){var d,t,l,s,u,f,c,a,b=0,r=D.prototype,w=new D(1),p=20,v=4,h=-7,g=21,m=-1e7,N=1e7,O=!0,y=F,S=!1,R=1,A=100,E={decimalSeparator:".",groupSeparator:",",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:" ",fractionGroupSize:0};function D(e,n){var t,r,i,o,s,u,f=this;if(!(f instanceof D))return O&&L(26,"constructor call without new",e),new D(e,n);if(null!=n&&y(n,2,64,b,"base")){if(u=e+"",10==(n|=0))return U(f=new D(e instanceof D?e:u),p+f.e+1,v);if((o="number"==typeof e)&&0*e!=0||!new RegExp("^-?"+(t="["+G.slice(0,n)+"]+")+"(?:\\."+t+")?$",n<37?"i":"").test(u))return M(f,u,o,n);o?(f.s=1/e<0?(u=u.slice(1),-1):1,O&&15<u.replace(/^0\.0*|\./,"").length&&L(b,$,e),o=!1):f.s=45===u.charCodeAt(0)?(u=u.slice(1),-1):1,u=_(u,10,n,f.s)}else{if(e instanceof D)return f.s=e.s,f.e=e.e,f.c=(e=e.c)?e.slice():e,void(b=0);if((o="number"==typeof e)&&0*e==0){if(f.s=1/e<0?(e=-e,-1):1,e===~~e){for(r=0,i=e;10<=i;i/=10,r++);return f.e=r,f.c=[e],void(b=0)}u=e+""}else{if(!T.test(u=e+""))return M(f,u,o);f.s=45===u.charCodeAt(0)?(u=u.slice(1),-1):1}}for(-1<(r=u.indexOf("."))&&(u=u.replace(".","")),0<(i=u.search(/e/i))?(r<0&&(r=i),r+=+u.slice(i+1),u=u.substring(0,i)):r<0&&(r=u.length),i=0;48===u.charCodeAt(i);i++);for(s=u.length;48===u.charCodeAt(--s););if(u=u.slice(i,s+1))if(s=u.length,o&&O&&15<s&&L(b,$,f.s*e),N<(r=r-i-1))f.c=f.e=null;else if(r<m)f.c=[f.e=0];else{if(f.e=r,f.c=[],i=(r+1)%j,r<0&&(i+=j),i<s){for(i&&f.c.push(+u.slice(0,i)),s-=j;i<s;)f.c.push(+u.slice(i,i+=j));u=u.slice(i),i=j-u.length}else i-=s;for(;i--;u+="0");f.c.push(+u)}else f.c=[f.e=0];b=0}function _(e,n,t,r){var i,o,s,u,f,l,c,a=e.indexOf("."),h=p,g=v;for(t<37&&(e=e.toLowerCase()),0<=a&&(s=A,A=0,e=e.replace(".",""),f=(c=new D(t)).pow(e.length-a),A=s,c.c=Q(ne(X(f.c),f.e),10,n),c.e=c.c.length),o=s=(l=Q(e,t,n)).length;0==l[--s];l.pop());if(!l[0])return"0";if(a<0?--o:(f.c=l,f.e=o,f.s=r,l=(f=d(f,c,h,g,n)).c,u=f.r,o=f.e),a=l[i=o+h+1],s=n/2,u=u||i<0||null!=l[i+1],u=g<4?(null!=a||u)&&(0==g||g==(f.s<0?3:2)):s<a||a==s&&(4==g||u||6==g&&1&l[i-1]||g==(f.s<0?8:7)),i<1||!l[0])e=u?ne("1",-h):"0";else{if(l.length=i,u)for(--n;++l[--i]>n;)l[i]=0,i||(++o,l.unshift(1));for(s=l.length;!l[--s];);for(a=0,e="";a<=s;e+=G.charAt(l[a++]));e=ne(e,o)}return e}function x(e,n,t,r){var i,o,s,u,f;if(t=null!=t&&y(t,0,8,r,k)?0|t:v,!e.c)return e.toString();if(i=e.c[0],s=e.e,null==n)f=X(e.c),f=19==r||24==r&&s<=h?ee(f,s):ne(f,s);else if(o=(e=U(new D(e),n,t)).e,u=(f=X(e.c)).length,19==r||24==r&&(n<=o||o<=h)){for(;u<n;f+="0",u++);f=ee(f,o)}else if(n-=s,f=ne(f,o),u<o+1){if(0<--n)for(f+=".";n--;f+="0");}else if(0<(n+=o-u))for(o+1==u&&(f+=".");n--;f+="0");return e.s<0&&i?"-"+f:f}function i(e,n){var t,r,i=0;for(K(e[0])&&(e=e[0]),t=new D(e[0]);++i<e.length;){if(!(r=new D(e[i])).s){t=r;break}n.call(t,r)&&(t=r)}return t}function F(e,n,t,r,i){return(e<n||t<e||e!=te(e))&&L(r,(i||"decimal places")+(e<n||t<e?" out of range":" not an integer"),e),!0}function I(e,n,t){for(var r=1,i=n.length;!n[--i];n.pop());for(i=n[0];10<=i;i/=10,r++);return(t=r+t*j-1)>N?e.c=e.e=null:t<m?e.c=[e.e=0]:(e.e=t,e.c=n),e}function L(e,n,t){var r=new Error(["new BigNumber","cmp","config","div","divToInt","eq","gt","gte","lt","lte","minus","mod","plus","precision","random","round","shift","times","toDigits","toExponential","toFixed","toFormat","toFraction","pow","toPrecision","toString","BigNumber"][e]+"() "+n+": "+t);throw r.name="BigNumber Error",b=0,r}function U(e,n,t,r){var i,o,s,u,f,l,c,a=e.c,h=H;if(a){e:{for(i=1,u=a[0];10<=u;u/=10,i++);if((o=n-i)<0)o+=j,s=n,c=(f=a[l=0])/h[i-s-1]%10|0;else if((l=B((o+1)/j))>=a.length){if(!r)break e;for(;a.length<=l;a.push(0));f=c=0,s=(o%=j)-j+(i=1)}else{for(f=u=a[l],i=1;10<=u;u/=10,i++);c=(s=(o%=j)-j+i)<0?0:f/h[i-s-1]%10|0}if(r=r||n<0||null!=a[l+1]||(s<0?f:f%h[i-s-1]),r=t<4?(c||r)&&(0==t||t==(e.s<0?3:2)):5<c||5==c&&(4==t||r||6==t&&(0<o?0<s?f/h[i-s]:0:a[l-1])%10&1||t==(e.s<0?8:7)),n<1||!a[0])return a.length=0,r?(n-=e.e+1,a[0]=h[n%j],e.e=-n||0):a[0]=e.e=0,e;if(0==o?(a.length=l,u=1,l--):(a.length=l+1,u=h[j-o],a[l]=0<s?q(f/h[i-s]%h[s])*u:0),r)for(;;){if(0==l){for(o=1,s=a[0];10<=s;s/=10,o++);for(s=a[0]+=u,u=1;10<=s;s/=10,u++);o!=u&&(e.e++,a[0]==z&&(a[0]=1));break}if(a[l]+=u,a[l]!=z)break;a[l--]=0,u=1}for(o=a.length;0===a[--o];a.pop());}e.e>N?e.c=e.e=null:e.e<m&&(e.c=[e.e=0])}return e}return D.another=e,D.ROUND_UP=0,D.ROUND_DOWN=1,D.ROUND_CEIL=2,D.ROUND_FLOOR=3,D.ROUND_HALF_UP=4,D.ROUND_HALF_DOWN=5,D.ROUND_HALF_EVEN=6,D.ROUND_HALF_CEIL=7,D.ROUND_HALF_FLOOR=8,D.EUCLID=9,D.config=function(){var e,n,t=0,r={},i=arguments,o=i[0],s=o&&"object"==typeof o?function(){if(o.hasOwnProperty(n))return null!=(e=o[n])}:function(){if(i.length>t)return null!=(e=i[t++])};return s(n="DECIMAL_PLACES")&&y(e,0,W,2,n)&&(p=0|e),r[n]=p,s(n="ROUNDING_MODE")&&y(e,0,8,2,n)&&(v=0|e),r[n]=v,s(n="EXPONENTIAL_AT")&&(K(e)?y(e[0],-W,0,2,n)&&y(e[1],0,W,2,n)&&(h=0|e[0],g=0|e[1]):y(e,-W,W,2,n)&&(h=-(g=0|(e<0?-e:e)))),r[n]=[h,g],s(n="RANGE")&&(K(e)?y(e[0],-W,-1,2,n)&&y(e[1],1,W,2,n)&&(m=0|e[0],N=0|e[1]):y(e,-W,W,2,n)&&(0|e?m=-(N=0|(e<0?-e:e)):O&&L(2,n+" cannot be zero",e))),r[n]=[m,N],s(n="ERRORS")&&(e===!!e||1===e||0===e?(b=0,y=(O=!!e)?F:Z):O&&L(2,n+P,e)),r[n]=O,s(n="CRYPTO")&&(e===!!e||1===e||0===e?(S=!(!e||!C||"object"!=typeof C),e&&!S&&O&&L(2,"crypto unavailable",C)):O&&L(2,n+P,e)),r[n]=S,s(n="MODULO_MODE")&&y(e,0,9,2,n)&&(R=0|e),r[n]=R,s(n="POW_PRECISION")&&y(e,0,W,2,n)&&(A=0|e),r[n]=A,s(n="FORMAT")&&("object"==typeof e?E=e:O&&L(2,n+" not an object",e)),r[n]=E,r},D.isBigNumber=function(e){return e instanceof D||e&&!0===e._isBigNumber||!1},D.max=function(){return i(arguments,r.lt)},D.min=function(){return i(arguments,r.gt)},D.random=(t=9007199254740992,l=Math.random()*t&2097151?function(){return q(Math.random()*t)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var n,t,r,i,o,s=0,u=[],f=new D(w);if(e=null!=e&&y(e,0,W,14)?0|e:p,i=B(e/j),S)if(C&&C.getRandomValues){for(n=C.getRandomValues(new Uint32Array(i*=2));s<i;)9e15<=(o=131072*n[s]+(n[s+1]>>>11))?(t=C.getRandomValues(new Uint32Array(2)),n[s]=t[0],n[s+1]=t[1]):(u.push(o%1e14),s+=2);s=i/2}else if(C&&C.randomBytes){for(n=C.randomBytes(i*=7);s<i;)9e15<=(o=281474976710656*(31&n[s])+1099511627776*n[s+1]+4294967296*n[s+2]+16777216*n[s+3]+(n[s+4]<<16)+(n[s+5]<<8)+n[s+6])?C.randomBytes(7).copy(n,s):(u.push(o%1e14),s+=7);s=i/7}else O&&L(14,"crypto unavailable",C);if(!s)for(;s<i;)(o=l())<9e15&&(u[s++]=o%1e14);for(i=u[--s],e%=j,i&&e&&(o=H[j-e],u[s]=q(i/o)*o);0===u[s];u.pop(),s--);if(s<0)u=[r=0];else{for(r=-1;0===u[0];u.shift(),r-=j);for(s=1,o=u[0];10<=o;o/=10,s++);s<j&&(r-=j-s)}return f.e=r,f.c=u,f}),d=function(){function A(e,n,t){var r,i,o,s,u=0,f=e.length,l=n%V,c=n/V|0;for(e=e.slice();f--;)u=((i=l*(o=e[f]%V)+(r=c*o+(s=e[f]/V|0)*l)%V*V+u)/t|0)+(r/V|0)+c*s,e[f]=i%t;return u&&e.unshift(u),e}function E(e,n,t,r){var i,o;if(t!=r)o=r<t?1:-1;else for(i=o=0;i<t;i++)if(e[i]!=n[i]){o=e[i]>n[i]?1:-1;break}return o}function _(e,n,t,r){for(var i=0;t--;)e[t]-=i,i=e[t]<n[t]?1:0,e[t]=i*r+e[t]-n[t];for(;!e[0]&&1<e.length;e.shift());}return function(e,n,t,r,i){var o,s,u,f,l,c,a,h,g,p,m,d,w,v,N,b,O,y=e.s==n.s?1:-1,S=e.c,R=n.c;if(!(S&&S[0]&&R&&R[0]))return new D(e.s&&n.s&&(S?!R||S[0]!=R[0]:R)?S&&0==S[0]||!R?0*y:y/0:NaN);for(g=(h=new D(y)).c=[],y=t+(s=e.e-n.e)+1,i||(i=z,s=J(e.e/j)-J(n.e/j),y=y/j|0),u=0;R[u]==(S[u]||0);u++);if(R[u]>(S[u]||0)&&s--,y<0)g.push(1),f=!0;else{for(v=S.length,b=R.length,y+=2,1<(l=q(i/(R[u=0]+1)))&&(R=A(R,l,i),S=A(S,l,i),b=R.length,v=S.length),w=b,m=(p=S.slice(0,b)).length;m<b;p[m++]=0);(O=R.slice()).unshift(0),N=R[0],R[1]>=i/2&&N++;do{if(l=0,(o=E(R,p,b,m))<0){if(d=p[0],b!=m&&(d=d*i+(p[1]||0)),1<(l=q(d/N)))for(i<=l&&(l=i-1),a=(c=A(R,l,i)).length,m=p.length;1==E(c,p,a,m);)l--,_(c,b<a?O:R,a,i),a=c.length,o=1;else 0==l&&(o=l=1),a=(c=R.slice()).length;if(a<m&&c.unshift(0),_(p,c,m,i),m=p.length,-1==o)for(;E(R,p,b,m)<1;)l++,_(p,b<m?O:R,m,i),m=p.length}else 0===o&&(l++,p=[0]);g[u++]=l,p[0]?p[m++]=S[w]||0:(p=[S[w]],m=1)}while((w++<v||null!=p[0])&&y--);f=null!=p[0],g[0]||g.shift()}if(i==z){for(u=1,y=g[0];10<=y;y/=10,u++);U(h,t+(h.e=u+s*j-1)+1,r,f)}else h.e=s,h.r=+f;return h}}(),s=/^(-?)0([xbo])/i,u=/^([^.]+)\.$/,f=/^\.([^.]+)$/,c=/^-?(Infinity|NaN)$/,a=/^\s*\+|^\s+|\s+$/g,M=function(e,n,t,r){var i,o=t?n:n.replace(a,"");if(c.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!t&&(o=o.replace(s,function(e,n,t){return i="x"==(t=t.toLowerCase())?16:"b"==t?2:8,r&&r!=i?e:n}),r&&(i=r,o=o.replace(u,"$1").replace(f,"0.$1")),n!=o))return new D(o,i);O&&L(b,"not a"+(r?" base "+r:"")+" number",n),e.s=null}e.c=e.e=null,b=0},r.absoluteValue=r.abs=function(){var e=new D(this);return e.s<0&&(e.s=1),e},r.ceil=function(){return U(new D(this),this.e+1,2)},r.comparedTo=r.cmp=function(e,n){return b=1,Y(this,new D(e,n))},r.decimalPlaces=r.dp=function(){var e,n,t=this.c;if(!t)return null;if(e=((n=t.length-1)-J(this.e/j))*j,n=t[n])for(;n%10==0;n/=10,e--);return e<0&&(e=0),e},r.dividedBy=r.div=function(e,n){return b=3,d(this,new D(e,n),p,v)},r.dividedToIntegerBy=r.divToInt=function(e,n){return b=4,d(this,new D(e,n),0,1)},r.equals=r.eq=function(e,n){return b=5,0===Y(this,new D(e,n))},r.floor=function(){return U(new D(this),this.e+1,3)},r.greaterThan=r.gt=function(e,n){return b=6,0<Y(this,new D(e,n))},r.greaterThanOrEqualTo=r.gte=function(e,n){return b=7,1===(n=Y(this,new D(e,n)))||0===n},r.isFinite=function(){return!!this.c},r.isInteger=r.isInt=function(){return!!this.c&&J(this.e/j)>this.c.length-2},r.isNaN=function(){return!this.s},r.isNegative=r.isNeg=function(){return this.s<0},r.isZero=function(){return!!this.c&&0==this.c[0]},r.lessThan=r.lt=function(e,n){return b=8,Y(this,new D(e,n))<0},r.lessThanOrEqualTo=r.lte=function(e,n){return b=9,-1===(n=Y(this,new D(e,n)))||0===n},r.minus=r.sub=function(e,n){var t,r,i,o,s=this,u=s.s;if(b=10,n=(e=new D(e,n)).s,!u||!n)return new D(NaN);if(u!=n)return e.s=-n,s.plus(e);var f=s.e/j,l=e.e/j,c=s.c,a=e.c;if(!f||!l){if(!c||!a)return c?(e.s=-n,e):new D(a?s:NaN);if(!c[0]||!a[0])return a[0]?(e.s=-n,e):new D(c[0]?s:3==v?-0:0)}if(f=J(f),l=J(l),c=c.slice(),u=f-l){for((o=u<0)?(u=-u,i=c):(l=f,i=a),i.reverse(),n=u;n--;i.push(0));i.reverse()}else for(r=(o=(u=c.length)<(n=a.length))?u:n,u=n=0;n<r;n++)if(c[n]!=a[n]){o=c[n]<a[n];break}if(o&&(i=c,c=a,a=i,e.s=-e.s),0<(n=(r=a.length)-(t=c.length)))for(;n--;c[t++]=0);for(n=z-1;u<r;){if(c[--r]<a[r]){for(t=r;t&&!c[--t];c[t]=n);--c[t],c[r]+=z}c[r]-=a[r]}for(;0==c[0];c.shift(),--l);return c[0]?I(e,c,l):(e.s=3==v?-1:1,e.c=[e.e=0],e)},r.modulo=r.mod=function(e,n){var t,r,i=this;return b=11,e=new D(e,n),!i.c||!e.s||e.c&&!e.c[0]?new D(NaN):!e.c||i.c&&!i.c[0]?new D(i):(9==R?(r=e.s,e.s=1,t=d(i,e,0,3),e.s=r,t.s*=r):t=d(i,e,0,R),i.minus(t.times(e)))},r.negated=r.neg=function(){var e=new D(this);return e.s=-e.s||null,e},r.plus=r.add=function(e,n){var t,r=this,i=r.s;if(b=12,n=(e=new D(e,n)).s,!i||!n)return new D(NaN);if(i!=n)return e.s=-n,r.minus(e);var o=r.e/j,s=e.e/j,u=r.c,f=e.c;if(!o||!s){if(!u||!f)return new D(i/0);if(!u[0]||!f[0])return f[0]?e:new D(u[0]?r:0*i)}if(o=J(o),s=J(s),u=u.slice(),i=o-s){for(0<i?(s=o,t=f):(i=-i,t=u),t.reverse();i--;t.push(0));t.reverse()}for((i=u.length)-(n=f.length)<0&&(t=f,f=u,u=t,n=i),i=0;n;)i=(u[--n]=u[n]+f[n]+i)/z|0,u[n]%=z;return i&&(u.unshift(i),++s),I(e,u,s)},r.precision=r.sd=function(e){var n,t,r=this.c;if(null!=e&&e!==!!e&&1!==e&&0!==e&&(O&&L(13,"argument"+P,e),e!=!!e&&(e=null)),!r)return null;if(n=(t=r.length-1)*j+1,t=r[t]){for(;t%10==0;t/=10,n--);for(t=r[0];10<=t;t/=10,n++);}return e&&this.e+1>n&&(n=this.e+1),n},r.round=function(e,n){var t=new D(this);return(null==e||y(e,0,W,15))&&U(t,~~e+this.e+1,null!=n&&y(n,0,8,15,k)?0|n:v),t},r.shift=function(e){var n=this;return y(e,-o,o,16,"argument")?n.times("1e"+te(e)):new D(n.c&&n.c[0]&&(e<-o||o<e)?n.s*(e<0?0:1/0):n)},r.squareRoot=r.sqrt=function(){var e,n,t,r,i,o=this,s=o.c,u=o.s,f=o.e,l=p+4,c=new D("0.5");if(1!==u||!s||!s[0])return new D(!u||u<0&&(!s||s[0])?NaN:s?o:1/0);if(0==(u=Math.sqrt(+o))||u==1/0?(((n=X(s)).length+f)%2==0&&(n+="0"),u=Math.sqrt(n),f=J((f+1)/2)-(f<0||f%2),t=new D(n=u==1/0?"1e"+f:(n=u.toExponential()).slice(0,n.indexOf("e")+1)+f)):t=new D(u+""),t.c[0])for((u=(f=t.e)+l)<3&&(u=0);;)if(i=t,t=c.times(i.plus(d(o,i,l,1))),X(i.c).slice(0,u)===(n=X(t.c)).slice(0,u)){if(t.e<f&&--u,"9999"!=(n=n.slice(u-3,u+1))&&(r||"4999"!=n)){+n&&(+n.slice(1)||"5"!=n.charAt(0))||(U(t,t.e+p+2,1),e=!t.times(t).eq(o));break}if(!r&&(U(i,i.e+p+2,0),i.times(i).eq(o))){t=i;break}l+=4,u+=4,r=1}return U(t,t.e+p+1,v,e)},r.times=r.mul=function(e,n){var t,r,i,o,s,u,f,l,c,a,h,g,p,m,d,w=this,v=w.c,N=(b=17,e=new D(e,n)).c;if(!(v&&N&&v[0]&&N[0]))return!w.s||!e.s||v&&!v[0]&&!N||N&&!N[0]&&!v?e.c=e.e=e.s=null:(e.s*=w.s,v&&N?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=J(w.e/j)+J(e.e/j),e.s*=w.s,(f=v.length)<(a=N.length)&&(p=v,v=N,N=p,i=f,f=a,a=i),i=f+a,p=[];i--;p.push(0));for(m=z,d=V,i=a;0<=--i;){for(t=0,h=N[i]%d,g=N[i]/d|0,o=i+(s=f);i<o;)t=((l=h*(l=v[--s]%d)+(u=g*l+(c=v[s]/d|0)*h)%d*d+p[o]+t)/m|0)+(u/d|0)+g*c,p[o--]=l%m;p[o]=t}return t?++r:p.shift(),I(e,p,r)},r.toDigits=function(e,n){var t=new D(this);return e=null!=e&&y(e,1,W,18,"precision")?0|e:null,n=null!=n&&y(n,0,8,18,k)?0|n:v,e?U(t,e,n):t},r.toExponential=function(e,n){return x(this,null!=e&&y(e,0,W,19)?1+~~e:null,n,19)},r.toFixed=function(e,n){return x(this,null!=e&&y(e,0,W,20)?~~e+this.e+1:null,n,20)},r.toFormat=function(e,n){var t=x(this,null!=e&&y(e,0,W,21)?~~e+this.e+1:null,n,21);if(this.c){var r,i=t.split("."),o=+E.groupSize,s=+E.secondaryGroupSize,u=E.groupSeparator,f=i[0],l=i[1],c=this.s<0,a=c?f.slice(1):f,h=a.length;if(s&&(r=o,o=s,h-=s=r),0<o&&0<h){for(r=h%o||o,f=a.substr(0,r);r<h;r+=o)f+=u+a.substr(r,o);0<s&&(f+=u+a.slice(r)),c&&(f="-"+f)}t=l?f+E.decimalSeparator+((s=+E.fractionGroupSize)?l.replace(new RegExp("\\d{"+s+"}\\B","g"),"$&"+E.fractionGroupSeparator):l):f}return t},r.toFraction=function(e){var n,t,r,i,o,s,u,f,l,c=O,a=this,h=a.c,g=new D(w),p=t=new D(w),m=u=new D(w);if(null!=e&&(O=!1,s=new D(e),O=c,(c=s.isInt())&&!s.lt(w)||(O&&L(22,"max denominator "+(c?"out of range":"not an integer"),e),e=!c&&s.c&&U(s,s.e+1,1).gte(w)?s:null)),!h)return a.toString();for(l=X(h),i=g.e=l.length-a.e-1,g.c[0]=H[(o=i%j)<0?j+o:o],e=!e||0<s.cmp(g)?0<i?g:p:s,o=N,N=1/0,s=new D(l),u.c[0]=0;f=d(s,g,0,1),1!=(r=t.plus(f.times(m))).cmp(e);)t=m,m=r,p=u.plus(f.times(r=p)),u=r,g=s.minus(f.times(r=g)),s=r;return r=d(e.minus(t),m,0,1),u=u.plus(r.times(p)),t=t.plus(r.times(m)),u.s=p.s=a.s,n=d(p,m,i*=2,v).minus(a).abs().cmp(d(u,t,i,v).minus(a).abs())<1?[p.toString(),m.toString()]:[u.toString(),t.toString()],N=o,n},r.toNumber=function(){return+this||(this.s?0*this.s:NaN)},r.toPower=r.pow=function(e){var n,t,r=q(e<0?-e:+e),i=this;if(!y(e,-o,o,23,"exponent")&&(!isFinite(e)||o<r&&(e/=0)||parseFloat(e)!=e&&!(e=NaN)))return new D(Math.pow(+i,e));for(n=A?B(A/j+2):0,t=new D(w);;){if(r%2){if(!(t=t.times(i)).c)break;n&&t.c.length>n&&(t.c.length=n)}if(!(r=q(r/2)))break;i=i.times(i),n&&i.c&&i.c.length>n&&(i.c.length=n)}return e<0&&(t=w.div(t)),n?U(t,A,v):t},r.toPrecision=function(e,n){return x(this,null!=e&&y(e,1,W,24,"precision")?0|e:null,n,24)},r.toString=function(e){var n,t=this.s,r=this.e;return null===r?t?(n="Infinity",t<0&&(n="-"+n)):n="NaN":(n=X(this.c),n=null!=e&&y(e,2,64,25,"base")?_(ne(n,r),0|e,10,t):r<=h||g<=r?ee(n,r):ne(n,r),t<0&&this.c[0]&&(n="-"+n)),n},r.truncated=r.trunc=function(){return U(new D(this),this.e+1,1)},r.valueOf=r.toJSON=function(){return this.toString()},r._isBigNumber=!0,null!=n&&D.config(n),D}(),"function"==typeof define&&define.amd)define(function(){return n});else if("undefined"!=typeof module&&module.exports){if(module.exports=n,!C)try{C=require("crypto")}catch(e){}}else e.BigNumber=n}(this);