diff options
author | David Cole <david.cole@kitware.com> | 2007-11-08 15:38:26 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2007-11-08 15:38:26 (GMT) |
commit | 4e752dee910d3901a438d97aedf49357a8cb5628 (patch) | |
tree | 3393d691a3e67c13610b9252e2f967d4433f95a6 /Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx | |
parent | e615e1416cc5139082593c07db99ead11c6d5d46 (diff) | |
download | CMake-4e752dee910d3901a438d97aedf49357a8cb5628.zip CMake-4e752dee910d3901a438d97aedf49357a8cb5628.tar.gz CMake-4e752dee910d3901a438d97aedf49357a8cb5628.tar.bz2 |
ENH: Add new Tutorial steps. Diff between Step5 and Step6 shows how to add a cpack driven installer to your project. Diff between Step6 and Step7 shows how to add ctest dashboard scripting capability.
Diffstat (limited to 'Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx')
-rw-r--r-- | Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx new file mode 100644 index 0000000..33659b7 --- /dev/null +++ b/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx @@ -0,0 +1,44 @@ +#include <stdio.h> +#include "MathFunctions.h" +#include "TutorialConfig.h" + +// include the generated table +#include "Table.h" + +#include <math.h> + +// a hack square root calculation using simple operations +double mysqrt(double x) +{ + if (x <= 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 + result = x; + if (x >= 1 && x < 10) + { + result = sqrtTable[static_cast<int>(x)]; + } + + // do ten iterations + int i; + for (i = 0; i < 10; ++i) + { + if (result <= 0) + { + result = 0.1; + } + delta = x - (result*result); + result = result + 0.5*delta/result; + fprintf(stdout,"Computing sqrt of %g to be %g\n",x,result); + } + + return result; +} |