Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
> Sweet! New one on me Tim already knows this but for the record the derivation is isn't tricky. With y=isqrt(x), then next root is at y+1 and the half way point is y+1/2 which isn't an integer. The corresponding squares are y**2, (y+1/2)**2, and (y+1)**2. With a multiple of four, those become 4*y**2, 4*(y+1/2)**2, and 4*y+1)**2 which are equivalent to the squares of consecutive integers: (2y)**2, (2y+1)**2, and (2y+2)**2. Adding one gives the roots 2y+1, 2y+2, and 2y+3. The floor division eliminates the constant term giving the desired roots y, y+1, and y+1. > can we use the decimal module's names for the supported rounding modes? I'm not sure those make sense because we never get to exactly half. There is only floor, ceil, and round, not half_up, half_even, etc. ---------- _______________________________________ 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