We have a floating point number
r between 0 and 1, and an integer
Find the fraction of integers with the smallest denominator, which approximates
r with at least
r(a floating point number) and
a/b(as float) approximates
bis the possible smallest such positive integer.
- then the result is
Any solution has to work in theory with arbitrary-precision types, but limitations caused by implementations' fixed-precision types do not matter.
Precision means the number of digits after "
r. Thus, if
a/b should start with
0.012. If the first
p digits of the fractional part of
r are 0, undefined behavior is acceptable.
- The algorithmically fastest algorithm wins. Speed is measured in O(p).
- If there are multiple fastest algorithms, then the shortest wins.
- My own answer is excluded from the set of the possible winners.
P.s. the math part is actually much easier as it seems, I suggest to read this post.