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