Use math functions from C++11 standard library

This commit is contained in:
Ray Speth 2015-10-19 13:11:19 -04:00
parent 0542e694a9
commit 87aaa6ad1e
3 changed files with 4 additions and 57 deletions

View file

@ -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 <math.h>', 'C++')
env['HAS_GLOBAL_ISNAN'] = conf.CheckStatement('::isnan(1.0)', '#include <cmath>')
env['HAS_STD_ISNAN'] = conf.CheckStatement('std::isnan(1.0)', '#include <cmath>')
env['HAS_UNDERSCORE_ISNAN'] = conf.CheckStatement('_isnan(1.0)',
'#include <cmath>\n#include <float.h>')
env['HAS_BOOST_MATH'] = conf.CheckCXXHeader('boost/math/special_functions/erf.hpp', '<>')
boost_version_source = get_expression_value(['<boost/version.hpp>'], '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 <math.h> 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))

View file

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

View file

@ -10,41 +10,15 @@
*/
#include "cantera/base/ct_defs.h"
#include <stdexcept>
#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 <ieeefp.h>
#include <sunmath.h>
#endif
// Compiler-dependent names for 'isnan' and 'finite'
#if defined(USE_UNDERSCORE_ISNAN)
// Windows
#include <float.h>
#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";
}