Actual source code: mathinf.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  1: #define PETSC_SKIP_COMPLEX
  2: #include <petscsys.h>
  3: /*@C
  4:       PetscIsNormalReal - Returns PETSC_TRUE if the input value satisfies isnormal()

  6:     Input Parameter:
  7: .     a - the PetscReal Value

  9:      Notes: uses the C99 standard isnormal() on systems where they exist.
 10:       Uses isnormalq() with __float128
 11:       Otherwises always returns true

 13:      Level: beginner
 14: @*/
 15: #if defined(PETSC_USE_REAL___FLOAT128)
 16: PetscBool PetscIsNormalReal(PetscReal a)
 17: {
 18:   return PETSC_TRUE;
 19: }
 20: #elif defined(PETSC_HAVE_ISNORMAL)
 21: PetscBool PetscIsNormalReal(PetscReal a)
 22: {
 23:   return isnormal(a) ? PETSC_TRUE : PETSC_FALSE;
 24: }
 25: #else
 26: PetscBool PetscIsNormalReal(PetscReal a)
 27: {
 28:   return PETSC_TRUE;
 29: }
 30: #endif

 32: /*@C
 33:       PetscIsInfOrNanReal - Returns an error code if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.

 35:     Input Parameter:
 36: .     a - the floating point number

 38:      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
 39:       Otherwises uses ((a - a) != 0.0), note that some optimizing compiles compile
 40:       out this form, thus removing the check.

 42:      Level: beginner
 43: @*/
 44: #if defined(PETSC_USE_REAL___FLOAT128)
 45: PetscErrorCode PetscIsInfOrNanReal(PetscReal a)
 46: {
 47:   return isinfq(a) || isnanq(a);
 48: }
 49: #elif defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
 50: PetscErrorCode PetscIsInfOrNanReal(PetscReal a)
 51: {
 52:   return isinf(a) || isnan(a);
 53: }
 54: #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
 55: #if defined(PETSC_HAVE_FLOAT_H)
 56: #include <float.h>  /* Microsoft Windows defines _finite() in float.h */
 57: #endif
 58: #if defined(PETSC_HAVE_IEEEFP_H)
 59: #include <ieeefp.h>  /* Solaris prototypes these here */
 60: #endif
 61: PetscErrorCode PetscIsInfOrNanReal(PetscReal a)
 62: {
 63:   return !_finite(a) || _isnan(a);
 64: }
 65: #else
 66: PetscErrorCode PetscIsInfOrNanReal(PetscReal a)
 67: {
 68:   return ((a - a) != 0);
 69: }
 70: #endif

 72: /*@C
 73:       PetscIsNanReal - Returns an error code if the input double has a Not-a-number (Nan) value, otherwise 0.

 75:     Input Parameter:
 76: .     a - the floating point number

 78:      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
 79:       Otherwises uses ((a - a) != 0.0), note that some optimizing compiles compile
 80:       out this form, thus removing the check.

 82:      Level: beginner
 83: @*/
 84: #if defined(PETSC_USE_REAL___FLOAT128)
 85: PetscErrorCode PetscIsNanReal(PetscReal a)
 86: {
 87:   return isnanq(a);
 88: }
 89: #elif defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
 90: PetscErrorCode PetscIsNanReal(PetscReal a)
 91: {
 92:   return isnan(a);
 93: }
 94: #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
 95: #if defined(PETSC_HAVE_FLOAT_H)
 96: #include <float.h>  /* Microsoft Windows defines _finite() in float.h */
 97: #endif
 98: #if defined(PETSC_HAVE_IEEEFP_H)
 99: #include <ieeefp.h>  /* Solaris prototypes these here */
100: #endif
101: PetscErrorCode PetscIsNanReal(PetscReal a)
102: {
103:   return _isnan(a);
104: }
105: #else
106: PetscErrorCode PetscIsNanReal(PetscReal a)
107: {
108:   return ((a - a) != 0);
109: }
110: #endif