From aaa0794f69cf8cde935048bc75ef9c45097d03b4 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Fri, 20 Feb 2015 16:01:25 +0000 Subject: [PATCH] v4.0.2 --- .travis.yml | 4 +++- README.md | 5 ++++- bower.json | 35 +++++++++++++++++++++++++++++++++++ decimal.js | 19 ++++++++----------- decimal.min.js | 5 +++-- doc/API.html | 17 ++++++++--------- doc/decimal.js.map | 1 + package.json | 4 ++-- 8 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 bower.json create mode 100644 doc/decimal.js.map diff --git a/.travis.yml b/.travis.yml index ec43125..3f920bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: + - "0.12" - "0.11" - "0.10" - "0.8" - - "0.6" \ No newline at end of file + - "0.6" + - iojs diff --git a/README.md b/README.md index f7e7d26..becff53 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ then will create *decimal.min.js*. -The *decimal.min.js* already present was created with *Microsoft Ajax Minifier 5.11*. +A source map will also be created in the *doc* directory. ## Feedback @@ -204,6 +204,9 @@ See LICENCE. ## Change Log +####4.0.2 +* 20/02/2015 Add bower.json. Add source map. Amend travis CI. Amend doc/comments. + ####4.0.1 * 11/12/2014 Assign correct constructor when duplicating a Decimal. diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..8e04f51 --- /dev/null +++ b/bower.json @@ -0,0 +1,35 @@ +{ + "name": "decimal.js", + "main": "decimal.js", + "version": "4.0.2", + "homepage": "https://github.com/MikeMcl/decimal.js", + "authors": [ + "Michael Mclaughlin " + ], + "description": "An arbitrary-precision Decimal type for JavaScript", + "moduleType": [ + "amd", + "globals", + "node" + ], + "keywords": [ + "arbitrary", + "precision", + "arithmetic", + "bignumber", + "decimal", + "float", + "biginteger", + "bigdecimal", + "bignum", + "math" + ], + "license": "MIT", + "ignore": [ + ".*", + "doc", + "test", + "package.json" + ] +} + diff --git a/decimal.js b/decimal.js index 42134fe..45eb064 100644 --- a/decimal.js +++ b/decimal.js @@ -1,10 +1,10 @@ -/*! decimal.js v4.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */ +/*! decimal.js v4.0.2 https://github.com/MikeMcl/decimal.js/LICENCE */ ;(function (global) { 'use strict'; /* - * decimal.js v4.0.1 + * decimal.js v4.0.2 * An arbitrary-precision Decimal type for JavaScript. * https://github.com/MikeMcl/decimal.js * Copyright (c) 2014 Michael Mclaughlin @@ -891,20 +891,17 @@ /* * Return the number of significant digits of this Decimal. * - * z {boolean|number} Whether to count integer-part trailing zeros: true, false, 1 or 0. + * [z] {boolean|number} Whether to count integer-part trailing zeros: true, false, 1 or 0. * */ P['precision'] = P['sd'] = function (z) { var n = null, x = this; - if ( z != n ) { + if ( z != n && z !== !!z && z !== 1 && z !== 0 ) { - if ( z !== !!z && z !== 1 && z !== 0 ) { - - // 'precision() argument not a boolean or binary digit: {z}' - ifExceptionsThrow( x['constructor'], 'argument', z, 'precision', 1 ); - } + // 'precision() argument not a boolean or binary digit: {z}' + ifExceptionsThrow( x['constructor'], 'argument', z, 'precision', 1 ); } if ( x['c'] ) { @@ -3682,7 +3679,7 @@ for ( ; i < n; ) { v = a[i]; - // 0 >= v < 4294967296 + // 0 <= v < 4294967296 // Probability that v >= 4.29e9, is 4967296 / 4294967296 = 0.00116 (1 in 865). if ( v >= 4.29e9 ) { @@ -3712,7 +3709,7 @@ crypto['randomBytes'](4).copy( a, i ); } else { - // 0 <= v <= 4289999999 + // 0 <= v <= 2139999999 // 0 <= ( v % 1e7 ) <= 9999999 r.push( v % 1e7 ); i += 4; diff --git a/decimal.min.js b/decimal.min.js index 2e33ab4..ef6cda5 100644 --- a/decimal.min.js +++ b/decimal.min.js @@ -1,2 +1,3 @@ -/*! decimal.js v4.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */ -(function(n){"use strict";function l(n){for(var t,e,f=1,r=n.length,u=n[0]+"";f=10;e/=10,o++);return e=t-o,e<0?(e+=i,s=0):(s=Math.ceil((e+1)/i),e%=i),o=h(10,i-e),f=n[s]%o|0,u==null?e<3?(e==0?f=f/100|0:e==1&&(f=f/10|0),c=r<4&&f==99999||r>3&&f==49999||f==5e4||f==0):c=(r<4&&f+1==o||r>3&&f+1==o/2)&&(n[s+1]/o/100|0)==h(10,e-2)-1||(f==o/2||f==0)&&(n[s+1]/o/100|0)==0:e<4?(e==0?f=f/1e3|0:e==1?f=f/100|0:e==2&&(f=f/10|0),c=(u||r<4)&&f==9999||!u&&r>3&&f==4999):c=((u||r<4)&&f+1==o||!u&&r>3&&f+1==o/2)&&(n[s+1]/o/1e3|0)==h(10,e-3)-1,c}function k(n,t,i){var r=n.constructor;return t==null||((c=t<0||t>8)||t!==0&&(r.errors?parseInt:parseFloat)(t)!=t)&&!f(r,"rounding mode",t,i,0)?r.rounding:t|0}function d(n,t,i,r){var u=n.constructor;return!(c=t<(r||0)||t>=et+1)&&(t===0||(u.errors?parseInt:parseFloat)(t)==t)||f(u,"argument",t,i,0)}function rt(n,t){var c,v,k,a,i,f,o,y=0,d=0,p=0,u=n.constructor,w=u.ONE,nt=u.rounding,b=u.precision;if(!n.c||!n.c[0]||n.e>17)return new u(n.c?n.c[0]?n.s<0?0:1/0:w:n.s?n.s<0?0:n:NaN);for(t==null?(e=!1,i=b):i=t,o=new u(.03125);n.e>-2;)n=n.times(o),p+=5;for(v=Math.log(h(2,p))/Math.LN10*2+5|0,i+=v,c=a=f=new u(w),u.precision=i;;){if(a=r(a.times(n),i,1),c=c.times(++d),o=f.plus(s(a,c,i,1)),l(o.c).slice(0,i)===l(f.c).slice(0,i)){for(k=p;k--;)f=r(f.times(f),i,1);if(t==null)if(y<3&&g(f.c,i-v,nt,y))u.precision=i+=10,c=a=o=new u(w),d=0,y++;else return r(f,u.precision=b,nt,e=!0);else return u.precision=b,f}f=o}}function nt(n,t,i,u){var f,o,s=n.constructor,e=(n=new s(n)).e;if(t==null?i=0:(r(n,++t,i),i=u?t:t+n.e-e),e=n.e,f=l(n.c),u==1||u==2&&(t<=e||e<=s.toExpNeg)){for(;f.length1&&(f=f.charAt(0)+"."+f.slice(1));f+=(e<0?"e":"e+")+e}else{if(u=f.length,e<0){for(o=i-u;++e;f="0"+f);f="0."+f}else if(++e>u){for(o=i-e,e-=u;e--;f+="0");o>0&&(f+=".")}else o=i-u,e0&&(f+=".");if(o>0)for(;o--;f+="0");}return n.s<0&&n.c[0]?"-"+f:f}function ot(n){var t=n.length-1,r=t*i+1;if(t=n[t]){for(;t%10==0;t/=10,r--);for(t=n[0];t>=10;t/=10,r++);}return r}function f(n,t,i,r,f){if(n.errors){var e=new Error((r||["new Decimal","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFraction","pow","random","log","sqrt","toNearest","divToInt"][u?u<0?-u:u:1/u<0?1:0])+"() "+(["number type has more than 15 significant digits","LN10 out of digits"][t]||t+([c?" out of range":" not an integer"," not a boolean or binary digit"][f]||""))+": "+i);e.name="Decimal Error";c=u=0;throw e;}}function st(n,t,i){var r=new n(n.ONE);for(e=!1;;){if(i&1&&(r=r.times(t)),i>>=1,!i)break;t=t.times(t)}return e=!0,r}function p(n,t){var c,a,d,w,b,et,u,h,nt,rt,ut,ot=1,tt=10,i=n,v=i.c,o=i.constructor,it=o.ONE,ft=o.rounding,k=o.precision;if(i.s<0||!v||!v[0]||!i.e&&v[0]==1&&v.length==1)return new o(v&&!v[0]?-1/0:i.s!=1?NaN:v?0:i);if(t==null?(e=!1,u=k):u=t,o.precision=u+=tt,c=l(v),a=c.charAt(0),Math.abs(w=i.e)<15e14){while(a<7&&a!=1||a==1&&c.charAt(1)>3)i=i.times(n),c=l(i.c),a=c.charAt(0),ot++;w=i.e;a>1?(i=new o("0."+c),w++):i=new o(a+"."+c.slice(1))}else return i=new o(a+"."+c.slice(1)),u+2>y.length&&f(o,1,u+2,"ln"),i=p(i,u-tt).plus(new o(y.slice(0,u+2)).times(w+"")),o.precision=k,t==null?r(i,k,ft,e=!0):i;for(rt=i,h=b=i=s(i.minus(it),i.plus(it),u,1),ut=r(i.times(i),u,1),d=3;;){if(b=r(b.times(ut),u,1),nt=h.plus(s(b,new o(d),u,1)),l(nt.c).slice(0,u)===l(h.c).slice(0,u))if(h=h.times(2),w!==0&&(u+2>y.length&&f(o,1,u+2,"ln"),h=h.plus(new o(y.slice(0,u+2)).times(w+""))),h=s(h,new o(ot),u,1),t==null)if(g(h.c,u-tt,ft,et))o.precision=u+=tt,nt=b=i=s(rt.minus(it),rt.plus(it),u,1),ut=r(i.times(i),u,1),d=et=1;else return r(h,o.precision=k,ft,e=!0);else return o.precision=k,h;h=nt;d+=2}}function r(n,t,r,u){var y,c,s,l,p,w,f,a,b=n.constructor;n:if(t!=null){if(!(f=n.c))return n;for(y=1,l=f[0];l>=10;l/=10,y++);if(c=t-y,c<0)c+=i,s=t,p=f[a=0],w=p/h(10,y-s-1)%10|0;else if(a=Math.ceil((c+1)/i),a>=f.length)if(u){for(;f.length<=a;f.push(0));p=w=0;y=1;c%=i;s=c-i+1}else break n;else{for(p=l=f[a],y=1;l>=10;l/=10,y++);c%=i;s=c-i+y;w=s<0?0:o(p/h(10,y-s-1)%10)}if(u=u||t<0||f[a+1]!=null||(s<0?p:p%h(10,y-s-1)),u=r<4?(w||u)&&(r==0||r==(n.s<0?3:2)):w>5||w==5&&(r==4||u||r==6&&(c>0?s>0?p/h(10,y-s):0:f[a-1])%10&1||r==(n.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=n.e+1,f[0]=h(10,t%i),n.e=-t||0):f[0]=n.e=0,n;if(c==0?(f.length=a,l=1,a--):(f.length=a+1,l=h(10,i-c),f[a]=s>0?(p/h(10,y-s)%h(10,s)|0)*l:0),u)for(;;)if(a==0){for(c=1,s=f[0];s>=10;s/=10,c++);for(s=f[0]+=l,l=1;s>=10;s/=10,l++);c!=l&&(n.e++,f[0]==v&&(f[0]=1));break}else{if(f[a]+=l,f[a]!=v)break;f[a--]=0;l=1}for(c=f.length;f[--c]===0;f.pop());}return e&&(n.e>b.maxE?n.c=n.e=null:n.eo^r?1:-1;for(i=-1,h=(e=f.length)<(o=s.length)?e:o;++is[i]^r?1:-1;return e==o?0:e>o^r?1:-1},t.decimalPlaces=t.dp=function(){var r,n,t=null;if(r=this.c){if(t=((n=r.length-1)-o(this.e/i))*i,n=r[n])for(;n%10==0;n/=10,t--);t<0&&(t=0)}return t},t.dividedBy=t.div=function(n,t){return u=2,s(this,new this.constructor(n,t))},t.dividedToIntegerBy=t.divToInt=function(n,t){var f=this,i=f.constructor;return u=18,r(s(f,new i(n,t),0,1,1),i.precision,i.rounding)},t.equals=t.eq=function(n,t){return u=3,this.cmp(n,t)===0},t.exponential=t.exp=function(){return rt(this)},t.floor=function(){return r(new this.constructor(this),this.e+1,3)},t.greaterThan=t.gt=function(n,t){return u=4,this.cmp(n,t)>0},t.greaterThanOrEqualTo=t.gte=function(n,t){return u=5,t=this.cmp(n,t),t==1||t===0},t.isFinite=function(){return!!this.c},t.isInteger=t.isInt=function(){return!!this.c&&o(this.e/i)>this.c.length-2},t.isNaN=function(){return!this.s},t.isNegative=t.isNeg=function(){return this.s<0},t.isZero=function(){return!!this.c&&this.c[0]==0},t.lessThan=t.lt=function(n,t){return u=6,this.cmp(n,t)<0},t.lessThanOrEqualTo=t.lte=function(n,t){return u=7,t=this.cmp(n,t),t==-1||t===0},t.logarithm=t.log=function(n,t){var k,i,b,o,it,d,h,a,v,w=this,c=w.constructor,nt=c.precision,tt=c.rounding;if(n==null)n=new c(10),k=!0;else{if(u=15,n=new c(n,t),i=n.c,n.s<0||!i||!i[0]||!n.e&&i[0]==1&&i.length==1)return new c(NaN);k=n.eq(10)}if(i=w.c,w.s<0||!i||!i[0]||!w.e&&i[0]==1&&i.length==1)return new c(i&&!i[0]?-1/0:w.s!=1?NaN:i?0:1/0);if(it=k&&(o=i[0],i.length>1||o!=1&&o!=10&&o!=100&&o!=1e3&&o!=1e4&&o!=1e5&&o!=1e6),e=!1,h=nt+5,a=h+10,d=p(w,h),k?(a>y.length&&f(c,1,a,"log"),b=new c(y.slice(0,a))):b=p(n,h),v=s(d,b,h,1),g(v.c,o=nt,tt))do if(h+=10,d=p(w,h),k?(a=h+10,a>y.length&&f(c,1,a,"log"),b=new c(y.slice(0,a))):b=p(n,h),v=s(d,b,h,1),!it){+l(v.c).slice(o+1,o+15)+1==1e14&&(v=r(v,nt+1,0));break}while(g(v.c,o+=10,tt));return e=!0,r(v,nt,tt)},t.minus=function(n,t){var a,c,p,k,l=this,w=l.constructor,h=l.s;if(u=8,n=new w(n,t),t=n.s,!h||!t)return new w(NaN);if(h!=t)return n.s=-t,l.plus(n);var f=l.c,s=n.c,b=o(n.e/i),y=o(l.e/i),g=w.precision,d=w.rounding;if(!y||!b){if(!f||!s)return f?(n.s=-t,n):new w(s?l:NaN);if(!f[0]||!s[0])return l=s[0]?(n.s=-t,n):new w(f[0]?l:d==3?-0:0),e?r(l,g,d):l}if(f=f.slice(),c=f.length,h=y-b){for((k=h<0)?(h=-h,a=f,c=s.length):(b=y,a=s),(y=Math.ceil(g/i))>c&&(c=y),h>(c+=2)&&(h=c,a.length=1),a.reverse(),t=h;t--;a.push(0));a.reverse()}else for((k=c<(p=s.length))&&(p=c),h=t=0;t0)for(;t--;f[p++]=0);for(y=v-1,t=s.length;t>h;){if(f[--t]=10;t/=10,h++);return n.e=h+b*i-1,e?r(n,g,d):n},t.modulo=t.mod=function(n,t){var h,f,i=this,o=i.constructor,c=o.modulo;return(u=9,n=new o(n,t),t=n.s,h=!i.c||!t||n.c&&!n.c[0],h||!n.c||i.c&&!i.c[0])?h?new o(NaN):r(new o(i),o.precision,o.rounding):(e=!1,c==9?(n.s=1,f=s(i,n,0,3,1),n.s=t,f.s*=t):f=s(i,n,0,c,1),f=f.times(n),e=!0,i.minus(f))},t.naturalLogarithm=t.ln=function(){return p(this)},t.negated=t.neg=function(){var n=new this.constructor(this);return n.s=-n.s||null,r(n)},t.plus=function(n,t){var l,c=this,y=c.constructor,f=c.s;if(u=10,n=new y(n,t),t=n.s,!f||!t)return new y(NaN);if(f!=t)return n.s=-t,c.minus(n);var s=c.c,h=n.c,p=o(n.e/i),a=o(c.e/i),w=y.precision,b=y.rounding;if(!a||!p){if(!s||!h)return new y(f/0);if(!s[0]||!h[0])return c=h[0]?n:new y(s[0]?c:f*0),e?r(c,w,b):c}if(s=s.slice(),f=a-p){for(f<0?(f=-f,l=s,t=h.length):(p=a,l=h,t=s.length),(a=Math.ceil(w/i))>t&&(t=a),f>++t&&(f=t,l.length=1),l.reverse();f--;l.push(0));l.reverse()}for(s.length-h.length<0&&(l=h,h=s,s=l),f=h.length,t=0,a=v;f;s[f]%=a)t=(s[--f]=s[f]+h[f]+t)/a|0;for(t&&(s.unshift(t),++p),f=s.length;s[--f]==0;s.pop());for(n.c=s,f=1,t=s[0];t>=10;t/=10,f++);return n.e=f+p*i-1,e?r(n,w,b):n},t.precision=t.sd=function(n){var t=null,i=this;return n!=t&&n!==!!n&&n!==1&&n!==0&&f(i.constructor,"argument",n,"precision",1),i.c&&(t=ot(i.c),n&&i.e+1>t&&(t=i.e+1)),t},t.round=function(){var n=this,t=n.constructor;return r(new t(n),n.e+1,t.rounding)},t.squareRoot=t.sqrt=function(){var p,n,c,i,y,h,f=this,a=f.c,u=f.s,t=f.e,v=f.constructor,w=new v(.5);if(u!==1||!a||!a[0])return new v(!u||u<0&&(!a||a[0])?NaN:a?f:1/0);for(e=!1,u=Math.sqrt(+f),u==0||u==1/0?(n=l(a),(n.length+t)%2==0&&(n+="0"),u=Math.sqrt(n),t=o((t+1)/2)-(t<0||t%2),u==1/0?n="1e"+t:(n=u.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),i=new v(n)):i=new v(u.toString()),c=(t=v.precision)+3;;)if(h=i,i=w.times(h.plus(s(f,h,c+2,1))),l(h.c).slice(0,c)===(n=l(i.c)).slice(0,c))if(n=n.slice(c-3,c+1),n!="9999"&&(y||n!="4999")){+n&&(+n.slice(1)||n.charAt(0)!="5")||(r(i,t+1,1),p=!i.times(i).eq(f));break}else{if(!y&&(r(h,t+1,0),h.times(h).eq(f))){i=h;break}c+=4;y=1}return e=!0,r(i,t,v.rounding,p)},t.times=function(n,t){var f,w,y=this,p=y.constructor,c=y.c,l=(u=11,n=new p(n,t),n.c),a=o(y.e/i),s=o(n.e/i),h=y.s;if(t=n.s,n.s=h==t?1:-1,!a&&(!c||!c[0])||!s&&(!l||!l[0]))return new p(!h||!t||c&&!c[0]&&!l||l&&!l[0]&&!c?NaN:!c||!l?n.s/0:n.s*0);for(w=a+s,h=c.length,t=l.length,h-1;a--){for(t=0,s=h+a;s>a;)t=f[s]+l[a]*c[s-a-1]+t,f[s--]=t%v|0,t=t/v|0;f[s]=(f[s]+t)%v|0}for(t?++w:f[0]||f.shift(),s=f.length;!f[--s];f.pop());for(n.c=f,h=1,t=f[0];t>=10;t/=10,h++);return n.e=h+w*i-1,e?r(n,p.precision,p.rounding):n},t.toDecimalPlaces=t.toDP=function(n,t){var i=this;return i=new i.constructor(i),n==null||!d(i,n,"toDP")?i:r(i,(n|0)+i.e+1,k(i,t,"toDP"))},t.toExponential=function(n,t){var i=this;return i.c?nt(i,n!=null&&d(i,n,"toExponential")?n|0:null,n!=null&&k(i,t,"toExponential"),1):i.toString()},t.toFixed=function(n,t){var i,r=this,u=r.constructor,f=u.toExpNeg,e=u.toExpPos;return n!=null&&(n=d(r,n,i="toFixed")?r.e+(n|0):null,t=k(r,t,i)),u.toExpNeg=-(u.toExpPos=1/0),n!=null&&r.c?(i=nt(r,n,t),r.s<0&&r.c&&(r.c[0]?i.indexOf("-")<0&&(i="-"+i):i=i.replace("-",""))):i=r.toString(),u.toExpNeg=f,u.toExpPos=e,i},t.toFormat=function(n,t){var o=this;if(!o.c)return o.toString();var r,l=o.s<0,f=o.constructor.format,a=f.groupSeparator,u=+f.groupSize,e=+f.secondaryGroupSize,v=o.toFixed(n,t).split("."),i=v[0],c=v[1],s=l?i.slice(1):i,h=s.length;if(e&&(h-=(r=u,u=e,e=r)),u>0&&h>0){for(r=h%u||u,i=s.substr(0,r);r0&&(i+=a+s.slice(r));l&&(i="-"+i)}return c?i+f.decimalSeparator+((e=+f.fractionGroupSize)?c.replace(new RegExp("\\d{"+e+"}\\B","g"),"$&"+f.fractionGroupSeparator):c):i},t.toFraction=function(n){var v,r,d,it,a,y,g,nt,b=this,t=b.constructor,p=v=new t(t.ONE),w=y=new t(0),tt=b.c,k=new t(w);if(!tt)return b.toString();for(d=k.e=ot(tt)-b.e-1,k.c[0]=h(10,(g=d%i)<0?i+g:g),(n==null||(!(u=12,a=new t(n)).s||(c=a.cmp(p)<0||!a.c)||t.errors&&o(a.e/i)0)&&(n=d>0?k:p),e=!1,a=new t(l(tt)),g=t.precision,t.precision=d=tt.length*i*2;;){if(nt=s(a,k,0,1,1),r=v.plus(nt.times(w)),r.cmp(n)==1)break;v=w;w=r;p=y.plus(nt.times(r=p));y=r;k=a.minus(nt.times(r=k));a=r}return r=s(n.minus(v),w,0,1,1),y=y.plus(r.times(p)),v=v.plus(r.times(w)),y.s=p.s=b.s,it=s(p,w,d,1).minus(b).abs().cmp(s(y,v,d,1).minus(b).abs())<1?[p+"",w+""]:[y+"",v+""],e=!0,t.precision=g,it},t.toNearest=function(n,t){var i=this,f=i.constructor;return i=new f(i),n==null?(n=new f(f.ONE),t=f.rounding):(u=17,n=new f(n),t=k(i,t,"toNearest")),n.c?i.c&&(n.c[0]?(e=!1,i=s(i,n,0,t<4?[4,5,7,8][t]:t,1).times(n),e=!0,r(i)):i.c=[i.e=0]):i.s&&(n.s&&(n.s=i.s),i=n),i},t.toNumber=function(){var n=this;return+n||(n.s?0*n.s:NaN)},t.toPower=t.pow=function(n,t){var nt,a,b,s,f=this,c=f.constructor,y=f.s,w=+(u=13,n=new c(n,t)),k=w<0?-w:w,v=c.precision,d=c.rounding;if(!f.c||!n.c||(b=!f.c[0])||!n.c[0])return new c(h(b?y*0:+f,w));if(f=new c(f),nt=f.c.length,!f.e&&f.c[0]==f.s&&nt==1)return f;if(t=n.c.length-1,n.e||n.c[0]!=n.s||t)if(a=o(n.e/i),b=a>=t,!b&&y<0)s=new c(NaN);else{if(b&&nt*i*kc.maxE+1||a0?y/0:0);e=!1;c.rounding=f.s=1;k=Math.min(12,(a+"").length);s=rt(n.times(p(f,v+k)),v);s=r(s,v+5,1);g(s.c,v,d)&&(a=v+10,s=r(rt(n.times(p(f,a+k)),a),a+5,1),+l(s.c).slice(v+1,v+15)+1==1e14&&(s=r(s,v+1,0)));s.s=y;e=!0;c.rounding=d}s=r(s,v,d)}else s=r(f,v,d);return s},t.toPrecision=function(n,t){var i=this;return n!=null&&d(i,n,"toPrecision",1)&&i.c?nt(i,--n|0,k(i,t,"toPrecision"),2):i.toString()},t.toSignificantDigits=t.toSD=function(n,t){var i=this,u=i.constructor;return i=new u(i),n==null||!d(i,n,"toSD",1)?r(i,u.precision,u.rounding):r(i,n|0,k(i,t,"toSD"))},t.toString=function(n){var e,t,o,r=this,u=r.constructor,i=r.e;if(i===null)t=r.s?"Infinity":"NaN";else{if(n===e&&(i<=u.toExpNeg||i>=u.toExpPos))return nt(r,null,u.rounding,1);if(t=l(r.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 i1)t=e+"."+t.slice(1);else if(e=="0")return e;if(n!=null)if((c=!(n>=2&&n<65))||n!=(n|0)&&u.errors)f(u,"base",n,"toString",0);else if(t=tt(u,t,n|0,10,r.s),t=="0")return t}return r.s<0?"-"+t:t},t.truncated=t.trunc=function(){return r(new this.constructor(this),this.e+1,1)},t.valueOf=t.toJSON=function(){return this.toString()},tt=function(){function n(n,t,i){for(var u,r=[0],f,e=0,o=n.length;ei-1&&(r[u+1]==null&&(r[u+1]=0),r[u+1]+=r[u]/i|0,r[u]%=i)}return r.reverse()}return function(t,i,r,u,f){var h,a,p,c,e,y,o=i.indexOf("."),l=t.precision,v=t.rounding;for(u<37&&(i=i.toLowerCase()),o>=0&&(i=i.replace(".",""),y=new t(u),c=st(t,y,i.length-o),y.c=n(c.toFixed(),10,r),y.e=y.c.length),e=n(i,u,r),h=a=e.length;e[--a]==0;e.pop());if(!e[0])return"0";if(o<0?h--:(c.c=e,c.e=h,c.s=f,c=s(c,y,l,v,0,r),e=c.c,p=c.r,h=c.e),o=e[l],a=r/2,p=p||e[l+1]!=null,v<4?(o!=null||p)&&(v==0||v==(c.s<0?3:2)):o>a||o==a&&(v==4||p||v==6&&e[l-1]&1||v==(c.s<0?8:7)))for(e.length=l,--r;++e[--l]>r;)e[l]=0,l||(++h,e.unshift(1));else e.length=l;for(a=e.length;!e[--a];);for(o=0,i="";o<=a;i+=it.charAt(e[o++]));if(h<0){for(;++h;i="0"+i);i="0."+i}else if(o=i.length,++h>o)for(h-=o;h--;i+="0");else hr?1:-1;else for(u=f=0;ut[u]?1:-1;break}return f}function u(n,t,i,r){for(var u=0;i--;)n[i]-=u,u=n[i]1;n.shift());}return function(f,e,s,h,c,l){var nt,et,w,rt,ot,y,tt,ft,it,ut,p,b,ht,vt,ct,st,yt,g,lt,at=f.constructor,d=f.s==e.s?1:-1,k=f.c,a=e.c;if(!k||!k[0]||!a||!a[0])return new at(!f.s||!e.s||(k?a&&k[0]==a[0]:!a)?NaN:k&&k[0]==0||!a?d*0:d/0);for(l?(rt=1,et=f.e-e.e):(l=v,rt=i,et=o(f.e/rt)-o(e.e/rt)),g=a.length,st=k.length,it=new at(d),ut=it.c=[],w=0;a[w]==(k[w]||0);w++);if(a[w]>(k[w]||0)&&et--,s==null?(d=s=at.precision,h=at.rounding):d=c?s+(f.e-e.e)+1:s,d<0)ut.push(1),ot=!0;else{if(d=d/rt+2|0,w=0,g==1){for(y=0,a=a[0],d++;(w1&&(a=n(a,y,l),k=n(k,y,l),g=a.length,st=k.length),ct=g,p=k.slice(0,g),b=p.length;b=l/2&&yt++;do y=0,nt=t(a,p,g,b),nt<0?(ht=p[0],g!=b&&(ht=ht*l+(p[1]||0)),y=ht/yt|0,y>1?(y>=l&&(y=l-1),tt=n(a,y,l),ft=tt.length,b=p.length,nt=t(tt,p,ft,b),nt==1&&(y--,u(tt,g=10;d/=10,w++);it.e=w+et*rt-1;r(it,c?s+it.e+1:s,h,ot)}return it}}(),w=function(){function l(n){var i,e,t,r=this,s="config",h=r.errors?parseInt:parseFloat;return n==e||typeof n!="object"&&!f(r,"object expected",n,s)?r:((t=n[i="precision"])!=e&&((c=t<1||t>et)||h(t)!=t?f(r,i,t,s,0):r[i]=t|0),(t=n[i="rounding"])!=e&&((c=t<0||t>8)||h(t)!=t?f(r,i,t,s,0):r[i]=t|0),(t=n[i="toExpNeg"])!=e&&((c=t<-b||t>0)||h(t)!=t?f(r,i,t,s,0):r[i]=o(t)),(t=n[i="toExpPos"])!=e&&((c=t<0||t>b)||h(t)!=t?f(r,i,t,s,0):r[i]=o(t)),(t=n[i="minE"])!=e&&((c=t<-b||t>0)||h(t)!=t?f(r,i,t,s,0):r[i]=o(t)),(t=n[i="maxE"])!=e&&((c=t<0||t>b)||h(t)!=t?f(r,i,t,s,0):r[i]=o(t)),(t=n[i="errors"])!=e&&(t===!!t||t===1||t===0?(c=u=0,r[i]=!!t):f(r,i,t,s,1)),(t=n[i="crypto"])!=e&&(t===!!t||t===1||t===0?r[i]=!!(t&&a&&typeof a=="object"):f(r,i,t,s,1)),(t=n[i="modulo"])!=e&&((c=t<0||t>9)||h(t)!=t?f(r,i,t,s,0):r[i]=t|0),(n=n[i="format"])!=e&&(typeof n=="object"?r[i]=n:f(r,"format object expected",n,s)),r)}function v(n){return new this(n).exp()}function y(n){return new this(n).ln()}function p(n,t){return new this(n).log(t)}function n(n,t,i){var r,u,f=0;for(ft.call(t[0])=="[object Array]"&&(t=t[0]),r=new n(t[0]);++f=429e7?o[t]=a.getRandomValues(new Uint32Array(1))[0]:e[t++]=u%1e7;else if(a&&a.randomBytes){for(o=a.randomBytes(r*=4);t=214e7?a.randomBytes(4).copy(o,t):(e.push(u%1e7),t+=4);t=r/4}else f(s,"crypto unavailable",a,"random");if(!t)for(;t=10;)u/=10,t++;t=2&&l<65))?(f(o,"base",l,0,0),w=n.test(h)):(b="["+it.slice(0,l=l|0)+"]+",h=h.replace(/\.$/,"").replace(/^\./,"0."),(w=new RegExp("^"+b+"(?:\\."+b+")?$",l<37?"i":"").test(h))?(y&&(h.replace(/^0\.0*|\./,"").length>15&&f(o,0,p),y=!y),h=tt(o,h,10,l,s.s)):h!="Infinity"&&h!="NaN"&&(f(o,"not a base "+l+" number",p),h="NaN")):w=n.test(h),!w)return s.c=s.e=null,h!="Infinity"&&(h!="NaN"&&f(o,"not a number",p),s.s=null),u=0,s}for((v=h.indexOf("."))>-1&&(h=h.replace(".","")),(a=h.search(/e/i))>0?(v<0&&(v=a),v+=+h.slice(a+1),h=h.substring(0,a)):v<0&&(v=h.length),a=0;h.charCodeAt(a)===48;a++);for(l=h.length;h.charCodeAt(--l)===48;);if(h=h.slice(a,l+1),h){if(l=h.length,y&&l>15&&f(o,0,p),s.e=v=v-a-1,s.c=[],a=(v+1)%i,v<0&&(a+=i),ao.maxE?s.c=s.e=null:s.et;t++){for(n=e[t]+"",r=y-n.length;r--;)n="0"+n;o+=n}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function r(e,n,r,t){var i,o,s,c,u;for(o=1,s=e[0];s>=10;s/=10,o++);return s=n-o,0>s?(s+=y,i=0):(i=Math.ceil((s+1)/y),s%=y),o=E(10,y-s),u=e[i]%o|0,null==t?3>s?(0==s?u=u/100|0:1==s&&(u=u/10|0),c=4>r&&99999==u||r>3&&49999==u||5e4==u||0==u):c=(4>r&&u+1==o||r>3&&u+1==o/2)&&(e[i+1]/o/100|0)==E(10,s-2)-1||(u==o/2||0==u)&&0==(e[i+1]/o/100|0):4>s?(0==s?u=u/1e3|0:1==s?u=u/100|0:2==s&&(u=u/10|0),c=(t||4>r)&&9999==u||!t&&r>3&&4999==u):c=((t||4>r)&&u+1==o||!t&&r>3&&u+1==o/2)&&(e[i+1]/o/1e3|0)==E(10,s-3)-1,c}function t(e,n,r){var t=e.constructor;return null==n||((m=0>n||n>8)||0!==n&&(t.errors?parseInt:parseFloat)(n)!=n)&&!u(t,"rounding mode",n,r,0)?t.rounding:0|n}function i(e,n,r,t){var i=e.constructor;return!(m=(t||0)>n||n>=A+1)&&(0===n||(i.errors?parseInt:parseFloat)(n)==n)||u(i,"argument",n,r,0)}function o(e,t){var i,o,s,c,u,l,f,h=0,g=0,p=0,m=e.constructor,d=m.ONE,v=m.rounding,N=m.precision;if(!e.c||!e.c[0]||e.e>17)return new m(e.c?e.c[0]?e.s<0?0:1/0:d:e.s?e.s<0?0:e:0/0);for(null==t?(w=!1,u=N):u=t,f=new m(.03125);e.e>-2;)e=e.times(f),p+=5;for(o=Math.log(E(2,p))/Math.LN10*2+5|0,u+=o,i=c=l=new m(d),m.precision=u;;){if(c=a(c.times(e),u,1),i=i.times(++g),f=l.plus(P(c,i,u,1)),n(f.c).slice(0,u)===n(l.c).slice(0,u)){for(s=p;s--;)l=a(l.times(l),u,1);if(null!=t)return m.precision=N,l;if(!(3>h&&r(l.c,u-o,v,h)))return a(l,m.precision=N,v,w=!0);m.precision=u+=10,i=c=f=new m(d),g=0,h++}l=f}}function s(e,r,t,i){var o,s,c=e.constructor,u=(e=new c(e)).e;if(null==r?t=0:(a(e,++r,t),t=i?r:r+e.e-u),u=e.e,o=n(e.c),1==i||2==i&&(u>=r||u<=c.toExpNeg)){for(;o.length1&&(o=o.charAt(0)+"."+o.slice(1)),o+=(0>u?"e":"e+")+u}else{if(i=o.length,0>u){for(s=t-i;++u;o="0"+o);o="0."+o}else if(++u>i){for(s=t-u,u-=i;u--;o+="0");s>0&&(o+=".")}else s=t-i,i>u?o=o.slice(0,u)+"."+o.slice(u):s>0&&(o+=".");if(s>0)for(;s--;o+="0");}return e.s<0&&e.c[0]?"-"+o:o}function c(e){var n=e.length-1,r=n*y+1;if(n=e[n]){for(;n%10==0;n/=10,r--);for(n=e[0];n>=10;n/=10,r++);}return r}function u(e,n,r,t,i){if(e.errors){var o=new Error((t||["new Decimal","cmp","div","eq","gt","gte","lt","lte","minus","mod","plus","times","toFraction","pow","random","log","sqrt","toNearest","divToInt"][v?0>v?-v:v:0>1/v?1:0])+"() "+(["number type has more than 15 significant digits","LN10 out of digits"][n]||n+([m?" out of range":" not an integer"," not a boolean or binary digit"][i]||""))+": "+r);throw o.name="Decimal Error",m=v=0,o}}function l(e,n,r){var t=new e(e.ONE);for(w=!1;1&r&&(t=t.times(n)),r>>=1,r;)n=n.times(n);return w=!0,t}function f(e,t){var i,o,s,c,l,h,g,p,m,d,v,N=1,E=10,x=e,b=x.c,y=x.constructor,O=y.ONE,S=y.rounding,D=y.precision;if(x.s<0||!b||!b[0]||!x.e&&1==b[0]&&1==b.length)return new y(b&&!b[0]?-1/0:1!=x.s?0/0:b?0:x);if(null==t?(w=!1,g=D):g=t,y.precision=g+=E,i=n(b),o=i.charAt(0),!(Math.abs(c=x.e)<15e14))return x=new y(o+"."+i.slice(1)),g+2>M.length&&u(y,1,g+2,"ln"),x=f(x,g-E).plus(new y(M.slice(0,g+2)).times(c+"")),y.precision=D,null==t?a(x,D,S,w=!0):x;for(;7>o&&1!=o||1==o&&i.charAt(1)>3;)x=x.times(e),i=n(x.c),o=i.charAt(0),N++;for(c=x.e,o>1?(x=new y("0."+i),c++):x=new y(o+"."+i.slice(1)),d=x,p=l=x=P(x.minus(O),x.plus(O),g,1),v=a(x.times(x),g,1),s=3;;){if(l=a(l.times(v),g,1),m=p.plus(P(l,new y(s),g,1)),n(m.c).slice(0,g)===n(p.c).slice(0,g)){if(p=p.times(2),0!==c&&(g+2>M.length&&u(y,1,g+2,"ln"),p=p.plus(new y(M.slice(0,g+2)).times(c+""))),p=P(p,new y(N),g,1),null!=t)return y.precision=D,p;if(!r(p.c,g-E,S,h))return a(p,y.precision=D,S,w=!0);y.precision=g+=E,m=l=x=P(d.minus(O),d.plus(O),g,1),v=a(x.times(x),g,1),s=h=1}p=m,s+=2}}function a(e,n,r,t){var i,o,s,c,u,l,f,a,h=e.constructor;e:if(null!=n){if(!(f=e.c))return e;for(i=1,c=f[0];c>=10;c/=10,i++);if(o=n-i,0>o)o+=y,s=n,u=f[a=0],l=u/E(10,i-s-1)%10|0;else if(a=Math.ceil((o+1)/y),a>=f.length){if(!t)break e;for(;f.length<=a;f.push(0));u=l=0,i=1,o%=y,s=o-y+1}else{for(u=c=f[a],i=1;c>=10;c/=10,i++);o%=y,s=o-y+i,l=0>s?0:N(u/E(10,i-s-1)%10)}if(t=t||0>n||null!=f[a+1]||(0>s?u:u%E(10,i-s-1)),t=4>r?(l||t)&&(0==r||r==(e.s<0?3:2)):l>5||5==l&&(4==r||t||6==r&&(o>0?s>0?u/E(10,i-s):0:f[a-1])%10&1||r==(e.s<0?8:7)),1>n||!f[0])return f.length=0,t?(n-=e.e+1,f[0]=E(10,n%y),e.e=-n||0):f[0]=e.e=0,e;if(0==o?(f.length=a,c=1,a--):(f.length=a+1,c=E(10,y-o),f[a]=s>0?(u/E(10,i-s)%E(10,s)|0)*c:0),t)for(;;){if(0==a){for(o=1,s=f[0];s>=10;s/=10,o++);for(s=f[0]+=c,c=1;s>=10;s/=10,c++);o!=c&&(e.e++,f[0]==b&&(f[0]=1));break}if(f[a]+=c,f[a]!=b)break;f[a--]=0,c=1}for(o=f.length;0===f[--o];f.pop());}return w&&(e.e>h.maxE?e.c=e.e=null:e.es,!i||!o)return u==l?0:!i^r?1:-1;if(u!=l)return u>l^r?1:-1;for(s=-1,c=(u=i.length)<(l=o.length)?u:l;++so[s]^r?1:-1;return u==l?0:u>l^r?1:-1},S.decimalPlaces=S.dp=function(){var e,n,r=null;if(e=this.c){if(r=((n=e.length-1)-N(this.e/y))*y,n=e[n])for(;n%10==0;n/=10,r--);0>r&&(r=0)}return r},S.dividedBy=S.div=function(e,n){return v=2,P(this,new this.constructor(e,n))},S.dividedToIntegerBy=S.divToInt=function(e,n){var r=this,t=r.constructor;return v=18,a(P(r,new t(e,n),0,1,1),t.precision,t.rounding)},S.equals=S.eq=function(e,n){return v=3,0===this.cmp(e,n)},S.exponential=S.exp=function(){return o(this)},S.floor=function(){return a(new this.constructor(this),this.e+1,3)},S.greaterThan=S.gt=function(e,n){return v=4,this.cmp(e,n)>0},S.greaterThanOrEqualTo=S.gte=function(e,n){return v=5,n=this.cmp(e,n),1==n||0===n},S.isFinite=function(){return!!this.c},S.isInteger=S.isInt=function(){return!!this.c&&N(this.e/y)>this.c.length-2},S.isNaN=function(){return!this.s},S.isNegative=S.isNeg=function(){return this.s<0},S.isZero=function(){return!!this.c&&0==this.c[0]},S.lessThan=S.lt=function(e,n){return v=6,this.cmp(e,n)<0},S.lessThanOrEqualTo=S.lte=function(e,n){return v=7,n=this.cmp(e,n),-1==n||0===n},S.logarithm=S.log=function(e,t){var i,o,s,c,l,h,g,p,m,d=this,N=d.constructor,E=N.precision,x=N.rounding,b=5;if(null==e)e=new N(10),i=!0;else{if(v=15,e=new N(e,t),o=e.c,e.s<0||!o||!o[0]||!e.e&&1==o[0]&&1==o.length)return new N(0/0);i=e.eq(10)}if(o=d.c,d.s<0||!o||!o[0]||!d.e&&1==o[0]&&1==o.length)return new N(o&&!o[0]?-1/0:1!=d.s?0/0:o?0:1/0);if(l=i&&(c=o[0],o.length>1||1!=c&&10!=c&&100!=c&&1e3!=c&&1e4!=c&&1e5!=c&&1e6!=c),w=!1,g=E+b,p=g+10,h=f(d,g),i?(p>M.length&&u(N,1,p,"log"),s=new N(M.slice(0,p))):s=f(e,g),m=P(h,s,g,1),r(m.c,c=E,x))do if(g+=10,h=f(d,g),i?(p=g+10,p>M.length&&u(N,1,p,"log"),s=new N(M.slice(0,p))):s=f(e,g),m=P(h,s,g,1),!l){+n(m.c).slice(c+1,c+15)+1==1e14&&(m=a(m,E+1,0));break}while(r(m.c,c+=10,x));return w=!0,a(m,E,x)},S.minus=function(e,n){var r,t,i,o,s=this,c=s.constructor,u=s.s;if(v=8,e=new c(e,n),n=e.s,!u||!n)return new c(0/0);if(u!=n)return e.s=-n,s.plus(e);var l=s.c,f=e.c,h=N(e.e/y),g=N(s.e/y),p=c.precision,m=c.rounding;if(!g||!h){if(!l||!f)return l?(e.s=-n,e):new c(f?s:0/0);if(!l[0]||!f[0])return s=f[0]?(e.s=-n,e):new c(l[0]?s:3==m?-0:0),w?a(s,p,m):s}if(l=l.slice(),t=l.length,u=g-h){for((o=0>u)?(u=-u,r=l,t=f.length):(h=g,r=f),(g=Math.ceil(p/y))>t&&(t=g),u>(t+=2)&&(u=t,r.length=1),r.reverse(),n=u;n--;r.push(0));r.reverse()}else for((o=t<(i=f.length))&&(i=t),u=n=0;i>n;n++)if(l[n]!=f[n]){o=l[n]0)for(;n--;l[i++]=0);for(g=b-1,n=f.length;n>u;){if(l[--n]=10;n/=10,u++);return e.e=u+h*y-1,w?a(e,p,m):e},S.modulo=S.mod=function(e,n){var r,t,i=this,o=i.constructor,s=o.modulo;return v=9,e=new o(e,n),n=e.s,r=!i.c||!n||e.c&&!e.c[0],r||!e.c||i.c&&!i.c[0]?r?new o(0/0):a(new o(i),o.precision,o.rounding):(w=!1,9==s?(e.s=1,t=P(i,e,0,3,1),e.s=n,t.s*=n):t=P(i,e,0,s,1),t=t.times(e),w=!0,i.minus(t))},S.naturalLogarithm=S.ln=function(){return f(this)},S.negated=S.neg=function(){var e=new this.constructor(this);return e.s=-e.s||null,a(e)},S.plus=function(e,n){var r,t=this,i=t.constructor,o=t.s;if(v=10,e=new i(e,n),n=e.s,!o||!n)return new i(0/0);if(o!=n)return e.s=-n,t.minus(e);var s=t.c,c=e.c,u=N(e.e/y),l=N(t.e/y),f=i.precision,h=i.rounding;if(!l||!u){if(!s||!c)return new i(o/0);if(!s[0]||!c[0])return t=c[0]?e:new i(s[0]?t:0*o),w?a(t,f,h):t}if(s=s.slice(),o=l-u){for(0>o?(o=-o,r=s,n=c.length):(u=l,r=c,n=s.length),(l=Math.ceil(f/y))>n&&(n=l),o>++n&&(o=n,r.length=1),r.reverse();o--;r.push(0));r.reverse()}for(s.length-c.length<0&&(r=c,c=s,s=r),o=c.length,n=0,l=b;o;s[o]%=l)n=(s[--o]=s[o]+c[o]+n)/l|0;for(n&&(s.unshift(n),++u),o=s.length;0==s[--o];s.pop());for(e.c=s,o=1,n=s[0];n>=10;n/=10,o++);return e.e=o+u*y-1,w?a(e,f,h):e},S.precision=S.sd=function(e){var n=null,r=this;return e!=n&&e!==!!e&&1!==e&&0!==e&&u(r.constructor,"argument",e,"precision",1),r.c&&(n=c(r.c),e&&r.e+1>n&&(n=r.e+1)),n},S.round=function(){var e=this,n=e.constructor;return a(new n(e),e.e+1,n.rounding)},S.squareRoot=S.sqrt=function(){var e,r,t,i,o,s,c=this,u=c.c,l=c.s,f=c.e,h=c.constructor,g=new h(.5);if(1!==l||!u||!u[0])return new h(!l||0>l&&(!u||u[0])?0/0:u?c:1/0);for(w=!1,l=Math.sqrt(+c),0==l||l==1/0?(r=n(u),(r.length+f)%2==0&&(r+="0"),l=Math.sqrt(r),f=N((f+1)/2)-(0>f||f%2),l==1/0?r="1e"+f:(r=l.toExponential(),r=r.slice(0,r.indexOf("e")+1)+f),i=new h(r)):i=new h(l.toString()),t=(f=h.precision)+3;;)if(s=i,i=g.times(s.plus(P(c,s,t+2,1))),n(s.c).slice(0,t)===(r=n(i.c)).slice(0,t)){if(r=r.slice(t-3,t+1),"9999"!=r&&(o||"4999"!=r)){(!+r||!+r.slice(1)&&"5"==r.charAt(0))&&(a(i,f+1,1),e=!i.times(i).eq(c));break}if(!o&&(a(s,f+1,0),s.times(s).eq(c))){i=s;break}t+=4,o=1}return w=!0,a(i,f,h.rounding,e)},S.times=function(e,n){var r,t,i=this,o=i.constructor,s=i.c,c=(v=11,e=new o(e,n),e.c),u=N(i.e/y),l=N(e.e/y),f=i.s;if(n=e.s,e.s=f==n?1:-1,!((u||s&&s[0])&&(l||c&&c[0])))return new o(!f||!n||s&&!s[0]&&!c||c&&!c[0]&&!s?0/0:s&&c?0*e.s:e.s/0);for(t=u+l,f=s.length,n=c.length,n>f&&(r=s,s=c,c=r,l=f,f=n,n=l),l=f+n,r=[];l--;r.push(0));for(u=n-1;u>-1;u--){for(n=0,l=f+u;l>u;)n=r[l]+c[u]*s[l-u-1]+n,r[l--]=n%b|0,n=n/b|0;r[l]=(r[l]+n)%b|0}for(n?++t:r[0]||r.shift(),l=r.length;!r[--l];r.pop());for(e.c=r,f=1,n=r[0];n>=10;n/=10,f++);return e.e=f+t*y-1,w?a(e,o.precision,o.rounding):e},S.toDecimalPlaces=S.toDP=function(e,n){var r=this;return r=new r.constructor(r),null!=e&&i(r,e,"toDP")?a(r,(0|e)+r.e+1,t(r,n,"toDP")):r},S.toExponential=function(e,n){var r=this;return r.c?s(r,null!=e&&i(r,e,"toExponential")?0|e:null,null!=e&&t(r,n,"toExponential"),1):r.toString()},S.toFixed=function(e,n){var r,o=this,c=o.constructor,u=c.toExpNeg,l=c.toExpPos;return null!=e&&(e=i(o,e,r="toFixed")?o.e+(0|e):null,n=t(o,n,r)),c.toExpNeg=-(c.toExpPos=1/0),null!=e&&o.c?(r=s(o,e,n),o.s<0&&o.c&&(o.c[0]?r.indexOf("-")<0&&(r="-"+r):r=r.replace("-",""))):r=o.toString(),c.toExpNeg=u,c.toExpPos=l,r},S.toFormat=function(e,n){var r=this;if(!r.c)return r.toString();var t,i=r.s<0,o=r.constructor.format,s=o.groupSeparator,c=+o.groupSize,u=+o.secondaryGroupSize,l=r.toFixed(e,n).split("."),f=l[0],a=l[1],h=i?f.slice(1):f,g=h.length;if(u&&(t=c,c=u,g-=u=t),c>0&&g>0){for(t=g%c||c,f=h.substr(0,t);g>t;t+=c)f+=s+h.substr(t,c);u>0&&(f+=s+h.slice(t)),i&&(f="-"+f)}return a?f+o.decimalSeparator+((u=+o.fractionGroupSize)?a.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+o.fractionGroupSeparator):a):f},S.toFraction=function(e){var r,t,i,o,s,l,f,a,h=this,g=h.constructor,p=r=new g(g.ONE),d=l=new g(0),x=h.c,b=new g(d);if(!x)return h.toString();for(i=b.e=c(x)-h.e-1,b.c[0]=E(10,(f=i%y)<0?y+f:f),(null==e||(!(v=12,s=new g(e)).s||(m=s.cmp(p)<0||!s.c)||g.errors&&N(s.e/y)0)&&(e=i>0?b:p),w=!1,s=new g(n(x)),f=g.precision,g.precision=i=x.length*y*2;a=P(s,b,0,1,1),t=r.plus(a.times(d)),1!=t.cmp(e);)r=d,d=t,p=l.plus(a.times(t=p)),l=t,b=s.minus(a.times(t=b)),s=t;return t=P(e.minus(r),d,0,1,1),l=l.plus(t.times(p)),r=r.plus(t.times(d)),l.s=p.s=h.s,o=P(p,d,i,1).minus(h).abs().cmp(P(l,r,i,1).minus(h).abs())<1?[p+"",d+""]:[l+"",r+""],w=!0,g.precision=f,o},S.toNearest=function(e,n){var r=this,i=r.constructor;return r=new i(r),null==e?(e=new i(i.ONE),n=i.rounding):(v=17,e=new i(e),n=t(r,n,"toNearest")),e.c?r.c&&(e.c[0]?(w=!1,r=P(r,e,0,4>n?[4,5,7,8][n]:n,1).times(e),w=!0,a(r)):r.c=[r.e=0]):r.s&&(e.s&&(e.s=r.s),r=e),r},S.toNumber=function(){var e=this;return+e||(e.s?0*e.s:0/0)},S.toPower=S.pow=function(e,t){var i,s,c,u,h=this,g=h.constructor,p=h.s,m=(v=13,+(e=new g(e,t))),d=0>m?-m:m,x=g.precision,b=g.rounding;if(!h.c||!e.c||(c=!h.c[0])||!e.c[0])return new g(E(c?0*p:+h,m));if(h=new g(h),i=h.c.length,!h.e&&h.c[0]==h.s&&1==i)return h;if(t=e.c.length-1,e.e||e.c[0]!=e.s||t)if(s=N(e.e/y),c=s>=t,!c&&0>p)u=new g(0/0);else{if(c&&F>i*y*d){if(u=l(g,h,d),e.s<0)return g.ONE.div(u)}else{if(p=0>p&&1&e.c[Math.max(s,t)]?-1:1,t=E(+h,m),s=0!=t&&isFinite(t)?new g(t+"").e:N(m*(Math.log("0."+n(h.c))/Math.LN10+h.e+1)),s>g.maxE+1||s0?p/0:0);w=!1,g.rounding=h.s=1,d=Math.min(12,(s+"").length),u=o(e.times(f(h,x+d)),x),u=a(u,x+5,1),r(u.c,x,b)&&(s=x+10,u=a(o(e.times(f(h,s+d)),s),s+5,1),+n(u.c).slice(x+1,x+15)+1==1e14&&(u=a(u,x+1,0))),u.s=p,w=!0,g.rounding=b}u=a(u,x,b)}else u=a(h,x,b);return u},S.toPrecision=function(e,n){var r=this;return null!=e&&i(r,e,"toPrecision",1)&&r.c?s(r,0|--e,t(r,n,"toPrecision"),2):r.toString()},S.toSignificantDigits=S.toSD=function(e,n){var r=this,o=r.constructor;return r=new o(r),null!=e&&i(r,e,"toSD",1)?a(r,0|e,t(r,n,"toSD")):a(r,o.precision,o.rounding)},S.toString=function(e){var r,t,i,o=this,c=o.constructor,l=o.e;if(null===l)t=o.s?"Infinity":"NaN";else{if(e===r&&(l<=c.toExpNeg||l>=c.toExpPos))return s(o,null,c.rounding,1);if(t=n(o.c),0>l){for(;++l;t="0"+t);t="0."+t}else if(i=t.length,l>0)if(++l>i)for(l-=i;l--;t+="0");else i>l&&(t=t.slice(0,l)+"."+t.slice(l));else if(r=t.charAt(0),i>1)t=r+"."+t.slice(1);else if("0"==r)return r;if(null!=e)if((m=!(e>=2&&65>e))||e!=(0|e)&&c.errors)u(c,"base",e,"toString",0);else if(t=h(c,t,0|e,10,o.s),"0"==t)return t}return o.s<0?"-"+t:t},S.truncated=S.trunc=function(){return a(new this.constructor(this),this.e+1,1)},S.valueOf=S.toJSON=function(){return this.toString()},h=function(){function e(e,n,r){for(var t,i,o=[0],s=0,c=e.length;c>s;){for(i=o.length;i--;o[i]*=n);for(o[t=0]+=O.indexOf(e.charAt(s++));tr-1&&(null==o[t+1]&&(o[t+1]=0),o[t+1]+=o[t]/r|0,o[t]%=r)}return o.reverse()}return function(n,r,t,i,o){var s,c,u,f,a,h,g=r.indexOf("."),p=n.precision,m=n.rounding;for(37>i&&(r=r.toLowerCase()),g>=0&&(r=r.replace(".",""),h=new n(i),f=l(n,h,r.length-g),h.c=e(f.toFixed(),10,t),h.e=h.c.length),a=e(r,i,t),s=c=a.length;0==a[--c];a.pop());if(!a[0])return"0";if(0>g?s--:(f.c=a,f.e=s,f.s=o,f=P(f,h,p,m,0,t),a=f.c,u=f.r,s=f.e),g=a[p],c=t/2,u=u||null!=a[p+1],4>m?(null!=g||u)&&(0==m||m==(f.s<0?3:2)):g>c||g==c&&(4==m||u||6==m&&1&a[p-1]||m==(f.s<0?8:7)))for(a.length=p,--t;++a[--p]>t;)a[p]=0,p||(++s,a.unshift(1));else a.length=p;for(c=a.length;!a[--c];);for(g=0,r="";c>=g;r+=O.charAt(a[g++]));if(0>s){for(;++s;r="0"+r);r="0."+r}else if(g=r.length,++s>g)for(s-=g;s--;r+="0");else g>s&&(r=r.slice(0,s)+"."+r.slice(s));return r}}();var P=function(){function e(e,n,r){var t,i=0,o=e.length;for(e=e.slice();o--;)t=e[o]*n+i,e[o]=t%r|0,i=t/r|0;return i&&e.unshift(i),e}function n(e,n,r,t){var i,o;if(r!=t)o=r>t?1:-1;else for(i=o=0;r>i;i++)if(e[i]!=n[i]){o=e[i]>n[i]?1:-1;break}return o}function r(e,n,r,t){for(var i=0;r--;)e[r]-=i,i=e[r]1;e.shift());}return function(t,i,o,s,c,u){var l,f,h,g,p,m,d,w,v,E,x,O,S,D,A,F,M,P,R,q=t.constructor,L=t.s==i.s?1:-1,I=t.c,U=i.c;if(!(I&&I[0]&&U&&U[0]))return new q(t.s&&i.s&&(I?!U||I[0]!=U[0]:U)?I&&0==I[0]||!U?0*L:L/0:0/0);for(u?(g=1,f=t.e-i.e):(u=b,g=y,f=N(t.e/g)-N(i.e/g)),P=U.length,F=I.length,v=new q(L),E=v.c=[],h=0;U[h]==(I[h]||0);h++);if(U[h]>(I[h]||0)&&f--,null==o?(L=o=q.precision,s=q.rounding):L=c?o+(t.e-i.e)+1:o,0>L)E.push(1),p=!0;else{if(L=L/g+2|0,h=0,1==P){for(m=0,U=U[0],L++;(F>h||m)&&L--;h++)D=m*u+(I[h]||0),E[h]=D/U|0,m=D%U|0;p=m||F>h}else{for(m=u/(U[0]+1)|0,m>1&&(U=e(U,m,u),I=e(I,m,u),P=U.length,F=I.length),A=P,x=I.slice(0,P),O=x.length;P>O;x[O++]=0);R=U.slice(),R.unshift(0),M=U[0],U[1]>=u/2&&M++;do m=0,l=n(U,x,P,O),0>l?(S=x[0],P!=O&&(S=S*u+(x[1]||0)),m=S/M|0,m>1?(m>=u&&(m=u-1),d=e(U,m,u),w=d.length,O=x.length,l=n(d,x,w,O),1==l&&(m--,r(d,w>P?R:U,w,u))):(0==m&&(l=m=1),d=U.slice()),w=d.length,O>w&&d.unshift(0),r(x,d,O,u),-1==l&&(O=x.length,l=n(U,x,P,O),1>l&&(m++,r(x,O>P?R:U,O,u))),O=x.length):0===l&&(m++,x=[0]),E[h++]=m,l&&x[0]?x[O++]=I[A]||0:(x=[I[A]],O=1);while((A++=10;L/=10,h++);v.e=h+f*g-1,a(v,c?o+v.e+1:o,s,p)}return v}}();if(g=function(){function e(e){var n,r,t,i=this,o="config",s=i.errors?parseInt:parseFloat;return e==r||"object"!=typeof e&&!u(i,"object expected",e,o)?i:((t=e[n="precision"])!=r&&((m=1>t||t>A)||s(t)!=t?u(i,n,t,o,0):i[n]=0|t),(t=e[n="rounding"])!=r&&((m=0>t||t>8)||s(t)!=t?u(i,n,t,o,0):i[n]=0|t),(t=e[n="toExpNeg"])!=r&&((m=-D>t||t>0)||s(t)!=t?u(i,n,t,o,0):i[n]=N(t)),(t=e[n="toExpPos"])!=r&&((m=0>t||t>D)||s(t)!=t?u(i,n,t,o,0):i[n]=N(t)),(t=e[n="minE"])!=r&&((m=-D>t||t>0)||s(t)!=t?u(i,n,t,o,0):i[n]=N(t)),(t=e[n="maxE"])!=r&&((m=0>t||t>D)||s(t)!=t?u(i,n,t,o,0):i[n]=N(t)),(t=e[n="errors"])!=r&&(t===!!t||1===t||0===t?(m=v=0,i[n]=!!t):u(i,n,t,o,1)),(t=e[n="crypto"])!=r&&(t===!!t||1===t||0===t?i[n]=!(!t||!d||"object"!=typeof d):u(i,n,t,o,1)),(t=e[n="modulo"])!=r&&((m=0>t||t>9)||s(t)!=t?u(i,n,t,o,0):i[n]=0|t),(e=e[n="format"])!=r&&("object"==typeof e?i[n]=e:u(i,"format object expected",e,o)),i)}function n(e){return new this(e).exp()}function r(e){return new this(e).ln()}function t(e,n){return new this(e).log(n)}function o(e,n,r){var t,i,o=0;for("[object Array]"==x.call(n[0])&&(n=n[0]),t=new e(n[0]);++oo;)t=n[o],t>=429e7?n[o]=d.getRandomValues(new Uint32Array(1))[0]:s[o++]=t%1e7;else if(d&&d.randomBytes){for(n=d.randomBytes(r*=4);r>o;)t=n[o]+(n[o+1]<<8)+(n[o+2]<<16)+((127&n[o+3])<<24),t>=214e7?d.randomBytes(4).copy(n,o):(s.push(t%1e7),o+=4);o=r/4}else u(c,"crypto unavailable",d,"random");if(!o)for(;r>o;)s[o++]=1e7*Math.random()|0;for(r=s[--o],e%=y,r&&e&&(t=E(10,y-e),s[o]=(r/t|0)*t);0===s[o];o--)s.pop();if(0>o)s=[r=0];else{for(r=-1;0===s[0];)s.shift(),r-=y;for(o=1,t=s[0];t>=10;)t/=10,o++;y>o&&(r-=y-o)}return l.e=r,l.c=s,l}function g(e){return new this(e).sqrt()}function p(i){function o(e,n){var r=this;if(!(r instanceof o))return u(o,"Decimal called without new",e),new o(e,n);if(r.constructor=o,e instanceof o){if(null==n)return v=0,r.s=e.s,r.e=e.e,r.c=(e=e.c)?e.slice():e,r;if(10==n)return a(new o(e),o.precision,o.rounding);e+=""}return b(o,r,e,n)}return o.precision=20,o.rounding=4,o.modulo=1,o.toExpNeg=-7,o.toExpPos=21,o.minE=-D,o.maxE=D,o.errors=!0,o.crypto=!1,o.format={decimalSeparator:".",groupSeparator:",",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:" ",fractionGroupSize:0},o.prototype=S,o.ONE=new o(1),o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=e,o.constructor=p,o.exp=n,o.ln=r,o.log=t,o.max=s,o.min=c,o.pow=l,o.sqrt=g,o.random=f,null!=i&&o.config(i),o}var b=function(){var e=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,n=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")};return function(r,t,i,o){var s,c,l,f,g,p;if("string"!=typeof i&&(i=(f="number"==typeof i||"[object Number]"==x.call(i))&&0===i&&0>1/i?"-0":i+""),g=i,null==o&&e.test(i))t.s=45===i.charCodeAt(0)?(i=i.slice(1),-1):1;else{if(10==o)return a(new r(i),r.precision,r.rounding);if(i=n.call(i).replace(/^\+(?!-)/,""),t.s=45===i.charCodeAt(0)?(i=i.replace(/^-(?!-)/,""),-1):1,null!=o?o!=(0|o)&&r.errors||(m=!(o>=2&&65>o))?(u(r,"base",o,0,0),p=e.test(i)):(s="["+O.slice(0,o=0|o)+"]+",i=i.replace(/\.$/,"").replace(/^\./,"0."),(p=new RegExp("^"+s+"(?:\\."+s+")?$",37>o?"i":"").test(i))?(f&&(i.replace(/^0\.0*|\./,"").length>15&&u(r,0,g),f=!f),i=h(r,i,10,o,t.s)):"Infinity"!=i&&"NaN"!=i&&(u(r,"not a base "+o+" number",g),i="NaN")):p=e.test(i),!p)return t.c=t.e=null,"Infinity"!=i&&("NaN"!=i&&u(r,"not a number",g),t.s=null),v=0,t}for((c=i.indexOf("."))>-1&&(i=i.replace(".","")),(l=i.search(/e/i))>0?(0>c&&(c=l),c+=+i.slice(l+1),i=i.substring(0,l)):0>c&&(c=i.length),l=0;48===i.charCodeAt(l);l++);for(o=i.length;48===i.charCodeAt(--o););if(i=i.slice(l,o+1)){if(o=i.length,f&&o>15&&u(r,0,g),t.e=c=c-l-1,t.c=[],l=(c+1)%y,0>c&&(l+=y),o>l){for(l&&t.c.push(+i.slice(0,l)),o-=y;o>l;)t.c.push(+i.slice(l,l+=y));i=i.slice(l),l=y-i.length}else l-=o;for(;l--;i+="0");t.c.push(+i),w&&(t.e>r.maxE?t.c=t.e=null:t.e - + decimal.js API