8000 Add algorithmic references · python/cpython@2aa88b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2aa88b0

Browse files
committed
Add algorithmic references
1 parent a17f2d9 commit 2aa88b0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/statistics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ def _fail_neg(values, errmsg='negative value'):
305305
yield x
306306

307307
def _isqrt_frac_rto(n: int, m: int) -> float:
308-
'Square root of n/m, rounded to the nearest integer using round-to-odd.'
308+
"""Square root of n/m, rounded to the nearest integer using round-to-odd."""
309+
# Refernce: https://www.lri.fr/~melquion/doc/05-imacs17_1-expose.pdf
309310
a = math.isqrt(n // m)
310311
return a | (a*a*m != n)
311312

312313
def _sqrt_frac(n: int, m: int) -> float:
313-
'Square root of n/m as a float, correctly rounded.'
314+
"""Square root of n/m as a float, correctly rounded."""
315+
# See algorithm sketch at: https://bugs.python.org/msg406911
314316
# The constant 109 is: 3 + 2 * sys.float_info.mant_dig
315317
q: int = (n.bit_length() - m.bit_length() - 109) // 2
316318
if q >= 0:

0 commit comments

Comments
 (0)
0