Cantera  2.1.2
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 #ifdef _WIN32
26 #include <float.h>
27 #endif
28 
29 using namespace std;
30 
31 namespace Cantera {
32 
33 void checkFinite(const double tmp)
34 {
35 #if defined _WIN32
36  if (_finite(tmp)) {
37  if (_isnan(tmp)) {
38  printf("checkFinite() ERROR: we have encountered a nan!\n");
39  } else if (_fpclass(tmp) == _FPCLASS_PINF) {
40  printf("checkFinite() ERROR: we have encountered a pos inf!\n");
41  } else {
42  printf("checkFinite() ERROR: we have encountered a neg inf!\n");
43  }
44  throw std::range_error("checkFinite()");
45  }
46 #elif defined __CYGWIN__
47  if (!finite(tmp)) {
48  if (isnan(tmp)) {
49  printf("checkFinite() ERROR: we have encountered a nan!\n");
50  } else if (isinf(tmp) == 1) {
51  printf("checkFinite() ERROR: we have encountered a pos inf!\n");
52  } else {
53  printf("checkFinite() ERROR: we have encountered a neg inf!\n");
54  }
55  throw std::range_error("checkFinite()");
56  }
57 #else
58  if (!::finite(tmp)) {
59  if (::isnan(tmp)) {
60  printf("checkFinite() ERROR: we have encountered a nan!\n");
61  } else if (::isinf(tmp) == 1) {
62  printf("checkFinite() ERROR: we have encountered a pos inf!\n");
63  } else {
64  printf("checkFinite() ERROR: we have encountered a neg inf!\n");
65  }
66  throw std::range_error("checkFinite()");
67  }
68 #endif
69 }
70 
71 }
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
Definition: checkFinite.cpp:33
This file contains definitions of terms that are used in internal routines and are unlikely to need m...