"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx" between
cmake-3.13.4.tar.gz and cmake-3.14.0-rc1.tar.gz

About: CMake is a cross-platform build system designed to build, test and package software. Release candidate.

mysqrt.cxx  (cmake-3.13.4):mysqrt.cxx  (cmake-3.14.0-rc1)
#include "MathFunctions.h" #include "MathFunctions.h"
#include "TutorialConfig.h" #include "TutorialConfig.h"
#include <stdio.h> #include <iostream>
// include the generated table // include the generated table
#include "Table.h" #include "Table.h"
#include <math.h> #include <cmath>
// a hack square root calculation using simple operations // a hack square root calculation using simple operations
double mysqrt(double x) double mysqrt(double x)
{ {
if (x <= 0) { if (x <= 0) {
return 0; return 0;
} }
double result;
// if we have both log and exp then use them
double delta;
// use the table to help find an initial value // use the table to help find an initial value
result = x; double result = x;
if (x >= 1 && x < 10) { if (x >= 1 && x < 10) {
result = sqrtTable[static_cast<int>(x)]; result = sqrtTable[static_cast<int>(x)];
} }
// do ten iterations // do ten iterations
int i; for (int i = 0; i < 10; ++i) {
for (i = 0; i < 10; ++i) {
if (result <= 0) { if (result <= 0) {
result = 0.1; result = 0.1;
} }
delta = x - (result * result); double delta = x - (result * result);
result = result + 0.5 * delta / result; result = result + 0.5 * delta / result;
fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result); std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
} }
return result; return result;
} }
 End of changes. 7 change blocks. 
12 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)