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