diff --git a/SConstruct b/SConstruct index d8d4a5406..9032bd90a 100644 --- a/SConstruct +++ b/SConstruct @@ -770,6 +770,12 @@ def get_expression_value(includes, expression): env['HAS_TIMES_H'] = conf.CheckCHeader('sys/times.h', '""') env['HAS_UNISTD_H'] = conf.CheckCHeader('unistd.h', '""') +# +# Check to see if the compiler supports C99 fenv.h +# Apparently, the only compiler not to is MS visual before 2013 +# +env['HAS_FENV_H'] = conf.CheckCHeader('fenv.h', '""') + env['HAS_MATH_H_ERF'] = conf.CheckDeclaration('erf', '#include ', 'C++') env['HAS_GLOBAL_ISNAN'] = conf.CheckStatement('::isnan(1.0)', '#include ') @@ -1210,6 +1216,12 @@ cdefine('USE_GLOBAL_ISNAN', 'HAS_GLOBAL_ISNAN') cdefine('USE_STD_ISNAN', 'HAS_STD_ISNAN') cdefine('USE_UNDERSCORE_ISNAN', 'HAS_UNDERSCORE_ISNAN') +# this turns on HAS_FENV_H +if env['HAS_FENV_H']: + configh['HAS_FENV_H'] = 1 +else: + configh['HAS_FENV_H'] = None + 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 977fc2a9d..bf0739e0b 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -76,6 +76,8 @@ typedef int ftnlen; // Fortran hidden string length type %(USE_GLOBAL_ISNAN)s %(USE_UNDERSCORE_ISNAN)s +%(HAS_FENV_H)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/ctexceptions.cpp b/src/base/ctexceptions.cpp index d77352195..b9a9e64b3 100644 --- a/src/base/ctexceptions.cpp +++ b/src/base/ctexceptions.cpp @@ -5,7 +5,9 @@ #include "cantera/base/global.h" #include "cantera/base/stringUtils.h" +#ifdef HAVE_FENVH #include +#endif #include #include @@ -78,16 +80,20 @@ std::string IndexError::getMessage() const } //============================================================================================================ bool check_FENV_OverUnder_Flow() { +#ifdef HAVE_FENV_H fexcept_t ff; fegetexceptflag(&ff, FE_OVERFLOW || FE_UNDERFLOW || FE_INVALID); if (ff) { return true; } +#endif return false; }; //============================================================================================================ void clear_FENV() { +#ifdef HAVE_FENV_H feclearexcept(FE_ALL_EXCEPT); +#endif } //============================================================================================================ diff --git a/src/thermo/GibbsExcessVPSSTP.cpp b/src/thermo/GibbsExcessVPSSTP.cpp index e7edd76e8..045f8a118 100644 --- a/src/thermo/GibbsExcessVPSSTP.cpp +++ b/src/thermo/GibbsExcessVPSSTP.cpp @@ -207,10 +207,15 @@ void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const ac[k] = exp(ac[k]); } if (realNumberRangeBehavior_ == FENV_CHECK_CTRB) { +#ifdef HAVE_FENV_H if (check_FENV_OverUnder_Flow()) { throw CanteraError("GibbsExcessVPSSTP::getActivityCoefficients()", "activity coefficient is over/underflowing"); } +#else + throw CanteraError("GibbsExcessVPSSTP::getActivityCoefficients()", + "realNumberRangeBehavior_ == FENV_CHECK_CTRB not supported by compiler"); +#endif } } }