How do I find the integers $x$ and $y$ minimizing $| t - x \cdot y |$ with $1 \leq x < N$ and $1 \leq y < M$ ?
Background: A clock signal is divided by two hardware prescalers (with a limited number of bits), how do I produce an output frequency that is as close as possible to the desired frequency ?
(24,417), (36,278), (72,139), (139,72), (278,36), (417,24)
i.e. the solution maybe does no exist, there is no solution with distance $0$ because t is prime. I have used a simple linear search for $x=\lfloor t / (y_{max}+1\rfloor.. x_{max}$ – gammatester Mar 20 '14 at 15:01N
andM
are necessarily powers of 2? How big ist
? Does it factor nicely? – Tavian Barnes Dec 08 '14 at 21:16