Algorithm to find the square root of a number?

The only algorithm I know for this problem is Newton's method (make an assumption and then improve it until it becomes good enough).

Any other ideas (use whatever language you prefer)

PS: Of course, I have no precedent for this, I just study it for academic reasons.

+3
source share
3 answers

There is always a John Carmack method , which is a highly efficient version of the Newton method.

+10
source

Here you can find a few.

+5
source

.

C 2 Newton:

double sqrt(const double x)  
{
  union
  {
    int i;
    double x;
  } u;

  u.x = x;
  u.i = (1<<29) + (u.i >> 1) - (1<<22); 
  return u.x;
}
0
source

Source: https://habr.com/ru/post/1705398/


All Articles