From 87aaa6ad1e001b876909582a2d4b8a3570f4ab57 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 19 Oct 2015 13:11:19 -0400 Subject: [PATCH] Use math functions from C++11 standard library --- SConstruct | 19 ------------------ include/cantera/base/config.h.in | 8 -------- src/base/checkFinite.cpp | 34 ++++---------------------------- 3 files changed, 4 insertions(+), 57 deletions(-) diff --git a/SConstruct b/SConstruct index ca5fa7716..3ee12182d 100644 --- a/SConstruct +++ b/SConstruct @@ -822,14 +822,7 @@ configh = {} env['HAS_TIMES_H'] = conf.CheckCHeader('sys/times.h', '""') env['HAS_UNISTD_H'] = conf.CheckCHeader('unistd.h', '""') -env['HAS_MATH_H_ERF'] = conf.CheckDeclaration('erf', '#include ', 'C++') -env['HAS_GLOBAL_ISNAN'] = conf.CheckStatement('::isnan(1.0)', '#include ') -env['HAS_STD_ISNAN'] = conf.CheckStatement('std::isnan(1.0)', '#include ') -env['HAS_UNDERSCORE_ISNAN'] = conf.CheckStatement('_isnan(1.0)', - '#include \n#include ') - -env['HAS_BOOST_MATH'] = conf.CheckCXXHeader('boost/math/special_functions/erf.hpp', '<>') boost_version_source = get_expression_value([''], 'BOOST_LIB_VERSION') retcode, boost_lib_version = conf.TryRun(boost_version_source, '.cpp') env['BOOST_LIB_VERSION'] = boost_lib_version.strip() @@ -1246,18 +1239,6 @@ cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') -if not env['HAS_MATH_H_ERF']: - if env['HAS_BOOST_MATH']: - configh['USE_BOOST_MATH'] = 1 - else: - config_error("Couldn't find 'erf' in either or Boost.Math.") -else: - configh['USE_BOOST_MATH'] = None - -cdefine('USE_GLOBAL_ISNAN', 'HAS_GLOBAL_ISNAN') -cdefine('USE_STD_ISNAN', 'HAS_STD_ISNAN') -cdefine('USE_UNDERSCORE_ISNAN', 'HAS_UNDERSCORE_ISNAN') - config_h = env.Command('include/cantera/base/config.h', 'include/cantera/base/config.h.in', ConfigBuilder(configh)) diff --git a/include/cantera/base/config.h.in b/include/cantera/base/config.h.in index 6b1f978ba..2b8beb2f4 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -55,9 +55,6 @@ typedef int ftnlen; // Fortran hidden string length type %(LAPACK_NAMES_LOWERCASE)s %(LAPACK_FTN_TRAILING_UNDERSCORE)s -//-------- BOOST -------- -%(USE_BOOST_MATH)s - //--------- operating system -------------------------------------- // The configure script defines this if the operating system is Mac @@ -71,11 +68,6 @@ typedef int ftnlen; // Fortran hidden string length type //---------- C++ Compiler Variations ------------------------------ -// Name for 'isnan' varies for different compilers / standard libraries -%(USE_STD_ISNAN)s -%(USE_GLOBAL_ISNAN)s -%(USE_UNDERSCORE_ISNAN)s - // This define is needed to account for the variability for how // static variables in templated classes are defined. Right now // this is only turned on for the SunPro compiler on Solaris. diff --git a/src/base/checkFinite.cpp b/src/base/checkFinite.cpp index dcfb51a5c..824bb0ccb 100644 --- a/src/base/checkFinite.cpp +++ b/src/base/checkFinite.cpp @@ -10,41 +10,15 @@ */ #include "cantera/base/ct_defs.h" - -#include #include "cantera/base/stringUtils.h" #include "cantera/base/ctexceptions.h" -// We expect that there will be special casing based on the computer -// system here - -#ifdef SOLARIS -#include -#include -#endif - -// Compiler-dependent names for 'isnan' and 'finite' -#if defined(USE_UNDERSCORE_ISNAN) - // Windows - #include - #define isnan(x) _isnan(x) - #define finite(x) _finite(x) -#elif defined(USE_GLOBAL_ISNAN) - // From C99 - using ::isnan; - using ::finite; -#elif defined(USE_STD_ISNAN) - // From C++11 - using std::isnan; - #define finite(x) std::isfinite(x) -#endif - namespace Cantera { void checkFinite(const double tmp) { - if (!finite(tmp)) { - if (isnan(tmp)) { + if (!std::isfinite(tmp)) { + if (std::isnan(tmp)) { throw CanteraError("checkFinite", "found NaN"); } else if (tmp > 0) { throw CanteraError("checkFinite", "found +Inf"); @@ -57,10 +31,10 @@ void checkFinite(const double tmp) void checkFinite(const std::string& name, double* values, size_t N) { for (size_t i = 0; i < N; i++) { - if (!finite(values[i])) { + if (!std::isfinite(values[i])) { std::string message = name + " contains non-finite elements:\n\n"; for (size_t j = 0; j < N; j++) { - if (!finite(values[j])) { + if (!std::isfinite(values[j])) { message += name + "[" + int2str(j) + "] = " + fp2str(values[j]) + "\n"; }