isqrt function
Returns the integer square root of n (the floor of its real square root).
Returns 0 for any n less than or equal to zero.
Example:
isqrt(17); // 4
isqrt(16); // 4
Implementation
int isqrt(int n) {
if (n <= 0) return 0;
int x = n;
int y = (x + 1) >> 1;
while (y < x) {
x = y;
y = (x + n ~/ x) >> 1;
}
return x;
}