Post Reply 
50G fraction question Q-> function max denominator
11-08-2019, 10:05 PM
Post: #17
RE: 50G fraction question Q-> function max denominator
(11-08-2019 08:43 PM)DavidM Wrote:  I'm sure the brute-force method can be improved upon, but I would prefer an approach which gives the same kind of solution, ie. the closest approximation with the lowest power-of-2 denominator (up to the max allowed, of course).

x' = round(x D) / D will gives you the same answer (for this case D = 2^n)

Perhaps it is easier to visualize if you consider denominator as the maximum D
In other words, fraction is not (yet) allowed to be simplified

x = (x D) / D = y / D

x' = y' / D, y' an integer

Now, what integer value of y' will minimize error ? y' = round(y)

error = |x - x'| = |y - y'| / D ≤ 0.5 / D
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: 50G fraction question Q-> function max denominator - Albert Chan - 11-08-2019 10:05 PM



User(s) browsing this thread: 2 Guest(s)