Merge pull request #426 from jrhea/div_by_zero_fix

add assertion to integer_squareroot() to prevent negative results.
This commit is contained in:
Danny Ryan 2019-01-10 19:20:58 -06:00 committed by GitHub
commit 5827b4cde2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -1097,6 +1097,7 @@ def integer_squareroot(n: int) -> int:
""" """
The largest integer ``x`` such that ``x**2`` is less than ``n``. The largest integer ``x`` such that ``x**2`` is less than ``n``.
""" """
assert n >= 0
x = n x = n
y = (x + 1) // 2 y = (x + 1) // 2
while y < x: while y < x: