(Plus 42) Fraction approximation equation
|
02-17-2022, 01:38 PM
(This post was last modified: 02-17-2022 08:41 PM by Vincent Weber.)
Post: #1
|
|||
|
|||
(Plus 42) Fraction approximation equation
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, 02:14 PM
Post: #2
|
|||
|
|||
RE: (Plus 42) Fraction approximation equation
(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:50 PM
Post: #3
|
|||
|
|||
RE: (Plus 42) Fraction approximation equation
(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"? Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
02-17-2022, 03:47 PM
Post: #4
|
|||
|
|||
RE: (Plus 42) Fraction approximation equation
(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 |
|||
02-17-2022, 08:38 PM
Post: #5
|
|||
|
|||
RE: (Plus 42) Fraction approximation equation
(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. — Ian Abbott |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)