Post Reply 
50G fraction question Q-> function max denominator
11-08-2019, 08:43 PM
Post: #15
RE: 50G fraction question Q-> function max denominator
(11-08-2019 07:01 PM)Albert Chan Wrote:  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

Which is certainly another variation on the theme, but not quite the same thing I was focusing on (denominators whose value is specifically an integral power of 2).

The context I'm thinking of here is something like a ruler which has score marks at 1, 1/2, 1/4, 1/8, 1/16, and 1/32 intervals for the units in question (for non-American viewers, this how most of our inch-based rulers are scored). Chain calculations with mixed decimals and fractions can be streamlined with a utility that provides this kind of function.

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).

I realize this is a highly-specific application, but I believe it's still in the spirit of the original poster's intent.
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 - DavidM - 11-08-2019 08:43 PM



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