From 761f8376a314c6d00bb275bf1a9cae90e04bef4e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 28 Jul 2015 16:32:20 -0500 Subject: [PATCH] Detect whether we can use floating point exceptions. --- cmake/checks/check_02_system_features.cmake | 36 +++++++++++++++++++++ include/deal.II/base/config.h.in | 1 + 2 files changed, 37 insertions(+) diff --git a/cmake/checks/check_02_system_features.cmake b/cmake/checks/check_02_system_features.cmake index cd58f41416..33aaccc9f0 100644 --- a/cmake/checks/check_02_system_features.cmake +++ b/cmake/checks/check_02_system_features.cmake @@ -19,6 +19,7 @@ # DEAL_II_HAVE_GETHOSTNAME # DEAL_II_HAVE_GETPID # DEAL_II_HAVE_JN +# DEAL_II_HAVE_FP_EXCEPTIONS # DEAL_II_HAVE_SYS_RESOURCE_H # DEAL_II_HAVE_SYS_TIME_H # DEAL_II_HAVE_SYS_TIMES_H @@ -67,6 +68,41 @@ IF(NOT m_LIBRARY MATCHES "-NOTFOUND") ENDIF() +# +# Check that we can use feenableexcept. Sets DEAL_II_HAVE_FP_EXCEPTIONS +# +# The test is a bit more complicated because we also check that no garbage +# exception is thrown if we convert -std::numeric_limits::max to a +# string. This sadly happens with some compiler support libraries :-( + +INCLUDE (CheckCXXSourceRuns) + +CHECK_CXX_SOURCE_RUNS(" + #include + #include + #include + + int main() + { + feenableexcept(FE_DIVBYZERO|FE_INVALID); + std::ostringstream description; + const double lower_bound = -std::numeric_limits::max(); + + description << lower_bound; + + return 0; + } + " + _HAVE_FP_EXCEPTIONS) + +IF(_HAVE_FP_EXCEPTIONS) + MESSAGE(STATUS "Checking for Floating Point Exception macros -- Success") + SET(DEAL_II_HAVE_FP_EXCEPTIONS 1) +ELSE() + MESSAGE(STATUS "Checking for Floating Point Exception macros -- Failed") +ENDIF() + + ######################################################################## # # # Mac OSX specific setup: # diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index 09fbfb319c..05a6ae90cd 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -128,6 +128,7 @@ #cmakedefine DEAL_II_HAVE_GETPID #cmakedefine DEAL_II_HAVE_TIMES #cmakedefine DEAL_II_HAVE_JN +#cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS #cmakedefine DEAL_II_MSVC -- 2.39.5