[Python-checkins] Turn math.isqrt assertion into a comment to clarify its purpose. (GH-14131)

Mark Dickinson webhook-mailer at python.org
Sun Jun 16 12:53:27 EDT 2019


https://github.com/python/cpython/commit/2dfeaa9222e2ed6b6e32faaf08e5b0f77318f0a7
commit: 2dfeaa9222e2ed6b6e32faaf08e5b0f77318f0a7
branch: master
author: Mark Dickinson <dickinsm at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-06-16T17:53:21+01:00
summary:

Turn math.isqrt assertion into a comment to clarify its purpose. (GH-14131)

files:
M Modules/mathmodule.c

diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 76d821c65b4c..82a9a14724f5 100644
--- 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)
 



More information about the Python-checkins mailing list