You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So decimal.js-light has all the API's and I am okey with not including infinity nan and null.
However i do need to use toFraction in the app. Is there a way i can extend it or how can I make a function that does the same as toFraction in decimal.js.
I tried to read and replicate the same thing that the function, but having a really hard time reading and reimplementing this:
P.toFraction=function(maxD){vard,d0,d1,d2,e,k,n,n0,n1,pr,q,r,x=this,xd=x.d,Ctor=x.constructor;if(!xd)returnnewCtor(x);n1=d0=newCtor(1);d1=n0=newCtor(0);d=newCtor(d1);e=d.e=getPrecision(xd)-x.e-1;k=e%LOG_BASE;d.d[0]=mathpow(10,k<0 ? LOG_BASE+k : k);if(maxD==null){// d is 10**e, the minimum max-denominator needed.maxD=e>0 ? d : n1;}else{n=newCtor(maxD);if(!n.isInt()||n.lt(n1))throwError(invalidArgument+n);maxD=n.gt(d) ? (e>0 ? d : n1) : n;}external=false;n=newCtor(digitsToString(xd));pr=Ctor.precision;Ctor.precision=e=xd.length*LOG_BASE*2;for(;;){q=divide(n,d,0,1,1);d2=d0.plus(q.times(d1));if(d2.cmp(maxD)==1)break;d0=d1;d1=d2;d2=n1;n1=n0.plus(q.times(d2));n0=d2;d2=d;d=n.minus(q.times(d2));n=d2;}d2=divide(maxD.minus(d0),d1,0,1,1);n0=n0.plus(d2.times(n1));d0=d0.plus(d2.times(d1));n0.s=n1.s=x.s;// Determine which fraction is closer to x, n0/d0 or n1/d1?r=divide(n1,d1,e,1).minus(x).abs().cmp(divide(n0,d0,e,1).minus(x).abs())<1
? [n1,d1] : [n0,d0];Ctor.precision=pr;external=true;returnr;};
The text was updated successfully, but these errors were encountered:
So decimal.js-light has all the API's and I am okey with not including infinity nan and null.
However i do need to use toFraction in the app. Is there a way i can extend it or how can I make a function that does the same as toFraction in
decimal.js
.I tried to read and replicate the same thing that the function, but having a really hard time reading and reimplementing this:
The text was updated successfully, but these errors were encountered: