Merge pull request #426 from jrhea/div_by_zero_fix
add assertion to integer_squareroot() to prevent negative results.
This commit is contained in:
commit
5827b4cde2
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue