projects
/
python
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
45e0411
)
Turn math.isqrt assertion into a comment to clarify its purpose. (GH-14131)
author
Mark Dickinson
<dickinsm@gmail.com>
Sun, 16 Jun 2019 16:53:21 +0000
(17:53 +0100)
committer
GitHub
<noreply@github.com>
Sun, 16 Jun 2019 16:53:21 +0000
(17:53 +0100)
Modules/mathmodule.c
patch
|
blob
|
history
diff --git
a/Modules/mathmodule.c
b/Modules/mathmodule.c
index 76d821c65b4c8b8ebd23f2325d12eae668124466..82a9a14724f5e143a1dd5ebb55952e6cfbafa5f9 100644
(file)
--- a/
Modules/mathmodule.c
+++ b/
Modules/mathmodule.c
@@
-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)