1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
/* bignumber.js v1.0.0 https://github.com/MikeMcl/bignumber.js/LICENCE */(function(e){"use strict";function y(e,t){var n,r,i,s=this;if(!(s instanceof y))return new y(e,t);if(e instanceof y){if(t===r){s.s=e.s,s.e=e.e,s.c=(e=e.c)?e.slice():e;return}e=e.toS()}typeof e!="string"&&(e=(n=Object.prototype.toString.call(e)=="[object Number]")&&e===0&&1/e<0?"-0":e+"");if(t===r&&v.test(e))s.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1;else{if(t==10)return(new y(e)).div(g);e=m.call(e).replace(/^\+([^-])/,"$1").replace(/^(-?)\./,"$10."),s.s=e.charAt(0)=="-"?(e=e.replace(/^-([^-])/,"$1"),-1):1,t!=null?t!=(t|0)&&!!f||(p=!(t>=2&&t<=36))?(b(t,2),i=v.test(e)):(r="["+h.slice(0,t|=0)+"]+",(i=(new RegExp("^"+r+"(?:\\."+r+")?$","i")).test(e))?(n&&(e.replace(".","").length>15&&b(e,0),n=!n),e=w(e,10,t,s.s)):e!="Infinity"&&e!="NaN"&&(b(e,1,t),e="NaN")):i=v.test(e);if(!i){s.c=s.e=null,e!="Infinity"&&(e!="NaN"&&b(e,3),s.s=null);return}}(r=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(r<0&&(r=i),r+=+e.slice(i+1),e=e.substring(0,i)):r<0&&(r=e.length),(t=e.length,n&&t>15)&&b(e,0);for(i=0;e.charAt(i)=="0";i++);if((r-=i+1)>a)s.c=s.e=null;else if(i==t||r<u)s.c=[s.e=0];else{for(;e.charAt(--t)=="0";);s.e=r,s.c=[];for(r=0;i<=t;s.c[r++]=+e.charAt(i++));}}function b(e,t,n,r,i,s){if(f){var o=["new BigNumber","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFr"][d?d<0?-d:d:1/d<0?1:0]+"()",u=p?" out of range":" not a"+(i?" non-zero":"n")+" integer";throw u=([o+" number type has more than 15 significant digits",o+" not a base "+n+" number",o+" base"+u,o+" not a number"][t]||n+"() "+t+(s?" not a boolean or binary digit":u+(r?" or not ["+(p?" negative, positive":" integer, integer")+" ]":"")))+": "+e,p=d=0,{name:"BigNumber Error",message:u,toString:function(){return this.name+": "+this.message}}}}function w(e,t,n,r){function l(e,r){var i,s=0,o=e.length,u,a=[0];for(r=r||n;s<o;s++){for(u=a.length,i=0;i<u;a[i]*=r,i++);for(a[0]+=h.indexOf(e.charAt(s)),i=0;i<a.length;i++)a[i]>t-1&&(a[i+1]==null&&(a[i+1]=0),a[i+1]+=a[i]/t^0,a[i]%=t)}return a.reverse()}function c(e){var t=0,n=e.length,r="";for(;t<n;r+=h.charAt(e[t++]));return r}var i,s,o,u,a,f;e=e.toLowerCase();if((i=e.indexOf("."))>-1){i=e.length-i-1,s=l((new y(n)).pow(i).toF(),10),u=e.split("."),o=l(u[1]),u=l(u[0]),f=E(o,s,o.length-s.length,r,t,u[u.length-1]&1),a=f.c;if(i=f.e){for(;++i;a.unshift(0));e=c(u)+"."+c(a)}else a[0]?u[i=u.length-1]<t-1?(++u[i],e=c(u)):e=(new y(c(u),t)).plus(g).toS(t):e=c(u)}else e=c(l(e));return e}function E(e,t,n,i,s,o){var f,l,c,h,p,d=t.slice(),v=f=t.length,m=e.length,b=e.slice(0,f),w=b.length,E=new y(g),S=E.c=[],T=0,N=r+(E.e=n)+1;E.s=i,i=N<0?0:N;for(;w++<f;b.push(0));d.unshift(0);do{for(c=0;c<s;c++){if(f!=(w=b.length))h=f>w?1:-1;else for(p=-1,h=0;++p<f;)if(t[p]!=b[p]){h=t[p]>b[p]?1:-1;break}if(!(h<0))break;for(l=w==f?t:d;w;){if(b[--w]<l[w]){for(p=w;p&&!b[--p];b[p]=s-1);--b[p],b[w]+=s}b[w]-=l[w]}for(;!b[0];b.shift());}S[T++]=h?c:++c,b[0]&&h?b[w]=e[v]||0:b=[e[v]]}while((v++<m||b[0]!=null)&&i--);return!S[0]&&T!=1&&(--E.e,S.shift()),T>N&&x(E,r,s,o,b[0]!=null),E.e>a?E.c=E.e=null:E.e<u&&(E.c=[E.e=0]),E}function S(e,t,n){var r=t-(e=new y(e)).e,i=e.c;if(!i)return e.toS();i.length>++t&&x(e,r,10),r=i[0]==0?r+1:n?t:e.e+r+1;for(;i.length<r;i.push(0));return r=e.e,n==1||n==2&&(--t<r||r<=s)?(e.s<0&&i[0]?"-":"")+(i.length>1?(i.splice(1,0,"."),i.join("")):i[0])+(r<0?"e":"e+")+r:e.toS()}function x(e,t,n,r,s){var o=e.c,u=e.s<0,a=n/2,f=e.e+t+1,l=o[f],c=s||f<0||o[f+1]!=null;s=i<4?(l!=null||c)&&(i==0||i==2&&!u||i==3&&u):l>a||l==a&&(i==4||c||i==6&&(o[f-1]&1||!t&&r)||i==7&&!u||i==8&&u);if(f<1||!o[0])return o.length=0,o.push(0),s?(o[0]=1,e.e=-t):e.e=0,e;o.length=f--;if(s)for(--n;++o[f]>n;)o[f]=0,f--||(++e.e,o.unshift(1));for(f=o.length;!o[--f];o.pop());return e}function T(e,t,n){var r=i;return i=n,e=new y(e),e.c&&x(e,t,10),i=r,e}var t=1e9,n=1e6,r=20,i=4,s=-7,o=21,u=-t,a=t,f=!0,l=parseInt,c=y.prototype,h="0123456789abcdefghijklmnopqrstuvwxyz",p,d=0,v=/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i,m=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=y(1);y.ROUND_UP=0,y.ROUND_DOWN=1,y.ROUND_CEIL=2,y.ROUND_FLOOR=3,y.ROUND_HALF_UP=4,y.ROUND_HALF_DOWN=5,y.ROUND_HALF_EVEN=6,y.ROUND_HALF_CEIL=7,y.ROUND_HALF_FLOOR=8,y.config=function(){var e,n,c=0,h={},v=arguments,m=v[0],g="config",y=function(e,t,n){return!((p=e<t||e>n)||l(e)!=e&&e!==0)},w=m&&typeof m=="object"?function(){if(m.hasOwnProperty(n))return(e=m[n])!=null}:function(){if(v.length>c)return(e=v[c++])!=null};return w(n="DECIMAL_PLACES")&&(y(e,0,t)?r=e|0:b(e,n,g)),h[n]=r,w(n="ROUNDING_MODE")&&(y(e,0,8)?i=e|0:b(e,n,g)),h[n]=i,w(n="EXPONENTIAL_AT")&&(y(e,-t,t)?s=-(o=~~(e<0?-e:+e)):!p&&e&&y(e[0],-t,0)&&y(e[1],0,t)?(s=~~e[0],o=~~e[1]):b(e,n,g,1)),h[n]=[s,o],w(n="RANGE")&&(y(e,-t,t)&&~~e?u=-(a=~~(e<0?-e:+e)):!p&&e&&y(e[0],-t,-1)&&y(e[1],1,t)?(u=~~e[0],a=~~e[1]):b(e,n,g,1,1)),h[n]=[u,a],w(n="ERRORS")&&(e===!!e||e===1||e===0?l=(p=d=0,f=!!e)?parseInt:parseFloat:b(e,n,g,0,0,1)),h[n]=f,h},c.abs=c.absoluteValue=function(){var e=new y(this);return e.s<0&&(e.s=1),e},c.ceil=function(){return T(this,0,2)},c.comparedTo=c.cmp=function(e,t){var n,r=this,i=r.c,s=(d=-d,e=new y(e,t)).c,o=r.s,u=e.s,a=r.e,f=e.e;if(!o||!u)return null;n=i&&!i[0],t=s&&!s[0];if(n||t)return n?t?0:-u:o;if(o!=u)return o;if(n=o<0,t=a==f,!i||!s)return t?0:!i^n?1:-1;if(!t)return a>f^n?1:-1;for(o=-1,u=(a=i.length)<(f=s.length)?a:f;++o<u;)if(i[o]!=s[o])return i[o]>s[o]^n?1:-1;return a==f?0:a>f^n?1:-1},c.dividedBy=c.div=function(e,t){var n=this.c,r=this.e,i=this.s,s=(d=2,e=new y(e,t)).c,o=e.e,u=e.s,a=i==u?1:-1;return!r&&(!n||!n[0])||!o&&(!s||!s[0])?new y(!i||!u||(n?s&&n[0]==s[0]:!s)?NaN:n&&n[0]==0||!s?a*0:a/0):E(n,s,r-o,a,10)},c.equals=c.eq=function(e,t){return d=3,this.cmp(e,t)===0},c.floor=function(){return T(this,0,3)},c.greaterThan=c.gt=function(e,t){return d=4,this.cmp(e,t)>0},c.greaterThanOrEqualTo=c.gte=function(e,t){return d=5,(t=this.cmp(e,t))==1||t===0},c.isFinite=c.isF=function(){return!!this.c},c.isNaN=function(){return!this.s},c.isNegative=c.isNeg=function(){return this.s<0},c.isZero=c.isZ=function(){return!!this.c&&this.c[0]==0},c.lessThan=c.lt=function(e,t){return d=6,this.cmp(e,t)<0},c.lessThanOrEqualTo=c.lte=function(e,t){return d=7,(t=this.cmp(e,t))==-1||t===0},c.minus=function(e,t){var n,r,i,s,o=this,a=o.s;t=(d=8,e=new y(e,t)).s;if(!a||!t)return new y(NaN);if(a!=t)return e.s=-t,o.plus(e);var f=o.c,l=o.e,c=e.c,h=e.e;if(!l||!h){if(!f||!c)return f?(e.s=-t,e):new y(c?o:NaN);if(!f[0]||!c[0])return c[0]?(e.s=-t,e):new y(f[0]?o:0)}if(f=f.slice(),a=l-h){n=(s=a<0)?(a=-a,f):(h=l,c);for(n.reverse(),t=a;t--;n.push(0));n.reverse()}else{i=((s=f.length<c.length)?f:c).length;for(a=t=0;t<i;t++)if(f[t]!=c[t]){s=f[t]<c[t];break}}s&&(n=f,f=c,c=n,e.s=-e.s);if((t=-((i=f.length)-c.length))>0)for(;t--;f[i++]=0);for(t=c.length;t>a;){if(f[--t]<c[t]){for(r=t;r&&!f[--r];f[r]=9);--f[r],f[t]+=10}f[t]-=c[t]}for(;f[--i]==0;f.pop());for(;f[0]==0;f.shift(),--h);if(h<u||!f[0])f=[h=0];return e.c=f,e.e=h,e},c.modulo=c.mod=function(e,t){var n=this,s=n.c,o=(d=9,e=new y(e,t)).c,u=n.s,a=e.s;return t=!u||!a||o&&!o[0],t||s&&!s[0]?new y(t?NaN:n):(n.s=e.s=1,t=e.cmp(n)==1,n.s=u,e.s=a,t?new y(n):(u=r,a=i,r=0,i=1,n=n.div(e),r=u,i=a,this.minus(n.times(e))))},c.negated=c.neg=function(){var e=new y(this);return e.s=-e.s||null,e},c.plus=function(e,t){var n,r=this,i=r.s;t=(d=10,e=new y(e,t)).s;if(!i||!t)return new y(NaN);if(i!=t)return e.s=-t,r.minus(e);var s=r.e,o=r.c,u=e.e,f=e.c;if(!s||!u){if(!o||!f)return new y(i/0);if(!o[0]||!f[0])return f[0]?e:new y(o[0]?r:i*0)}if(o=o.slice(),i=s-u){n=i>0?(u=s,f):(i=-i,o);for(n.reverse();i--;n.push(0));n.reverse()}o.length-f.length<0&&(n=f,f=o,o=n);for(i=f.length,t=0;i;t=(o[--i]=o[i]+f[i]+t)/10^0,o[i]%=10);t&&(o.unshift(t),++u>a&&(o=u=null));for(i=o.length;o[--i]==0;o.pop());return e.c=o,e.e=u,e},c.toPower=c.pow=function(e){var t,r=e*0==0?e|0:e,i=new y(this),t=new y(g);if(((p=e<-n||e>n)&&(r=e*1/0)||l(e)!=e&&e!==0&&!(r=NaN))&&!b(e,"exponent","pow")||!r)return new y(Math.pow(i.toS(),r));for(r=r<0?-r:r;;){r&1&&(t=t.times(i)),r>>=1;if(!r)break;i=i.times(i)}return e<0?g.div(t):t},c.round=function(e,n){return e=e==null||((p=e<0||e>t)||l(e)!=e)&&!b(e,"decimal places","round")?0:e|0,n=n==null||((p=n<0||n>8)||l(n)!=n&&n!==0)&&!b(n,"mode","round")?i:n|0,T(this,e,n)},c.squareRoot=c.sqrt=function(){var e,t,n,i=this,s=i.c,o=i.s,u=i.e,a=new y("0.5");if(o!==1||!s||!s[0])return new y(!o||o<0&&(!s||s[0])?NaN:s?i:1/0);o=Math.sqrt(i.toS()),o==0||o==1/0?(e=s.join(""),e.length+u&1||(e+="0"),t=new y(Math.sqrt(e).toString()),t.e=((u+1)/2|0)-(u<0||u&1)):t=new y(o.toString()),o=t.e+(r+=4);do n=t,t=a.times(n.plus(i.div(n)));while(n.c.slice(0,o).join("")!==t.c.slice(0,o).join(""));return x(t,r-=4,10),t},c.times=function(e,t){var n,r=this,i=r.c,s=(d=11,e=new y(e,t)).c,o=r.e,f=e.e,l=r.s;e.s=l==(t=e.s)?1:-1;if(!o&&(!i||!i[0])||!f&&(!s||!s[0]))return new y(!l||!t||i&&!i[0]&&!s||s&&!s[0]&&!i?NaN:!i||!s?e.s/0:e.s*0);e.e=o+f,(l=i.length)<(t=s.length)&&(n=i,i=s,s=n,f=l,l=t,t=f);for(f=l+t,n=[];f--;n.push(0));for(o=t-1;o>-1;o--){for(t=0,f=l+o;f>o;t=n[f]+s[o]*i[f-o-1]+t,n[f--]=t%10|0,t=t/10|0);t&&(n[f]=(n[f]+t)%10)}t&&++e.e,!n[0]&&n.shift();for(f=n.length;!n[--f];n.pop());return e.c=e.e>a?e.e=null:e.e<u?[e.e=0]:n,e},c.toExponential=c.toE=function(e){return S(this,(e==null||((p=e<0||e>t)||l(e)!=e&&e!==0)&&!b(e,"decimal places","toE"))&&this.c?this.c.length-1:e|0,1)},c.toFixed=c.toF=function(e){var n,r,i,u=this;return e==null||((p=e<0||e>t)||l(e)!=e&&e!==0)&&!b(e,"decimal places","toF")||(i=u.e+(e|0)),n=s,e=o,s=-(o=1/0),i==r?r=u.toS():(r=S(u,i),u.s<0&&u.c&&(u.c[0]?r.indexOf("-")<0&&(r="-"+r):r=r.replace(/^-/,""))),s=n,o=e,r},c.toFraction=c.toFr=function(e){var t,n,s,o,u,l,c,h=o=new y(g),v=s=new y("0"),m=this,w=m.c,E=a,S=r,x=i,T=new y(g);if(!w)return m.toS();c=T.e=w.length-m.e-1;if(e==null||(!(d=12,l=new y(e)).s||(p=l.cmp(h)<0||!l.c)||f&&l.e<l.c.length-1)&&!b(e,"max denominator","toFr")||(e=l).cmp(T)>0)e=c>0?T:h;a=1/0,l=new y(w.join(""));for(r=0,i=1;;){t=l.div(T),u=o.plus(t.times(v));if(u.cmp(e)==1)break;o=v,v=u,h=s.plus(t.times(u=h)),s=u,T=l.minus(t.times(u=T)),l=u}return u=e.minus(o).div(v),s=s.plus(u.times(h)),o=o.plus(u.times(v)),s.s=h.s=m.s,r=c*2,i=x,n=h.div(v).minus(m).abs().cmp(s.div(o).minus(m).abs())<1?[h.toS(),v.toS()]:[s.toS(),o.toS()],a=E,r=S,n},c.toPrecision=c.toP=function(e){return e==null||((p=e<1||e>t)||l(e)!=e)&&!b(e,"precision","toP")?this.toS():S(this,--e|0,2)},c.toString=c.toS=function(e){var t,n,r,i=this,u=i.e;if(u===null)n=i.s?"Infinity":"NaN";else{if(e===t&&(u<=s||u>=o))return S(i,i.c.length-1,1);n=i.c.join("");if(u<0){for(;++u;n="0"+n);n="0."+n}else if(r=n.length,u>0)if(++u>r)for(u-=r;u--;n+="0");else u<r&&(n=n.slice(0,u)+"."+n.slice(u));else if(t=n.charAt(0),r>1)n=t+"."+n.slice(1);else if(t=="0")return t;if(e!=null)if((p=!(e>=2&&e<=36))||e!=(e|0)&&!!f)b(e,"base","toS");else{n=w(n,e|0,10,i.s);if(n=="0")return n}}return i.s<0?"-"+n:n},c.valueOf=function(){return this.toS()},typeof module!="undefined"&&module.exports?module.exports=y:typeof define=="function"&&define.amd?define(function(){return y}):e.BigNumber=y})(this); |