summaryrefslogtreecommitdiffstats
path: root/Help/guide/tutorial/Step6/MathFunctions
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-02 13:20:52 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-06-02 13:21:05 (GMT)
commit84fe677eaed822a5ff86a9ae32cac0c1a5d788c4 (patch)
tree2745fa69ace38875fcddc451e503d18be0a9ca0b /Help/guide/tutorial/Step6/MathFunctions
parent18be0f926789ad47d70e54e57f34b2ee4f297307 (diff)
parent5c84eca2108c8b47a74391c732710c67e23adfa3 (diff)
downloadCMake-84fe677eaed822a5ff86a9ae32cac0c1a5d788c4.zip
CMake-84fe677eaed822a5ff86a9ae32cac0c1a5d788c4.tar.gz
CMake-84fe677eaed822a5ff86a9ae32cac0c1a5d788c4.tar.bz2
Merge topic 'tutorial-cmath' into release-3.23
5c84eca210 Tutorial: Simplify logic checking for cmath functions Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7314
Diffstat (limited to 'Help/guide/tutorial/Step6/MathFunctions')
-rw-r--r--Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt28
-rw-r--r--Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx2
2 files changed, 16 insertions, 14 deletions
diff --git a/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt
index f64c6ac..42e098a 100644
--- a/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt
@@ -7,19 +7,21 @@ target_include_directories(MathFunctions
)
# does this system provide the log and exp functions?
-include(CheckSymbolExists)
-check_symbol_exists(log "math.h" HAVE_LOG)
-check_symbol_exists(exp "math.h" HAVE_EXP)
-if(NOT (HAVE_LOG AND HAVE_EXP))
- unset(HAVE_LOG CACHE)
- unset(HAVE_EXP CACHE)
- set(CMAKE_REQUIRED_LIBRARIES "m")
- check_symbol_exists(log "math.h" HAVE_LOG)
- check_symbol_exists(exp "math.h" HAVE_EXP)
- if(HAVE_LOG AND HAVE_EXP)
- target_link_libraries(MathFunctions PRIVATE m)
- endif()
-endif()
+include(CheckCXXSourceCompiles)
+check_cxx_source_compiles("
+ #include <cmath>
+ int main() {
+ std::log(1.0);
+ return 0;
+ }
+" HAVE_LOG)
+check_cxx_source_compiles("
+ #include <cmath>
+ int main() {
+ std::exp(1.0);
+ return 0;
+ }
+" HAVE_EXP)
# add compile definitions
if(HAVE_LOG AND HAVE_EXP)
diff --git a/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx b/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx
index 0637063..7eecd26 100644
--- a/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx
+++ b/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx
@@ -12,7 +12,7 @@ double mysqrt(double x)
// if we have both log and exp then use them
#if defined(HAVE_LOG) && defined(HAVE_EXP)
- double result = exp(log(x) * 0.5);
+ double result = std::exp(std::log(x) * 0.5);
std::cout << "Computing sqrt of " << x << " to be " << result
<< " using log and exp" << std::endl;
#else