oh right -- mediants! I&#x27;ve never heard of Stern-Brocot but I know what it is.<p>Why not just use continued fractions directly? <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continued_fraction#Calculating_continued_fraction_representations" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continued_fraction#Calculating...</a><p>e.g.<p>p = 3.141592653589793<p><pre><code>  = 3 + 1 &#x2F; 7.062513305931052

  = 3 + 1 &#x2F; (7 + 1 &#x2F; 15.996594406684103)

  = 3 + 1 &#x2F; (7 + 1 &#x2F; (15 + 1 &#x2F; 1.0034172310150002))

  = 3 + 1 &#x2F; (7 + 1 &#x2F; (15 + 1 &#x2F; (1 + 1&#x2F;292.63459087501246)))
</code></pre>
so the continued fraction coefficients are 3;7;15;1;292 (see <a href="http:&#x2F;&#x2F;mathworld.wolfram.com&#x2F;PiContinuedFraction.html" rel="nofollow">http:&#x2F;&#x2F;mathworld.wolfram.com&#x2F;PiContinuedFraction.html</a> or <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continued_fraction#Continued_fraction_expansions_of_.CF.80" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continued_fraction#Continued_f...</a>) and can be converted to rationals at each step using the semiconvergent recursion formula <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continued_fraction#Semiconvergents" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continued_fraction#Semiconverg...</a>  to get approximants 3&#x2F;1, 22&#x2F;7,<p>(3 + 15 * 22) &#x2F; (1 + 15 * 7) = 333&#x2F;106,<p>(22 + 1 * 333) &#x2F; (7 + 1 * 106) = 355&#x2F;113,<p>(333 + 292 * 355) &#x2F; (106 + 292 * 113) = 103993&#x2F;33102,<p>etc.