File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -316,12 +316,15 @@ def _isqrt_frac_rto(n: int, m: int) -> float:
316
316
317
317
def _sqrt_frac (n : int , m : int ) -> float :
318
318
"""Square root of n/m as a float, correctly rou
8000
nded."""
319
- # See algorithm sketch at: https://bugs.python.org/msg406911
320
- q : int = (n .bit_length () - m .bit_length () - _sqrt_shift ) // 2
319
+ # See principle and proof sketch at: https://bugs.python.org/msg407078
320
+ q = (n .bit_length () - m .bit_length () - _sqrt_shift ) // 2
321
321
if q >= 0 :
322
- return (_isqrt_frac_rto (n , m << 2 * q ) << q ) / 1
322
+ numerator = _isqrt_frac_rto (n , m << 2 * q ) << q
323
+ denominator = 1
323
324
else :
324
- return _isqrt_frac_rto (n << - 2 * q , m ) / (1 << - q )
325
+ numerator = _isqrt_frac_rto (n << - 2 * q , m )
326
+ denominator = 1 << - q
327
+ return numerator / denominator # Convert to float
325
328
326
329
327
330
# === Measures of central tendency (averages) ===
You can’t perform that action at this time.
0 commit comments