(Plus 42) Fraction approximation equation - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: Not HP Calculators ( /forum-7.html)+--- Forum: Not quite HP Calculators - but related ( /forum-8.html)+--- Thread: (Plus 42) Fraction approximation equation ( /thread-18047.html) |

(Plus 42) Fraction approximation equation - Vincent Weber - 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 RE: (Plus 42) Fraction approximation equation - Thomas Okken - 02-17-2022 02:14 PM
(02-17-2022 01:38 PM)Vincent Weber Wrote: FRAC:0×FOR(SEQ(L(N:IP(X)):L(D:1)):L(RES:ABS(N÷D-X))>TOL:0:SEQ(L(D+1):L(N:RND(D×X:0))))+RES You can prevent :D from turning into by putting a zero-width space or a zero-width non-joiner between the : and the D. (The difference is whether a line break may occur or not.) https://unicode-table.com/en/200B/ https://unicode-table.com/en/200C/ RE: (Plus 42) Fraction approximation equation - Massimo Gnerucci - 02-17-2022 02:50 PM
(02-17-2022 02:14 PM)Thomas Okken Wrote:(02-17-2022 01:38 PM)Vincent Weber Wrote: 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 Isn't it simpler to just "Disable Smilies"? RE: (Plus 42) Fraction approximation equation - Vincent Weber - 02-17-2022 03:47 PM
(02-17-2022 02:50 PM)Massimo Gnerucci Wrote:(02-17-2022 02:14 PM)Thomas Okken Wrote: You can prevent :D from turning into by putting a zero-width space or a zero-width non-joiner between the : and the D. Thanks Thomas and Massimo, I didn't notice that ! Since I'm lazy, I chose the "disable smilies" option Cheers RE: (Plus 42) Fraction approximation equation - ijabbott - 02-17-2022 08:38 PM
(02-17-2022 02:50 PM)Massimo Gnerucci Wrote:(02-17-2022 02:14 PM)Thomas Okken Wrote: You can prevent :D from turning into by putting a zero-width space or a zero-width non-joiner between the : and the D. Disabling smilies is also better for cut and pasting. |