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

> Is
>
>  i, rem = isqrt_rem(n)
>  i + (rem != 0)
>
> better than
>
>   (isqrt(n<<2) + 1) >> 1
>
> or
>
>   n and isqrt(n-1) + 1
>
> ?

Define "better"? The first way is by far the most obvious of the three, and the 
second way the least obvious. The first way also "wins" on being  a variation 
of a uniform pattern that can deliver the floor, ceiling, or rounded result, 
depending on which simple comparison result is added. It's not "a trick" - it's 
the opposite of clever ;-)

The first way is also unique in being the only one of the three that does _not_ 
do any Python-level arithmetic on integers as wide as `n`. `i` and `rem` are no 
more than about half the bit length of `n`. `n << 2` and `n - 1` in the others 
have to create new int objects at least as wide as `n`.

----------

_______________________________________
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