1: #include <petscmacros.h>
3: #if !PetscDefined(SKIP_COMPLEX)
4: #define PETSC_SKIP_COMPLEX
5: #endif
7: #include <petscsys.h>
8: /*@
9: PetscIsNormalReal - Returns `PETSC_TRUE` if the input value satisfies `isnormal()`
11: Input Parameter:
12: . a - the `PetscReal` Value
14: Level: beginner
16: Developer Notes:
17: Uses the C99 standard `isnormal()` on systems where they exist.
19: Uses `isnormalq()` with `__float128`
21: Otherwise always returns true
23: .seealso: `PetscIsInfReal()`, `PetscIsNanReal()`
24: @*/
25: #if PetscDefined(USE_REAL___FLOAT128) || PetscDefined(USE_REAL___FP16)
26: PetscBool PetscIsNormalReal(PetscReal a)
27: {
28: return PETSC_TRUE;
29: }
30: #elif PetscDefined(HAVE_ISNORMAL)
31: PetscBool PetscIsNormalReal(PetscReal a)
32: {
33: return isnormal(a) ? PETSC_TRUE : PETSC_FALSE;
34: }
35: #else
36: PetscBool PetscIsNormalReal(PetscReal a)
37: {
38: return PETSC_TRUE;
39: }
40: #endif
42: #if PetscDefined(HAVE_NO_FINITE_MATH_ONLY)
43: #define PETSC_FORCE_NO_FINITE_MATH_ONLY __attribute__((optimize("no-finite-math-only")))
44: #else
45: #define PETSC_FORCE_NO_FINITE_MATH_ONLY
46: #endif
48: /*@
49: PetscIsInfReal - Returns whether the `PetscReal` input is an infinity value.
51: Input Parameter:
52: . a - the floating point number
54: Level: beginner
56: Developer Notes:
57: Uses the C99 standard `isinf()` on systems where it exists.
59: Otherwise uses (a && a/2 == a), note that some optimizing compilers compile out this form, thus removing the check.
61: .seealso: `PetscIsNormalReal()`, `PetscIsNanReal()`
62: @*/
63: #if PetscDefined(USE_REAL___FLOAT128)
64: PetscBool PetscIsInfReal(PetscReal a)
65: {
66: return isinfq(a) ? PETSC_TRUE : PETSC_FALSE;
67: }
68: #elif PetscDefined(HAVE_ISINF)
69: PETSC_FORCE_NO_FINITE_MATH_ONLY PetscBool PetscIsInfReal(PetscReal a)
70: {
71: return isinf(a) ? PETSC_TRUE : PETSC_FALSE;
72: }
73: #elif PetscDefined(HAVE__FINITE)
74: #if PetscDefined(HAVE_FLOAT_H)
75: #include <float.h> /* Microsoft Windows defines _finite() in float.h */
76: #endif
77: #if PetscDefined(HAVE_IEEEFP_H)
78: #include <ieeefp.h> /* Solaris prototypes these here */
79: #endif
80: PetscBool PetscIsInfReal(PetscReal a)
81: {
82: return !_finite(a) ? PETSC_TRUE : PETSC_FALSE;
83: }
84: #else
85: PetscBool PetscIsInfReal(PetscReal a)
86: {
87: return (a && a / 2 == a) ? PETSC_TRUE : PETSC_FALSE;
88: }
89: #endif
91: /*@
92: PetscIsNanReal - Returns whether the `PetscReal` input is a Not-a-Number (NaN) value.
94: Input Parameter:
95: . a - the floating point number
97: Level: beginner
99: Developer Notes:
100: Uses the C99 standard `isnan()` on systems where it exists.
102: Otherwise uses (a != a), note that some optimizing compilers compile
103: out this form, thus removing the check.
105: .seealso: `PetscIsNormalReal()`, `PetscIsInfReal()`
106: @*/
107: #if PetscDefined(USE_REAL___FLOAT128)
108: PetscBool PetscIsNanReal(PetscReal a)
109: {
110: return isnanq(a) ? PETSC_TRUE : PETSC_FALSE;
111: }
112: #elif PetscDefined(HAVE_ISNAN)
113: PETSC_FORCE_NO_FINITE_MATH_ONLY PetscBool PetscIsNanReal(PetscReal a)
114: {
115: return isnan(a) ? PETSC_TRUE : PETSC_FALSE;
116: }
117: #elif PetscDefined(HAVE__ISNAN)
118: #if PetscDefined(HAVE_FLOAT_H)
119: #include <float.h> /* Microsoft Windows defines _isnan() in float.h */
120: #endif
121: #if PetscDefined(HAVE_IEEEFP_H)
122: #include <ieeefp.h> /* Solaris prototypes these here */
123: #endif
124: PetscBool PetscIsNanReal(PetscReal a)
125: {
126: return _isnan(a) ? PETSC_TRUE : PETSC_FALSE;
127: }
128: #else
129: PetscBool PetscIsNanReal(PetscReal a)
130: {
131: return (a != a) ? PETSC_TRUE : PETSC_FALSE;
132: }
133: #endif