Actual source code: mathinf.c

petsc-3.3-p7 2013-05-11
  1: #include <petscsys.h>
  2: /*@C
  3:       PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.

  5:     Input Parameter:
  6: .     a - the double


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

 13:      Level: beginner
 14: @*/
 15: #if defined(PETSC_USE_REAL___FLOAT128)
 16: PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
 17:   return isinfq(PetscAbsScalar(a)) || isnanq(PetscAbsScalar(a));
 18: }
 19:  PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
 20:   return isinfq(a) || isnanq(a);
 21: }
 22: #elif defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
 23:  PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
 24:   return isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a));
 25: }
 26:  PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
 27:   return isinf(a) || isnan(a);
 28: }
 29: #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
 30: #if defined(PETSC_HAVE_FLOAT_H)
 31: #include "float.h"  /* Microsoft Windows defines _finite() in float.h */
 32: #endif
 33: #if defined(PETSC_HAVE_IEEEFP_H)
 34: #include "ieeefp.h"  /* Solaris prototypes these here */
 35: #endif
 36:  PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
 37:   return !_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a));
 38: }
 39:  PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
 40:   return !_finite(a) || _isnan(a);
 41: }
 42: #else
 43:  PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
 44:   return  ((a - a) != (PetscScalar)0);
 45: }
 46:  PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
 47:   return ((a - a) != 0);
 48: }
 49: #endif