[math-fun] Nearest rationals algorithm