02-17-2022, 01:38 PM
Hi all,
Since Plus42 does not (have) yet a fraction mode à la 32SII/35S, and since this mode is anyway limited (4096 denominator maximum, no expression of tolerance, just max denominator) I made an equation for it.
It has no intelligence whatsoever, no limited fractions algorithm, just plain stupid brute force try of every possible denominator. Plus42 is so fast anyway :)
Just enter X, the value to be approximated, and TOL (e.g. 1E-8), the tolerance of the approximation. Press EVAL, now N holds the numerator of the approximated fraction, D the denominator, and RES the difference with the original number.
Cheers
FRAC:0×FOR(SEQ(L(N:IP(X)):L(D:1)):L(RES:ABS(N÷D-X))>TOL:0:SEQ(L(D:D+1):L(N:RND(D×X:0))))+RES
Since Plus42 does not (have) yet a fraction mode à la 32SII/35S, and since this mode is anyway limited (4096 denominator maximum, no expression of tolerance, just max denominator) I made an equation for it.
It has no intelligence whatsoever, no limited fractions algorithm, just plain stupid brute force try of every possible denominator. Plus42 is so fast anyway :)
Just enter X, the value to be approximated, and TOL (e.g. 1E-8), the tolerance of the approximation. Press EVAL, now N holds the numerator of the approximated fraction, D the denominator, and RES the difference with the original number.
Cheers
FRAC:0×FOR(SEQ(L(N:IP(X)):L(D:1)):L(RES:ABS(N÷D-X))>TOL:0:SEQ(L(D:D+1):L(N:RND(D×X:0))))+RES