diff options
Diffstat (limited to 'Help/guide/tutorial/Step5/MathFunctions')
| -rw-r--r-- | Help/guide/tutorial/Step5/MathFunctions/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | Help/guide/tutorial/Step5/MathFunctions/MathFunctions.h | 1 | ||||
| -rw-r--r-- | Help/guide/tutorial/Step5/MathFunctions/mysqrt.cxx | 24 | 
3 files changed, 36 insertions, 0 deletions
| diff --git a/Help/guide/tutorial/Step5/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step5/MathFunctions/CMakeLists.txt new file mode 100644 index 0000000..b12f27d --- /dev/null +++ b/Help/guide/tutorial/Step5/MathFunctions/CMakeLists.txt @@ -0,0 +1,11 @@ +add_library(MathFunctions mysqrt.cxx) + +# state that anybody linking to us needs to include the current source dir +# to find MathFunctions.h, while we don't. +target_include_directories(MathFunctions +          INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} +          ) + +# install rules +install(TARGETS MathFunctions DESTINATION lib) +install(FILES MathFunctions.h DESTINATION include) diff --git a/Help/guide/tutorial/Step5/MathFunctions/MathFunctions.h b/Help/guide/tutorial/Step5/MathFunctions/MathFunctions.h new file mode 100644 index 0000000..cd36bcc --- /dev/null +++ b/Help/guide/tutorial/Step5/MathFunctions/MathFunctions.h @@ -0,0 +1 @@ +double mysqrt(double x); diff --git a/Help/guide/tutorial/Step5/MathFunctions/mysqrt.cxx b/Help/guide/tutorial/Step5/MathFunctions/mysqrt.cxx new file mode 100644 index 0000000..abe767d --- /dev/null +++ b/Help/guide/tutorial/Step5/MathFunctions/mysqrt.cxx @@ -0,0 +1,24 @@ +#include <iostream> + +#include "MathFunctions.h" + +// a hack square root calculation using simple operations +double mysqrt(double x) +{ +  if (x <= 0) { +    return 0; +  } + +  double result = x; + +  // do ten iterations +  for (int i = 0; i < 10; ++i) { +    if (result <= 0) { +      result = 0.1; +    } +    double delta = x - (result * result); +    result = result + 0.5 * delta / result; +    std::cout << "Computing sqrt of " << x << " to be " << result << std::endl; +  } +  return result; +} | 
