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