eos-common
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,2 +0,251 @@ | ||
var n,e,i="0123456789abcdef",t="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",r="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",s={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-9e15,maxE:9e15,crypto:!1},o=!0,u="[DecimalError] Invalid argument: ",c=Math.floor,f=Math.pow,a=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,h=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,l=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,d=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,g=t.length-1,p=r.length-1,m={name:"[object Decimal]"};function w(n){var e,i,t,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,e=1;e<r;e++)(i=7-(t=n[e]+"").length)&&(s+=O(i)),s+=t;(i=7-(t=(o=n[e])+"").length)&&(s+=O(i))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}function v(n,e,i){if(n!==~~n||n<e||n>i)throw Error(u+n)}function N(n,e,i,t){var r,s,o,u;for(s=n[0];s>=10;s/=10)--e;return--e<0?(e+=7,r=0):(r=Math.ceil((e+1)/7),e%=7),s=f(10,7-e),u=n[r]%s|0,null==t?e<3?(0==e?u=u/100|0:1==e&&(u=u/10|0),o=i<4&&99999==u||i>3&&49999==u||5e4==u||0==u):o=(i<4&&u+1==s||i>3&&u+1==s/2)&&(n[r+1]/s/100|0)==f(10,e-2)-1||(u==s/2||0==u)&&0==(n[r+1]/s/100|0):e<4?(0==e?u=u/1e3|0:1==e?u=u/100|0:2==e&&(u=u/10|0),o=(t||i<4)&&9999==u||!t&&i>3&&4999==u):o=((t||i<4)&&u+1==s||!t&&i>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==f(10,e-3)-1,o}function b(n,e,t){for(var r,s,o=[0],u=0,c=n.length;u<c;){for(s=o.length;s--;)o[s]*=e;for(o[0]+=i.indexOf(n.charAt(u++)),r=0;r<o.length;r++)o[r]>t-1&&(void 0===o[r+1]&&(o[r+1]=0),o[r+1]+=o[r]/t|0,o[r]%=t)}return o.reverse()}m.absoluteValue=m.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),x(n)},m.ceil=function(){return x(new this.constructor(this),this.e+1,2)},m.comparedTo=m.cmp=function(n){var e,i,t,r,s=this,o=s.d,u=(n=new s.constructor(n)).d,c=s.s,f=n.s;if(!o||!u)return c&&f?c!==f?c:o===u?0:!o^c<0?1:-1:NaN;if(!o[0]||!u[0])return o[0]?c:u[0]?-f:0;if(c!==f)return c;if(s.e!==n.e)return s.e>n.e^c<0?1:-1;for(e=0,i=(t=o.length)<(r=u.length)?t:r;e<i;++e)if(o[e]!==u[e])return o[e]>u[e]^c<0?1:-1;return t===r?0:t>r^c<0?1:-1},m.cosine=m.cos=function(){var n,i,t=this,r=t.constructor;return t.d?t.d[0]?(n=r.precision,i=r.rounding,r.precision=n+Math.max(t.e,t.sd())+7,r.rounding=1,t=function(n,e){var i,t,r=e.d.length;r<32?(i=Math.ceil(r/3),t=(1/R(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10");n.precision+=i,e=C(n,1,e.times(t),new n(1));for(var s=i;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return n.precision-=i,e}(r,U(r,t)),r.precision=n,r.rounding=i,x(2==e||3==e?t.neg():t,n,i,!0)):new r(1):new r(NaN)},m.cubeRoot=m.cbrt=function(){var n,e,i,t,r,s,u,a,h,l,d=this,g=d.constructor;if(!d.isFinite()||d.isZero())return new g(d);for(o=!1,(s=d.s*f(d.s*d,1/3))&&Math.abs(s)!=1/0?t=new g(s.toString()):(i=w(d.d),(s=((n=d.e)-i.length+1)%3)&&(i+=1==s||-2==s?"0":"00"),s=f(i,1/3),n=c((n+1)/3)-(n%3==(n<0?-1:2)),(t=new g(i=s==1/0?"5e"+n:(i=s.toExponential()).slice(0,i.indexOf("e")+1)+n)).s=d.s),u=(n=g.precision)+3;;)if(l=(h=(a=t).times(a).times(a)).plus(d),t=E(l.plus(d).times(a),l.plus(h),u+2,1),w(a.d).slice(0,u)===(i=w(t.d)).slice(0,u)){if("9999"!=(i=i.slice(u-3,u+1))&&(r||"4999"!=i)){+i&&(+i.slice(1)||"5"!=i.charAt(0))||(x(t,n+1,1),e=!t.times(t).times(t).eq(d));break}if(!r&&(x(a,n+1,0),a.times(a).times(a).eq(d))){t=a;break}u+=4,r=1}return o=!0,x(t,n,g.rounding,e)},m.decimalPlaces=m.dp=function(){var n,e=this.d,i=NaN;if(e){if(i=7*((n=e.length-1)-c(this.e/7)),n=e[n])for(;n%10==0;n/=10)i--;i<0&&(i=0)}return i},m.dividedBy=m.div=function(n){return E(this,new this.constructor(n))},m.dividedToIntegerBy=m.divToInt=function(n){var e=this.constructor;return x(E(this,new e(n),0,1,1),e.precision,e.rounding)},m.equals=m.eq=function(n){return 0===this.cmp(n)},m.floor=function(){return x(new this.constructor(this),this.e+1,3)},m.greaterThan=m.gt=function(n){return this.cmp(n)>0},m.greaterThanOrEqualTo=m.gte=function(n){var e=this.cmp(n);return 1==e||0===e},m.hyperbolicCosine=m.cosh=function(){var n,e,i,t,r,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;i=o.precision,t=o.rounding,o.precision=i+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?e=(1/R(4,n=Math.ceil(r/3))).toString():(n=16,e="2.3283064365386962890625e-10"),s=C(o,1,s.times(e),new o(1),!0);for(var c,f=n,a=new o(8);f--;)c=s.times(s),s=u.minus(c.times(a.minus(c.times(a))));return x(s,o.precision=i,o.rounding=t,!0)},m.hyperbolicSine=m.sinh=function(){var n,e,i,t,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(e=s.precision,i=s.rounding,s.precision=e+Math.max(r.e,r.sd())+4,s.rounding=1,(t=r.d.length)<3)r=C(s,2,r,r,!0);else{n=(n=1.4*Math.sqrt(t))>16?16:0|n,r=C(s,2,r=r.times(1/R(5,n)),r,!0);for(var o,u=new s(5),c=new s(16),f=new s(20);n--;)o=r.times(r),r=r.times(u.plus(o.times(c.times(o).plus(f))))}return s.precision=e,s.rounding=i,x(r,e,i,!0)},m.hyperbolicTangent=m.tanh=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+7,t.rounding=1,E(i.sinh(),i.cosh(),t.precision=n,t.rounding=e)):new t(i.s)},m.inverseCosine=m.acos=function(){var n,e=this,i=e.constructor,t=e.abs().cmp(1),r=i.precision,s=i.rounding;return-1!==t?0===t?e.isNeg()?_(i,r,s):new i(0):new i(NaN):e.isZero()?_(i,r+4,s).times(.5):(i.precision=r+6,i.rounding=1,e=e.asin(),n=_(i,r+4,s).times(.5),i.precision=r,i.rounding=s,n.minus(e))},m.inverseHyperbolicCosine=m.acosh=function(){var n,e,i=this,t=i.constructor;return i.lte(1)?new t(i.eq(1)?0:NaN):i.isFinite()?(n=t.precision,e=t.rounding,t.precision=n+Math.max(Math.abs(i.e),i.sd())+4,t.rounding=1,o=!1,i=i.times(i).minus(1).sqrt().plus(i),o=!0,t.precision=n,t.rounding=e,i.ln()):new t(i)},m.inverseHyperbolicSine=m.asinh=function(){var n,e,i=this,t=i.constructor;return!i.isFinite()||i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+2*Math.max(Math.abs(i.e),i.sd())+6,t.rounding=1,o=!1,i=i.times(i).plus(1).sqrt().plus(i),o=!0,t.precision=n,t.rounding=e,i.ln())},m.inverseHyperbolicTangent=m.atanh=function(){var n,e,i,t,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=s.precision,e=s.rounding,t=r.sd(),Math.max(t,n)<2*-r.e-1?x(new s(r),n,e,!0):(s.precision=i=t-r.e,r=E(r.plus(1),new s(1).minus(r),i+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=e,r.times(.5))):new s(NaN)},m.inverseSine=m.asin=function(){var n,e,i,t,r=this,s=r.constructor;return r.isZero()?new s(r):(e=r.abs().cmp(1),i=s.precision,t=s.rounding,-1!==e?0===e?((n=_(s,i+4,t).times(.5)).s=r.s,n):new s(NaN):(s.precision=i+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=t,r.times(2)))},m.inverseTangent=m.atan=function(){var n,e,i,t,r,s,u,c,f,a=this,h=a.constructor,l=h.precision,d=h.rounding;if(a.isFinite()){if(a.isZero())return new h(a);if(a.abs().eq(1)&&l+4<=p)return(u=_(h,l+4,d).times(.25)).s=a.s,u}else{if(!a.s)return new h(NaN);if(l+4<=p)return(u=_(h,l+4,d).times(.5)).s=a.s,u}for(h.precision=c=l+10,h.rounding=1,n=i=Math.min(28,c/7+2|0);n;--n)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(o=!1,e=Math.ceil(c/7),t=1,f=a.times(a),u=new h(a),r=a;-1!==n;)if(r=r.times(f),s=u.minus(r.div(t+=2)),r=r.times(f),void 0!==(u=s.plus(r.div(t+=2))).d[e])for(n=e;u.d[n]===s.d[n]&&n--;);return i&&(u=u.times(2<<i-1)),o=!0,x(u,h.precision=l,h.rounding=d,!0)},m.isFinite=function(){return!!this.d},m.isInteger=m.isInt=function(){return!!this.d&&c(this.e/7)>this.d.length-2},m.isNaN=function(){return!this.s},m.isNegative=m.isNeg=function(){return this.s<0},m.isPositive=m.isPos=function(){return this.s>0},m.isZero=function(){return!!this.d&&0===this.d[0]},m.lessThan=m.lt=function(n){return this.cmp(n)<0},m.lessThanOrEqualTo=m.lte=function(n){return this.cmp(n)<1},m.logarithm=m.log=function(n){var e,i,t,r,s,u,c,f,a=this.constructor,h=a.precision,l=a.rounding;if(null==n)n=new a(10),e=!0;else{if(i=(n=new a(n)).d,n.s<0||!i||!i[0]||n.eq(1))return new a(NaN);e=n.eq(10)}if(i=this.d,this.s<0||!i||!i[0]||this.eq(1))return new a(i&&!i[0]?-1/0:1!=this.s?NaN:i?0:1/0);if(e)if(i.length>1)s=!0;else{for(r=i[0];r%10==0;)r/=10;s=1!==r}if(o=!1,u=Z(this,c=h+5),t=e?D(a,c+10):Z(n,c),N((f=E(u,t,c,1)).d,r=h,l))do{if(u=Z(this,c+=10),t=e?D(a,c+10):Z(n,c),f=E(u,t,c,1),!s){+w(f.d).slice(r+1,r+15)+1==1e14&&(f=x(f,h+1,0));break}}while(N(f.d,r+=10,l));return o=!0,x(f,h,l)},m.minus=m.sub=function(n){var e,i,t,r,s,u,f,a,h,l,d,g,p=this,m=p.constructor;if(n=new m(n),!p.d||!n.d)return p.s&&n.s?p.d?n.s=-n.s:n=new m(n.d||p.s!==n.s?p:NaN):n=new m(NaN),n;if(p.s!=n.s)return n.s=-n.s,p.plus(n);if(h=p.d,g=n.d,f=m.precision,a=m.rounding,!h[0]||!g[0]){if(g[0])n.s=-n.s;else{if(!h[0])return new m(3===a?-0:0);n=new m(p)}return o?x(n,f,a):n}if(i=c(n.e/7),l=c(p.e/7),h=h.slice(),s=l-i){for((d=s<0)?(e=h,s=-s,u=g.length):(e=g,i=l,u=h.length),s>(t=Math.max(Math.ceil(f/7),u)+2)&&(s=t,e.length=1),e.reverse(),t=s;t--;)e.push(0);e.reverse()}else{for((d=(t=h.length)<(u=g.length))&&(u=t),t=0;t<u;t++)if(h[t]!=g[t]){d=h[t]<g[t];break}s=0}for(d&&(e=h,h=g,g=e,n.s=-n.s),u=h.length,t=g.length-u;t>0;--t)h[u++]=0;for(t=g.length;t>s;){if(h[--t]<g[t]){for(r=t;r&&0===h[--r];)h[r]=1e7-1;--h[r],h[t]+=1e7}h[t]-=g[t]}for(;0===h[--u];)h.pop();for(;0===h[0];h.shift())--i;return h[0]?(n.d=h,n.e=M(h,i),o?x(n,f,a):n):new m(3===a?-0:0)},m.modulo=m.mod=function(n){var e,i=this,t=i.constructor;return n=new t(n),!i.d||!n.s||n.d&&!n.d[0]?new t(NaN):!n.d||i.d&&!i.d[0]?x(new t(i),t.precision,t.rounding):(o=!1,9==t.modulo?(e=E(i,n.abs(),0,3,1)).s*=n.s:e=E(i,n,0,t.modulo,1),e=e.times(n),o=!0,i.minus(e))},m.naturalExponential=m.exp=function(){return S(this)},m.naturalLogarithm=m.ln=function(){return Z(this)},m.negated=m.neg=function(){var n=new this.constructor(this);return n.s=-n.s,x(n)},m.plus=m.add=function(n){var e,i,t,r,s,u,f,a,h,l,d=this,g=d.constructor;if(n=new g(n),!d.d||!n.d)return d.s&&n.s?d.d||(n=new g(n.d||d.s===n.s?d:NaN)):n=new g(NaN),n;if(d.s!=n.s)return n.s=-n.s,d.minus(n);if(h=d.d,l=n.d,f=g.precision,a=g.rounding,!h[0]||!l[0])return l[0]||(n=new g(d)),o?x(n,f,a):n;if(s=c(d.e/7),t=c(n.e/7),h=h.slice(),r=s-t){for(r<0?(i=h,r=-r,u=l.length):(i=l,t=s,u=h.length),r>(u=(s=Math.ceil(f/7))>u?s+1:u+1)&&(r=u,i.length=1),i.reverse();r--;)i.push(0);i.reverse()}for((u=h.length)-(r=l.length)<0&&(r=u,i=l,l=h,h=i),e=0;r;)e=(h[--r]=h[r]+l[r]+e)/1e7|0,h[r]%=1e7;for(e&&(h.unshift(e),++t),u=h.length;0==h[--u];)h.pop();return n.d=h,n.e=M(h,t),o?x(n,f,a):n},m.precision=m.sd=function(n){var e,i=this;if(void 0!==n&&n!==!!n&&1!==n&&0!==n)throw Error(u+n);return i.d?(e=q(i.d),n&&i.e+1>e&&(e=i.e+1)):e=NaN,e},m.round=function(){var n=this,e=n.constructor;return x(new e(n),n.e+1,e.rounding)},m.sine=m.sin=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+Math.max(t.e,t.sd())+7,r.rounding=1,t=function(n,e){var i,t=e.d.length;if(t<3)return C(n,2,e,e);i=(i=1.4*Math.sqrt(t))>16?16:0|i,e=e.times(1/R(5,i)),e=C(n,2,e,e);for(var r,s=new n(5),o=new n(16),u=new n(20);i--;)r=e.times(e),e=e.times(s.plus(r.times(o.times(r).minus(u))));return e}(r,U(r,t)),r.precision=n,r.rounding=i,x(e>2?t.neg():t,n,i,!0)):new r(NaN)},m.squareRoot=m.sqrt=function(){var n,e,i,t,r,s,u=this,f=u.d,a=u.e,h=u.s,l=u.constructor;if(1!==h||!f||!f[0])return new l(!h||h<0&&(!f||f[0])?NaN:f?u:1/0);for(o=!1,0==(h=Math.sqrt(+u))||h==1/0?(((e=w(f)).length+a)%2==0&&(e+="0"),h=Math.sqrt(e),a=c((a+1)/2)-(a<0||a%2),t=new l(e=h==1/0?"1e"+a:(e=h.toExponential()).slice(0,e.indexOf("e")+1)+a)):t=new l(h.toString()),i=(a=l.precision)+3;;)if(t=(s=t).plus(E(u,s,i+2,1)).times(.5),w(s.d).slice(0,i)===(e=w(t.d)).slice(0,i)){if("9999"!=(e=e.slice(i-3,i+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(x(t,a+1,1),n=!t.times(t).eq(u));break}if(!r&&(x(s,a+1,0),s.times(s).eq(u))){t=s;break}i+=4,r=1}return o=!0,x(t,a,l.rounding,n)},m.tangent=m.tan=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+10,r.rounding=1,(t=t.sin()).s=1,t=E(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=i,x(2==e||4==e?t.neg():t,n,i,!0)):new r(NaN)},m.times=m.mul=function(n){var e,i,t,r,s,u,f,a,h,l=this,d=l.constructor,g=l.d,p=(n=new d(n)).d;if(n.s*=l.s,!(g&&g[0]&&p&&p[0]))return new d(!n.s||g&&!g[0]&&!p||p&&!p[0]&&!g?NaN:g&&p?0*n.s:n.s/0);for(i=c(l.e/7)+c(n.e/7),(a=g.length)<(h=p.length)&&(s=g,g=p,p=s,u=a,a=h,h=u),s=[],t=u=a+h;t--;)s.push(0);for(t=h;--t>=0;){for(e=0,r=a+t;r>t;)f=s[r]+p[t]*g[r-t-1]+e,s[r--]=f%1e7|0,e=f/1e7|0;s[r]=(s[r]+e)%1e7|0}for(;!s[--u];)s.pop();return e?++i:s.shift(),n.d=s,n.e=M(s,i),o?x(n,d.precision,d.rounding):n},m.toBinary=function(n,e){return L(this,2,n,e)},m.toDecimalPlaces=m.toDP=function(n,e){var i=this,t=i.constructor;return i=new t(i),void 0===n?i:(v(n,0,1e9),void 0===e?e=t.rounding:v(e,0,8),x(i,n+i.e+1,e))},m.toExponential=function(n,e){var i,t=this,r=t.constructor;return void 0===n?i=y(t,!0):(v(n,0,1e9),void 0===e?e=r.rounding:v(e,0,8),i=y(t=x(new r(t),n+1,e),!0,n+1)),t.isNeg()&&!t.isZero()?"-"+i:i},m.toFixed=function(n,e){var i,t,r=this,s=r.constructor;return void 0===n?i=y(r):(v(n,0,1e9),void 0===e?e=s.rounding:v(e,0,8),i=y(t=x(new s(r),n+r.e+1,e),!1,n+t.e+1)),r.isNeg()&&!r.isZero()?"-"+i:i},m.toFraction=function(n){var e,i,t,r,s,c,a,h,l,d,g,p,m=this,v=m.d,N=m.constructor;if(!v)return new N(m);if(l=i=new N(1),t=h=new N(0),c=(s=(e=new N(t)).e=q(v)-m.e-1)%7,e.d[0]=f(10,c<0?7+c:c),null==n)n=s>0?e:l;else{if(!(a=new N(n)).isInt()||a.lt(l))throw Error(u+a);n=a.gt(e)?s>0?e:l:a}for(o=!1,a=new N(w(v)),d=N.precision,N.precision=s=7*v.length*2;g=E(a,e,0,1,1),1!=(r=i.plus(g.times(t))).cmp(n);)i=t,t=r,r=l,l=h.plus(g.times(r)),h=r,r=e,e=a.minus(g.times(r)),a=r;return r=E(n.minus(i),t,0,1,1),h=h.plus(r.times(l)),i=i.plus(r.times(t)),h.s=l.s=m.s,p=E(l,t,s,1).minus(m).abs().cmp(E(h,i,s,1).minus(m).abs())<1?[l,t]:[h,i],N.precision=d,o=!0,p},m.toHexadecimal=m.toHex=function(n,e){return L(this,16,n,e)},m.toNearest=function(n,e){var i=this,t=i.constructor;if(i=new t(i),null==n){if(!i.d)return i;n=new t(1),e=t.rounding}else{if(n=new t(n),void 0===e?e=t.rounding:v(e,0,8),!i.d)return n.s?i:n;if(!n.d)return n.s&&(n.s=i.s),n}return n.d[0]?(o=!1,i=E(i,n,0,e,1).times(n),o=!0,x(i)):(n.s=i.s,i=n),i},m.toNumber=function(){return+this},m.toOctal=function(n,e){return L(this,8,n,e)},m.toPower=m.pow=function(n){var e,i,t,r,s,u,a=this,h=a.constructor,l=+(n=new h(n));if(!(a.d&&n.d&&a.d[0]&&n.d[0]))return new h(f(+a,l));if((a=new h(a)).eq(1))return a;if(t=h.precision,s=h.rounding,n.eq(1))return x(a,t,s);if((e=c(n.e/7))>=n.d.length-1&&(i=l<0?-l:l)<=9007199254740991)return r=F(h,a,i,t),n.s<0?new h(1).div(r):x(r,t,s);if((u=a.s)<0){if(e<n.d.length-1)return new h(NaN);if(0==(1&n.d[e])&&(u=1),0==a.e&&1==a.d[0]&&1==a.d.length)return a.s=u,a}return(e=0!=(i=f(+a,l))&&isFinite(i)?new h(i+"").e:c(l*(Math.log("0."+w(a.d))/Math.LN10+a.e+1)))>h.maxE+1||e<h.minE-1?new h(e>0?u/0:0):(o=!1,h.rounding=a.s=1,i=Math.min(12,(e+"").length),(r=S(n.times(Z(a,t+i)),t)).d&&N((r=x(r,t+5,1)).d,t,s)&&(e=t+10,+w((r=x(S(n.times(Z(a,e+i)),e),e+5,1)).d).slice(t+1,t+15)+1==1e14&&(r=x(r,t+1,0))),r.s=u,o=!0,h.rounding=s,x(r,t,s))},m.toPrecision=function(n,e){var i,t=this,r=t.constructor;return void 0===n?i=y(t,t.e<=r.toExpNeg||t.e>=r.toExpPos):(v(n,1,1e9),void 0===e?e=r.rounding:v(e,0,8),i=y(t=x(new r(t),n,e),n<=t.e||t.e<=r.toExpNeg,n)),t.isNeg()&&!t.isZero()?"-"+i:i},m.toSignificantDigits=m.toSD=function(n,e){var i=this.constructor;return void 0===n?(n=i.precision,e=i.rounding):(v(n,1,1e9),void 0===e?e=i.rounding:v(e,0,8)),x(new i(this),n,e)},m.toString=function(){var n=this,e=n.constructor,i=y(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+i:i},m.truncated=m.trunc=function(){return x(new this.constructor(this),this.e+1,1)},m.valueOf=m.toJSON=function(){var n=this,e=n.constructor,i=y(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+i:i};var E=function(){function e(n,e,i){var t,r=0,s=n.length;for(n=n.slice();s--;)t=n[s]*e+r,n[s]=t%i|0,r=t/i|0;return r&&n.unshift(r),n}function i(n,e,i,t){var r,s;if(i!=t)s=i>t?1:-1;else for(r=s=0;r<i;r++)if(n[r]!=e[r]){s=n[r]>e[r]?1:-1;break}return s}function t(n,e,i,t){for(var r=0;i--;)n[i]-=r,r=n[i]<e[i]?1:0,n[i]=r*t+n[i]-e[i];for(;!n[0]&&n.length>1;)n.shift()}return function(r,s,o,u,f,a){var h,l,d,g,p,m,w,v,N,b,E,y,M,D,_,q,O,F,A,I,S=r.constructor,Z=r.s==s.s?1:-1,B=r.d,P=s.d;if(!(B&&B[0]&&P&&P[0]))return new S(r.s&&s.s&&(B?!P||B[0]!=P[0]:P)?B&&0==B[0]||!P?0*Z:Z/0:NaN);for(a?(p=1,l=r.e-s.e):(a=1e7,p=7,l=c(r.e/p)-c(s.e/p)),A=P.length,O=B.length,b=(N=new S(Z)).d=[],d=0;P[d]==(B[d]||0);d++);if(P[d]>(B[d]||0)&&l--,null==o?(D=o=S.precision,u=S.rounding):D=f?o+(r.e-s.e)+1:o,D<0)b.push(1),m=!0;else{if(D=D/p+2|0,d=0,1==A){for(g=0,P=P[0],D++;(d<O||g)&&D--;d++)_=g*a+(B[d]||0),b[d]=_/P|0,g=_%P|0;m=g||d<O}else{for((g=a/(P[0]+1)|0)>1&&(P=e(P,g,a),B=e(B,g,a),A=P.length,O=B.length),q=A,y=(E=B.slice(0,A)).length;y<A;)E[y++]=0;(I=P.slice()).unshift(0),F=P[0],P[1]>=a/2&&++F;do{g=0,(h=i(P,E,A,y))<0?(M=E[0],A!=y&&(M=M*a+(E[1]||0)),(g=M/F|0)>1?(g>=a&&(g=a-1),1==(h=i(w=e(P,g,a),E,v=w.length,y=E.length))&&(g--,t(w,A<v?I:P,v,a))):(0==g&&(h=g=1),w=P.slice()),(v=w.length)<y&&w.unshift(0),t(E,w,y,a),-1==h&&(h=i(P,E,A,y=E.length))<1&&(g++,t(E,A<y?I:P,y,a)),y=E.length):0===h&&(g++,E=[0]),b[d++]=g,h&&E[0]?E[y++]=B[q]||0:(E=[B[q]],y=1)}while((q++<O||void 0!==E[0])&&D--);m=void 0!==E[0]}b[0]||b.shift()}if(1==p)N.e=l,n=m;else{for(d=1,g=b[0];g>=10;g/=10)d++;N.e=d+l*p-1,x(N,f?o+N.e+1:o,u,m)}return N}}();function x(n,e,i,t){var r,s,u,c,a,h,l,d,g,p=n.constructor;n:if(null!=e){if(!(d=n.d))return n;for(r=1,c=d[0];c>=10;c/=10)r++;if((s=e-r)<0)s+=7,u=e,a=(l=d[g=0])/f(10,r-u-1)%10|0;else if((g=Math.ceil((s+1)/7))>=(c=d.length)){if(!t)break n;for(;c++<=g;)d.push(0);l=a=0,r=1,u=(s%=7)-7+1}else{for(l=c=d[g],r=1;c>=10;c/=10)r++;a=(u=(s%=7)-7+r)<0?0:l/f(10,r-u-1)%10|0}if(t=t||e<0||void 0!==d[g+1]||(u<0?l:l%f(10,r-u-1)),h=i<4?(a||t)&&(0==i||i==(n.s<0?3:2)):a>5||5==a&&(4==i||t||6==i&&(s>0?u>0?l/f(10,r-u):0:d[g-1])%10&1||i==(n.s<0?8:7)),e<1||!d[0])return d.length=0,h?(e-=n.e+1,d[0]=f(10,(7-e%7)%7),n.e=-e||0):d[0]=n.e=0,n;if(0==s?(d.length=g,c=1,g--):(d.length=g+1,c=f(10,7-s),d[g]=u>0?(l/f(10,r-u)%f(10,u)|0)*c:0),h)for(;;){if(0==g){for(s=1,u=d[0];u>=10;u/=10)s++;for(u=d[0]+=c,c=1;u>=10;u/=10)c++;s!=c&&(n.e++,1e7==d[0]&&(d[0]=1));break}if(d[g]+=c,1e7!=d[g])break;d[g--]=0,c=1}for(s=d.length;0===d[--s];)d.pop()}return o&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e<p.minE&&(n.e=0,n.d=[0])),n}function y(n,e,i){if(!n.isFinite())return B(n);var t,r=n.e,s=w(n.d),o=s.length;return e?(i&&(t=i-o)>0?s=s.charAt(0)+"."+s.slice(1)+O(t):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):r<0?(s="0."+O(-r-1)+s,i&&(t=i-o)>0&&(s+=O(t))):r>=o?(s+=O(r+1-o),i&&(t=i-r-1)>0&&(s=s+"."+O(t))):((t=r+1)<o&&(s=s.slice(0,t)+"."+s.slice(t)),i&&(t=i-o)>0&&(r+1===o&&(s+="."),s+=O(t))),s}function M(n,e){var i=n[0];for(e*=7;i>=10;i/=10)e++;return e}function D(n,e,i){if(e>g)throw o=!0,i&&(n.precision=i),Error("[DecimalError] Precision limit exceeded");return x(new n(t),e,1,!0)}function _(n,e,i){if(e>p)throw Error("[DecimalError] Precision limit exceeded");return x(new n(r),e,i,!0)}function q(n){var e=n.length-1,i=7*e+1;if(e=n[e]){for(;e%10==0;e/=10)i--;for(e=n[0];e>=10;e/=10)i++}return i}function O(n){for(var e="";n--;)e+="0";return e}function F(n,e,i,t){var r,s=new n(1),u=Math.ceil(t/7+4);for(o=!1;;){if(i%2&&k((s=s.times(e)).d,u)&&(r=!0),0===(i=c(i/2))){i=s.d.length-1,r&&0===s.d[i]&&++s.d[i];break}k((e=e.times(e)).d,u)}return o=!0,s}function A(n){return 1&n.d[n.d.length-1]}function I(n,e,i){for(var t,r=new n(e[0]),s=0;++s<e.length;){if(!(t=new n(e[s])).s){r=t;break}r[i](t)&&(r=t)}return r}function S(n,e){var i,t,r,s,u,c,a,h=0,l=0,d=0,g=n.constructor,p=g.rounding,m=g.precision;if(!n.d||!n.d[0]||n.e>17)return new g(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==e?(o=!1,a=m):a=e,c=new g(.03125);n.e>-2;)n=n.times(c),d+=5;for(a+=t=Math.log(f(2,d))/Math.LN10*2+5|0,i=s=u=new g(1),g.precision=a;;){if(s=x(s.times(n),a,1),i=i.times(++l),w((c=u.plus(E(s,i,a,1))).d).slice(0,a)===w(u.d).slice(0,a)){for(r=d;r--;)u=x(u.times(u),a,1);if(null!=e)return g.precision=m,u;if(!(h<3&&N(u.d,a-t,p,h)))return x(u,g.precision=m,p,o=!0);g.precision=a+=10,i=s=c=new g(1),l=0,h++}u=c}}function Z(n,e){var i,t,r,s,u,c,f,a,h,l,d,g=1,p=n,m=p.d,v=p.constructor,b=v.rounding,y=v.precision;if(p.s<0||!m||!m[0]||!p.e&&1==m[0]&&1==m.length)return new v(m&&!m[0]?-1/0:1!=p.s?NaN:m?0:p);if(null==e?(o=!1,h=y):h=e,v.precision=h+=10,t=(i=w(m)).charAt(0),!(Math.abs(s=p.e)<15e14))return a=D(v,h+2,y).times(s+""),p=Z(new v(t+"."+i.slice(1)),h-10).plus(a),v.precision=y,null==e?x(p,y,b,o=!0):p;for(;t<7&&1!=t||1==t&&i.charAt(1)>3;)t=(i=w((p=p.times(n)).d)).charAt(0),g++;for(s=p.e,t>1?(p=new v("0."+i),s++):p=new v(t+"."+i.slice(1)),l=p,f=u=p=E(p.minus(1),p.plus(1),h,1),d=x(p.times(p),h,1),r=3;;){if(u=x(u.times(d),h,1),w((a=f.plus(E(u,new v(r),h,1))).d).slice(0,h)===w(f.d).slice(0,h)){if(f=f.times(2),0!==s&&(f=f.plus(D(v,h+2,y).times(s+""))),f=E(f,new v(g),h,1),null!=e)return v.precision=y,f;if(!N(f.d,h-10,b,c))return x(f,v.precision=y,b,o=!0);v.precision=h+=10,a=u=p=E(l.minus(1),l.plus(1),h,1),d=x(p.times(p),h,1),r=c=1}f=a,r+=2}}function B(n){return String(n.s*n.s/0)}function P(n,e){var i,t,r;for((i=e.indexOf("."))>-1&&(e=e.replace(".","")),(t=e.search(/e/i))>0?(i<0&&(i=t),i+=+e.slice(t+1),e=e.substring(0,t)):i<0&&(i=e.length),t=0;48===e.charCodeAt(t);t++);for(r=e.length;48===e.charCodeAt(r-1);--r);if(e=e.slice(t,r)){if(r-=t,n.e=i=i-t-1,n.d=[],t=(i+1)%7,i<0&&(t+=7),t<r){for(t&&n.d.push(+e.slice(0,t)),r-=7;t<r;)n.d.push(+e.slice(t,t+=7));t=7-(e=e.slice(t)).length}else t-=r;for(;t--;)e+="0";n.d.push(+e),o&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function T(n,e){var i,t,r,s,c,d,g,p,m;if("Infinity"===e||"NaN"===e)return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(h.test(e))i=16,e=e.toLowerCase();else if(a.test(e))i=2;else{if(!l.test(e))throw Error(u+e);i=8}for((s=e.search(/p/i))>0?(g=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),c=(s=e.indexOf("."))>=0,t=n.constructor,c&&(s=(d=(e=e.replace(".","")).length)-s,r=F(t,new t(i),s,2*s)),s=m=(p=b(e,i,1e7)).length-1;0===p[s];--s)p.pop();return s<0?new t(0*n.s):(n.e=M(p,m),n.d=p,o=!1,c&&(n=E(n,r,4*d)),g&&(n=n.times(Math.abs(g)<54?f(2,g):qn.pow(2,g))),o=!0,n)}function C(n,e,i,t,r){var s,u,c,f,a=n.precision,h=Math.ceil(a/7);for(o=!1,f=i.times(i),c=new n(t);;){if(u=E(c.times(f),new n(e++*e++),a,1),c=r?t.plus(u):t.minus(u),t=E(u.times(f),new n(e++*e++),a,1),void 0!==(u=c.plus(t)).d[h]){for(s=h;u.d[s]===c.d[s]&&s--;);if(-1==s)break}s=c,c=t,t=u,u=s}return o=!0,u.d.length=h+1,u}function R(n,e){for(var i=n;--e;)i*=n;return i}function U(n,i){var t,r=i.s<0,s=_(n,n.precision,1),o=s.times(.5);if((i=i.abs()).lte(o))return e=r?4:1,i;if((t=i.divToInt(s)).isZero())e=r?3:2;else{if((i=i.minus(t.times(s))).lte(o))return e=A(t)?r?2:3:r?4:1,i;e=A(t)?r?1:4:r?3:2}return i.minus(s).abs()}function L(e,t,r,s){var o,u,c,f,a,h,l,d,g,p=e.constructor,m=void 0!==r;if(m?(v(r,1,1e9),void 0===s?s=p.rounding:v(s,0,8)):(r=p.precision,s=p.rounding),e.isFinite()){for(m?(o=2,16==t?r=4*r-3:8==t&&(r=3*r-2)):o=t,(c=(l=y(e)).indexOf("."))>=0&&(l=l.replace(".",""),(g=new p(1)).e=l.length-c,g.d=b(y(g),10,o),g.e=g.d.length),u=a=(d=b(l,10,o)).length;0==d[--a];)d.pop();if(d[0]){if(c<0?u--:((e=new p(e)).d=d,e.e=u,d=(e=E(e,g,r,s,0,o)).d,u=e.e,h=n),c=d[r],f=o/2,h=h||void 0!==d[r+1],h=s<4?(void 0!==c||h)&&(0===s||s===(e.s<0?3:2)):c>f||c===f&&(4===s||h||6===s&&1&d[r-1]||s===(e.s<0?8:7)),d.length=r,h)for(;++d[--r]>o-1;)d[r]=0,r||(++u,d.unshift(1));for(a=d.length;!d[a-1];--a);for(c=0,l="";c<a;c++)l+=i.charAt(d[c]);if(m){if(a>1)if(16==t||8==t){for(c=16==t?4:3,--a;a%c;a++)l+="0";for(a=(d=b(l,o,t)).length;!d[a-1];--a);for(c=1,l="1.";c<a;c++)l+=i.charAt(d[c])}else l=l.charAt(0)+"."+l.slice(1);l=l+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)l="0"+l;l="0."+l}else if(++u>a)for(u-=a;u--;)l+="0";else u<a&&(l=l.slice(0,u)+"."+l.slice(u))}else l=m?"0p+0":"0";l=(16==t?"0x":2==t?"0b":8==t?"0o":"")+l}else l=B(e);return e.s<0?"-"+l:l}function k(n,e){if(n.length>e)return n.length=e,!0}function H(n){return new this(n).abs()}function j(n){return new this(n).acos()}function V(n){return new this(n).acosh()}function $(n,e){return new this(n).plus(e)}function W(n){return new this(n).asin()}function J(n){return new this(n).asinh()}function z(n){return new this(n).atan()}function G(n){return new this(n).atanh()}function K(n,e){n=new this(n),e=new this(e);var i,t=this.precision,r=this.rounding,s=t+4;return n.s&&e.s?n.d||e.d?!e.d||n.isZero()?(i=e.s<0?_(this,t,r):new this(0)).s=n.s:!n.d||e.isZero()?(i=_(this,s,1).times(.5)).s=n.s:e.s<0?(this.precision=s,this.rounding=1,i=this.atan(E(n,e,s,1)),e=_(this,s,1),this.precision=t,this.rounding=r,i=n.s<0?i.minus(e):i.plus(e)):i=this.atan(E(n,e,s,1)):(i=_(this,s,1).times(e.s>0?.25:.75)).s=n.s:i=new this(NaN),i}function Q(n){return new this(n).cbrt()}function X(n){return x(n=new this(n),n.e+1,2)}function Y(n){if(!n||"object"!=typeof n)throw Error("[DecimalError] Object expected");var e,i,t,r=!0===n.defaults,o=["precision",1,1e9,"rounding",0,8,"toExpNeg",-9e15,0,"toExpPos",0,9e15,"maxE",0,9e15,"minE",-9e15,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(i=o[e],r&&(this[i]=s[i]),void 0!==(t=n[i])){if(!(c(t)===t&&t>=o[e+1]&&t<=o[e+2]))throw Error(u+i+": "+t);this[i]=t}if(i="crypto",r&&(this[i]=s[i]),void 0!==(t=n[i])){if(!0!==t&&!1!==t&&0!==t&&1!==t)throw Error(u+i+": "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error("[DecimalError] crypto unavailable");this[i]=!0}else this[i]=!1}return this}function nn(n){return new this(n).cos()}function en(n){return new this(n).cosh()}function tn(n,e){return new this(n).div(e)}function rn(n){return new this(n).exp()}function sn(n){return x(n=new this(n),n.e+1,3)}function on(){var n,e,i=new this(0);for(o=!1,n=0;n<arguments.length;)if((e=new this(arguments[n++])).d)i.d&&(i=i.plus(e.times(e)));else{if(e.s)return o=!0,new this(1/0);i=e}return o=!0,i.sqrt()}function un(n){return n instanceof qn||n&&"[object Decimal]"===n.name||!1}function cn(n){return new this(n).ln()}function fn(n,e){return new this(n).log(e)}function an(n){return new this(n).log(2)}function hn(n){return new this(n).log(10)}function ln(){return I(this,arguments,"lt")}function dn(){return I(this,arguments,"gt")}function gn(n,e){return new this(n).mod(e)}function pn(n,e){return new this(n).mul(e)}function mn(n,e){return new this(n).pow(e)}function wn(n){var e,i,t,r,s=0,o=new this(1),u=[];if(void 0===n?n=this.precision:v(n,1,1e9),t=Math.ceil(n/7),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(t));s<t;)(r=e[s])>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=r%1e7;else{if(!crypto.randomBytes)throw Error("[DecimalError] crypto unavailable");for(e=crypto.randomBytes(t*=4);s<t;)(r=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((127&e[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(e,s):(u.push(r%1e7),s+=4);s=t/4}else for(;s<t;)u[s++]=1e7*Math.random()|0;for(n%=7,(t=u[--s])&&n&&(r=f(10,7-n),u[s]=(t/r|0)*r);0===u[s];s--)u.pop();if(s<0)i=0,u=[0];else{for(i=-1;0===u[0];i-=7)u.shift();for(t=1,r=u[0];r>=10;r/=10)t++;t<7&&(i-=7-t)}return o.e=i,o.d=u,o}function vn(n){return x(n=new this(n),n.e+1,this.rounding)}function Nn(n){return(n=new this(n)).d?n.d[0]?n.s:0*n.s:n.s||NaN}function bn(n){return new this(n).sin()}function En(n){return new this(n).sinh()}function xn(n){return new this(n).sqrt()}function yn(n,e){return new this(n).sub(e)}function Mn(n){return new this(n).tan()}function Dn(n){return new this(n).tanh()}function _n(n){return x(n=new this(n),n.e+1,1)}m[Symbol.for("nodejs.util.inspect.custom")]=m.toString,m[Symbol.toStringTag]="Decimal";var qn=function n(e){var i,t,r;function s(n){var e,i,t,r=this;if(!(r instanceof s))return new s(n);if(r.constructor=s,n instanceof s)return r.s=n.s,void(o?!n.d||n.e>s.maxE?(r.e=NaN,r.d=null):n.e<s.minE?(r.e=0,r.d=[0]):(r.e=n.e,r.d=n.d.slice()):(r.e=n.e,r.d=n.d?n.d.slice():n.d));if("number"===(t=typeof n)){if(0===n)return r.s=1/n<0?-1:1,r.e=0,void(r.d=[0]);if(n<0?(n=-n,r.s=-1):r.s=1,n===~~n&&n<1e7){for(e=0,i=n;i>=10;i/=10)e++;return void(o?e>s.maxE?(r.e=NaN,r.d=null):e<s.minE?(r.e=0,r.d=[0]):(r.e=e,r.d=[n]):(r.e=e,r.d=[n]))}return 0*n!=0?(n||(r.s=NaN),r.e=NaN,void(r.d=null)):P(r,n.toString())}if("string"!==t)throw Error(u+n);return 45===(i=n.charCodeAt(0))?(n=n.slice(1),r.s=-1):(43===i&&(n=n.slice(1)),r.s=1),d.test(n)?P(r,n):T(r,n)}if(s.prototype=m,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=Y,s.clone=n,s.isDecimal=un,s.abs=H,s.acos=j,s.acosh=V,s.add=$,s.asin=W,s.asinh=J,s.atan=z,s.atanh=G,s.atan2=K,s.cbrt=Q,s.ceil=X,s.cos=nn,s.cosh=en,s.div=tn,s.exp=rn,s.floor=sn,s.hypot=on,s.ln=cn,s.log=fn,s.log10=hn,s.log2=an,s.max=ln,s.min=dn,s.mod=gn,s.mul=pn,s.pow=mn,s.random=wn,s.round=vn,s.sign=Nn,s.sin=bn,s.sinh=En,s.sqrt=xn,s.sub=yn,s.tan=Mn,s.tanh=Dn,s.trunc=_n,void 0===e&&(e={}),e&&!0!==e.defaults)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<r.length;)e.hasOwnProperty(t=r[i++])||(e[t]=this[t]);return s.config(e),s}(s);function On(n,e){if(!n)throw new Error(e)}t=new qn(t),r=new qn(r);class Fn{constructor(n,e){this.amount=0,this.amount=n,this.symbol=e,On(this.is_amount_within_range(),"magnitude of asset amount must be less than 2^62")}is_amount_within_range(){return-Fn.max_amount<=this.amount&&this.amount<=Fn.max_amount}is_valid(){return!0}toString(){return`${this.toDecimal().toFixed(this.symbol.precision())} ${this.symbol.code()}`}toDecimal(){return new qn(this.amount).div(Math.pow(10,this.symbol.precision()))}toNumber(){return Number(this.toDecimal().toNumber().toFixed(this.symbol.precision()))}}Fn.max_amount=2**62-1;class An{constructor(n){this.value=0,n&&(this.value="number"==typeof n?Number(n):function(n){let e=BigInt(0);n.length>7&&On(!1,"string is too long to be a valid symbol_code");for(const i of n.split("").reverse().join(""))(i<"A"||i>"Z")&&On(!1,"only uppercase letters allowed in symbol_code string"),e<<=BigInt(8),e|=BigInt(i.charCodeAt(0));return Number(e)}(n))}raw(){return this.value}length(){let n=BigInt(this.value),e=0;for(;255&Number(n)&&e<=7;)e++,n>>=BigInt(8);return e}to_string(){return function(n){const e=BigInt(255);if(0==n)return"";let i="",t=BigInt(n);for(let n=0;n<7;++n,t>>=BigInt(8)){if(t==BigInt(0))return i;i+=String.fromCharCode(Number(t&e))}return i}(this.value)}is_valid(){let n=BigInt(this.value);for(let e=0;e<7;e++){const i=String.fromCharCode(255&Number(n));if(!("A"<=i&&i<="Z"))return!1;if(n>>=BigInt(8),!(255&Number(n)))do{if(n>>=BigInt(8),255&Number(n))return!1;e++}while(e<7)}return!0}isEqual(n){return n.value===this.value}}class In{constructor(n,e){this._code=n,this._precision=e}code(){return this._code}isEqual(n){return n.code===this.code&&n.precision()===this.precision()}precision(){return this._precision}}class Sn{sec_since_epoch(){return Date.now()}}function Zn(){return new Sn}const Bn=new Date(Date.UTC(2e3,0,1,0,0,0,0)).getTime(),Pn=86400;function Tn(n){const[e,i]=n.split(" "),t=(e.split(".")[1]||[]).length,r=new qn(e).times(new qn(10).pow(t)).toNumber();return new Fn(r,new In(i,t))}function Cn(){const n=new Date(Date.UTC(2e3,0,1,0,0,0,0)).getTime();return Math.floor((Date.now()-n)/1e3/604800)/52}function Rn(n){return n*Math.pow(2,Cn())}function Un(n){return n/Math.pow(2,Cn())}export{Fn as Asset,In as Symbol,Bn as block_timestamp_epoch,On as check,Zn as current_time_point,Pn as seconds_per_day,Tn as split,Rn as stake2vote,An as symbol_code,Un as vote2stake,Cn as voteWeightToday}; | ||
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/core/eosio/check.hpp | ||
/** | ||
* Assert if the predicate fails and use the supplied message. | ||
* | ||
* @param {boolean} pred Pre-condition | ||
* @param {string} msg Error Message | ||
* @returns {void} | ||
* @example | ||
* | ||
* check(a == b, "a does not equal b"); | ||
*/ | ||
function check(pred, msg) { | ||
if (!pred) { | ||
throw new Error(msg); | ||
} | ||
} | ||
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp | ||
function str_to_symbol_code(str) { | ||
let value = BigInt(0); | ||
if (str.length > 7) { | ||
check(false, "string is too long to be a valid symbol_code"); | ||
} | ||
for (const itr of str.split("").reverse().join("")) { | ||
if (itr < 'A' || itr > 'Z') { | ||
check(false, "only uppercase letters allowed in symbol_code string"); | ||
} | ||
value <<= BigInt(8); | ||
value |= BigInt(itr.charCodeAt(0)); | ||
} | ||
return Number(value); | ||
} | ||
function write_as_string(value) { | ||
const mask = BigInt(0x00000000000000FF); | ||
if (value == 0) | ||
return ''; | ||
let begin = ""; | ||
let v = BigInt(value); | ||
for (let i = 0; i < 7; ++i, v >>= BigInt(8)) { | ||
if (v == BigInt(0)) | ||
return begin; | ||
begin += String.fromCharCode(Number(v & mask)); | ||
} | ||
return begin; | ||
} | ||
/** | ||
* @class Stores the symbol code | ||
* @brief Stores the symbol code as a uint64_t value | ||
*/ | ||
class symbol_code { | ||
// constructor() | ||
constructor(str) { | ||
this.value = 0; // uint64_t | ||
if (str) { | ||
if (typeof str == 'number') | ||
this.value = Number(str); | ||
else | ||
this.value = str_to_symbol_code(str); | ||
} | ||
} | ||
raw() { | ||
return this.value; | ||
} | ||
length() { | ||
let sym = BigInt(this.value); | ||
let len = 0; | ||
while (Number(sym) & 0xFF && len <= 7) { | ||
len++; | ||
sym >>= BigInt(8); | ||
} | ||
return len; | ||
} | ||
to_string() { | ||
return write_as_string(this.value); | ||
} | ||
is_valid() { | ||
let sym = BigInt(this.value); | ||
for (let i = 0; i < 7; i++) { | ||
const c = String.fromCharCode(Number(sym) & 0xFF); | ||
if (!("A" <= c && c <= "Z")) | ||
return false; | ||
sym >>= BigInt(8); | ||
if (!(Number(sym) & 0xFF)) { | ||
do { | ||
sym >>= BigInt(8); | ||
if ((Number(sym) & 0xFF)) | ||
return false; | ||
i++; | ||
} while (i < 7); | ||
} | ||
} | ||
return true; | ||
} | ||
isEqual(comparison) { | ||
return comparison.value === this.value; | ||
} | ||
} | ||
class Symbol { | ||
/** | ||
* Symbol | ||
* | ||
* @name Symbol | ||
* @param {string} code Symbol Code | ||
* @param {number} precision Precision | ||
* @returns {Symbol} Symbol | ||
* @example | ||
* | ||
* const sym = new Symbol("EOS", 4); | ||
* sym.code() //=> "EOS" | ||
* sym.precision //=> 4 | ||
*/ | ||
constructor(code, precision) { | ||
this._code = (typeof code == "string") ? new symbol_code(code) : code; | ||
this._precision = precision; | ||
} | ||
code() { | ||
return this._code; | ||
} | ||
isEqual(comparison) { | ||
return comparison.code === this.code && comparison.precision() === this.precision(); | ||
} | ||
precision() { | ||
return this._precision; | ||
} | ||
} | ||
// import { Decimal } from "decimal.js"; | ||
/** | ||
* Split quantity string | ||
* | ||
* @param {string} quantity Quantity string | ||
* @returns {Asset} | ||
* @example | ||
* | ||
* const quantity = split("1.0000 EOS"); | ||
* quantity.amount //=> 10000 | ||
* quantity.symbol.precision //=> 4 | ||
* quantity.symbol.code() //=> "EOS" | ||
*/ | ||
function split(quantity) { | ||
const [amount, symbol] = quantity.split(" "); | ||
const precision = (amount.split(".")[1] || []).length; | ||
const amount_uint64 = Number(amount) * Math.pow(10, precision); | ||
return new Asset(amount_uint64, new Symbol(symbol, precision)); | ||
} | ||
function asset_to_double(quantity) { | ||
if (quantity.amount == 0) | ||
return 0.0; | ||
return quantity.amount / Math.pow(10, quantity.symbol.precision()); | ||
} | ||
function double_to_asset(amount, sym) { | ||
return new Asset(amount * Math.pow(10, sym.precision()), sym); | ||
} | ||
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp | ||
/** | ||
* Asset | ||
* | ||
* @name Asset | ||
* @param {number} amount The amount of the asset | ||
* @param {Symbol} sym The name of the symbol | ||
* @returns {Asset} Asset | ||
* @example | ||
* | ||
* const quantity = new Asset(10000, new Symbol("EOS", 4)); | ||
* quantity.toString() //=> "1.0000 EOS"; | ||
* quantity.symbol.code() //=> "EOS" | ||
* quantity.symbol.precision //=> 4 | ||
*/ | ||
class Asset { | ||
constructor(amount, sym) { | ||
/** | ||
* {int64_t} The amount of the asset | ||
*/ | ||
this.amount = 0; | ||
this.amount = amount; | ||
this.symbol = sym; | ||
check(this.is_amount_within_range(), "magnitude of asset amount must be less than 2^62"); | ||
// check( this.symbol.is_valid(), "invalid symbol name" ); | ||
} | ||
/** | ||
* Check if the amount doesn't exceed the max amount | ||
* | ||
* @return true - if the amount doesn't exceed the max amount | ||
* @return false - otherwise | ||
*/ | ||
is_amount_within_range() { | ||
return -Asset.max_amount <= this.amount && this.amount <= Asset.max_amount; | ||
} | ||
/** | ||
* Check if the asset is valid. %A valid asset has its amount <= max_amount and its symbol name valid | ||
* | ||
* @return true - if the asset is valid | ||
* @return false - otherwise | ||
*/ | ||
is_valid() { | ||
// return this.is_amount_within_range() && this.symbol.is_valid(); | ||
return true; | ||
} | ||
to_string() { | ||
const amount = this.to_double().toFixed(this.symbol.precision()); | ||
return `${amount} ${this.symbol.code().to_string()}`; | ||
} | ||
to_double() { | ||
return asset_to_double(this); | ||
} | ||
} | ||
/** | ||
* {constexpr int64_t} Maximum amount possible for this asset. It's capped to 2^62 - 1 | ||
*/ | ||
Asset.max_amount = 2 ** 62 - 1; | ||
class Time { | ||
sec_since_epoch() { | ||
return Date.now(); | ||
} | ||
} | ||
function current_time_point() { | ||
return new Time(); | ||
} | ||
const block_timestamp_epoch = new Date(Date.UTC(2000, 0, 1, 0, 0, 0, 0)).getTime(); | ||
const seconds_per_day = 60 * 60 * 24; | ||
// https://github.com/EOSIO/eosio.contracts/blob/master/contracts/eosio.system/src/voting.cpp | ||
/** | ||
* voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value. | ||
*/ | ||
function voteWeightToday() { | ||
const seconds_per_day = 86400; | ||
const block_timestamp_epoch = new Date(Date.UTC(2000, 0, 1, 0, 0, 0, 0)).getTime(); | ||
return Math.floor((Date.now() - block_timestamp_epoch) / 1000 / (seconds_per_day * 7)) / 52; | ||
} | ||
/** | ||
* Convert EOS stake into decaying value | ||
* | ||
* @param {number} vote vote | ||
*/ | ||
function stake2vote(staked) { | ||
return staked * Math.pow(2, voteWeightToday()); | ||
} | ||
/** | ||
* Convert vote decay value into EOS stake | ||
* | ||
* @param {number} staked staked | ||
*/ | ||
function vote2stake(vote) { | ||
return vote / Math.pow(2, voteWeightToday()); | ||
} | ||
export { Asset, Symbol, asset_to_double, block_timestamp_epoch, check, current_time_point, double_to_asset, seconds_per_day, split, stake2vote, symbol_code, vote2stake, voteWeightToday }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,2 +0,267 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,e,t="0123456789abcdef",i="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",r="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",s={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-9e15,maxE:9e15,crypto:!1},o=!0,u="[DecimalError] Invalid argument: ",c=Math.floor,f=Math.pow,a=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,h=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,l=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,d=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,p=i.length-1,g=r.length-1,m={name:"[object Decimal]"};function w(n){var e,t,i,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,e=1;e<r;e++)(t=7-(i=n[e]+"").length)&&(s+=O(t)),s+=i;(t=7-(i=(o=n[e])+"").length)&&(s+=O(t))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}function v(n,e,t){if(n!==~~n||n<e||n>t)throw Error(u+n)}function N(n,e,t,i){var r,s,o,u;for(s=n[0];s>=10;s/=10)--e;return--e<0?(e+=7,r=0):(r=Math.ceil((e+1)/7),e%=7),s=f(10,7-e),u=n[r]%s|0,null==i?e<3?(0==e?u=u/100|0:1==e&&(u=u/10|0),o=t<4&&99999==u||t>3&&49999==u||5e4==u||0==u):o=(t<4&&u+1==s||t>3&&u+1==s/2)&&(n[r+1]/s/100|0)==f(10,e-2)-1||(u==s/2||0==u)&&0==(n[r+1]/s/100|0):e<4?(0==e?u=u/1e3|0:1==e?u=u/100|0:2==e&&(u=u/10|0),o=(i||t<4)&&9999==u||!i&&t>3&&4999==u):o=((i||t<4)&&u+1==s||!i&&t>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==f(10,e-3)-1,o}function b(n,e,i){for(var r,s,o=[0],u=0,c=n.length;u<c;){for(s=o.length;s--;)o[s]*=e;for(o[0]+=t.indexOf(n.charAt(u++)),r=0;r<o.length;r++)o[r]>i-1&&(void 0===o[r+1]&&(o[r+1]=0),o[r+1]+=o[r]/i|0,o[r]%=i)}return o.reverse()}m.absoluteValue=m.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),E(n)},m.ceil=function(){return E(new this.constructor(this),this.e+1,2)},m.comparedTo=m.cmp=function(n){var e,t,i,r,s=this,o=s.d,u=(n=new s.constructor(n)).d,c=s.s,f=n.s;if(!o||!u)return c&&f?c!==f?c:o===u?0:!o^c<0?1:-1:NaN;if(!o[0]||!u[0])return o[0]?c:u[0]?-f:0;if(c!==f)return c;if(s.e!==n.e)return s.e>n.e^c<0?1:-1;for(e=0,t=(i=o.length)<(r=u.length)?i:r;e<t;++e)if(o[e]!==u[e])return o[e]>u[e]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1},m.cosine=m.cos=function(){var n,t,i=this,r=i.constructor;return i.d?i.d[0]?(n=r.precision,t=r.rounding,r.precision=n+Math.max(i.e,i.sd())+7,r.rounding=1,i=function(n,e){var t,i,r=e.d.length;r<32?(t=Math.ceil(r/3),i=(1/C(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10");n.precision+=t,e=k(n,1,e.times(i),new n(1));for(var s=t;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return n.precision-=t,e}(r,R(r,i)),r.precision=n,r.rounding=t,E(2==e||3==e?i.neg():i,n,t,!0)):new r(1):new r(NaN)},m.cubeRoot=m.cbrt=function(){var n,e,t,i,r,s,u,a,h,l,d=this,p=d.constructor;if(!d.isFinite()||d.isZero())return new p(d);for(o=!1,(s=d.s*f(d.s*d,1/3))&&Math.abs(s)!=1/0?i=new p(s.toString()):(t=w(d.d),(s=((n=d.e)-t.length+1)%3)&&(t+=1==s||-2==s?"0":"00"),s=f(t,1/3),n=c((n+1)/3)-(n%3==(n<0?-1:2)),(i=new p(t=s==1/0?"5e"+n:(t=s.toExponential()).slice(0,t.indexOf("e")+1)+n)).s=d.s),u=(n=p.precision)+3;;)if(l=(h=(a=i).times(a).times(a)).plus(d),i=x(l.plus(d).times(a),l.plus(h),u+2,1),w(a.d).slice(0,u)===(t=w(i.d)).slice(0,u)){if("9999"!=(t=t.slice(u-3,u+1))&&(r||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(E(i,n+1,1),e=!i.times(i).times(i).eq(d));break}if(!r&&(E(a,n+1,0),a.times(a).times(a).eq(d))){i=a;break}u+=4,r=1}return o=!0,E(i,n,p.rounding,e)},m.decimalPlaces=m.dp=function(){var n,e=this.d,t=NaN;if(e){if(t=7*((n=e.length-1)-c(this.e/7)),n=e[n])for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t},m.dividedBy=m.div=function(n){return x(this,new this.constructor(n))},m.dividedToIntegerBy=m.divToInt=function(n){var e=this.constructor;return E(x(this,new e(n),0,1,1),e.precision,e.rounding)},m.equals=m.eq=function(n){return 0===this.cmp(n)},m.floor=function(){return E(new this.constructor(this),this.e+1,3)},m.greaterThan=m.gt=function(n){return this.cmp(n)>0},m.greaterThanOrEqualTo=m.gte=function(n){var e=this.cmp(n);return 1==e||0===e},m.hyperbolicCosine=m.cosh=function(){var n,e,t,i,r,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;t=o.precision,i=o.rounding,o.precision=t+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?e=(1/C(4,n=Math.ceil(r/3))).toString():(n=16,e="2.3283064365386962890625e-10"),s=k(o,1,s.times(e),new o(1),!0);for(var c,f=n,a=new o(8);f--;)c=s.times(s),s=u.minus(c.times(a.minus(c.times(a))));return E(s,o.precision=t,o.rounding=i,!0)},m.hyperbolicSine=m.sinh=function(){var n,e,t,i,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(e=s.precision,t=s.rounding,s.precision=e+Math.max(r.e,r.sd())+4,s.rounding=1,(i=r.d.length)<3)r=k(s,2,r,r,!0);else{n=(n=1.4*Math.sqrt(i))>16?16:0|n,r=k(s,2,r=r.times(1/C(5,n)),r,!0);for(var o,u=new s(5),c=new s(16),f=new s(20);n--;)o=r.times(r),r=r.times(u.plus(o.times(c.times(o).plus(f))))}return s.precision=e,s.rounding=t,E(r,e,t,!0)},m.hyperbolicTangent=m.tanh=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+7,i.rounding=1,x(t.sinh(),t.cosh(),i.precision=n,i.rounding=e)):new i(t.s)},m.inverseCosine=m.acos=function(){var n,e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,s=t.rounding;return-1!==i?0===i?e.isNeg()?D(t,r,s):new t(0):new t(NaN):e.isZero()?D(t,r+4,s).times(.5):(t.precision=r+6,t.rounding=1,e=e.asin(),n=D(t,r+4,s).times(.5),t.precision=r,t.rounding=s,n.minus(e))},m.inverseHyperbolicCosine=m.acosh=function(){var n,e,t=this,i=t.constructor;return t.lte(1)?new i(t.eq(1)?0:NaN):t.isFinite()?(n=i.precision,e=i.rounding,i.precision=n+Math.max(Math.abs(t.e),t.sd())+4,i.rounding=1,o=!1,t=t.times(t).minus(1).sqrt().plus(t),o=!0,i.precision=n,i.rounding=e,t.ln()):new i(t)},m.inverseHyperbolicSine=m.asinh=function(){var n,e,t=this,i=t.constructor;return!t.isFinite()||t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,i.rounding=1,o=!1,t=t.times(t).plus(1).sqrt().plus(t),o=!0,i.precision=n,i.rounding=e,t.ln())},m.inverseHyperbolicTangent=m.atanh=function(){var n,e,t,i,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=s.precision,e=s.rounding,i=r.sd(),Math.max(i,n)<2*-r.e-1?E(new s(r),n,e,!0):(s.precision=t=i-r.e,r=x(r.plus(1),new s(1).minus(r),t+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=e,r.times(.5))):new s(NaN)},m.inverseSine=m.asin=function(){var n,e,t,i,r=this,s=r.constructor;return r.isZero()?new s(r):(e=r.abs().cmp(1),t=s.precision,i=s.rounding,-1!==e?0===e?((n=D(s,t+4,i).times(.5)).s=r.s,n):new s(NaN):(s.precision=t+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=t,s.rounding=i,r.times(2)))},m.inverseTangent=m.atan=function(){var n,e,t,i,r,s,u,c,f,a=this,h=a.constructor,l=h.precision,d=h.rounding;if(a.isFinite()){if(a.isZero())return new h(a);if(a.abs().eq(1)&&l+4<=g)return(u=D(h,l+4,d).times(.25)).s=a.s,u}else{if(!a.s)return new h(NaN);if(l+4<=g)return(u=D(h,l+4,d).times(.5)).s=a.s,u}for(h.precision=c=l+10,h.rounding=1,n=t=Math.min(28,c/7+2|0);n;--n)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(o=!1,e=Math.ceil(c/7),i=1,f=a.times(a),u=new h(a),r=a;-1!==n;)if(r=r.times(f),s=u.minus(r.div(i+=2)),r=r.times(f),void 0!==(u=s.plus(r.div(i+=2))).d[e])for(n=e;u.d[n]===s.d[n]&&n--;);return t&&(u=u.times(2<<t-1)),o=!0,E(u,h.precision=l,h.rounding=d,!0)},m.isFinite=function(){return!!this.d},m.isInteger=m.isInt=function(){return!!this.d&&c(this.e/7)>this.d.length-2},m.isNaN=function(){return!this.s},m.isNegative=m.isNeg=function(){return this.s<0},m.isPositive=m.isPos=function(){return this.s>0},m.isZero=function(){return!!this.d&&0===this.d[0]},m.lessThan=m.lt=function(n){return this.cmp(n)<0},m.lessThanOrEqualTo=m.lte=function(n){return this.cmp(n)<1},m.logarithm=m.log=function(n){var e,t,i,r,s,u,c,f,a=this.constructor,h=a.precision,l=a.rounding;if(null==n)n=new a(10),e=!0;else{if(t=(n=new a(n)).d,n.s<0||!t||!t[0]||n.eq(1))return new a(NaN);e=n.eq(10)}if(t=this.d,this.s<0||!t||!t[0]||this.eq(1))return new a(t&&!t[0]?-1/0:1!=this.s?NaN:t?0:1/0);if(e)if(t.length>1)s=!0;else{for(r=t[0];r%10==0;)r/=10;s=1!==r}if(o=!1,u=Z(this,c=h+5),i=e?M(a,c+10):Z(n,c),N((f=x(u,i,c,1)).d,r=h,l))do{if(u=Z(this,c+=10),i=e?M(a,c+10):Z(n,c),f=x(u,i,c,1),!s){+w(f.d).slice(r+1,r+15)+1==1e14&&(f=E(f,h+1,0));break}}while(N(f.d,r+=10,l));return o=!0,E(f,h,l)},m.minus=m.sub=function(n){var e,t,i,r,s,u,f,a,h,l,d,p,g=this,m=g.constructor;if(n=new m(n),!g.d||!n.d)return g.s&&n.s?g.d?n.s=-n.s:n=new m(n.d||g.s!==n.s?g:NaN):n=new m(NaN),n;if(g.s!=n.s)return n.s=-n.s,g.plus(n);if(h=g.d,p=n.d,f=m.precision,a=m.rounding,!h[0]||!p[0]){if(p[0])n.s=-n.s;else{if(!h[0])return new m(3===a?-0:0);n=new m(g)}return o?E(n,f,a):n}if(t=c(n.e/7),l=c(g.e/7),h=h.slice(),s=l-t){for((d=s<0)?(e=h,s=-s,u=p.length):(e=p,t=l,u=h.length),s>(i=Math.max(Math.ceil(f/7),u)+2)&&(s=i,e.length=1),e.reverse(),i=s;i--;)e.push(0);e.reverse()}else{for((d=(i=h.length)<(u=p.length))&&(u=i),i=0;i<u;i++)if(h[i]!=p[i]){d=h[i]<p[i];break}s=0}for(d&&(e=h,h=p,p=e,n.s=-n.s),u=h.length,i=p.length-u;i>0;--i)h[u++]=0;for(i=p.length;i>s;){if(h[--i]<p[i]){for(r=i;r&&0===h[--r];)h[r]=1e7-1;--h[r],h[i]+=1e7}h[i]-=p[i]}for(;0===h[--u];)h.pop();for(;0===h[0];h.shift())--t;return h[0]?(n.d=h,n.e=_(h,t),o?E(n,f,a):n):new m(3===a?-0:0)},m.modulo=m.mod=function(n){var e,t=this,i=t.constructor;return n=new i(n),!t.d||!n.s||n.d&&!n.d[0]?new i(NaN):!n.d||t.d&&!t.d[0]?E(new i(t),i.precision,i.rounding):(o=!1,9==i.modulo?(e=x(t,n.abs(),0,3,1)).s*=n.s:e=x(t,n,0,i.modulo,1),e=e.times(n),o=!0,t.minus(e))},m.naturalExponential=m.exp=function(){return S(this)},m.naturalLogarithm=m.ln=function(){return Z(this)},m.negated=m.neg=function(){var n=new this.constructor(this);return n.s=-n.s,E(n)},m.plus=m.add=function(n){var e,t,i,r,s,u,f,a,h,l,d=this,p=d.constructor;if(n=new p(n),!d.d||!n.d)return d.s&&n.s?d.d||(n=new p(n.d||d.s===n.s?d:NaN)):n=new p(NaN),n;if(d.s!=n.s)return n.s=-n.s,d.minus(n);if(h=d.d,l=n.d,f=p.precision,a=p.rounding,!h[0]||!l[0])return l[0]||(n=new p(d)),o?E(n,f,a):n;if(s=c(d.e/7),i=c(n.e/7),h=h.slice(),r=s-i){for(r<0?(t=h,r=-r,u=l.length):(t=l,i=s,u=h.length),r>(u=(s=Math.ceil(f/7))>u?s+1:u+1)&&(r=u,t.length=1),t.reverse();r--;)t.push(0);t.reverse()}for((u=h.length)-(r=l.length)<0&&(r=u,t=l,l=h,h=t),e=0;r;)e=(h[--r]=h[r]+l[r]+e)/1e7|0,h[r]%=1e7;for(e&&(h.unshift(e),++i),u=h.length;0==h[--u];)h.pop();return n.d=h,n.e=_(h,i),o?E(n,f,a):n},m.precision=m.sd=function(n){var e,t=this;if(void 0!==n&&n!==!!n&&1!==n&&0!==n)throw Error(u+n);return t.d?(e=q(t.d),n&&t.e+1>e&&(e=t.e+1)):e=NaN,e},m.round=function(){var n=this,e=n.constructor;return E(new e(n),n.e+1,e.rounding)},m.sine=m.sin=function(){var n,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(n=r.precision,t=r.rounding,r.precision=n+Math.max(i.e,i.sd())+7,r.rounding=1,i=function(n,e){var t,i=e.d.length;if(i<3)return k(n,2,e,e);t=(t=1.4*Math.sqrt(i))>16?16:0|t,e=e.times(1/C(5,t)),e=k(n,2,e,e);for(var r,s=new n(5),o=new n(16),u=new n(20);t--;)r=e.times(e),e=e.times(s.plus(r.times(o.times(r).minus(u))));return e}(r,R(r,i)),r.precision=n,r.rounding=t,E(e>2?i.neg():i,n,t,!0)):new r(NaN)},m.squareRoot=m.sqrt=function(){var n,e,t,i,r,s,u=this,f=u.d,a=u.e,h=u.s,l=u.constructor;if(1!==h||!f||!f[0])return new l(!h||h<0&&(!f||f[0])?NaN:f?u:1/0);for(o=!1,0==(h=Math.sqrt(+u))||h==1/0?(((e=w(f)).length+a)%2==0&&(e+="0"),h=Math.sqrt(e),a=c((a+1)/2)-(a<0||a%2),i=new l(e=h==1/0?"1e"+a:(e=h.toExponential()).slice(0,e.indexOf("e")+1)+a)):i=new l(h.toString()),t=(a=l.precision)+3;;)if(i=(s=i).plus(x(u,s,t+2,1)).times(.5),w(s.d).slice(0,t)===(e=w(i.d)).slice(0,t)){if("9999"!=(e=e.slice(t-3,t+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(E(i,a+1,1),n=!i.times(i).eq(u));break}if(!r&&(E(s,a+1,0),s.times(s).eq(u))){i=s;break}t+=4,r=1}return o=!0,E(i,a,l.rounding,n)},m.tangent=m.tan=function(){var n,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(n=r.precision,t=r.rounding,r.precision=n+10,r.rounding=1,(i=i.sin()).s=1,i=x(i,new r(1).minus(i.times(i)).sqrt(),n+10,0),r.precision=n,r.rounding=t,E(2==e||4==e?i.neg():i,n,t,!0)):new r(NaN)},m.times=m.mul=function(n){var e,t,i,r,s,u,f,a,h,l=this,d=l.constructor,p=l.d,g=(n=new d(n)).d;if(n.s*=l.s,!(p&&p[0]&&g&&g[0]))return new d(!n.s||p&&!p[0]&&!g||g&&!g[0]&&!p?NaN:p&&g?0*n.s:n.s/0);for(t=c(l.e/7)+c(n.e/7),(a=p.length)<(h=g.length)&&(s=p,p=g,g=s,u=a,a=h,h=u),s=[],i=u=a+h;i--;)s.push(0);for(i=h;--i>=0;){for(e=0,r=a+i;r>i;)f=s[r]+g[i]*p[r-i-1]+e,s[r--]=f%1e7|0,e=f/1e7|0;s[r]=(s[r]+e)%1e7|0}for(;!s[--u];)s.pop();return e?++t:s.shift(),n.d=s,n.e=_(s,t),o?E(n,d.precision,d.rounding):n},m.toBinary=function(n,e){return U(this,2,n,e)},m.toDecimalPlaces=m.toDP=function(n,e){var t=this,i=t.constructor;return t=new i(t),void 0===n?t:(v(n,0,1e9),void 0===e?e=i.rounding:v(e,0,8),E(t,n+t.e+1,e))},m.toExponential=function(n,e){var t,i=this,r=i.constructor;return void 0===n?t=y(i,!0):(v(n,0,1e9),void 0===e?e=r.rounding:v(e,0,8),t=y(i=E(new r(i),n+1,e),!0,n+1)),i.isNeg()&&!i.isZero()?"-"+t:t},m.toFixed=function(n,e){var t,i,r=this,s=r.constructor;return void 0===n?t=y(r):(v(n,0,1e9),void 0===e?e=s.rounding:v(e,0,8),t=y(i=E(new s(r),n+r.e+1,e),!1,n+i.e+1)),r.isNeg()&&!r.isZero()?"-"+t:t},m.toFraction=function(n){var e,t,i,r,s,c,a,h,l,d,p,g,m=this,v=m.d,N=m.constructor;if(!v)return new N(m);if(l=t=new N(1),i=h=new N(0),c=(s=(e=new N(i)).e=q(v)-m.e-1)%7,e.d[0]=f(10,c<0?7+c:c),null==n)n=s>0?e:l;else{if(!(a=new N(n)).isInt()||a.lt(l))throw Error(u+a);n=a.gt(e)?s>0?e:l:a}for(o=!1,a=new N(w(v)),d=N.precision,N.precision=s=7*v.length*2;p=x(a,e,0,1,1),1!=(r=t.plus(p.times(i))).cmp(n);)t=i,i=r,r=l,l=h.plus(p.times(r)),h=r,r=e,e=a.minus(p.times(r)),a=r;return r=x(n.minus(t),i,0,1,1),h=h.plus(r.times(l)),t=t.plus(r.times(i)),h.s=l.s=m.s,g=x(l,i,s,1).minus(m).abs().cmp(x(h,t,s,1).minus(m).abs())<1?[l,i]:[h,t],N.precision=d,o=!0,g},m.toHexadecimal=m.toHex=function(n,e){return U(this,16,n,e)},m.toNearest=function(n,e){var t=this,i=t.constructor;if(t=new i(t),null==n){if(!t.d)return t;n=new i(1),e=i.rounding}else{if(n=new i(n),void 0===e?e=i.rounding:v(e,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?(o=!1,t=x(t,n,0,e,1).times(n),o=!0,E(t)):(n.s=t.s,t=n),t},m.toNumber=function(){return+this},m.toOctal=function(n,e){return U(this,8,n,e)},m.toPower=m.pow=function(n){var e,t,i,r,s,u,a=this,h=a.constructor,l=+(n=new h(n));if(!(a.d&&n.d&&a.d[0]&&n.d[0]))return new h(f(+a,l));if((a=new h(a)).eq(1))return a;if(i=h.precision,s=h.rounding,n.eq(1))return E(a,i,s);if((e=c(n.e/7))>=n.d.length-1&&(t=l<0?-l:l)<=9007199254740991)return r=A(h,a,t,i),n.s<0?new h(1).div(r):E(r,i,s);if((u=a.s)<0){if(e<n.d.length-1)return new h(NaN);if(0==(1&n.d[e])&&(u=1),0==a.e&&1==a.d[0]&&1==a.d.length)return a.s=u,a}return(e=0!=(t=f(+a,l))&&isFinite(t)?new h(t+"").e:c(l*(Math.log("0."+w(a.d))/Math.LN10+a.e+1)))>h.maxE+1||e<h.minE-1?new h(e>0?u/0:0):(o=!1,h.rounding=a.s=1,t=Math.min(12,(e+"").length),(r=S(n.times(Z(a,i+t)),i)).d&&N((r=E(r,i+5,1)).d,i,s)&&(e=i+10,+w((r=E(S(n.times(Z(a,e+t)),e),e+5,1)).d).slice(i+1,i+15)+1==1e14&&(r=E(r,i+1,0))),r.s=u,o=!0,h.rounding=s,E(r,i,s))},m.toPrecision=function(n,e){var t,i=this,r=i.constructor;return void 0===n?t=y(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(v(n,1,1e9),void 0===e?e=r.rounding:v(e,0,8),t=y(i=E(new r(i),n,e),n<=i.e||i.e<=r.toExpNeg,n)),i.isNeg()&&!i.isZero()?"-"+t:t},m.toSignificantDigits=m.toSD=function(n,e){var t=this.constructor;return void 0===n?(n=t.precision,e=t.rounding):(v(n,1,1e9),void 0===e?e=t.rounding:v(e,0,8)),E(new t(this),n,e)},m.toString=function(){var n=this,e=n.constructor,t=y(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t},m.truncated=m.trunc=function(){return E(new this.constructor(this),this.e+1,1)},m.valueOf=m.toJSON=function(){var n=this,e=n.constructor,t=y(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+t:t};var x=function(){function e(n,e,t){var i,r=0,s=n.length;for(n=n.slice();s--;)i=n[s]*e+r,n[s]=i%t|0,r=i/t|0;return r&&n.unshift(r),n}function t(n,e,t,i){var r,s;if(t!=i)s=t>i?1:-1;else for(r=s=0;r<t;r++)if(n[r]!=e[r]){s=n[r]>e[r]?1:-1;break}return s}function i(n,e,t,i){for(var r=0;t--;)n[t]-=r,r=n[t]<e[t]?1:0,n[t]=r*i+n[t]-e[t];for(;!n[0]&&n.length>1;)n.shift()}return function(r,s,o,u,f,a){var h,l,d,p,g,m,w,v,N,b,x,y,_,M,D,q,O,A,F,I,S=r.constructor,Z=r.s==s.s?1:-1,B=r.d,P=s.d;if(!(B&&B[0]&&P&&P[0]))return new S(r.s&&s.s&&(B?!P||B[0]!=P[0]:P)?B&&0==B[0]||!P?0*Z:Z/0:NaN);for(a?(g=1,l=r.e-s.e):(a=1e7,g=7,l=c(r.e/g)-c(s.e/g)),F=P.length,O=B.length,b=(N=new S(Z)).d=[],d=0;P[d]==(B[d]||0);d++);if(P[d]>(B[d]||0)&&l--,null==o?(M=o=S.precision,u=S.rounding):M=f?o+(r.e-s.e)+1:o,M<0)b.push(1),m=!0;else{if(M=M/g+2|0,d=0,1==F){for(p=0,P=P[0],M++;(d<O||p)&&M--;d++)D=p*a+(B[d]||0),b[d]=D/P|0,p=D%P|0;m=p||d<O}else{for((p=a/(P[0]+1)|0)>1&&(P=e(P,p,a),B=e(B,p,a),F=P.length,O=B.length),q=F,y=(x=B.slice(0,F)).length;y<F;)x[y++]=0;(I=P.slice()).unshift(0),A=P[0],P[1]>=a/2&&++A;do{p=0,(h=t(P,x,F,y))<0?(_=x[0],F!=y&&(_=_*a+(x[1]||0)),(p=_/A|0)>1?(p>=a&&(p=a-1),1==(h=t(w=e(P,p,a),x,v=w.length,y=x.length))&&(p--,i(w,F<v?I:P,v,a))):(0==p&&(h=p=1),w=P.slice()),(v=w.length)<y&&w.unshift(0),i(x,w,y,a),-1==h&&(h=t(P,x,F,y=x.length))<1&&(p++,i(x,F<y?I:P,y,a)),y=x.length):0===h&&(p++,x=[0]),b[d++]=p,h&&x[0]?x[y++]=B[q]||0:(x=[B[q]],y=1)}while((q++<O||void 0!==x[0])&&M--);m=void 0!==x[0]}b[0]||b.shift()}if(1==g)N.e=l,n=m;else{for(d=1,p=b[0];p>=10;p/=10)d++;N.e=d+l*g-1,E(N,f?o+N.e+1:o,u,m)}return N}}();function E(n,e,t,i){var r,s,u,c,a,h,l,d,p,g=n.constructor;n:if(null!=e){if(!(d=n.d))return n;for(r=1,c=d[0];c>=10;c/=10)r++;if((s=e-r)<0)s+=7,u=e,a=(l=d[p=0])/f(10,r-u-1)%10|0;else if((p=Math.ceil((s+1)/7))>=(c=d.length)){if(!i)break n;for(;c++<=p;)d.push(0);l=a=0,r=1,u=(s%=7)-7+1}else{for(l=c=d[p],r=1;c>=10;c/=10)r++;a=(u=(s%=7)-7+r)<0?0:l/f(10,r-u-1)%10|0}if(i=i||e<0||void 0!==d[p+1]||(u<0?l:l%f(10,r-u-1)),h=t<4?(a||i)&&(0==t||t==(n.s<0?3:2)):a>5||5==a&&(4==t||i||6==t&&(s>0?u>0?l/f(10,r-u):0:d[p-1])%10&1||t==(n.s<0?8:7)),e<1||!d[0])return d.length=0,h?(e-=n.e+1,d[0]=f(10,(7-e%7)%7),n.e=-e||0):d[0]=n.e=0,n;if(0==s?(d.length=p,c=1,p--):(d.length=p+1,c=f(10,7-s),d[p]=u>0?(l/f(10,r-u)%f(10,u)|0)*c:0),h)for(;;){if(0==p){for(s=1,u=d[0];u>=10;u/=10)s++;for(u=d[0]+=c,c=1;u>=10;u/=10)c++;s!=c&&(n.e++,1e7==d[0]&&(d[0]=1));break}if(d[p]+=c,1e7!=d[p])break;d[p--]=0,c=1}for(s=d.length;0===d[--s];)d.pop()}return o&&(n.e>g.maxE?(n.d=null,n.e=NaN):n.e<g.minE&&(n.e=0,n.d=[0])),n}function y(n,e,t){if(!n.isFinite())return B(n);var i,r=n.e,s=w(n.d),o=s.length;return e?(t&&(i=t-o)>0?s=s.charAt(0)+"."+s.slice(1)+O(i):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):r<0?(s="0."+O(-r-1)+s,t&&(i=t-o)>0&&(s+=O(i))):r>=o?(s+=O(r+1-o),t&&(i=t-r-1)>0&&(s=s+"."+O(i))):((i=r+1)<o&&(s=s.slice(0,i)+"."+s.slice(i)),t&&(i=t-o)>0&&(r+1===o&&(s+="."),s+=O(i))),s}function _(n,e){var t=n[0];for(e*=7;t>=10;t/=10)e++;return e}function M(n,e,t){if(e>p)throw o=!0,t&&(n.precision=t),Error("[DecimalError] Precision limit exceeded");return E(new n(i),e,1,!0)}function D(n,e,t){if(e>g)throw Error("[DecimalError] Precision limit exceeded");return E(new n(r),e,t,!0)}function q(n){var e=n.length-1,t=7*e+1;if(e=n[e]){for(;e%10==0;e/=10)t--;for(e=n[0];e>=10;e/=10)t++}return t}function O(n){for(var e="";n--;)e+="0";return e}function A(n,e,t,i){var r,s=new n(1),u=Math.ceil(i/7+4);for(o=!1;;){if(t%2&&L((s=s.times(e)).d,u)&&(r=!0),0===(t=c(t/2))){t=s.d.length-1,r&&0===s.d[t]&&++s.d[t];break}L((e=e.times(e)).d,u)}return o=!0,s}function F(n){return 1&n.d[n.d.length-1]}function I(n,e,t){for(var i,r=new n(e[0]),s=0;++s<e.length;){if(!(i=new n(e[s])).s){r=i;break}r[t](i)&&(r=i)}return r}function S(n,e){var t,i,r,s,u,c,a,h=0,l=0,d=0,p=n.constructor,g=p.rounding,m=p.precision;if(!n.d||!n.d[0]||n.e>17)return new p(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==e?(o=!1,a=m):a=e,c=new p(.03125);n.e>-2;)n=n.times(c),d+=5;for(a+=i=Math.log(f(2,d))/Math.LN10*2+5|0,t=s=u=new p(1),p.precision=a;;){if(s=E(s.times(n),a,1),t=t.times(++l),w((c=u.plus(x(s,t,a,1))).d).slice(0,a)===w(u.d).slice(0,a)){for(r=d;r--;)u=E(u.times(u),a,1);if(null!=e)return p.precision=m,u;if(!(h<3&&N(u.d,a-i,g,h)))return E(u,p.precision=m,g,o=!0);p.precision=a+=10,t=s=c=new p(1),l=0,h++}u=c}}function Z(n,e){var t,i,r,s,u,c,f,a,h,l,d,p=1,g=n,m=g.d,v=g.constructor,b=v.rounding,y=v.precision;if(g.s<0||!m||!m[0]||!g.e&&1==m[0]&&1==m.length)return new v(m&&!m[0]?-1/0:1!=g.s?NaN:m?0:g);if(null==e?(o=!1,h=y):h=e,v.precision=h+=10,i=(t=w(m)).charAt(0),!(Math.abs(s=g.e)<15e14))return a=M(v,h+2,y).times(s+""),g=Z(new v(i+"."+t.slice(1)),h-10).plus(a),v.precision=y,null==e?E(g,y,b,o=!0):g;for(;i<7&&1!=i||1==i&&t.charAt(1)>3;)i=(t=w((g=g.times(n)).d)).charAt(0),p++;for(s=g.e,i>1?(g=new v("0."+t),s++):g=new v(i+"."+t.slice(1)),l=g,f=u=g=x(g.minus(1),g.plus(1),h,1),d=E(g.times(g),h,1),r=3;;){if(u=E(u.times(d),h,1),w((a=f.plus(x(u,new v(r),h,1))).d).slice(0,h)===w(f.d).slice(0,h)){if(f=f.times(2),0!==s&&(f=f.plus(M(v,h+2,y).times(s+""))),f=x(f,new v(p),h,1),null!=e)return v.precision=y,f;if(!N(f.d,h-10,b,c))return E(f,v.precision=y,b,o=!0);v.precision=h+=10,a=u=g=x(l.minus(1),l.plus(1),h,1),d=E(g.times(g),h,1),r=c=1}f=a,r+=2}}function B(n){return String(n.s*n.s/0)}function P(n,e){var t,i,r;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(t<0&&(t=i),t+=+e.slice(i+1),e=e.substring(0,i)):t<0&&(t=e.length),i=0;48===e.charCodeAt(i);i++);for(r=e.length;48===e.charCodeAt(r-1);--r);if(e=e.slice(i,r)){if(r-=i,n.e=t=t-i-1,n.d=[],i=(t+1)%7,t<0&&(i+=7),i<r){for(i&&n.d.push(+e.slice(0,i)),r-=7;i<r;)n.d.push(+e.slice(i,i+=7));i=7-(e=e.slice(i)).length}else i-=r;for(;i--;)e+="0";n.d.push(+e),o&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function T(n,e){var t,i,r,s,c,d,p,g,m;if("Infinity"===e||"NaN"===e)return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(h.test(e))t=16,e=e.toLowerCase();else if(a.test(e))t=2;else{if(!l.test(e))throw Error(u+e);t=8}for((s=e.search(/p/i))>0?(p=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),c=(s=e.indexOf("."))>=0,i=n.constructor,c&&(s=(d=(e=e.replace(".","")).length)-s,r=A(i,new i(t),s,2*s)),s=m=(g=b(e,t,1e7)).length-1;0===g[s];--s)g.pop();return s<0?new i(0*n.s):(n.e=_(g,m),n.d=g,o=!1,c&&(n=x(n,r,4*d)),p&&(n=n.times(Math.abs(p)<54?f(2,p):qn.pow(2,p))),o=!0,n)}function k(n,e,t,i,r){var s,u,c,f,a=n.precision,h=Math.ceil(a/7);for(o=!1,f=t.times(t),c=new n(i);;){if(u=x(c.times(f),new n(e++*e++),a,1),c=r?i.plus(u):i.minus(u),i=x(u.times(f),new n(e++*e++),a,1),void 0!==(u=c.plus(i)).d[h]){for(s=h;u.d[s]===c.d[s]&&s--;);if(-1==s)break}s=c,c=i,i=u,u=s}return o=!0,u.d.length=h+1,u}function C(n,e){for(var t=n;--e;)t*=n;return t}function R(n,t){var i,r=t.s<0,s=D(n,n.precision,1),o=s.times(.5);if((t=t.abs()).lte(o))return e=r?4:1,t;if((i=t.divToInt(s)).isZero())e=r?3:2;else{if((t=t.minus(i.times(s))).lte(o))return e=F(i)?r?2:3:r?4:1,t;e=F(i)?r?1:4:r?3:2}return t.minus(s).abs()}function U(e,i,r,s){var o,u,c,f,a,h,l,d,p,g=e.constructor,m=void 0!==r;if(m?(v(r,1,1e9),void 0===s?s=g.rounding:v(s,0,8)):(r=g.precision,s=g.rounding),e.isFinite()){for(m?(o=2,16==i?r=4*r-3:8==i&&(r=3*r-2)):o=i,(c=(l=y(e)).indexOf("."))>=0&&(l=l.replace(".",""),(p=new g(1)).e=l.length-c,p.d=b(y(p),10,o),p.e=p.d.length),u=a=(d=b(l,10,o)).length;0==d[--a];)d.pop();if(d[0]){if(c<0?u--:((e=new g(e)).d=d,e.e=u,d=(e=x(e,p,r,s,0,o)).d,u=e.e,h=n),c=d[r],f=o/2,h=h||void 0!==d[r+1],h=s<4?(void 0!==c||h)&&(0===s||s===(e.s<0?3:2)):c>f||c===f&&(4===s||h||6===s&&1&d[r-1]||s===(e.s<0?8:7)),d.length=r,h)for(;++d[--r]>o-1;)d[r]=0,r||(++u,d.unshift(1));for(a=d.length;!d[a-1];--a);for(c=0,l="";c<a;c++)l+=t.charAt(d[c]);if(m){if(a>1)if(16==i||8==i){for(c=16==i?4:3,--a;a%c;a++)l+="0";for(a=(d=b(l,o,i)).length;!d[a-1];--a);for(c=1,l="1.";c<a;c++)l+=t.charAt(d[c])}else l=l.charAt(0)+"."+l.slice(1);l=l+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)l="0"+l;l="0."+l}else if(++u>a)for(u-=a;u--;)l+="0";else u<a&&(l=l.slice(0,u)+"."+l.slice(u))}else l=m?"0p+0":"0";l=(16==i?"0x":2==i?"0b":8==i?"0o":"")+l}else l=B(e);return e.s<0?"-"+l:l}function L(n,e){if(n.length>e)return n.length=e,!0}function H(n){return new this(n).abs()}function j(n){return new this(n).acos()}function V(n){return new this(n).acosh()}function $(n,e){return new this(n).plus(e)}function W(n){return new this(n).asin()}function J(n){return new this(n).asinh()}function z(n){return new this(n).atan()}function G(n){return new this(n).atanh()}function K(n,e){n=new this(n),e=new this(e);var t,i=this.precision,r=this.rounding,s=i+4;return n.s&&e.s?n.d||e.d?!e.d||n.isZero()?(t=e.s<0?D(this,i,r):new this(0)).s=n.s:!n.d||e.isZero()?(t=D(this,s,1).times(.5)).s=n.s:e.s<0?(this.precision=s,this.rounding=1,t=this.atan(x(n,e,s,1)),e=D(this,s,1),this.precision=i,this.rounding=r,t=n.s<0?t.minus(e):t.plus(e)):t=this.atan(x(n,e,s,1)):(t=D(this,s,1).times(e.s>0?.25:.75)).s=n.s:t=new this(NaN),t}function Q(n){return new this(n).cbrt()}function X(n){return E(n=new this(n),n.e+1,2)}function Y(n){if(!n||"object"!=typeof n)throw Error("[DecimalError] Object expected");var e,t,i,r=!0===n.defaults,o=["precision",1,1e9,"rounding",0,8,"toExpNeg",-9e15,0,"toExpPos",0,9e15,"maxE",0,9e15,"minE",-9e15,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(t=o[e],r&&(this[t]=s[t]),void 0!==(i=n[t])){if(!(c(i)===i&&i>=o[e+1]&&i<=o[e+2]))throw Error(u+t+": "+i);this[t]=i}if(t="crypto",r&&(this[t]=s[t]),void 0!==(i=n[t])){if(!0!==i&&!1!==i&&0!==i&&1!==i)throw Error(u+t+": "+i);if(i){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error("[DecimalError] crypto unavailable");this[t]=!0}else this[t]=!1}return this}function nn(n){return new this(n).cos()}function en(n){return new this(n).cosh()}function tn(n,e){return new this(n).div(e)}function rn(n){return new this(n).exp()}function sn(n){return E(n=new this(n),n.e+1,3)}function on(){var n,e,t=new this(0);for(o=!1,n=0;n<arguments.length;)if((e=new this(arguments[n++])).d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return o=!0,new this(1/0);t=e}return o=!0,t.sqrt()}function un(n){return n instanceof qn||n&&"[object Decimal]"===n.name||!1}function cn(n){return new this(n).ln()}function fn(n,e){return new this(n).log(e)}function an(n){return new this(n).log(2)}function hn(n){return new this(n).log(10)}function ln(){return I(this,arguments,"lt")}function dn(){return I(this,arguments,"gt")}function pn(n,e){return new this(n).mod(e)}function gn(n,e){return new this(n).mul(e)}function mn(n,e){return new this(n).pow(e)}function wn(n){var e,t,i,r,s=0,o=new this(1),u=[];if(void 0===n?n=this.precision:v(n,1,1e9),i=Math.ceil(n/7),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));s<i;)(r=e[s])>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=r%1e7;else{if(!crypto.randomBytes)throw Error("[DecimalError] crypto unavailable");for(e=crypto.randomBytes(i*=4);s<i;)(r=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((127&e[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(e,s):(u.push(r%1e7),s+=4);s=i/4}else for(;s<i;)u[s++]=1e7*Math.random()|0;for(n%=7,(i=u[--s])&&n&&(r=f(10,7-n),u[s]=(i/r|0)*r);0===u[s];s--)u.pop();if(s<0)t=0,u=[0];else{for(t=-1;0===u[0];t-=7)u.shift();for(i=1,r=u[0];r>=10;r/=10)i++;i<7&&(t-=7-i)}return o.e=t,o.d=u,o}function vn(n){return E(n=new this(n),n.e+1,this.rounding)}function Nn(n){return(n=new this(n)).d?n.d[0]?n.s:0*n.s:n.s||NaN}function bn(n){return new this(n).sin()}function xn(n){return new this(n).sinh()}function En(n){return new this(n).sqrt()}function yn(n,e){return new this(n).sub(e)}function _n(n){return new this(n).tan()}function Mn(n){return new this(n).tanh()}function Dn(n){return E(n=new this(n),n.e+1,1)}m[Symbol.for("nodejs.util.inspect.custom")]=m.toString,m[Symbol.toStringTag]="Decimal";var qn=function n(e){var t,i,r;function s(n){var e,t,i,r=this;if(!(r instanceof s))return new s(n);if(r.constructor=s,n instanceof s)return r.s=n.s,void(o?!n.d||n.e>s.maxE?(r.e=NaN,r.d=null):n.e<s.minE?(r.e=0,r.d=[0]):(r.e=n.e,r.d=n.d.slice()):(r.e=n.e,r.d=n.d?n.d.slice():n.d));if("number"===(i=typeof n)){if(0===n)return r.s=1/n<0?-1:1,r.e=0,void(r.d=[0]);if(n<0?(n=-n,r.s=-1):r.s=1,n===~~n&&n<1e7){for(e=0,t=n;t>=10;t/=10)e++;return void(o?e>s.maxE?(r.e=NaN,r.d=null):e<s.minE?(r.e=0,r.d=[0]):(r.e=e,r.d=[n]):(r.e=e,r.d=[n]))}return 0*n!=0?(n||(r.s=NaN),r.e=NaN,void(r.d=null)):P(r,n.toString())}if("string"!==i)throw Error(u+n);return 45===(t=n.charCodeAt(0))?(n=n.slice(1),r.s=-1):(43===t&&(n=n.slice(1)),r.s=1),d.test(n)?P(r,n):T(r,n)}if(s.prototype=m,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=Y,s.clone=n,s.isDecimal=un,s.abs=H,s.acos=j,s.acosh=V,s.add=$,s.asin=W,s.asinh=J,s.atan=z,s.atanh=G,s.atan2=K,s.cbrt=Q,s.ceil=X,s.cos=nn,s.cosh=en,s.div=tn,s.exp=rn,s.floor=sn,s.hypot=on,s.ln=cn,s.log=fn,s.log10=hn,s.log2=an,s.max=ln,s.min=dn,s.mod=pn,s.mul=gn,s.pow=mn,s.random=wn,s.round=vn,s.sign=Nn,s.sin=bn,s.sinh=xn,s.sqrt=En,s.sub=yn,s.tan=_n,s.tanh=Mn,s.trunc=Dn,void 0===e&&(e={}),e&&!0!==e.defaults)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return s.config(e),s}(s);function On(n,e){if(!n)throw new Error(e)}i=new qn(i),r=new qn(r);class An{constructor(n,e){this.amount=0,this.amount=n,this.symbol=e,On(this.is_amount_within_range(),"magnitude of asset amount must be less than 2^62")}is_amount_within_range(){return-An.max_amount<=this.amount&&this.amount<=An.max_amount}is_valid(){return!0}toString(){return`${this.toDecimal().toFixed(this.symbol.precision())} ${this.symbol.code()}`}toDecimal(){return new qn(this.amount).div(Math.pow(10,this.symbol.precision()))}toNumber(){return Number(this.toDecimal().toNumber().toFixed(this.symbol.precision()))}}An.max_amount=2**62-1;class Fn{constructor(n,e){this._code=n,this._precision=e}code(){return this._code}isEqual(n){return n.code===this.code&&n.precision()===this.precision()}precision(){return this._precision}}class In{sec_since_epoch(){return Date.now()}}const Sn=new Date(Date.UTC(2e3,0,1,0,0,0,0)).getTime();function Zn(){const n=new Date(Date.UTC(2e3,0,1,0,0,0,0)).getTime();return Math.floor((Date.now()-n)/1e3/604800)/52}exports.Asset=An,exports.Symbol=Fn,exports.block_timestamp_epoch=Sn,exports.check=On,exports.current_time_point=function(){return new In},exports.seconds_per_day=86400,exports.split=function(n){const[e,t]=n.split(" "),i=(e.split(".")[1]||[]).length,r=new qn(e).times(new qn(10).pow(i)).toNumber();return new An(r,new Fn(t,i))},exports.stake2vote=function(n){return n*Math.pow(2,Zn())},exports.symbol_code=class{constructor(n){this.value=0,n&&(this.value="number"==typeof n?Number(n):function(n){let e=BigInt(0);n.length>7&&On(!1,"string is too long to be a valid symbol_code");for(const t of n.split("").reverse().join(""))(t<"A"||t>"Z")&&On(!1,"only uppercase letters allowed in symbol_code string"),e<<=BigInt(8),e|=BigInt(t.charCodeAt(0));return Number(e)}(n))}raw(){return this.value}length(){let n=BigInt(this.value),e=0;for(;255&Number(n)&&e<=7;)e++,n>>=BigInt(8);return e}to_string(){return function(n){const e=BigInt(255);if(0==n)return"";let t="",i=BigInt(n);for(let n=0;n<7;++n,i>>=BigInt(8)){if(i==BigInt(0))return t;t+=String.fromCharCode(Number(i&e))}return t}(this.value)}is_valid(){let n=BigInt(this.value);for(let e=0;e<7;e++){const t=String.fromCharCode(255&Number(n));if(!("A"<=t&&t<="Z"))return!1;if(n>>=BigInt(8),!(255&Number(n)))do{if(n>>=BigInt(8),255&Number(n))return!1;e++}while(e<7)}return!0}isEqual(n){return n.value===this.value}},exports.vote2stake=function(n){return n/Math.pow(2,Zn())},exports.voteWeightToday=Zn; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/core/eosio/check.hpp | ||
/** | ||
* Assert if the predicate fails and use the supplied message. | ||
* | ||
* @param {boolean} pred Pre-condition | ||
* @param {string} msg Error Message | ||
* @returns {void} | ||
* @example | ||
* | ||
* check(a == b, "a does not equal b"); | ||
*/ | ||
function check(pred, msg) { | ||
if (!pred) { | ||
throw new Error(msg); | ||
} | ||
} | ||
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp | ||
function str_to_symbol_code(str) { | ||
let value = BigInt(0); | ||
if (str.length > 7) { | ||
check(false, "string is too long to be a valid symbol_code"); | ||
} | ||
for (const itr of str.split("").reverse().join("")) { | ||
if (itr < 'A' || itr > 'Z') { | ||
check(false, "only uppercase letters allowed in symbol_code string"); | ||
} | ||
value <<= BigInt(8); | ||
value |= BigInt(itr.charCodeAt(0)); | ||
} | ||
return Number(value); | ||
} | ||
function write_as_string(value) { | ||
const mask = BigInt(0x00000000000000FF); | ||
if (value == 0) | ||
return ''; | ||
let begin = ""; | ||
let v = BigInt(value); | ||
for (let i = 0; i < 7; ++i, v >>= BigInt(8)) { | ||
if (v == BigInt(0)) | ||
return begin; | ||
begin += String.fromCharCode(Number(v & mask)); | ||
} | ||
return begin; | ||
} | ||
/** | ||
* @class Stores the symbol code | ||
* @brief Stores the symbol code as a uint64_t value | ||
*/ | ||
class symbol_code { | ||
// constructor() | ||
constructor(str) { | ||
this.value = 0; // uint64_t | ||
if (str) { | ||
if (typeof str == 'number') | ||
this.value = Number(str); | ||
else | ||
this.value = str_to_symbol_code(str); | ||
} | ||
} | ||
raw() { | ||
return this.value; | ||
} | ||
length() { | ||
let sym = BigInt(this.value); | ||
let len = 0; | ||
while (Number(sym) & 0xFF && len <= 7) { | ||
len++; | ||
sym >>= BigInt(8); | ||
} | ||
return len; | ||
} | ||
to_string() { | ||
return write_as_string(this.value); | ||
} | ||
is_valid() { | ||
let sym = BigInt(this.value); | ||
for (let i = 0; i < 7; i++) { | ||
const c = String.fromCharCode(Number(sym) & 0xFF); | ||
if (!("A" <= c && c <= "Z")) | ||
return false; | ||
sym >>= BigInt(8); | ||
if (!(Number(sym) & 0xFF)) { | ||
do { | ||
sym >>= BigInt(8); | ||
if ((Number(sym) & 0xFF)) | ||
return false; | ||
i++; | ||
} while (i < 7); | ||
} | ||
} | ||
return true; | ||
} | ||
isEqual(comparison) { | ||
return comparison.value === this.value; | ||
} | ||
} | ||
class Symbol { | ||
/** | ||
* Symbol | ||
* | ||
* @name Symbol | ||
* @param {string} code Symbol Code | ||
* @param {number} precision Precision | ||
* @returns {Symbol} Symbol | ||
* @example | ||
* | ||
* const sym = new Symbol("EOS", 4); | ||
* sym.code() //=> "EOS" | ||
* sym.precision //=> 4 | ||
*/ | ||
constructor(code, precision) { | ||
this._code = (typeof code == "string") ? new symbol_code(code) : code; | ||
this._precision = precision; | ||
} | ||
code() { | ||
return this._code; | ||
} | ||
isEqual(comparison) { | ||
return comparison.code === this.code && comparison.precision() === this.precision(); | ||
} | ||
precision() { | ||
return this._precision; | ||
} | ||
} | ||
// import { Decimal } from "decimal.js"; | ||
/** | ||
* Split quantity string | ||
* | ||
* @param {string} quantity Quantity string | ||
* @returns {Asset} | ||
* @example | ||
* | ||
* const quantity = split("1.0000 EOS"); | ||
* quantity.amount //=> 10000 | ||
* quantity.symbol.precision //=> 4 | ||
* quantity.symbol.code() //=> "EOS" | ||
*/ | ||
function split(quantity) { | ||
const [amount, symbol] = quantity.split(" "); | ||
const precision = (amount.split(".")[1] || []).length; | ||
const amount_uint64 = Number(amount) * Math.pow(10, precision); | ||
return new Asset(amount_uint64, new Symbol(symbol, precision)); | ||
} | ||
function asset_to_double(quantity) { | ||
if (quantity.amount == 0) | ||
return 0.0; | ||
return quantity.amount / Math.pow(10, quantity.symbol.precision()); | ||
} | ||
function double_to_asset(amount, sym) { | ||
return new Asset(amount * Math.pow(10, sym.precision()), sym); | ||
} | ||
// https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp | ||
/** | ||
* Asset | ||
* | ||
* @name Asset | ||
* @param {number} amount The amount of the asset | ||
* @param {Symbol} sym The name of the symbol | ||
* @returns {Asset} Asset | ||
* @example | ||
* | ||
* const quantity = new Asset(10000, new Symbol("EOS", 4)); | ||
* quantity.toString() //=> "1.0000 EOS"; | ||
* quantity.symbol.code() //=> "EOS" | ||
* quantity.symbol.precision //=> 4 | ||
*/ | ||
class Asset { | ||
constructor(amount, sym) { | ||
/** | ||
* {int64_t} The amount of the asset | ||
*/ | ||
this.amount = 0; | ||
this.amount = amount; | ||
this.symbol = sym; | ||
check(this.is_amount_within_range(), "magnitude of asset amount must be less than 2^62"); | ||
// check( this.symbol.is_valid(), "invalid symbol name" ); | ||
} | ||
/** | ||
* Check if the amount doesn't exceed the max amount | ||
* | ||
* @return true - if the amount doesn't exceed the max amount | ||
* @return false - otherwise | ||
*/ | ||
is_amount_within_range() { | ||
return -Asset.max_amount <= this.amount && this.amount <= Asset.max_amount; | ||
} | ||
/** | ||
* Check if the asset is valid. %A valid asset has its amount <= max_amount and its symbol name valid | ||
* | ||
* @return true - if the asset is valid | ||
* @return false - otherwise | ||
*/ | ||
is_valid() { | ||
// return this.is_amount_within_range() && this.symbol.is_valid(); | ||
return true; | ||
} | ||
to_string() { | ||
const amount = this.to_double().toFixed(this.symbol.precision()); | ||
return `${amount} ${this.symbol.code().to_string()}`; | ||
} | ||
to_double() { | ||
return asset_to_double(this); | ||
} | ||
} | ||
/** | ||
* {constexpr int64_t} Maximum amount possible for this asset. It's capped to 2^62 - 1 | ||
*/ | ||
Asset.max_amount = 2 ** 62 - 1; | ||
class Time { | ||
sec_since_epoch() { | ||
return Date.now(); | ||
} | ||
} | ||
function current_time_point() { | ||
return new Time(); | ||
} | ||
const block_timestamp_epoch = new Date(Date.UTC(2000, 0, 1, 0, 0, 0, 0)).getTime(); | ||
const seconds_per_day = 60 * 60 * 24; | ||
// https://github.com/EOSIO/eosio.contracts/blob/master/contracts/eosio.system/src/voting.cpp | ||
/** | ||
* voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value. | ||
*/ | ||
function voteWeightToday() { | ||
const seconds_per_day = 86400; | ||
const block_timestamp_epoch = new Date(Date.UTC(2000, 0, 1, 0, 0, 0, 0)).getTime(); | ||
return Math.floor((Date.now() - block_timestamp_epoch) / 1000 / (seconds_per_day * 7)) / 52; | ||
} | ||
/** | ||
* Convert EOS stake into decaying value | ||
* | ||
* @param {number} vote vote | ||
*/ | ||
function stake2vote(staked) { | ||
return staked * Math.pow(2, voteWeightToday()); | ||
} | ||
/** | ||
* Convert vote decay value into EOS stake | ||
* | ||
* @param {number} staked staked | ||
*/ | ||
function vote2stake(vote) { | ||
return vote / Math.pow(2, voteWeightToday()); | ||
} | ||
exports.Asset = Asset; | ||
exports.Symbol = Symbol; | ||
exports.asset_to_double = asset_to_double; | ||
exports.block_timestamp_epoch = block_timestamp_epoch; | ||
exports.check = check; | ||
exports.current_time_point = current_time_point; | ||
exports.double_to_asset = double_to_asset; | ||
exports.seconds_per_day = seconds_per_day; | ||
exports.split = split; | ||
exports.stake2vote = stake2vote; | ||
exports.symbol_code = symbol_code; | ||
exports.vote2stake = vote2stake; | ||
exports.voteWeightToday = voteWeightToday; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "eos-common", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "EOSIO Smart Contract common library used for Typescript", | ||
@@ -21,3 +21,3 @@ "main": "dist/index.js", | ||
"build": "rollup -c rollup.config.ts", | ||
"prepublishOnly": "npm run build", | ||
"prepublishOnly": "npm run test && npm run build", | ||
"test": "jest --coverage", | ||
@@ -51,5 +51,3 @@ "posttest": "eslint . --ext .ts", | ||
}, | ||
"dependencies": { | ||
"decimal.js": "10.x" | ||
} | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
16
644
27581
- Removeddecimal.js@10.x
- Removeddecimal.js@10.4.3(transitive)