Mark Dickinson <dicki...@gmail.com> added the comment:
Hmm. isqrt_frac_rto is unnecessarily complicated. Here's a more streamlined version of the code. import math def isqrt_frac_rto(n, m): """ Square root of n/m, rounded to the nearest integer using round-to-odd. """ a = math.isqrt(n*m) // m return a | (a*a*m != n) def sqrt_frac(n, m): """ Square root of n/m as a float, correctly rounded. """ q = (n.bit_length() - m.bit_length() - 109) // 2 if q >= 0: return float(isqrt_frac_rto(n, m << 2 * q) << q) else: return isqrt_frac_rto(n << -2 * q, m) / (1 << -q) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45876> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com