Check for fenv.h availability. Apparently, MS visual doesn't have C99 support before 2013, so previous commit didn't compile on MSVISUAL.

If fenv.h not available, program now error exits if fenv functions are requested.
This commit is contained in:
Harry Moffat 2014-08-26 17:55:44 +00:00
parent b7bce3f66d
commit 08fe85b4cd
4 changed files with 25 additions and 0 deletions

View file

@ -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 <math.h>', 'C++')
env['HAS_GLOBAL_ISNAN'] = conf.CheckStatement('::isnan(1.0)', '#include <cmath>')
@ -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))

View file

@ -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.

View file

@ -5,7 +5,9 @@
#include "cantera/base/global.h"
#include "cantera/base/stringUtils.h"
#ifdef HAVE_FENVH
#include <fenv.h>
#endif
#include <sstream>
#include <typeinfo>
@ -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
}
//============================================================================================================

View file

@ -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
}
}
}