summaryrefslogtreecommitdiffstats
path: root/Help/guide/tutorial/Complete/MathFunctions
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-08-20 13:16:35 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-08-20 13:19:22 (GMT)
commitb80417f0fd1491d1c0f5d57019b47d4c13729545 (patch)
treee55ae56966bd154cec46c56184a9f4a6f1b09d7e /Help/guide/tutorial/Complete/MathFunctions
parent8c1d3e3b79fb921bfada3b19e6bb4115da4a4e6e (diff)
parent6f6a32a0f601688da24e1737509a0b6e1ed4f63f (diff)
downloadCMake-b80417f0fd1491d1c0f5d57019b47d4c13729545.zip
CMake-b80417f0fd1491d1c0f5d57019b47d4c13729545.tar.gz
CMake-b80417f0fd1491d1c0f5d57019b47d4c13729545.tar.bz2
Merge topic 'cmake-tutorial'
6f6a32a0f6 Tutorial: Improve Step 9 6a35d630dc Tutorial: Improve Step 8 61d4d990d6 Tutorial: Improve Step 7 a36731c634 Tutorial: Improve Step 6 df9cdf629c Tutorial: Improve Step 5 442c0f0d46 Tutorial: Improve Step 4 bc64401c3d Tutorial: Improve Step 3 49ce4d6ff4 Tutorial: Improve Step 2 ... Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3528
Diffstat (limited to 'Help/guide/tutorial/Complete/MathFunctions')
-rw-r--r--Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt14
-rw-r--r--Help/guide/tutorial/Complete/MathFunctions/mysqrt.cxx13
2 files changed, 4 insertions, 23 deletions
diff --git a/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt
index c12955d..dfa84c9 100644
--- a/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt
@@ -13,11 +13,7 @@ target_include_directories(MathFunctions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if(USE_MYMATH)
- # 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)
+ target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
# first we add the executable that generates the table
add_executable(MakeTable MakeTable.cxx)
@@ -41,18 +37,12 @@ if(USE_MYMATH)
${CMAKE_CURRENT_BINARY_DIR}
)
+ # state that SqrtLibrary need PIC when the default is shared libraries
set_target_properties(SqrtLibrary PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
-
-
- target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
- if(HAVE_LOG AND HAVE_EXP)
- target_compile_definitions(SqrtLibrary
- PRIVATE "HAVE_LOG" "HAVE_EXP")
- endif()
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
diff --git a/Help/guide/tutorial/Complete/MathFunctions/mysqrt.cxx b/Help/guide/tutorial/Complete/MathFunctions/mysqrt.cxx
index 96d9421..ff37312 100644
--- a/Help/guide/tutorial/Complete/MathFunctions/mysqrt.cxx
+++ b/Help/guide/tutorial/Complete/MathFunctions/mysqrt.cxx
@@ -4,8 +4,6 @@
// include the generated table
#include "Table.h"
-#include <cmath>
-
namespace mathfunctions {
namespace detail {
// a hack square root calculation using simple operations
@@ -15,20 +13,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) {
@@ -38,7 +29,7 @@ double mysqrt(double x)
result = result + 0.5 * delta / result;
std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
-#endif
+
return result;
}
}