[issue36887] Add integer square root, math.isqrt

Mark Dickinson report at bugs.python.org
Sat May 11 10:33:21 EDT 2019


Mark Dickinson <dickinsm at gmail.com> added the comment:

> I am wondering whether int(sqrt(float(n))) can be used as a good initial approximation.

It can, but I'd prefer to avoid floating-point arithmetic (we don't have any guarantees about the accuracy of sqrt, so you'd always need a check and a fallback for the case where sqrt isn't accurate enough), and there are other purely-integer-based ways to produce a fast initial approximation. I do have some plans to add optimizations, but wanted to get the basic algorithm in first.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36887>
_______________________________________


More information about the Python-bugs-list mailing list