bignumber.js
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
/*! bignumber.js v2.0.0 https://github.com/MikeMcl/bignumber.js/LICENCE */ | ||
(function(n){"use strict";function t(n,i){var b,a,l,p,o,w,s=this;if(!(s instanceof t))return new t(n,i);if(n instanceof t){if(i==null){u=0;s.s=n.s;s.e=n.e;s.c=(n=n.c)?n.slice():n;return}n+=""}else if(p=(o=typeof n)=="number"){if(i==null&&n===~~n){for(s.s=1/n<0?(n=-n,-1):1,a=u=0,l=n;l>=10;l/=10,a++);s.e=a;s.c=[n];return}n=n===0&&1/n<0?"-0":n+""}else o!="string"&&(n+="");if(o=n,i==null&&ft.test(o))s.s=o.charCodeAt(0)===45?(o=o.slice(1),-1):1;else{if(i==10)return s=new t(o),y(s,c+s.e+1,h);if(o=lt.call(o).replace(/^\+(?!-)/,""),s.s=o.charCodeAt(0)===45?(o=o.replace(/^-(?!-)/,""),-1):1,i!=null?i!=~~i&&d||(e=!(i>=2&&i<65))?(f(i,2),w=ft.test(o)):(b="["+ut.slice(0,i=i|0)+"]+",o=o.replace(/\.$/,"").replace(/^\./,"0."),(w=new RegExp("^"+b+"(?:\\."+b+")?$",i<37?"i":"").test(o))?(p&&(o.replace(/^0\.0*|\./,"").length>15&&f(n,0),p=!p),o=ct(o,10,i,s.s)):o!="Infinity"&&o!="NaN"&&(f(n,1,i),n="NaN")):w=ft.test(o),!w){s.c=s.e=null;o!="Infinity"&&(o!="NaN"&&f(n,3),s.s=null);u=0;return}}for((a=o.indexOf("."))>-1&&(o=o.replace(".","")),(l=o.search(/e/i))>0?(a<0&&(a=l),a+=+o.slice(l+1),o=o.substring(0,l)):a<0&&(a=o.length),l=0;o.charCodeAt(l)===48;l++);for(i=o.length;o.charCodeAt(--i)===48;);if(o=o.slice(l,i+1),o)if(i=o.length,p&&i>15&&f(n,0),a=a-l-1,a>v)s.c=s.e=null;else if(a<nt)s.c=[s.e=0];else{if(s.e=a,s.c=[],l=(a+1)%r,a<0&&(l+=r),l<i){for(l&&s.c.push(+o.slice(0,l)),i-=r;l<i;s.c.push(+o.slice(l,l+=r)));o=o.slice(l);l=r-o.length}else l-=i;for(;l--;o+="0");s.c.push(+o)}else s.c=[s.e=0];u=0}function et(n,t,i){for(var f=1,u=t.length;!t[--u];t.pop());for(u=t[0];u>=10;u/=10,f++);return(i=f+i*r-1)>v?n.c=n.e=null:i<nt?n.c=[n.e=0]:(n.e=i,n.c=t),n}function tt(n){for(var t,f,e=1,i=n.length,u=n[0]+"";e<i;){for(t=n[e++]+"",f=r-t.length;f--;t="0"+t);u+=t}for(i=u.length;u.charCodeAt(--i)===48;);return u.slice(0,i+1||1)}function ht(n,t,i){for(var u,r=[0],f,e=0,o=n.length;e<o;){for(f=r.length;f--;r[f]*=t);for(r[u=0]+=ut.indexOf(n.charAt(e++));u<r.length;u++)r[u]>i-1&&(r[u+1]==null&&(r[u+1]=0),r[u+1]+=r[u]/i|0,r[u]%=i)}return r.reverse()}function ct(n,i,r,u){var l,e,v,y,s,f,w,o=n.indexOf("."),p=h;for(r<37&&(n=n.toLowerCase()),o>=0&&(n=n.replace(".",""),w=new t(r),s=w.pow(n.length-o),w.c=ht(s.toFixed(),10,i),w.e=w.c.length),f=ht(n,r,i),e=v=f.length;f[--v]==0;f.pop());if(!f[0])return"0";if(o<0?--e:(s.c=f,s.e=e,s.s=u,s=a(s,w,c,p,i),f=s.c,y=s.r,e=s.e),l=e+c+1,o=f[l],v=i/2,y=y||l<0||f[l+1]!=null,y=p<4?(o!=null||y)&&(p==0||p==(s.s<0?3:2)):o>v||o==v&&(p==4||y||p==6&&f[l-1]&1||p==(s.s<0?8:7)),l<1||!f[0])f.length=1,v=0,y?(f[0]=1,e=-c):e=f[0]=0;else{if(f.length=l,y)for(--i;++f[--l]>i;)f[l]=0,l||(++e,f.unshift(1));for(v=f.length;!f[--v];);}for(o=0,n="";o<=v;n+=ut.charAt(f[o++]));if(e<0){for(;++e;n="0"+n);n="0."+n}else if(o=n.length,++e>o)for(e-=o;e--;n+="0");else e<o&&(n=n.slice(0,e)+"."+n.slice(e));return n}function rt(n,i,r){var o,u,e,f=(n=new t(n)).e;if(i==null?o=0:(y(n,++i,h),o=r?i:i+n.e-f,f=n.e),u=tt(n.c),r==1||r==2&&(i<=f||f<=p)){for(;u.length<o;u+="0");u.length>1&&(u=u.charAt(0)+"."+u.slice(1));u+=(f<0?"e":"e+")+f}else{if(r=u.length,f<0){for(e=o-r;++f;u="0"+u);u="0."+u}else if(++f>r){for(e=o-f,f-=r;f--;u+="0");e>0&&(u+=".")}else e=o-r,f<r?u=u.slice(0,f)+"."+u.slice(f):e>0&&(u+=".");if(e>0)for(;e--;u+="0");}return n.s<0&&n.c[0]?"-"+u:u}function f(n,t,i,r,f,o){if(d){var c,s=["new BigNumber","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFraction","divToInt"][u?u<0?-u:u:1/u<0?1:0]+"()",h=e?" out of range":" not a"+(f?" non-zero":"n")+" integer";h=([s+" number type has more than 15 significant digits",s+" not a base "+i+" number",s+" base"+h,s+" not a number"][t]||i+"() "+t+(o?" not a boolean or binary digit":h+(r?" or not ["+(e?" negative, positive":" integer, integer")+" ]":"")))+": "+n;e=u=0;c=new Error(h);c.name="BigNumber Error";throw c;}}function y(n,t,i,u){var c,o,e,s,a,h,p,f,y=st;if(f=n.c){n:{for(c=1,s=f[0];s>=10;s/=10,c++);if(o=t-c,o<0)o+=r,e=t,a=f[h=0],p=a/y[c-e-1]%10|0;else if(h=Math.ceil((o+1)/r),h>=f.length)if(u){for(;f.length<=h;f.push(0));a=p=0;c=1;o%=r;e=o-r+1}else break n;else{for(a=s=f[h],c=1;s>=10;s/=10,c++);o%=r;e=o-r+c;p=e<0?0:a/y[c-e-1]%10|0}if(u=u||t<0||f[h+1]!=null||(e<0?a:a%y[c-e-1]),u=i<4?(p||u)&&(i==0||i==(n.s<0?3:2)):p>5||p==5&&(i==4||u||i==6&&(o>0?e>0?a/y[c-e]:0:f[h-1])%10&1||i==(n.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=n.e+1,f[0]=y[t%r],n.e=-t||0):f[0]=n.e=0,n;if(o==0?(f.length=h,s=1,h--):(f.length=h+1,s=y[r-o],f[h]=e>0?g(a/y[c-e]%y[e])*s:0),u)for(;;)if(h==0){for(o=1,e=f[0];e>=10;e/=10,o++);for(e=f[0]+=s,s=1;e>=10;e/=10,s++);o!=s&&(n.e++,f[0]==l&&(f[0]=1));break}else{if(f[h]+=s,f[h]!=l)break;f[h--]=0;s=1}for(o=f.length;f[--o]===0;f.pop());}n.e>v?n.c=n.e=null:n.e<nt&&(n.c=[n.e=0])}return n}var o=1e9,ot=1e6,c=20,h=4,p=-7,k=21,nt=-o,v=o,d=!0,w=parseInt,b={decimalSeparator:".",groupSeparator:",",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:" ",fractionGroupSize:0},i=t.prototype,ut="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_",e,u=0,g=Math.floor,ft=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,lt=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},l=1e14,r=14,s=1e7,st=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],it=new t(1),a;t.ROUND_UP=0;t.ROUND_DOWN=1;t.ROUND_CEIL=2;t.ROUND_FLOOR=3;t.ROUND_HALF_UP=4;t.ROUND_HALF_DOWN=5;t.ROUND_HALF_EVEN=6;t.ROUND_HALF_CEIL=7;t.ROUND_HALF_FLOOR=8;t.config=function(){var n,t,g=0,i={},y=arguments,a=y[0],s="config",r=function(n,t,i){return!((e=n<t||n>i)||w(n)!=n&&n!==0)},l=a&&typeof a=="object"?function(){if(a.hasOwnProperty(t))return(n=a[t])!=null}:function(){if(y.length>g)return(n=y[g++])!=null};if(l(t="DECIMAL_PLACES")&&(r(n,0,o)?c=n|0:f(n,t,s)),i[t]=c,l(t="ROUNDING_MODE")&&(r(n,0,8)?h=n|0:f(n,t,s)),i[t]=h,l(t="EXPONENTIAL_AT")&&(r(n,-o,o)?p=-(k=~~(n<0?-n:+n)):!e&&n&&r(n[0],-o,0)&&r(n[1],0,o)?(p=~~n[0],k=~~n[1]):f(n,t,s,1)),i[t]=[p,k],l(t="RANGE")&&(r(n,-o,o)&&~~n?nt=-(v=~~(n<0?-n:+n)):!e&&n&&r(n[0],-o,-1)&&r(n[1],1,o)?(nt=~~n[0],v=~~n[1]):f(n,t,s,1,1)),i[t]=[nt,v],l(t="ERRORS")&&(n===!!n||n===1||n===0?(e=u=0,w=(d=!!n)?parseInt:parseFloat):f(n,t,s,0,0,1)),i[t]=d,l(t="FORMAT"))if(typeof n=="object")b=n;else if(d){i=new Error(s+"() "+t+" not an object: "+n);i.name="BigNumber Error";throw i;}return i[t]=b,i};a=function(){function n(n,t,i){var f,e,o,h,r=0,u=n.length,c=t%s,l=t/s|0;for(n=n.slice();u--;)o=n[u]%s,h=n[u]/s|0,f=l*o+h*c,e=c*o+f%s*s+r,r=(e/i|0)+(f/s|0)+l*h,n[u]=e%i;return r&&n.unshift(r),n}function i(n,t,i,r){var u,f;if(i!=r)f=i>r?1:-1;else for(u=f=0;u<i;u++)if(n[u]!=t[u]){f=n[u]>t[u]?1:-1;break}return f}function u(n,t,i,r){for(var u=0;i--;)n[i]-=u,u=n[i]<t[i]?1:0,n[i]=u*r+n[i]-t[i];for(;!n[0]&&n.length>1;n.shift());}return function(f,e,o,s,h){var nt,ut,a,ot,p,tt,ft,it,et,v,w,st,ht,rt,lt,k,ct,d=f.s==e.s?1:-1,b=f.c,c=e.c;if(!b||!b[0]||!c||!c[0])return new t(!f.s||!e.s||(b?c&&b[0]==c[0]:!c)?NaN:b&&b[0]==0||!c?d*0:d/0);for(it=new t(d),et=it.c=[],ut=f.e-e.e,d=o+ut+1,h||(h=l,ut=(rt=f.e/r,a=rt|0,rt>0||rt===a?a:a-1)-(k=e.e/r,a=k|0,k>0||k===a?a:a-1),d=d/r|0),a=0;c[a]==(b[a]||0);a++);if(c[a]>(b[a]||0)&&ut--,d<0)et.push(1),ot=!0;else{for(rt=b.length,k=c.length,a=0,d+=2,p=g(h/(c[0]+1)),p>1&&(c=n(c,p,h),b=n(b,p,h),k=c.length,rt=b.length),ht=k,v=b.slice(0,k),w=v.length;w<k;v[w++]=0);ct=c.slice();ct.unshift(0);lt=c[0];c[1]>=h/2&<++;do p=0,nt=i(c,v,k,w),nt<0?(st=v[0],k!=w&&(st=st*h+(v[1]||0)),p=g(st/lt),p>1?(p>=h&&(p=h-1),tt=n(c,p,h),ft=tt.length,w=v.length,nt=i(tt,v,ft,w),nt==1&&(p--,u(tt,k<ft?ct:c,ft,h))):(p==0&&(nt=p=1),tt=c.slice()),ft=tt.length,ft<w&&tt.unshift(0),u(v,tt,w,h),nt==-1&&(w=v.length,nt=i(c,v,k,w),nt<1&&(p++,u(v,k<w?ct:c,w,h))),w=v.length):nt===0&&(p++,v=[0]),et[a++]=p,nt&&v[0]?v[w++]=b[ht]||0:(v=[b[ht]],w=1);while((ht++<rt||v[0]!=null)&&d--);ot=v[0]!=null;et[0]||et.shift()}if(h==l){for(a=1,d=et[0];d>=10;d/=10,a++);y(it,o+(it.e=a+ut*r-1)+1,s,ot)}else it.e=ut,it.r=+ot;return it}}();i.absoluteValue=i.abs=function(){var n=new t(this);return n.s<0&&(n.s=1),n};i.ceil=function(){return y(new t(this),this.e+1,2)};i.comparedTo=i.cmp=function(n,i){var f,l=this,e=l.c,o=(u=-u,n=new t(n,i)).c,r=l.s,c=n.s,s=l.e,h=n.e;if(!r||!c)return null;if(f=e&&!e[0],i=o&&!o[0],f||i)return f?i?0:-c:r;if(r!=c)return r;if(f=r<0,i=s==h,!e||!o)return i?0:!e^f?1:-1;if(!i)return s>h^f?1:-1;for(r=-1,c=(s=e.length)<(h=o.length)?s:h;++r<c;)if(e[r]!=o[r])return e[r]>o[r]^f?1:-1;return s==h?0:s>h^f?1:-1};i.decimalPlaces=i.dp=function(){var n,t,i=this.c;if(!i)return null;if(n=((t=i.length-1)-g(this.e/r))*r,t=i[t])for(;t%10==0;t/=10,n--);return n<0&&(n=0),n};i.dividedBy=i.div=function(n,i){return u=2,a(this,new t(n,i),c,h)};i.dividedToIntegerBy=i.divToInt=function(n,i){return u=13,a(this,new t(n,i),0,1)};i.equals=i.eq=function(n,t){return u=3,this.cmp(n,t)===0};i.floor=function(){return y(new t(this),this.e+1,3)};i.greaterThan=i.gt=function(n,t){return u=4,this.cmp(n,t)>0};i.greaterThanOrEqualTo=i.gte=function(n,t){return u=5,(t=this.cmp(n,t))==1||t===0};i.isFinite=function(){return!!this.c};i.isInteger=i.isInt=function(){return!!this.c&&g(this.e/r)>this.c.length-2};i.isNaN=function(){return!this.s};i.isNegative=i.isNeg=function(){return this.s<0};i.isZero=function(){return!!this.c&&this.c[0]==0};i.lessThan=i.lt=function(n,t){return u=6,this.cmp(n,t)<0};i.lessThanOrEqualTo=i.lte=function(n,t){return u=7,(t=this.cmp(n,t))==-1||t===0};i.minus=function(n,i){var e,c,v,w,p=this,s=p.s;if(u=8,n=new t(n,i),i=n.s,!s||!i)return new t(NaN);if(s!=i)return n.s=-i,p.plus(n);var y=p.e/r,a=n.e/r,f=p.c,o=n.c;if(!y||!a){if(!f||!o)return f?(n.s=-i,n):new t(o?p:NaN);if(!f[0]||!o[0])return o[0]?(n.s=-i,n):new t(f[0]?p:h==3?-0:0)}if(e=y|0,y=y>0||y===e?e:e-1,e=a|0,a=a>0||a===e?e:e-1,f=f.slice(),s=y-a){for((w=s<0)?(s=-s,v=f):(a=y,v=o),v.reverse(),i=s;i--;v.push(0));v.reverse()}else for(c=(w=(s=f.length)<(i=o.length))?s:i,s=i=0;i<c;i++)if(f[i]!=o[i]){w=f[i]<o[i];break}if(w&&(v=f,f=o,o=v,n.s=-n.s),i=(c=o.length)-(e=f.length),i>0)for(;i--;f[e++]=0);for(i=l-1;c>s;){if(f[--c]<o[c]){for(e=c;e&&!f[--e];f[e]=i);--f[e];f[c]+=l}f[c]-=o[c]}for(;f[0]==0;f.shift(),--a);return f[0]?et(n,f,a):(n.s=h==3?-1:1,n.c=[n.e=0],n)};i.modulo=i.mod=function(n,i){u=9;var r=this,f=r.c,e=(n=new t(n,i)).c,o=r.s,s=n.s;return(i=!o||!s||e&&!e[0],i||f&&!f[0])?new t(i?NaN:r):(r.s=n.s=1,i=n.cmp(r)==1,r.s=o,n.s=s,i?new t(r):r.minus(a(r,n,0,1).times(n)))};i.negated=i.neg=function(){var n=new t(this);return n.s=-n.s||null,n};i.plus=function(n,i){var h,a=this,f=a.s;if(u=10,n=new t(n,i),i=n.s,!f||!i)return new t(NaN);if(f!=i)return n.s=-i,a.minus(n);var c=a.e/r,o=n.e/r,e=a.c,s=n.c;if(!c||!o){if(!e||!s)return new t(f/0);if(!e[0]||!s[0])return s[0]?n:new t(e[0]?a:f*0)}if(f=c|0,c=c>0||c===f?f:f-1,f=o|0,o=o>0||o===f?f:f-1,e=e.slice(),f=c-o){for(f>0?(o=c,h=s):(f=-f,h=e),h.reverse();f--;h.push(0));h.reverse()}for(f=e.length,i=s.length,f-i<0&&(h=s,s=e,e=h,i=f),f=0;i;)f=(e[--i]=e[i]+s[i]+f)/l|0,e[i]%=l;return f&&(e.unshift(f),++o),et(n,e,o)};i.round=function(n,i){return n=n==null||((e=n<0||n>o)||w(n)!=n)&&!f(n,"decimal places","round")?0:n|0,i=i==null||((e=i<0||i>8)||w(i)!=i&&i!==0)&&!f(i,"mode","round")?h:i|0,y(new t(this),n+this.e+1,i)};i.squareRoot=i.sqrt=function(){var v,i,r,s,f,e=this,o=e.c,n=e.s,u=e.e,l=c+4,p=new t("0.5");if(n!==1||!o||!o[0])return new t(!n||n<0&&(!o||o[0])?NaN:o?e:1/0);if(n=Math.sqrt(+e),n==0||n==1/0?(i=tt(o),(i.length+u)%2==0&&(i+="0"),n=Math.sqrt(i),u=g((u+1)/2)-(u<0||u%2),n==1/0?i="1e"+u:(i=n.toExponential(),i=i.slice(0,i.indexOf("e")+1)+u),r=new t(i)):r=new t(n.toString()),r.c[0])for(u=r.e,n=u+l,n<3&&(n=0);;)if(f=r,r=p.times(f.plus(a(e,f,l,1))),tt(f.c).slice(0,n)===(i=tt(r.c)).slice(0,n))if(r.e<u&&--n,i=i.slice(n-3,n+1),i!="9999"&&(s||i!="4999")){+i&&(+i.slice(1)||i.charAt(0)!="5")||(y(r,r.e+c+2,1),v=!r.times(r).eq(e));break}else{if(!s&&(y(f,f.e+c+2,0),f.times(f).eq(e))){r=f;break}l+=4;n+=4;s=1}return y(r,r.e+c+1,h,v)};i.times=function(n,i){var p,e,w,b,a,y,k,d,g,nt=this,o=nt.c,h=(u=11,n=new t(n,i)).c,c=nt.e/r,f=n.e/r,v=nt.s;if(n.s=v==(i=n.s)?1:-1,!c&&(!o||!o[0])||!f&&(!h||!h[0]))return new t(!v||!i||o&&!o[0]&&!h||h&&!h[0]&&!o?NaN:!o||!h?n.s/0:n.s*0);for(e=(e=c|0,c>0||c===e?e:e-1)+(e=f|0,f>0||f===e?e:e-1),v=o.length,i=h.length,v<i&&(a=o,o=h,h=a,f=v,v=i,i=f),f=v+i,a=[];f--;a.push(0));for(c=i;--c>=0;){for(p=0,f=v+c,w=v,d=h[c]%s,g=h[c]/s|0;f>c;)y=o[--w]%s,k=o[w]/s|0,b=g*y+k*d,y=d*y+b%s*s+a[f]+p,p=(y/l|0)+(b/s|0)+g*k,a[f--]=y%l;a[f]=p}return p?++e:a.shift(),et(n,a,e)};i.toExponential=function(n){var t=this;return t.c?rt(t,n==null||((e=n<0||n>o)||w(n)!=n&&n!==0)&&!f(n,"decimal places","toExponential")?null:n|0,1):t.toString()};i.toFixed=function(n){var t,i=this,r=p,u=k;return n=n==null||((e=n<0||n>o)||w(n)!=n&&n!==0)&&!f(n,"decimal places","toFixed")?null:i.e+(n|0),p=-(k=1/0),n!=null&&i.c?(t=rt(i,n),i.s<0&&i.c&&(i.c[0]?t.indexOf("-")<0&&(t="-"+t):t=t.replace("-",""))):t=i.toString(),p=r,k=u,t};i.toFormat=function(n){var f=this;if(!f.c)return f.toString();var t,h=f.s<0,c=b.groupSeparator,r=+b.groupSize,u=+b.secondaryGroupSize,l=f.toFixed(n).split("."),i=l[0],s=l[1],e=h?i.slice(1):i,o=e.length;if(u&&(t=r,r=u,u=t,o-=t),r>0&&o>0){for(t=o%r||r,i=e.substr(0,t);t<o;t+=r)i+=c+e.substr(t,r);u>0&&(i+=c+e.slice(t));h&&(i="-"+i)}return s?i+b.decimalSeparator+((u=+b.fractionGroupSize)?s.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+b.fractionGroupSeparator):s):i};i.toFraction=function(n){var ut,c,i,w,k,o,s,nt,rt,l=c=new t(it),y=s=new t(it),b=this,ft=b.c,p=new t(it);if(!ft)return b.toString();for(rt=tt(ft),w=p.e=rt.length-b.e-1,p.c[0]=st[(k=w%r)<0?r+k:k],(n==null||(!(u=12,o=new t(n)).s||(e=o.cmp(l)<0||!o.c)||d&&g(o.e/r)<o.c.length-1)&&!f(n,"max denominator","toFraction")||(n=o).cmp(p)>0)&&(n=w>0?p:l),k=v,v=1/0,o=new t(rt),s.c[0]=0;;){if(nt=a(o,p,0,1),i=c.plus(nt.times(y)),i.cmp(n)==1)break;c=y;y=i;l=s.plus(nt.times(i=l));s=i;p=o.minus(nt.times(i=p));o=i}return i=a(n.minus(c),y,0,1),s=s.plus(i.times(l)),c=c.plus(i.times(y)),s.s=l.s=b.s,w*=2,ut=a(l,y,w,h).minus(b).abs().cmp(a(s,c,w,h).minus(b).abs())<1?[l.toString(),y.toString()]:[s.toString(),c.toString()],v=k,ut};i.toNumber=function(){var n=this;return+n||(n.s?0*n.s:NaN)};i.toPower=i.pow=function(n){var i=n*0==0?~~n:n,r=new t(this),u=new t(it);if(((e=n<-ot||n>ot)&&(i=n/0)||w(n)!=n&&n!==0&&!(i=NaN))&&!f(n,"exponent","pow")||!i)return new t(Math.pow(+r,i));for(i=i<0?-i:i;;){if(i&1&&(u=u.times(r)),i>>=1,!i)break;r=r.times(r)}return n<0?it.div(u):u};i.toPrecision=function(n){var t=this;return n==null||((e=n<1||n>o)||w(n)!=n)&&!f(n,"precision","toPrecision")||!t.c?t.toString():rt(t,--n|0,2)};i.toString=function(n){var r,t,o,u=this,i=u.e;if(i===null)t=u.s?"Infinity":"NaN";else{if(n==r&&(i<=p||i>=k))return rt(u,r,1);if(t=tt(u.c),i<0){for(;++i;t="0"+t);t="0."+t}else if(o=t.length,i>0)if(++i>o)for(i-=o;i--;t+="0");else i<o&&(t=t.slice(0,i)+"."+t.slice(i));else if(r=t.charAt(0),o>1)t=r+"."+t.slice(1);else if(r=="0")return r;if(n!=null)if((e=!(n>=2&&n<65))||n!=~~n&&d)f(n,"base","toS");else if(t=ct(t,n|0,10,u.s),t=="0")return t}return u.s<0?"-"+t:t};i.valueOf=i.toJSON=function(){return this.toString()};typeof module!="undefined"&&module.exports?module.exports=t:typeof define=="function"&&define.amd?define(function(){return t}):n.BigNumber=t})(this) | ||
/*! bignumber.js v2.0.1 https://github.com/MikeMcl/bignumber.js/LICENCE */ | ||
(function(n){"use strict";function it(n){function a(n,i){var h,e,f,s,o,r,u=this;if(!(u instanceof a))return ht&<(26,"constructor call without new",n),new a(n,i);if(i!=null&&ot(i,2,64,st,"base")){if(i=i|0,r=n+"",i==10)return u=new a(n instanceof a?n:r),at(u,yt+u.e+1,ct);if((s=typeof n=="number")&&n*0!=0||!new RegExp("^-?"+(h="["+b.slice(0,i)+"]+")+"(?:\\."+h+")?$",i<37?"i":"").test(r))return y(u,r,s,i);s?(u.s=1/n<0?(r=r.slice(1),-1):1,ht&&r.replace(/^0\.0*|\./,"").length>15&<(st,tt,n),s=!1):u.s=r.charCodeAt(0)===45?(r=r.slice(1),-1):1;r=fi(r,10,i,u.s)}else{if(n instanceof a){u.s=n.s;u.e=n.e;u.c=(n=n.c)?n.slice():n;st=0;return}if((s=typeof n=="number")&&n*0==0){if(u.s=1/n<0?(n=-n,-1):1,n===~~n){for(e=0,f=n;f>=10;f/=10,e++);u.e=e;u.c=[n];st=0;return}r=n+""}else{if(!ut.test(r=n+""))return y(u,r,s);u.s=r.charCodeAt(0)===45?(r=r.slice(1),-1):1}}for((e=r.indexOf("."))>-1&&(r=r.replace(".","")),(f=r.search(/e/i))>0?(e<0&&(e=f),e+=+r.slice(f+1),r=r.substring(0,f)):e<0&&(e=r.length),f=0;r.charCodeAt(f)===48;f++);for(o=r.length;r.charCodeAt(--o)===48;);if(r=r.slice(f,o+1),r)if(o=r.length,s&&ht&&o>15&<(st,tt,u.s*n),e=e-f-1,e>pt)u.c=u.e=null;else if(e<gt)u.c=[u.e=0];else{if(u.e=e,u.c=[],f=(e+1)%t,e<0&&(f+=t),f<o){for(f&&u.c.push(+r.slice(0,f)),o-=t;f<o;)u.c.push(+r.slice(f,f+=t));r=r.slice(f);f=t-r.length}else f-=o;for(;f--;r+="0");u.c.push(+r)}else u.c=[u.e=0];st=0}function fi(n,t,i,r){var e,v,o,l,f,u,p,h=n.indexOf("."),w=yt,y=ct;for(i<37&&(n=n.toLowerCase()),h>=0&&(o=bt,bt=0,n=n.replace(".",""),p=new a(i),f=p.pow(n.length-h),bt=o,p.c=rt(c(s(f.c),f.e),10,t),p.e=p.c.length),u=rt(n,i,t),v=o=u.length;u[--o]==0;u.pop());if(!u[0])return"0";if(h<0?--v:(f.c=u,f.e=v,f.s=r,f=vt(f,p,w,y,t),u=f.c,l=f.r,v=f.e),e=v+w+1,h=u[e],o=t/2,l=l||e<0||u[e+1]!=null,l=y<4?(h!=null||l)&&(y==0||y==(f.s<0?3:2)):h>o||h==o&&(y==4||l||y==6&&u[e-1]&1||y==(f.s<0?8:7)),e<1||!u[0])n=l?c("1",-w):"0";else{if(u.length=e,l)for(--t;++u[--e]>t;)u[e]=0,e||(++v,u.unshift(1));for(o=u.length;!u[--o];);for(h=0,n="";h<=o;n+=b.charAt(u[h++]));n=c(n,v)}return n}function ri(n,t,i,r){var h,f,o,e,u;if(i=i!=null&&ot(i,0,8,r,w)?i|0:ct,!n.c)return n.toString();if(h=n.c[0],o=n.e,t==null)u=s(n.c),u=r==19||r==24&&o<=dt?g(u,o):c(u,o);else if(n=at(new a(n),t,i),f=n.e,u=s(n.c),e=u.length,r==19||r==24&&(t<=f||f<=dt)){for(;e<t;u+="0",e++);u=g(u,f)}else if(t-=o,u=c(u,f),f+1>e){if(--t>0)for(u+=".";t--;u+="0");}else if(t+=f-e,t>0)for(f+1==e&&(u+=".");t--;u+="0");return n.s<0&&h?"-"+u:u}function ei(n,t){var i,r,u=0;for(d(n[0])&&(n=n[0]),i=new a(n[0]);++u<n.length;)if(r=new a(n[u]),r.s)t.call(i,r)&&(i=r);else{i=r;break}return i}function oi(n,t,i,r,u){return(n<t||n>i||n!=nt(n))&<(r,(u||"decimal places")+(n<t||n>i?" out of range":" not an integer"),n),!0}function ui(n,i,r){for(var f=1,u=i.length;!i[--u];i.pop());for(u=i[0];u>=10;u/=10,f++);return(r=f+r*t-1)>pt?n.c=n.e=null:r<gt?n.c=[n.e=0]:(n.e=r,n.c=i),n}function lt(n,t,i){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"][n]+"() "+t+": "+i);r.name="BigNumber Error";st=0;throw r;}function at(n,i,r,u){var a,h,s,c,y,l,w,o=n.c,p=k;if(o){n:{for(a=1,c=o[0];c>=10;c/=10,a++);if(h=i-a,h<0)h+=t,s=i,y=o[l=0],w=y/p[a-s-1]%10|0;else if(l=v((h+1)/t),l>=o.length)if(u){for(;o.length<=l;o.push(0));y=w=0;a=1;h%=t;s=h-t+1}else break n;else{for(y=c=o[l],a=1;c>=10;c/=10,a++);h%=t;s=h-t+a;w=s<0?0:y/p[a-s-1]%10|0}if(u=u||i<0||o[l+1]!=null||(s<0?y:y%p[a-s-1]),u=r<4?(w||u)&&(r==0||r==(n.s<0?3:2)):w>5||w==5&&(r==4||u||r==6&&(h>0?s>0?y/p[a-s]:0:o[l-1])%10&1||r==(n.s<0?8:7)),i<1||!o[0])return o.length=0,u?(i-=n.e+1,o[0]=p[i%t],n.e=-i||0):o[0]=n.e=0,n;if(h==0?(o.length=l,c=1,l--):(o.length=l+1,c=p[t-h],o[l]=s>0?e(y/p[a-s]%p[s])*c:0),u)for(;;)if(l==0){for(h=1,s=o[0];s>=10;s/=10,h++);for(s=o[0]+=c,c=1;s>=10;s/=10,c++);h!=c&&(n.e++,o[0]==f&&(o[0]=1));break}else{if(o[l]+=c,o[l]!=f)break;o[l--]=0;c=1}for(h=o.length;o[--h]===0;o.pop());}n.e>pt?n.c=n.e=null:n.e<gt&&(n.c=[n.e=0])}return n}var vt,st=0,et=a.prototype,wt=new a(1),yt=20,ct=4,dt=-7,ni=21,gt=-1e7,pt=1e7,ht=!0,ot=oi,ti=!1,ii=1,bt=100,kt={decimalSeparator:".",groupSeparator:",",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:" ",fractionGroupSize:0};return a.another=it,a.ROUND_UP=0,a.ROUND_DOWN=1,a.ROUND_CEIL=2,a.ROUND_FLOOR=3,a.ROUND_HALF_UP=4,a.ROUND_HALF_DOWN=5,a.ROUND_HALF_EVEN=6,a.ROUND_HALF_CEIL=7,a.ROUND_HALF_FLOOR=8,a.EUCLID=9,a.config=function(){var n,t,s=0,u={},o=arguments,e=o[0],f=e&&typeof e=="object"?function(){if(e.hasOwnProperty(t))return(n=e[t])!=null}:function(){if(o.length>s)return(n=o[s++])!=null};return f(t="DECIMAL_PLACES")&&ot(n,0,i,2,t)&&(yt=n|0),u[t]=yt,f(t="ROUNDING_MODE")&&ot(n,0,8,2,t)&&(ct=n|0),u[t]=ct,f(t="EXPONENTIAL_AT")&&(d(n)?ot(n[0],-i,0,2,t)&&ot(n[1],0,i,2,t)&&(dt=n[0]|0,ni=n[1]|0):ot(n,-i,i,2,t)&&(dt=-(ni=(n<0?-n:n)|0))),u[t]=[dt,ni],f(t="RANGE")&&(d(n)?ot(n[0],-i,-1,2,t)&&ot(n[1],1,i,2,t)&&(gt=n[0]|0,pt=n[1]|0):ot(n,-i,i,2,t)&&(n|0?gt=-(pt=(n<0?-n:n)|0):ht&<(2,t+" cannot be zero",n))),u[t]=[gt,pt],f(t="ERRORS")&&(n===!!n||n===1||n===0?(st=0,ot=(ht=!!n)?oi:ft):ht&<(2,t+p,n)),u[t]=ht,f(t="CRYPTO")&&(n===!!n||n===1||n===0?(ti=!!(n&&r&&typeof r=="object"),n&&!ti&&ht&<(2,"crypto unavailable",r)):ht&<(2,t+p,n)),u[t]=ti,f(t="MODULO_MODE")&&ot(n,0,9,2,t)&&(ii=n|0),u[t]=ii,f(t="POW_PRECISION")&&ot(n,0,i,2,t)&&(bt=n|0),u[t]=bt,f(t="FORMAT")&&(typeof n=="object"?kt=n:ht&<(2,t+" not an object",n)),u[t]=kt,u},a.max=function(){return ei(arguments,et.lt)},a.min=function(){return ei(arguments,et.gt)},a.random=function(){var n=9007199254740992,u=Math.random()*n&2097151?function(){return e(Math.random()*n)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(n){var s,y,l,c,o,f=0,h=[],p=new a(wt);if(n=n==null||!ot(n,0,i,14)?yt:n|0,c=v(n/t),ti)if(r&&r.getRandomValues){for(s=r.getRandomValues(new Uint32Array(c*=2));f<c;)o=s[f]*131072+(s[f+1]>>>11),o>=9e15?(y=r.getRandomValues(new Uint32Array(2)),s[f]=y[0],s[f+1]=y[1]):(h.push(o%1e14),f+=2);f=c/2}else if(r&&r.randomBytes){for(s=r.randomBytes(c*=7);f<c;)o=(s[f]&31)*281474976710656+s[f+1]*1099511627776+s[f+2]*4294967296+s[f+3]*16777216+(s[f+4]<<16)+(s[f+5]<<8)+s[f+6],o>=9e15?r.randomBytes(7).copy(s,f):(h.push(o%1e14),f+=7);f=c/7}else ht&<(14,"crypto unavailable",r);if(!f)for(;f<c;)o=u(),o<9e15&&(h[f++]=o%1e14);for(c=h[--f],n%=t,c&&n&&(o=k[t-n],h[f]=e(c/o)*o);h[f]===0;h.pop(),f--);if(f<0)h=[l=0];else{for(l=-1;h[0]===0;h.shift(),l-=t);for(f=1,o=h[0];o>=10;o/=10,f++);f<t&&(l-=t-f)}return p.e=l,p.c=h,p}}(),vt=function(){function n(n,t,i){var f,e,s,h,r=0,u=n.length,c=t%o,l=t/o|0;for(n=n.slice();u--;)s=n[u]%o,h=n[u]/o|0,f=l*s+h*c,e=c*s+f%o*o+r,r=(e/i|0)+(f/o|0)+l*h,n[u]=e%i;return r&&n.unshift(r),n}function i(n,t,i,r){var u,f;if(i!=r)f=i>r?1:-1;else for(u=f=0;u<i;u++)if(n[u]!=t[u]){f=n[u]>t[u]?1:-1;break}return f}function r(n,t,i,r){for(var u=0;i--;)n[i]-=u,u=n[i]<t[i]?1:0,n[i]=u*r+n[i]-t[i];for(;!n[0]&&n.length>1;n.shift());}return function(o,s,h,c,l){var g,rt,d,et,p,tt,ut,it,ft,y,w,ot,st,ct,lt,nt,ht,k=o.s==s.s?1:-1,b=o.c,v=s.c;if(!b||!b[0]||!v||!v[0])return new a(!o.s||!s.s||(b?v&&b[0]==v[0]:!v)?NaN:b&&b[0]==0||!v?k*0:k/0);for(it=new a(k),ft=it.c=[],rt=o.e-s.e,k=h+rt+1,l||(l=f,rt=u(o.e/t)-u(s.e/t),k=k/t|0),d=0;v[d]==(b[d]||0);d++);if(v[d]>(b[d]||0)&&rt--,k<0)ft.push(1),et=!0;else{for(ct=b.length,nt=v.length,d=0,k+=2,p=e(l/(v[0]+1)),p>1&&(v=n(v,p,l),b=n(b,p,l),nt=v.length,ct=b.length),st=nt,y=b.slice(0,nt),w=y.length;w<nt;y[w++]=0);ht=v.slice();ht.unshift(0);lt=v[0];v[1]>=l/2&<++;do p=0,g=i(v,y,nt,w),g<0?(ot=y[0],nt!=w&&(ot=ot*l+(y[1]||0)),p=e(ot/lt),p>1?(p>=l&&(p=l-1),tt=n(v,p,l),ut=tt.length,w=y.length,g=i(tt,y,ut,w),g==1&&(p--,r(tt,nt<ut?ht:v,ut,l))):(p==0&&(g=p=1),tt=v.slice()),ut=tt.length,ut<w&&tt.unshift(0),r(y,tt,w,l),g==-1&&(w=y.length,g=i(v,y,nt,w),g<1&&(p++,r(y,nt<w?ht:v,w,l))),w=y.length):g===0&&(p++,y=[0]),ft[d++]=p,g&&y[0]?y[w++]=b[st]||0:(y=[b[st]],w=1);while((st++<ct||y[0]!=null)&&k--);et=y[0]!=null;ft[0]||ft.shift()}if(l==f){for(d=1,k=ft[0];k>=10;k/=10,d++);at(it,h+(it.e=d+rt*t-1)+1,c,et)}else it.e=rt,it.r=+et;return it}}(),y=function(){var n=/^(-?)0([xbo])(?=\w[\w.]*$)/i,t=/^([^.]+)\.$/,i=/^\.([^.]+)$/,r=/^-?(Infinity|NaN)$/,u=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(f,e,o,s){var c,h=o?e:e.replace(u,"");if(r.test(h))f.s=isNaN(h)?null:h<0?-1:1;else{if(!o&&(h=h.replace(n,function(n,t,i){return c=(i=i.toLowerCase())=="x"?16:i=="b"?2:8,!s||s==c?t:n}),s&&(c=s,h=h.replace(t,"$1").replace(i,"0.$1")),e!=h))return new a(h,c);ht&<(st,"not a"+(s?" base "+s:"")+" number",e);f.s=null}f.c=f.e=null;st=0}}(),et.absoluteValue=et.abs=function(){var n=new a(this);return n.s<0&&(n.s=1),n},et.ceil=function(){return at(new a(this),this.e+1,2)},et.comparedTo=et.cmp=function(n,t){return st=1,l(this,new a(n,t))},et.decimalPlaces=et.dp=function(){var n,i,r=this.c;if(!r)return null;if(n=((i=r.length-1)-u(this.e/t))*t,i=r[i])for(;i%10==0;i/=10,n--);return n<0&&(n=0),n},et.dividedBy=et.div=function(n,t){return st=3,vt(this,new a(n,t),yt,ct)},et.dividedToIntegerBy=et.divToInt=function(n,t){return st=4,vt(this,new a(n,t),0,1)},et.equals=et.eq=function(n,t){return st=5,l(this,new a(n,t))===0},et.floor=function(){return at(new a(this),this.e+1,3)},et.greaterThan=et.gt=function(n,t){return st=6,l(this,new a(n,t))>0},et.greaterThanOrEqualTo=et.gte=function(n,t){return st=7,(t=l(this,new a(n,t)))===1||t===0},et.isFinite=function(){return!!this.c},et.isInteger=et.isInt=function(){return!!this.c&&u(this.e/t)>this.c.length-2},et.isNaN=function(){return!this.s},et.isNegative=et.isNeg=function(){return this.s<0},et.isZero=function(){return!!this.c&&this.c[0]==0},et.lessThan=et.lt=function(n,t){return st=8,l(this,new a(n,t))<0},et.lessThanOrEqualTo=et.lte=function(n,t){return st=9,(t=l(this,new a(n,t)))===-1||t===0},et.minus=et.sub=function(n,i){var h,s,c,p,v=this,o=v.s;if(st=10,n=new a(n,i),i=n.s,!o||!i)return new a(NaN);if(o!=i)return n.s=-i,v.plus(n);var y=v.e/t,l=n.e/t,r=v.c,e=n.c;if(!y||!l){if(!r||!e)return r?(n.s=-i,n):new a(e?v:NaN);if(!r[0]||!e[0])return e[0]?(n.s=-i,n):new a(r[0]?v:ct==3?-0:0)}if(y=u(y),l=u(l),r=r.slice(),o=y-l){for((p=o<0)?(o=-o,c=r):(l=y,c=e),c.reverse(),i=o;i--;c.push(0));c.reverse()}else for(s=(p=(o=r.length)<(i=e.length))?o:i,o=i=0;i<s;i++)if(r[i]!=e[i]){p=r[i]<e[i];break}if(p&&(c=r,r=e,e=c,n.s=-n.s),i=(s=e.length)-(h=r.length),i>0)for(;i--;r[h++]=0);for(i=f-1;s>o;){if(r[--s]<e[s]){for(h=s;h&&!r[--h];r[h]=i);--r[h];r[s]+=f}r[s]-=e[s]}for(;r[0]==0;r.shift(),--l);return r[0]?ui(n,r,l):(n.s=ct==3?-1:1,n.c=[n.e=0],n)},et.modulo=et.mod=function(n,t){var r,u,i=this;if(st=11,n=new a(n,t),i.c&&n.s&&(!n.c||n.c[0])){if(!n.c||i.c&&!i.c[0])return new a(i)}else return new a(NaN);return ii==9?(u=n.s,n.s=1,r=vt(i,n,0,3),n.s=u,r.s*=u):r=vt(i,n,0,ii),i.minus(r.times(n))},et.negated=et.neg=function(){var n=new a(this);return n.s=-n.s||null,n},et.plus=et.add=function(n,i){var s,c=this,r=c.s;if(st=12,n=new a(n,i),i=n.s,!r||!i)return new a(NaN);if(r!=i)return n.s=-i,c.minus(n);var l=c.e/t,h=n.e/t,e=c.c,o=n.c;if(!l||!h){if(!e||!o)return new a(r/0);if(!e[0]||!o[0])return o[0]?n:new a(e[0]?c:r*0)}if(l=u(l),h=u(h),e=e.slice(),r=l-h){for(r>0?(h=l,s=o):(r=-r,s=e),s.reverse();r--;s.push(0));s.reverse()}for(r=e.length,i=o.length,r-i<0&&(s=o,o=e,e=s,i=r),r=0;i;)r=(e[--i]=e[i]+o[i]+r)/f|0,e[i]%=f;return r&&(e.unshift(r),++h),ui(n,e,h)},et.precision=et.sd=function(n){var r,i,f=this,u=f.c;if(n!=null&&n!==!!n&&n!==1&&n!==0&&(ht&<(13,"argument"+p,n),n!=!!n&&(n=null)),!u)return null;if(i=u.length-1,r=i*t+1,i=u[i]){for(;i%10==0;i/=10,r--);for(i=u[0];i>=10;i/=10,r++);}return n&&f.e+1>r&&(r=f.e+1),r},et.round=function(n,t){var r=new a(this);return(n==null||ot(n,0,i,15))&&at(r,~~n+this.e+1,t==null||!ot(t,0,8,15,w)?ct:t|0),r},et.shift=function(n){var t=this;return ot(n,-h,h,16,"argument")?t.times("1e"+nt(n)):new a(t.c&&t.c[0]&&(n<-h||n>h)?t.s*(n<0?0:1/0):t)},et.squareRoot=et.sqrt=function(){var l,t,i,h,f,e=this,o=e.c,n=e.s,r=e.e,c=yt+4,v=new a("0.5");if(n!==1||!o||!o[0])return new a(!n||n<0&&(!o||o[0])?NaN:o?e:1/0);if(n=Math.sqrt(+e),n==0||n==1/0?(t=s(o),(t.length+r)%2==0&&(t+="0"),n=Math.sqrt(t),r=u((r+1)/2)-(r<0||r%2),n==1/0?t="1e"+r:(t=n.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),i=new a(t)):i=new a(n+""),i.c[0])for(r=i.e,n=r+c,n<3&&(n=0);;)if(f=i,i=v.times(f.plus(vt(e,f,c,1))),s(f.c).slice(0,n)===(t=s(i.c)).slice(0,n))if(i.e<r&&--n,t=t.slice(n-3,n+1),t!="9999"&&(h||t!="4999")){+t&&(+t.slice(1)||t.charAt(0)!="5")||(at(i,i.e+yt+2,1),l=!i.times(i).eq(e));break}else{if(!h&&(at(f,f.e+yt+2,0),f.times(f).eq(e))){i=f;break}c+=4;n+=4;h=1}return at(i,i.e+yt+1,ct,l)},et.times=et.mul=function(n,i){var p,d,s,w,k,g,l,v,nt,y,tt,it,h,rt,c,b=this,r=b.c,e=(st=17,n=new a(n,i)).c;if(!r||!e||!r[0]||!e[0])return b.s&&n.s&&(!r||r[0]||e)&&(!e||e[0]||r)?(n.s*=b.s,r&&e?(n.c=[0],n.e=0):n.c=n.e=null):n.c=n.e=n.s=null,n;for(d=u(b.e/t)+u(n.e/t),n.s*=b.s,l=r.length,y=e.length,l<y&&(h=r,r=e,e=h,s=l,l=y,y=s),s=l+y,h=[];s--;h.push(0));for(rt=f,c=o,s=y;--s>=0;){for(p=0,tt=e[s]%c,it=e[s]/c|0,k=l,w=s+k;w>s;)v=r[--k]%c,nt=r[k]/c|0,g=it*v+nt*tt,v=tt*v+g%c*c+h[w]+p,p=(v/rt|0)+(g/c|0)+it*nt,h[w--]=v%rt;h[w]=p}return p?++d:h.shift(),ui(n,h,d)},et.toDigits=function(n,t){var r=new a(this);return n=n==null||!ot(n,1,i,18,"precision")?null:n|0,t=t==null||!ot(t,0,8,18,w)?ct:t|0,n?at(r,n,t):r},et.toExponential=function(n,t){return ri(this,n!=null&&ot(n,0,i,19)?~~n+1:null,t,19)},et.toFixed=function(n,t){return ri(this,n!=null&&ot(n,0,i,20)?~~n+this.e+1:null,t,20)},et.toFormat=function(n,t){var h=ri(this,n!=null&&ot(n,0,i,21)?~~n+this.e+1:null,t,21);if(this.c){var r,l=h.split("."),f=+kt.groupSize,e=+kt.secondaryGroupSize,a=kt.groupSeparator,u=l[0],c=l[1],v=this.s<0,o=v?u.slice(1):u,s=o.length;if(e&&(r=f,f=e,e=r,s-=r),f>0&&s>0){for(r=s%f||f,u=o.substr(0,r);r<s;r+=f)u+=a+o.substr(r,f);e>0&&(u+=a+o.slice(r));v&&(u="-"+u)}h=c?u+kt.decimalSeparator+((e=+kt.fractionGroupSize)?c.replace(new RegExp("\\d{"+e+"}\\B","g"),"$&"+kt.fractionGroupSeparator):c):u}return h},et.toFraction=function(n){var b,f,r,c,v,i,u,y,w,p=ht,l=this,d=l.c,e=new a(wt),o=f=new a(wt),h=u=new a(wt);if(n!=null&&(ht=!1,i=new a(n),ht=p,(p=i.isInt())&&!i.lt(wt)||(ht&<(22,"max denominator "+(p?"out of range":"not an integer"),n),n=!p&&i.c&&at(i,i.e+1,1).gte(wt)?i:null)),!d)return l.toString();for(w=s(d),c=e.e=w.length-l.e-1,e.c[0]=k[(v=c%t)<0?t+v:v],n=!n||i.cmp(e)>0?c>0?e:o:i,v=pt,pt=1/0,i=new a(w),u.c[0]=0;;){if(y=vt(i,e,0,1),r=f.plus(y.times(h)),r.cmp(n)==1)break;f=h;h=r;o=u.plus(y.times(r=o));u=r;e=i.minus(y.times(r=e));i=r}return r=vt(n.minus(f),h,0,1),u=u.plus(r.times(o)),f=f.plus(r.times(h)),u.s=o.s=l.s,c*=2,b=vt(o,h,c,ct).minus(l).abs().cmp(vt(u,f,c,ct).minus(l).abs())<1?[o.toString(),h.toString()]:[u.toString(),f.toString()],pt=v,b},et.toNumber=function(){var n=this;return+n||(n.s?n.s*0:NaN)},et.toPower=et.pow=function(n){var r,i,f=e(n<0?-n:+n),u=this;if(!ot(n,-h,h,23,"exponent")&&(!isFinite(n)||f>h&&(n/=0)||parseFloat(n)!=n&&!(n=NaN)))return new a(Math.pow(+u,n));for(r=bt?v(bt/t+2):0,i=new a(wt);;){if(f%2){if(i=i.times(u),!i.c)break;r&&i.c.length>r&&(i.c.length=r)}if(f=e(f/2),!f)break;u=u.times(u);r&&u.c&&u.c.length>r&&(u.c.length=r)}return n<0&&(i=wt.div(i)),r?at(i,bt,ct):i},et.toPrecision=function(n,t){return ri(this,n!=null&&ot(n,1,i,24,"precision")?n|0:null,t,24)},et.toString=function(n){var t,r=this,u=r.s,i=r.e;return i===null?u?(t="Infinity",u<0&&(t="-"+t)):t="NaN":(t=s(r.c),t=n!=null&&ot(n,2,64,25,"base")?fi(c(t,i),n|0,10,u):i<=dt||i>=ni?g(t,i):c(t,i),u<0&&r.c[0]&&(t="-"+t)),t},et.truncated=et.trunc=function(){return at(new a(this),this.e+1,1)},et.valueOf=et.toJSON=function(){return this.toString()},n!=null&&a.config(n),a}function u(n){var t=n|0;return n>0||n===t?t:t-1}function s(n){for(var i,f,e=1,r=n.length,u=n[0]+"";e<r;){for(i=n[e++]+"",f=t-i.length;f--;i="0"+i);u+=i}for(r=u.length;u.charCodeAt(--r)===48;);return u.slice(0,r+1||1)}function l(n,t){var r,f,u=n.c,e=t.c,i=n.s,h=t.s,o=n.e,s=t.e;if(!i||!h)return null;if(r=u&&!u[0],f=e&&!e[0],r||f)return r?f?0:-h:i;if(i!=h)return i;if(r=i<0,f=o==s,!u||!e)return f?0:!u^r?1:-1;if(!f)return o>s^r?1:-1;for(h=(o=u.length)<(s=e.length)?o:s,i=0;i<h;i++)if(u[i]!=e[i])return u[i]>e[i]^r?1:-1;return o==s?0:o>s^r?1:-1}function ft(n,t,i){return(n=nt(n))>=t&&n<=i}function d(n){return Object.prototype.toString.call(n)=="[object Array]"}function rt(n,t,i){for(var u,r=[0],f,e=0,o=n.length;e<o;){for(f=r.length;f--;r[f]*=t);for(r[u=0]+=b.indexOf(n.charAt(e++));u<r.length;u++)r[u]>i-1&&(r[u+1]==null&&(r[u+1]=0),r[u+1]+=r[u]/i|0,r[u]%=i)}return r.reverse()}function g(n,t){return(n.length>1?n.charAt(0)+"."+n.slice(1):n)+(t<0?"e":"e+")+t}function c(n,t){var r,i;if(t<0){for(i="0.";++t;i+="0");n=i+n}else if(r=n.length,++t>r){for(i="0",t-=r;--t;i+="0");n+=i}else t<r&&(n=n.slice(0,t)+"."+n.slice(t));return n}function nt(n){return n=parseFloat(n),n<0?v(n):e(n)}var a,r,y,ut=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,v=Math.ceil,e=Math.floor,p=" not a boolean or binary digit",w="rounding mode",tt="number type has more than 15 significant digits",b="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_",f=1e14,t=14,h=9007199254740991,k=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],o=1e7,i=1e9;if(a=it(),typeof define=="function"&&define.amd)define(function(){return a});else if(typeof module!="undefined"&&module.exports){if(module.exports=a,!r)try{r=require("crypto")}catch(et){}}else n.BigNumber=a})(this) |
{ | ||
"name": "bignumber.js", | ||
"description": "A library for arbitrary-precision decimal and non-decimal arithmetic", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"keywords": [ | ||
@@ -34,4 +34,4 @@ "arbitrary", | ||
"test": "node ./test/every-test.js", | ||
"build": "uglifyjs bignumber.js -c -m -o bignumber.min.js --preamble '/* bignumber.js v2.0.0 https://github.com/MikeMcl/bignumber.js/LICENCE */'" | ||
"build": "uglifyjs bignumber.js -c -m -o bignumber.min.js --preamble '/* bignumber.js v2.0.1 https://github.com/MikeMcl/bignumber.js/LICENCE */'" | ||
} | ||
} |
254
README.md
@@ -1,8 +0,8 @@ | ||
[![Build Status](https://travis-ci.org/MikeMcl/bignumber.js.svg)](https://travis-ci.org/MikeMcl/bignumber.js) | ||
![bignumber.js](https://raw.githubusercontent.com/MikeMcl/bignumber.js/gh-pages/bignumberjs.png) | ||
# bignumber.js # | ||
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic. | ||
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic. | ||
[![Build Status](https://travis-ci.org/MikeMcl/bignumber.js.svg)](https://travis-ci.org/MikeMcl/bignumber.js) | ||
*Note: This is version 2 of the library, for version 1.x.x see the tagged releases or switch to the 'original' branch. The advantages of version 2 are that it is considerably faster for numbers with many digits and that there are a few added methods (see Change Log below). The disadvantages are more lines of code and increased code complexity, and the loss of simplicity in no longer having the coefficient of a BigNumber stored in base 10. The 'original' version will continue to be supported.* | ||
<br /> | ||
@@ -12,3 +12,3 @@ ## Features | ||
- Faster, smaller, and perhaps easier to use than JavaScript versions of Java's BigDecimal | ||
- 6 KB minified and gzipped | ||
- 8 KB minified and gzipped | ||
- Simple API but full-featured | ||
@@ -18,11 +18,15 @@ - Works with numbers with or without fraction digits in bases from 2 to 64 inclusive | ||
- Includes a `toFraction` and a correctly-rounded `squareRoot` method | ||
- Supports cryptographically-secure pseudo-random number generation | ||
- No dependencies | ||
- ECMAScript 3 compliant | ||
- Wide platform compatibility: uses JavaScript 1.5 (ECMAScript 3) features only | ||
- Comprehensive [documentation](http://mikemcl.github.io/bignumber.js/) and test set | ||
![API](https://raw.githubusercontent.com/MikeMcl/bignumber.js/gh-pages/API.png) | ||
If an even smaller and simpler library is required see [big.js](https://github.com/MikeMcl/big.js/). | ||
It's half the size but only works with decimal numbers and only has half the methods. | ||
It also does not allow `NaN` or `Infinity`, or have the configuration options of this library. | ||
See also [decimal.js](https://github.com/MikeMcl/decimal.js/). | ||
If a smaller and simpler library is required see [big.js](https://github.com/MikeMcl/big.js/). | ||
It's less than half the size but only works with decimal numbers and only has half the methods. | ||
It also does not allow `NaN` or `Infinity`, or have the configuration options of this library. | ||
See also [decimal.js](https://github.com/MikeMcl/decimal.js/), which among other things adds support for non-integer powers, and performs all operations to a specified number of significant digits. | ||
## Load | ||
@@ -32,25 +36,21 @@ | ||
It can be loaded via a script tag in an HTML document for the browser | ||
```html | ||
<script src='relative/path/to/bignumber.js'></script> | ||
``` | ||
<script src='./relative/path/to/bignumber.js'></script> | ||
For [Node.js](http://nodejs.org) or [io.js](https://iojs.org/en/index.html), the library is available from the [npm](https://npmjs.org/) registry | ||
or as a CommonJS, [Node.js](http://nodejs.org) or AMD module using `require`. | ||
For Node, put the *bignumber.js* file into the same directory as the file that is requiring it and use | ||
var BigNumber = require('./bignumber.js'); | ||
or put it in a *node_modules* directory within the directory and use `require('bignumber.js')`. | ||
The library is also available from the [npm](https://npmjs.org/) registry, so | ||
$ npm install bignumber.js | ||
will install this directory in a *node_modules* directory within the current directory. | ||
```javascript | ||
var BigNumber = require('bignumber.js'); | ||
``` | ||
To load with AMD loader libraries such as [requireJS](http://requirejs.org/): | ||
require(['path/to/bignumber'], function(BigNumber) { | ||
// Use BigNumber here in local scope. No global BigNumber. | ||
}); | ||
```javascript | ||
require(['path/to/bignumber'], function(BigNumber) { | ||
// Use BigNumber here in local scope. No global BigNumber. | ||
}); | ||
``` | ||
@@ -62,87 +62,132 @@ ## Use | ||
The library exports a single function: BigNumber, the constructor of BigNumber instances. | ||
It accepts a value of type Number *(up to 15 significant digits only)*, String or BigNumber Object, | ||
The library exports a single function: `BigNumber`, the constructor of BigNumber instances. | ||
x = new BigNumber(123.4567) | ||
y = BigNumber('123456.7e-3') // 'new' is optional | ||
z = new BigNumber(x) | ||
x.equals(y) && y.equals(z) && x.equals(z) // true | ||
It accepts a value of type number *(up to 15 significant digits only)*, string or BigNumber object, | ||
```javascript | ||
x = new BigNumber(123.4567) | ||
y = BigNumber('123456.7e-3') | ||
z = new BigNumber(x) | ||
x.equals(y) && y.equals(z) && x.equals(z) // true | ||
``` | ||
and a base from 2 to 64 inclusive can be specified. | ||
x = new BigNumber(1011, 2) // "11" | ||
y = new BigNumber('zz.9', 36) // "1295.25" | ||
z = x.plus(y) // "1306.25" | ||
```javascript | ||
x = new BigNumber(1011, 2) // "11" | ||
y = new BigNumber('zz.9', 36) // "1295.25" | ||
z = x.plus(y) // "1306.25" | ||
``` | ||
A BigNumber is immutable in the sense that it is not changed by its methods. | ||
0.3 - 0.1 // 0.19999999999999998 | ||
x = new BigNumber(0.3) | ||
x.minus(0.1) // "0.2" | ||
x // "0.3" | ||
```javascript | ||
0.3 - 0.1 // 0.19999999999999998 | ||
x = new BigNumber(0.3) | ||
x.minus(0.1) // "0.2" | ||
x // "0.3" | ||
``` | ||
The methods that return a BigNumber can be chained. | ||
x.dividedBy(y).plus(z).times(9).floor() | ||
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').ceil() | ||
```javascript | ||
x.dividedBy(y).plus(z).times(9).floor() | ||
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').ceil() | ||
``` | ||
Many method names have a shorter alias. | ||
x.squareRoot().dividedBy(y).toPower(3).equals(x.sqrt().div(y).pow(3)) // true | ||
x.cmp(y.mod(z).neg()) == 1 && x.comparedTo(y.modulo(z).negated()) == 1 // true | ||
```javascript | ||
x.squareRoot().dividedBy(y).toPower(3).equals(x.sqrt().div(y).pow(3)) // true | ||
x.cmp(y.mod(z).neg()) == 1 && x.comparedTo(y.modulo(z).negated()) == 1 // true | ||
``` | ||
Like JavaScript's Number type, there are `toExponential`, `toFixed` and `toPrecision` methods | ||
Like JavaScript's number type, there are `toExponential`, `toFixed` and `toPrecision` methods | ||
x = new BigNumber(255.5) | ||
x.toExponential(5) // "2.55500e+2" | ||
x.toFixed(5) // "255.50000" | ||
x.toPrecision(5) // "255.50" | ||
x.toNumber() // 255.5 | ||
```javascript | ||
x = new BigNumber(255.5) | ||
x.toExponential(5) // "2.55500e+2" | ||
x.toFixed(5) // "255.50000" | ||
x.toPrecision(5) // "255.50" | ||
x.toNumber() // 255.5 | ||
``` | ||
and a base can be specified for `toString`. | ||
x.toString(16) // "ff.8" | ||
```javascript | ||
x.toString(16) // "ff.8" | ||
``` | ||
There is also a `toFormat` method which may be useful for internationalisation | ||
y = new BigNumber('1234567.898765') | ||
y.toFormat(2) // "1,234,567.90" | ||
```javascript | ||
y = new BigNumber('1234567.898765') | ||
y.toFormat(2) // "1,234,567.90" | ||
``` | ||
The maximum number of decimal places of the result of an operation involving division (i.e. a division, square root, base conversion or negative power operation) is set using the `config` method of the `BigNumber` constructor. | ||
The other arithmetic operations always give the exact result. | ||
BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: 4 }) | ||
// Alternatively, BigNumber.config( 10, 4 ); | ||
```javascript | ||
BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: 4 }) | ||
// Alternatively, BigNumber.config( 10, 4 ); | ||
x = new BigNumber(2); | ||
y = new BigNumber(3); | ||
z = x.div(y) // "0.6666666667" | ||
z.sqrt() // "0.8164965809" | ||
z.pow(-3) // "3.3749999995" | ||
z.toString(2) // "0.1010101011" | ||
z.times(z) // "0.44444444448888888889" | ||
z.times(z).round(10) // "0.4444444445" | ||
x = new BigNumber(2); | ||
y = new BigNumber(3); | ||
z = x.div(y) // "0.6666666667" | ||
z.sqrt() // "0.8164965809" | ||
z.pow(-3) // "3.3749999995" | ||
z.toString(2) // "0.1010101011" | ||
z.times(z) // "0.44444444448888888889" | ||
z.times(z).round(10) // "0.4444444445" | ||
``` | ||
There is a `toFraction` method with an optional *maximum denominator* argument | ||
y = new BigNumber(355) | ||
pi = y.dividedBy(113) // "3.1415929204" | ||
pi.toFraction() // [ "7853982301", "2500000000" ] | ||
pi.toFraction(1000) // [ "355", "113" ] | ||
```javascript | ||
y = new BigNumber(355) | ||
pi = y.dividedBy(113) // "3.1415929204" | ||
pi.toFraction() // [ "7853982301", "2500000000" ] | ||
pi.toFraction(1000) // [ "355", "113" ] | ||
``` | ||
and `isNaN` and `isFinite` methods, as `NaN` and `Infinity` are valid `BigNumber` values. | ||
x = new BigNumber(NaN) // "NaN" | ||
y = new BigNumber(Infinity) // "Infinity" | ||
x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true | ||
```javascript | ||
x = new BigNumber(NaN) // "NaN" | ||
y = new BigNumber(Infinity) // "Infinity" | ||
x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true | ||
``` | ||
The value of a BigNumber is stored in a decimal floating point format in terms of a coefficient, exponent and sign. | ||
x = new BigNumber(-123.456); | ||
x.c // [ 123, 45600000000000 ] coefficient (i.e. significand) | ||
x.e // 2 exponent | ||
x.s // -1 sign | ||
For futher information see the [API](http://mikemcl.github.io/bignumber.js/) reference from the *doc* folder. | ||
```javascript | ||
x = new BigNumber(-123.456); | ||
x.c // [ 123, 45600000000000 ] coefficient (i.e. significand) | ||
x.e // 2 exponent | ||
x.s // -1 sign | ||
``` | ||
Multiple BigNumber constructors can be created, each with their own independent configuration which applies to all BigNumber's created from it. | ||
```javascript | ||
// Set DECIMAL_PLACES for the original BigNumber constructor | ||
BigNumber.config({ DECIMAL_PLACES: 10 }) | ||
// Create another BigNumber constructor, optionally passing in a configuration object | ||
BN = BigNumber.another({ DECIMAL_PLACES: 5 }) | ||
x = new BigNumber(1) | ||
y = new BN(1) | ||
x.div(3) // '0.3333333333' | ||
y.div(3) // '0.33333' | ||
``` | ||
For futher information see the [API](http://mikemcl.github.io/bignumber.js/) reference in the *doc* directory. | ||
## Test | ||
@@ -160,3 +205,3 @@ | ||
To test a single method | ||
To test a single method, e.g. | ||
@@ -167,38 +212,20 @@ $ node test/toFraction | ||
*bignumber-vs-number.html* enables some of the methods of bignumber.js to be compared with those of JavaScript's Number type. | ||
*bignumber-vs-number.html* enables some of the methods of bignumber.js to be compared with those of JavaScript's number type. | ||
## Performance | ||
## Versions | ||
The *perf* directory contains two applications and a *lib* directory containing the BigDecimal libraries used by both. | ||
This is version 2.x.x of the library, for version 1.x.x see the tagged releases or switch to the 'original' branch. The advantages of version 2 are that it is considerably faster for numbers with many digits and that there are a some added methods (see Change Log below). The disadvantages are more lines of code and increased code complexity, and the loss of simplicity in no longer having the coefficient of a BigNumber stored in base 10. The 'original' version will continue to be supported. | ||
*bignumber-vs-bigdecimal.html* tests the performance of bignumber.js against the JavaScript translations of two versions of BigDecimal, its use should be more or less self-explanatory. | ||
(The GWT version doesn't work in IE 6.) | ||
## Performance | ||
* GWT: java.math.BigDecimal | ||
<https://github.com/iriscouch/bigdecimal.js> | ||
* ICU4J: com.ibm.icu.math.BigDecimal | ||
<https://github.com/dtrebbien/BigDecimal.js> | ||
See the [README](https://github.com/MikeMcl/bignumber.js/perf/README.md) in the *perf* directory. | ||
The BigDecimal in Node's npm registry is the GWT version. Despite its seeming popularity I have found it to have some serious bugs, see the Node script *perf/lib/bigdecimal_GWT/bugs.js* for examples of flaws in its *remainder*, *divide* and *compareTo* methods. | ||
## Build | ||
*bigtime.js* is a Node command-line application which tests the performance of bignumber.js against the GWT version of BigDecimal from the npm registry. | ||
For Node, if [uglify-js](https://github.com/mishoo/UglifyJS2) is installed | ||
For example, to compare the time taken by the bignumber.js `plus` method and the BigDecimal `add` method: | ||
npm install uglify-js -g | ||
$ node bigtime plus 10000 40 | ||
then | ||
This will time 10000 calls to each, using operands of up to 40 random digits and will check that the results match. | ||
For help: | ||
$ node bigtime -h | ||
See the README in the directory for more information. | ||
## Build | ||
I.e. minify. | ||
For Node, if uglify-js is installed globally ( `npm install uglify-js -g` ) then | ||
npm run build | ||
@@ -208,2 +235,4 @@ | ||
The *bignumber.min.js* already present was created with *Microsoft Ajax Minifier 5.14*. | ||
## Feedback | ||
@@ -214,7 +243,7 @@ | ||
Michael | ||
<a href="mailto:M8ch88l@gmail.com">M8ch88l@gmail.com</a> | ||
Bitcoin donation | ||
**1CauoGYrEoJFhcyxGVaiLTE6f3WCaSUjnm** | ||
Thank you | ||
BTC | ||
:small_orange_diamond: 1GHTAxHbBHW5TrUu6oq84Yr3LUCcUXKZmJ :small_orange_diamond: | ||
@@ -225,6 +254,19 @@ ## Licence | ||
See LICENCE. | ||
See [LICENCE](https://github.com/MikeMcl/bignumber.js/LICENCE). | ||
## Change Log | ||
####2.0.1 | ||
* 17/02/2015 | ||
* Add `max`, `min`, `precision`, `random`, `shift`, `toDigits` and `truncated` methods. | ||
* Add the short-forms: `add`, `mul`, `sd`, `sub` and `trunc`. | ||
* Add an `another` method to enable multiple independent constructors to be created. | ||
* Add support for the base 2, 8 and 16 prefixes `0b`, `0o` and `0x`. | ||
* Enable a rounding mode to be specified as a second parameter to `toExponential`, `toFixed`, `toFormat` and `toPrecision`. | ||
* Add a `CRYPTO` configuration property so cryptographically-secure pseudo-random number generation can be specified. | ||
* Add a `MODULO_MODE` configuration property to enable the rounding mode used by the `modulo` operation to be specified. | ||
* Add a `POW_PRECISION` configuration property to enable the number of significant digits calculated by the power operation to be limited. | ||
* Improve code quality. | ||
* Improve documentation. | ||
####2.0.0 | ||
@@ -231,0 +273,0 @@ * 29/12/2014 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211528
2137
310
2