4 #include "MathFunctions.h"
6 // a hack square root calculation using simple operations
7 double mysqrt(double x)
13 // if we have both log and exp then use them
14 #if defined(HAVE_LOG) && defined(HAVE_EXP)
15 double result = std::exp(std::log(x) * 0.5);
16 std::cout << "Computing sqrt of " << x << " to be " << result
17 << " using log and exp" << std::endl;
22 for (int i = 0; i < 10; ++i) {
26 double delta = x - (result * result);
27 result = result + 0.5 * delta / result;
28 std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;