[ create a new paste ] login | about

Link: http://codepad.org/Ry9iRGbZ    [ raw code | output | fork ]

C, pasted on Nov 23:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>

#define EPS 1e-10
float my_sqrt(float x){
  float S=x, a=1,b=x;
  while(fabs(a-b)>EPS) { a=(a+b)/2; b = S / a; }
  return (a+b)/2;
}

int main()
{
  printf("%f\n", my_sqrt(1e22));
  return 0;
}


Output:
1
99999998890.981537


Create a new paste based on this one


Comments: