Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
checkFinite.cpp
Go to the documentation of this file.
1 /**
2  * @file checkFinite.cpp Declarations for routines that check for the
3  * presence of NaNs in the code.
4  */
5 /*
6  * Copyright 2004 Sandia Corporation. Under the terms of Contract
7  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
8  * retains certain rights in this software.
9  * See file License.txt for licensing information.
10  */
11 
12 #include "cantera/base/ct_defs.h"
13 
14 #include <stdexcept>
15 #include <cstdio>
16 
17 // We expect that there will be special casing based on the computer
18 // system here
19 
20 #ifdef SOLARIS
21 #include <ieeefp.h>
22 #include <sunmath.h>
23 #endif
24 
25 // Compiler-dependent names for 'isnan' and 'finite'
26 #if defined(USE_UNDERSCORE_ISNAN)
27  // Windows
28  #include <float.h>
29  #define isnan(x) _isnan(x)
30  #define finite(x) _finite(x)
31 #elif defined(USE_GLOBAL_ISNAN)
32  // From C99
33  using ::isnan;
34  using ::finite;
35 #elif defined(USE_STD_ISNAN)
36  // From C++11
37  using std::isnan;
38  #define finite(x) std::isfinite(x)
39 #endif
40 
41 namespace Cantera {
42 
43 void checkFinite(const double tmp)
44 {
45  if (!finite(tmp)) {
46  if (isnan(tmp)) {
47  printf("checkFinite() ERROR: we have encountered a nan!\n");
48  } else if (tmp > 0) {
49  printf("checkFinite() ERROR: we have encountered a pos inf!\n");
50  } else {
51  printf("checkFinite() ERROR: we have encountered a neg inf!\n");
52  }
53  throw std::range_error("checkFinite()");
54  }
55 }
56 
57 }
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
Definition: checkFinite.cpp:43
This file contains definitions of terms that are used in internal routines and are unlikely to need m...