mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Turn math.isqrt assertion into a comment to clarify its purpose. (GH-14131)
(cherry picked from commit 2dfeaa9222
)
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
parent
599f7ecb70
commit
3f3efed331
1 changed files with 1 additions and 1 deletions
|
@ -1527,10 +1527,10 @@ Here's Python code equivalent to the C implementation below:
|
|||
a = 1
|
||||
d = 0
|
||||
for s in reversed(range(c.bit_length())):
|
||||
# Loop invariant: (a-1)**2 < (n >> 2*(c - d)) < (a+1)**2
|
||||
e = d
|
||||
d = c >> s
|
||||
a = (a << d - e - 1) + (n >> 2*c - e - d + 1) // a
|
||||
assert (a-1)**2 < n >> 2*(c - d) < (a+1)**2
|
||||
|
||||
return a - (a*a > n)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue