Actual source code: mathinf.c

petsc-3.6.1 2015-08-06
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