50G fraction question Q-> function max denominator
|
11-08-2019, 07:01 PM
Post: #14
|
|||
|
|||
RE: 50G fraction question Q-> function max denominator
(10-29-2019 02:16 PM)DavidM Wrote: After thinking about this question a bit, a slightly different idea came to mind. I was wondering how I would determine which fraction whose denominator is a power of two would be the best fit for a given real number. I'm sure there's a more elegant way to do this, but I came up with the following brute-force approach which simply checks each possibility starting with "/2" and multiplying the denominator by 2 up to the specified limit. The closest combination is then returned as a symbolic number in the form "a+b/c" (or simply "b/c" as appropriate) ... For x best estimate with maximum denominator D, *AND* final denominator divides D, simply calculate round(x D) / D Example: x = e, D=512 => round(e * 512) / 512 = 1392 / 512 = 2 + 23/32 x = Pi, D=3600 => round(Pi * 3600) / 3600 = 11310 / 3600 = 3 + 17/120 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)