unsigned int L = 0; unsigned int M; unsigned int R = y + 1; while (L != R - 1) { M = (L + R) / 2; if (M * M <= y) L = M; else R = M; } return L; } Numerical example For example, if one computes using binary search, one obtains the sequence This computation takes 21 iteration steps, whereas linear search (ascending, starting from ) needs steps. Algorithm using Newton's method One way of calculating and is to use Heron's method, which is a special case of Newton's method, to find a solution for the equation , giving the iterative formula The sequence converges quadratically to as . Stopping criterion One can prove that is the largest possible number for which the stopping criterion ensures in the algorithm above. In implementations which use number formats that cannot represent all rational numbers exactly (for example, floating point), a stopping constant less than one should be used to protect against roundoff errors. Domain of computation Although is irrational for many , the sequence contains only rational terms when is rational. Thus, with this method it is unnecessary to exit the field of rational numbers in order to calculate , a fact which has some theoretical advantages. Using only integer division For computing for very large integers n, one can use the quotient of Euclidean division for both of the division operations. This has the advantage of only using integers for each intermediate value, thus making the use of floating point representations of large numbers unnecessary. It is equivalent to using the iterative formula By using the fact that one can show that this will reach within a finite number of iterations. In the original version, one has for , and for . So in the integer version, one has and until the final solution is reached. For the final solution , one has and , so the stopping criterion is . However, is not necessarily a fixed point of the above iterative formula. Indeed, it can be shown that is a fixed point if and only if is not a perfect square. If is a perfect square, the sequence ends up in a period-two cycle between and instead of converging. Example implementation in C // Square root of integer unsigned int int_sqrt(unsigned int s) { // Zero yields zero // One yields one if