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: Developer Notes:
10: Uses the C99 standard `isnormal()` on systems where they exist.
12: Uses `isnormalq()` with `__float128`
14: Otherwise always returns true
16: Level: beginner
18: .seealso: `PetscIsInfReal()`, `PetscIsNanReal()`
19: @*/
20: #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
21: PetscBool PetscIsNormalReal(PetscReal a)
22: {
23: return PETSC_TRUE;
24: }
25: #elif defined(PETSC_HAVE_ISNORMAL)
26: PetscBool PetscIsNormalReal(PetscReal a)
27: {
28: return isnormal(a) ? PETSC_TRUE : PETSC_FALSE;
29: }
30: #else
31: PetscBool PetscIsNormalReal(PetscReal a)
32: {
33: return PETSC_TRUE;
34: }
35: #endif
37: /*@C
38: PetscIsInfReal - Returns whether the input is an infinity value.
40: Input Parameter:
41: . a - the floating point number
43: Developer Notes:
44: Uses the C99 standard `isinf()` on systems where it exists.
46: Otherwise uses (a && a/2 == a), note that some optimizing compilers compile out this form, thus removing the check.
48: Level: beginner
50: .seealso: `PetscIsNormalReal()`, `PetscIsNanReal()`
51: @*/
52: #if defined(PETSC_USE_REAL___FLOAT128)
53: PetscBool PetscIsInfReal(PetscReal a)
54: {
55: return isinfq(a) ? PETSC_TRUE : PETSC_FALSE;
56: }
57: #elif defined(PETSC_HAVE_ISINF)
58: PetscBool PetscIsInfReal(PetscReal a)
59: {
60: return isinf(a) ? PETSC_TRUE : PETSC_FALSE;
61: }
62: #elif defined(PETSC_HAVE__FINITE)
63: #if defined(PETSC_HAVE_FLOAT_H)
64: #include <float.h> /* Microsoft Windows defines _finite() in float.h */
65: #endif
66: #if defined(PETSC_HAVE_IEEEFP_H)
67: #include <ieeefp.h> /* Solaris prototypes these here */
68: #endif
69: PetscBool PetscIsInfReal(PetscReal a)
70: {
71: return !_finite(a) ? PETSC_TRUE : PETSC_FALSE;
72: }
73: #else
74: PetscBool PetscIsInfReal(PetscReal a)
75: {
76: return (a && a / 2 == a) ? PETSC_TRUE : PETSC_FALSE;
77: }
78: #endif
80: /*@C
81: PetscIsNanReal - Returns whether the input is a Not-a-Number (NaN) value.
83: Input Parameter:
84: . a - the floating point number
86: Developer Notes:
87: Uses the C99 standard `isnan()` on systems where it exists.
89: Otherwise uses (a != a), note that some optimizing compilers compile
90: out this form, thus removing the check.
92: Level: beginner
94: .seealso: `PetscIsNormalReal()`, `PetscIsInfReal()`
95: @*/
96: #if defined(PETSC_USE_REAL___FLOAT128)
97: PetscBool PetscIsNanReal(PetscReal a)
98: {
99: return isnanq(a) ? PETSC_TRUE : PETSC_FALSE;
100: }
101: #elif defined(PETSC_HAVE_ISNAN)
102: PetscBool PetscIsNanReal(PetscReal a)
103: {
104: return isnan(a) ? PETSC_TRUE : PETSC_FALSE;
105: }
106: #elif defined(PETSC_HAVE__ISNAN)
107: #if defined(PETSC_HAVE_FLOAT_H)
108: #include <float.h> /* Microsoft Windows defines _isnan() in float.h */
109: #endif
110: #if defined(PETSC_HAVE_IEEEFP_H)
111: #include <ieeefp.h> /* Solaris prototypes these here */
112: #endif
113: PetscBool PetscIsNanReal(PetscReal a)
114: {
115: return _isnan(a) ? PETSC_TRUE : PETSC_FALSE;
116: }
117: #else
118: PetscBool PetscIsNanReal(PetscReal a)
119: {
120: return (a != a) ? PETSC_TRUE : PETSC_FALSE;
121: }
122: #endif