# HP Forums

Full Version: (Plus 42) Fraction approximation equation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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/
(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

You can prevent :‌D from turning into :D 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/

Isn't it simpler to just "Disable Smilies"?
(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.
(The difference is whether a line break may occur or not.)

https://unicode-table.com/en/200B/
https://unicode-table.com/en/200C/

Isn't it simpler to just "Disable Smilies"?

Thanks Thomas and Massimo, I didn't notice that !
Since I'm lazy, I chose the "disable smilies" option
Cheers
(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.
(The difference is whether a line break may occur or not.)

https://unicode-table.com/en/200B/
https://unicode-table.com/en/200C/

Isn't it simpler to just "Disable Smilies"?

Disabling smilies is also better for cut and pasting.
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :