1 #define PETSC_SKIP_COMPLEX 2 #include <petscsys.h> 3 /*@C 4 PetscIsNormalReal - Returns `PETSC_TRUE` if the input value satisfies `isnormal()` 5 6 Input Parameter: 7 . a - the PetscReal Value 8 9 Developer Notes: 10 Uses the C99 standard `isnormal()` on systems where they exist. 11 12 Uses `isnormalq()` with `__float128` 13 14 Otherwise always returns true 15 16 Level: beginner 17 18 .seealso: `PetscIsInfReal()`, `PetscIsNanReal()` 19 @*/ 20 #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 21 PetscBool PetscIsNormalReal(PetscReal a) { 22 return PETSC_TRUE; 23 } 24 #elif defined(PETSC_HAVE_ISNORMAL) 25 PetscBool PetscIsNormalReal(PetscReal a) { 26 return isnormal(a) ? PETSC_TRUE : PETSC_FALSE; 27 } 28 #else 29 PetscBool PetscIsNormalReal(PetscReal a) { 30 return PETSC_TRUE; 31 } 32 #endif 33 34 /*@C 35 PetscIsInfReal - Returns whether the input is an infinity value. 36 37 Input Parameter: 38 . a - the floating point number 39 40 Developer Notes: 41 Uses the C99 standard `isinf()` on systems where it exists. 42 43 Otherwise uses (a && a/2 == a), note that some optimizing compilers compile out this form, thus removing the check. 44 45 Level: beginner 46 47 .seealso: `PetscIsNormalReal()`, `PetscIsNanReal()` 48 @*/ 49 #if defined(PETSC_USE_REAL___FLOAT128) 50 PetscBool PetscIsInfReal(PetscReal a) { 51 return isinfq(a) ? PETSC_TRUE : PETSC_FALSE; 52 } 53 #elif defined(PETSC_HAVE_ISINF) 54 PetscBool PetscIsInfReal(PetscReal a) { 55 return isinf(a) ? PETSC_TRUE : PETSC_FALSE; 56 } 57 #elif defined(PETSC_HAVE__FINITE) 58 #if defined(PETSC_HAVE_FLOAT_H) 59 #include <float.h> /* Microsoft Windows defines _finite() in float.h */ 60 #endif 61 #if defined(PETSC_HAVE_IEEEFP_H) 62 #include <ieeefp.h> /* Solaris prototypes these here */ 63 #endif 64 PetscBool PetscIsInfReal(PetscReal a) { 65 return !_finite(a) ? PETSC_TRUE : PETSC_FALSE; 66 } 67 #else 68 PetscBool PetscIsInfReal(PetscReal a) { 69 return (a && a / 2 == a) ? PETSC_TRUE : PETSC_FALSE; 70 } 71 #endif 72 73 /*@C 74 PetscIsNanReal - Returns whether the input is a Not-a-Number (NaN) value. 75 76 Input Parameter: 77 . a - the floating point number 78 79 Developer Notes: 80 Uses the C99 standard `isnan()` on systems where it exists. 81 82 Otherwise uses (a != a), note that some optimizing compilers compile 83 out this form, thus removing the check. 84 85 Level: beginner 86 87 .seealso: `PetscIsNormalReal()`, `PetscIsInfReal()` 88 @*/ 89 #if defined(PETSC_USE_REAL___FLOAT128) 90 PetscBool PetscIsNanReal(PetscReal a) { 91 return isnanq(a) ? PETSC_TRUE : PETSC_FALSE; 92 } 93 #elif defined(PETSC_HAVE_ISNAN) 94 PetscBool PetscIsNanReal(PetscReal a) { 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 return _isnan(a) ? PETSC_TRUE : PETSC_FALSE; 106 } 107 #else 108 PetscBool PetscIsNanReal(PetscReal a) { 109 return (a != a) ? PETSC_TRUE : PETSC_FALSE; 110 } 111 #endif 112