Tim Peters <t...@python.org> added the comment:

Suppose we added isqrt_rem(n), returning the integer pair (i, rem) such that

    n == i**2 + rem
    0 <= rem <= 2*i

Then:

- Want the floor of sqrt(n)? i.
- The ceiling? i + (rem != 0).
- Rounded? i + (rem > i).
- Is n a perfect square? not rem.

That's how mpz addresses these, although it has a different function to compute 
the floor without returning the remainder too.

I wouldn't object to that - just +0, though. Depending on implementation 
details, which I haven't investigated, it may or may not be materially faster 
than doing:

def isqrt_rem(n):
    return (i := isqrt(n)), n - i*i

myself.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46187>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to