diff options
Diffstat (limited to 'Help/guide/tutorial/Step8')
-rw-r--r-- | Help/guide/tutorial/Step8/CMakeLists.txt | 28 | ||||
-rw-r--r-- | Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx | 14 | ||||
-rw-r--r-- | Help/guide/tutorial/Step8/TutorialConfig.h.in | 4 | ||||
-rw-r--r-- | Help/guide/tutorial/Step8/tutorial.cxx | 7 |
5 files changed, 16 insertions, 40 deletions
diff --git a/Help/guide/tutorial/Step8/CMakeLists.txt b/Help/guide/tutorial/Step8/CMakeLists.txt index a0316a0..19b9913 100644 --- a/Help/guide/tutorial/Step8/CMakeLists.txt +++ b/Help/guide/tutorial/Step8/CMakeLists.txt @@ -1,34 +1,24 @@ -cmake_minimum_required(VERSION 3.3) -project(Tutorial) +cmake_minimum_required(VERSION 3.10) +# set the project name and version +project(Tutorial VERSION 1.0) + +# specify the C++ standard set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) -# set the version number -set(Tutorial_VERSION_MAJOR 1) -set(Tutorial_VERSION_MINOR 0) - -# does this system provide the log and exp functions? -include(CheckSymbolExists) -set(CMAKE_REQUIRED_LIBRARIES "m") -check_symbol_exists(log "math.h" HAVE_LOG) -check_symbol_exists(exp "math.h" HAVE_EXP) - # should we use our own math functions option(USE_MYMATH "Use tutorial provided math implementation" ON) # configure a header file to pass some of the CMake settings # to the source code -configure_file( - "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in" - "${PROJECT_BINARY_DIR}/TutorialConfig.h" - ) +configure_file(TutorialConfig.h.in TutorialConfig.h) -# add the MathFunctions library? +# add the MathFunctions library if(USE_MYMATH) add_subdirectory(MathFunctions) list(APPEND EXTRA_LIBS MathFunctions) -endif(USE_MYMATH) +endif() # add the executable add_executable(Tutorial tutorial.cxx) @@ -60,7 +50,7 @@ set_tests_properties(Usage # define a function to simplify adding tests function(do_test target arg result) -add_test(NAME Comp${arg} COMMAND ${target} ${arg}) + add_test(NAME Comp${arg} COMMAND ${target} ${arg}) set_tests_properties(Comp${arg} PROPERTIES PASS_REGULAR_EXPRESSION ${result} ) diff --git a/Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt index 3c3a816..9ede4b3 100644 --- a/Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt +++ b/Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt @@ -21,8 +21,7 @@ add_library(MathFunctions # state that we depend on our binary dir to find Table.h target_include_directories(MathFunctions INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${Tutorial_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) # install rules diff --git a/Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx b/Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx index 5b862fb..2ae60c6 100644 --- a/Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx +++ b/Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx @@ -1,12 +1,9 @@ #include "MathFunctions.h" -#include "TutorialConfig.h" #include <iostream> // include the generated table #include "Table.h" -#include <cmath> - // a hack square root calculation using simple operations double mysqrt(double x) { @@ -14,20 +11,13 @@ double mysqrt(double x) return 0; } - // if we have both log and exp then use them -#if defined(HAVE_LOG) && defined(HAVE_EXP) - double result = exp(log(x) * 0.5); - std::cout << "Computing sqrt of " << x << " to be " << result << " using log" - << std::endl; -#else // use the table to help find an initial value double result = x; if (x >= 1 && x < 10) { + std::cout << "Use the table to help find an initial value " << std::endl; result = sqrtTable[static_cast<int>(x)]; } - // if we have both log and exp then use them - // do ten iterations for (int i = 0; i < 10; ++i) { if (result <= 0) { @@ -37,6 +27,6 @@ double mysqrt(double x) result = result + 0.5 * delta / result; std::cout << "Computing sqrt of " << x << " to be " << result << std::endl; } -#endif + return result; } diff --git a/Help/guide/tutorial/Step8/TutorialConfig.h.in b/Help/guide/tutorial/Step8/TutorialConfig.h.in index e97ce24..e23f521 100644 --- a/Help/guide/tutorial/Step8/TutorialConfig.h.in +++ b/Help/guide/tutorial/Step8/TutorialConfig.h.in @@ -2,7 +2,3 @@ #define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@ #define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@ #cmakedefine USE_MYMATH - -// does the platform provide exp and log functions? -#cmakedefine HAVE_LOG -#cmakedefine HAVE_EXP diff --git a/Help/guide/tutorial/Step8/tutorial.cxx b/Help/guide/tutorial/Step8/tutorial.cxx index 8156a9c..b3c6a4f 100644 --- a/Help/guide/tutorial/Step8/tutorial.cxx +++ b/Help/guide/tutorial/Step8/tutorial.cxx @@ -20,13 +20,14 @@ int main(int argc, char* argv[]) return 1; } - double inputValue = std::stod(argv[1]); + // convert input to double + const double inputValue = std::stod(argv[1]); // which square root function should we use? #ifdef USE_MYMATH - double outputValue = mysqrt(inputValue); + const double outputValue = mysqrt(inputValue); #else - double outputValue = sqrt(inputValue); + const double outputValue = sqrt(inputValue); #endif std::cout << "The square root of " << inputValue << " is " << outputValue |