The problem is to detemine both an integer numerator and integer denominator (both in the range 0 through 1023) for a quotient that matches a target value as closely as possible.

For a simple example the target value may be 0.595. In this case a denominator of 595 and numerator of 1000 would provide and exact to 0.595 when the quotient is calculated.

A harder example might be 0.595452. In this case a numerator of 596 and a denominator of 1001 provides a fairly close match, but is there a closer one?

I have thought this through and think there may be a way to do this using an itterative method. What would be neat is if there was a method that could be used to calculate the numerator and denominator values directly that matches any target value (within a range) as closely as possible.

Any ideas would be appreciated.

Regards