TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Tests / Tutorial / Step2 / MathFunctions / mysqrt.cxx
1 #include <stdio.h>
2 #include "MathFunctions.h"
3
4 // a hack square root calculation using simple operations
5 double mysqrt(double x)
6 {
7   if (x <= 0)
8     {
9     return 0;
10     }
11   
12   double result;
13   double delta;  
14   result = x;
15
16   // do ten iterations
17   int i;
18   for (i = 0; i < 10; ++i)
19     {
20     if (result <= 0)
21       {
22       result = 0.1;
23       }
24     delta = x - (result*result);
25     result = result + 0.5*delta/result;
26     fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result);
27     }
28   return result;
29 }