Message406889
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) |
|
Date |
User |
Action |
Args |
2021-11-23 21:06:41 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, steven.daprano |
2021-11-23 21:06:41 | mark.dickinson | set | messageid: <1637701601.87.0.953252074656.issue45876@roundup.psfhosted.org> |
2021-11-23 21:06:41 | mark.dickinson | link | issue45876 messages |
2021-11-23 21:06:41 | mark.dickinson | create | |
|