Tim Peters <t...@python.org> added the comment:
FYI, I had a simpler derivation in mind. Say sqrt(n) = r + f where r = isqrt(n) and 0 <= f < 1. Then sqrt(4n) = 2 * sqrt(n) = 2*(r + f) = 2r + 2f, with 0 <= 2f < 2. If f < 0.5, 2f < 1, so isqrt(4n) = 2r, and we shouldn't round r up either. If f > 0.5, 2f > 1, so sqrt(4n) = 2r + 1 + (2f - 1), with 0 <= 2f - 1 < 1, so isqrt(4n) = 2*r + 1. In this case (f > 0.5) we need to round r up. f = 0.5 can't happen. Regardless, I don't believe I would have thought of this myself! It was an unexpected delight :- ---------- _______________________________________ 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