Actual source code: mathinf.c

petsc-3.11.4 2019-09-28
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:
 10:     uses the C99 standard isnormal() on systems where they exist.
 11:       Uses isnormalq() with __float128
 12:       Otherwises always returns true

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

 33: /*@C
 34:       PetscIsInfReal - Returns whether the input is an infinity value.

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

 39:      Notes:
 40:     uses the C99 standard isinf() on systems where it exists.
 41:       Otherwises uses (a && a/2 == a), note that some optimizing compiles compile
 42:       out this form, thus removing the check.

 44:      Level: beginner
 45: @*/
 46: #if defined(PETSC_USE_REAL___FLOAT128)
 47: PetscBool PetscIsInfReal(PetscReal a)
 48: {
 49:   return isinfq(a) ? PETSC_TRUE : PETSC_FALSE;
 50: }
 51: #elif defined(PETSC_HAVE_ISINF)
 52: PetscBool PetscIsInfReal(PetscReal a)
 53: {
 54:   return isinf(a) ? PETSC_TRUE : PETSC_FALSE;
 55: }
 56: #elif defined(PETSC_HAVE__FINITE)
 57: #if defined(PETSC_HAVE_FLOAT_H)
 58: #include <float.h>  /* Microsoft Windows defines _finite() in float.h */
 59: #endif
 60: #if defined(PETSC_HAVE_IEEEFP_H)
 61: #include <ieeefp.h>  /* Solaris prototypes these here */
 62: #endif
 63: PetscBool PetscIsInfReal(PetscReal a)
 64: {
 65:   return !_finite(a) ? PETSC_TRUE : PETSC_FALSE;
 66: }
 67: #else
 68: PetscBool PetscIsInfReal(PetscReal a)
 69: {
 70:   return (a && a/2 == a) ? PETSC_TRUE : PETSC_FALSE;
 71: }
 72: #endif

 74: /*@C
 75:       PetscIsNanReal - Returns whether the input is a Not-a-Number (NaN) value.

 77:     Input Parameter:
 78: .     a - the floating point number

 80:      Notes:
 81:     uses the C99 standard isnan() on systems where it exists.
 82:       Otherwises uses (a != a), note that some optimizing compiles compile
 83:       out this form, thus removing the check.

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