1*74c01ffaSSatish Balay #if !defined(PETSC_SKIP_COMPLEX) 20c567f5aSSatish Balay #define PETSC_SKIP_COMPLEX 3*74c01ffaSSatish Balay #endif 4*74c01ffaSSatish Balay 5532fbc7fSSatish Balay #include <petscsys.h> 6532fbc7fSSatish Balay /*@C 7811af0c4SBarry Smith PetscIsNormalReal - Returns `PETSC_TRUE` if the input value satisfies `isnormal()` 8532fbc7fSSatish Balay 9532fbc7fSSatish Balay Input Parameter: 10667f096bSBarry Smith . a - the `PetscReal` Value 11667f096bSBarry Smith 12667f096bSBarry Smith Level: beginner 13532fbc7fSSatish Balay 14811af0c4SBarry Smith Developer Notes: 15811af0c4SBarry Smith Uses the C99 standard `isnormal()` on systems where they exist. 16811af0c4SBarry Smith 17811af0c4SBarry Smith Uses `isnormalq()` with `__float128` 18811af0c4SBarry Smith 19811af0c4SBarry Smith Otherwise always returns true 208b49ba18SBarry Smith 21811af0c4SBarry Smith .seealso: `PetscIsInfReal()`, `PetscIsNanReal()` 228b49ba18SBarry Smith @*/ 23570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 24d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNormalReal(PetscReal a) 25d71ae5a4SJacob Faibussowitsch { 268fa295daSBarry Smith return PETSC_TRUE; 278b49ba18SBarry Smith } 288b49ba18SBarry Smith #elif defined(PETSC_HAVE_ISNORMAL) 29d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNormalReal(PetscReal a) 30d71ae5a4SJacob Faibussowitsch { 31bb88209dSBarry Smith return isnormal(a) ? PETSC_TRUE : PETSC_FALSE; 328b49ba18SBarry Smith } 338b49ba18SBarry Smith #else 34d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNormalReal(PetscReal a) 35d71ae5a4SJacob Faibussowitsch { 368b49ba18SBarry Smith return PETSC_TRUE; 378b49ba18SBarry Smith } 388b49ba18SBarry Smith #endif 398b49ba18SBarry Smith 408b49ba18SBarry Smith /*@C 41667f096bSBarry Smith PetscIsInfReal - Returns whether the `PetscReal` input is an infinity value. 428b49ba18SBarry Smith 438b49ba18SBarry Smith Input Parameter: 448b49ba18SBarry Smith . a - the floating point number 45532fbc7fSSatish Balay 46667f096bSBarry Smith Level: beginner 47667f096bSBarry Smith 48811af0c4SBarry Smith Developer Notes: 49811af0c4SBarry Smith Uses the C99 standard `isinf()` on systems where it exists. 50811af0c4SBarry Smith 51811af0c4SBarry Smith Otherwise uses (a && a/2 == a), note that some optimizing compilers compile out this form, thus removing the check. 52532fbc7fSSatish Balay 53811af0c4SBarry Smith .seealso: `PetscIsNormalReal()`, `PetscIsNanReal()` 54532fbc7fSSatish Balay @*/ 55532fbc7fSSatish Balay #if defined(PETSC_USE_REAL___FLOAT128) 56d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 57d71ae5a4SJacob Faibussowitsch { 589f4f8022SLisandro Dalcin return isinfq(a) ? PETSC_TRUE : PETSC_FALSE; 59532fbc7fSSatish Balay } 609f4f8022SLisandro Dalcin #elif defined(PETSC_HAVE_ISINF) 61d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 62d71ae5a4SJacob Faibussowitsch { 639f4f8022SLisandro Dalcin return isinf(a) ? PETSC_TRUE : PETSC_FALSE; 64532fbc7fSSatish Balay } 659f4f8022SLisandro Dalcin #elif defined(PETSC_HAVE__FINITE) 66532fbc7fSSatish Balay #if defined(PETSC_HAVE_FLOAT_H) 67aaa7dc30SBarry Smith #include <float.h> /* Microsoft Windows defines _finite() in float.h */ 68532fbc7fSSatish Balay #endif 69532fbc7fSSatish Balay #if defined(PETSC_HAVE_IEEEFP_H) 70aaa7dc30SBarry Smith #include <ieeefp.h> /* Solaris prototypes these here */ 71532fbc7fSSatish Balay #endif 72d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 73d71ae5a4SJacob Faibussowitsch { 749f4f8022SLisandro Dalcin return !_finite(a) ? PETSC_TRUE : PETSC_FALSE; 75532fbc7fSSatish Balay } 76532fbc7fSSatish Balay #else 77d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 78d71ae5a4SJacob Faibussowitsch { 799f4f8022SLisandro Dalcin return (a && a / 2 == a) ? PETSC_TRUE : PETSC_FALSE; 80532fbc7fSSatish Balay } 81532fbc7fSSatish Balay #endif 82532fbc7fSSatish Balay 83bae46576SBarry Smith /*@C 84667f096bSBarry Smith PetscIsNanReal - Returns whether the `PetscReal` input is a Not-a-Number (NaN) value. 85bae46576SBarry Smith 86bae46576SBarry Smith Input Parameter: 87bae46576SBarry Smith . a - the floating point number 88bae46576SBarry Smith 89667f096bSBarry Smith Level: beginner 90667f096bSBarry Smith 91811af0c4SBarry Smith Developer Notes: 92811af0c4SBarry Smith Uses the C99 standard `isnan()` on systems where it exists. 93811af0c4SBarry Smith 94811af0c4SBarry Smith Otherwise uses (a != a), note that some optimizing compilers compile 95bae46576SBarry Smith out this form, thus removing the check. 96bae46576SBarry Smith 97811af0c4SBarry Smith .seealso: `PetscIsNormalReal()`, `PetscIsInfReal()` 98bae46576SBarry Smith @*/ 99bae46576SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 100d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 101d71ae5a4SJacob Faibussowitsch { 1023948c36eSLisandro Dalcin return isnanq(a) ? PETSC_TRUE : PETSC_FALSE; 103bae46576SBarry Smith } 1043948c36eSLisandro Dalcin #elif defined(PETSC_HAVE_ISNAN) 105d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 106d71ae5a4SJacob Faibussowitsch { 1073948c36eSLisandro Dalcin return isnan(a) ? PETSC_TRUE : PETSC_FALSE; 108bae46576SBarry Smith } 1093948c36eSLisandro Dalcin #elif defined(PETSC_HAVE__ISNAN) 110bae46576SBarry Smith #if defined(PETSC_HAVE_FLOAT_H) 1113948c36eSLisandro Dalcin #include <float.h> /* Microsoft Windows defines _isnan() in float.h */ 112bae46576SBarry Smith #endif 113bae46576SBarry Smith #if defined(PETSC_HAVE_IEEEFP_H) 114bae46576SBarry Smith #include <ieeefp.h> /* Solaris prototypes these here */ 115bae46576SBarry Smith #endif 116d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 117d71ae5a4SJacob Faibussowitsch { 1183948c36eSLisandro Dalcin return _isnan(a) ? PETSC_TRUE : PETSC_FALSE; 119bae46576SBarry Smith } 120bae46576SBarry Smith #else 121d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 122d71ae5a4SJacob Faibussowitsch { 1233948c36eSLisandro Dalcin return (a != a) ? PETSC_TRUE : PETSC_FALSE; 124bae46576SBarry Smith } 125bae46576SBarry Smith #endif 126