10c567f5aSSatish Balay #define PETSC_SKIP_COMPLEX 2532fbc7fSSatish Balay #include <petscsys.h> 3532fbc7fSSatish Balay /*@C 4811af0c4SBarry Smith PetscIsNormalReal - Returns `PETSC_TRUE` if the input value satisfies `isnormal()` 5532fbc7fSSatish Balay 6532fbc7fSSatish Balay Input Parameter: 7*667f096bSBarry Smith . a - the `PetscReal` Value 8*667f096bSBarry Smith 9*667f096bSBarry Smith Level: beginner 10532fbc7fSSatish Balay 11811af0c4SBarry Smith Developer Notes: 12811af0c4SBarry Smith Uses the C99 standard `isnormal()` on systems where they exist. 13811af0c4SBarry Smith 14811af0c4SBarry Smith Uses `isnormalq()` with `__float128` 15811af0c4SBarry Smith 16811af0c4SBarry Smith Otherwise always returns true 178b49ba18SBarry Smith 18811af0c4SBarry Smith .seealso: `PetscIsInfReal()`, `PetscIsNanReal()` 198b49ba18SBarry Smith @*/ 20570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 21d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNormalReal(PetscReal a) 22d71ae5a4SJacob Faibussowitsch { 238fa295daSBarry Smith return PETSC_TRUE; 248b49ba18SBarry Smith } 258b49ba18SBarry Smith #elif defined(PETSC_HAVE_ISNORMAL) 26d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNormalReal(PetscReal a) 27d71ae5a4SJacob Faibussowitsch { 28bb88209dSBarry Smith return isnormal(a) ? PETSC_TRUE : PETSC_FALSE; 298b49ba18SBarry Smith } 308b49ba18SBarry Smith #else 31d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNormalReal(PetscReal a) 32d71ae5a4SJacob Faibussowitsch { 338b49ba18SBarry Smith return PETSC_TRUE; 348b49ba18SBarry Smith } 358b49ba18SBarry Smith #endif 368b49ba18SBarry Smith 378b49ba18SBarry Smith /*@C 38*667f096bSBarry Smith PetscIsInfReal - Returns whether the `PetscReal` input is an infinity value. 398b49ba18SBarry Smith 408b49ba18SBarry Smith Input Parameter: 418b49ba18SBarry Smith . a - the floating point number 42532fbc7fSSatish Balay 43*667f096bSBarry Smith Level: beginner 44*667f096bSBarry Smith 45811af0c4SBarry Smith Developer Notes: 46811af0c4SBarry Smith Uses the C99 standard `isinf()` on systems where it exists. 47811af0c4SBarry Smith 48811af0c4SBarry Smith Otherwise uses (a && a/2 == a), note that some optimizing compilers compile out this form, thus removing the check. 49532fbc7fSSatish Balay 50811af0c4SBarry Smith .seealso: `PetscIsNormalReal()`, `PetscIsNanReal()` 51532fbc7fSSatish Balay @*/ 52532fbc7fSSatish Balay #if defined(PETSC_USE_REAL___FLOAT128) 53d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 54d71ae5a4SJacob Faibussowitsch { 559f4f8022SLisandro Dalcin return isinfq(a) ? PETSC_TRUE : PETSC_FALSE; 56532fbc7fSSatish Balay } 579f4f8022SLisandro Dalcin #elif defined(PETSC_HAVE_ISINF) 58d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 59d71ae5a4SJacob Faibussowitsch { 609f4f8022SLisandro Dalcin return isinf(a) ? PETSC_TRUE : PETSC_FALSE; 61532fbc7fSSatish Balay } 629f4f8022SLisandro Dalcin #elif defined(PETSC_HAVE__FINITE) 63532fbc7fSSatish Balay #if defined(PETSC_HAVE_FLOAT_H) 64aaa7dc30SBarry Smith #include <float.h> /* Microsoft Windows defines _finite() in float.h */ 65532fbc7fSSatish Balay #endif 66532fbc7fSSatish Balay #if defined(PETSC_HAVE_IEEEFP_H) 67aaa7dc30SBarry Smith #include <ieeefp.h> /* Solaris prototypes these here */ 68532fbc7fSSatish Balay #endif 69d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 70d71ae5a4SJacob Faibussowitsch { 719f4f8022SLisandro Dalcin return !_finite(a) ? PETSC_TRUE : PETSC_FALSE; 72532fbc7fSSatish Balay } 73532fbc7fSSatish Balay #else 74d71ae5a4SJacob Faibussowitsch PetscBool PetscIsInfReal(PetscReal a) 75d71ae5a4SJacob Faibussowitsch { 769f4f8022SLisandro Dalcin return (a && a / 2 == a) ? PETSC_TRUE : PETSC_FALSE; 77532fbc7fSSatish Balay } 78532fbc7fSSatish Balay #endif 79532fbc7fSSatish Balay 80bae46576SBarry Smith /*@C 81*667f096bSBarry Smith PetscIsNanReal - Returns whether the `PetscReal` input is a Not-a-Number (NaN) value. 82bae46576SBarry Smith 83bae46576SBarry Smith Input Parameter: 84bae46576SBarry Smith . a - the floating point number 85bae46576SBarry Smith 86*667f096bSBarry Smith Level: beginner 87*667f096bSBarry Smith 88811af0c4SBarry Smith Developer Notes: 89811af0c4SBarry Smith Uses the C99 standard `isnan()` on systems where it exists. 90811af0c4SBarry Smith 91811af0c4SBarry Smith Otherwise uses (a != a), note that some optimizing compilers compile 92bae46576SBarry Smith out this form, thus removing the check. 93bae46576SBarry Smith 94811af0c4SBarry Smith .seealso: `PetscIsNormalReal()`, `PetscIsInfReal()` 95bae46576SBarry Smith @*/ 96bae46576SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 97d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 98d71ae5a4SJacob Faibussowitsch { 993948c36eSLisandro Dalcin return isnanq(a) ? PETSC_TRUE : PETSC_FALSE; 100bae46576SBarry Smith } 1013948c36eSLisandro Dalcin #elif defined(PETSC_HAVE_ISNAN) 102d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 103d71ae5a4SJacob Faibussowitsch { 1043948c36eSLisandro Dalcin return isnan(a) ? PETSC_TRUE : PETSC_FALSE; 105bae46576SBarry Smith } 1063948c36eSLisandro Dalcin #elif defined(PETSC_HAVE__ISNAN) 107bae46576SBarry Smith #if defined(PETSC_HAVE_FLOAT_H) 1083948c36eSLisandro Dalcin #include <float.h> /* Microsoft Windows defines _isnan() in float.h */ 109bae46576SBarry Smith #endif 110bae46576SBarry Smith #if defined(PETSC_HAVE_IEEEFP_H) 111bae46576SBarry Smith #include <ieeefp.h> /* Solaris prototypes these here */ 112bae46576SBarry Smith #endif 113d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 114d71ae5a4SJacob Faibussowitsch { 1153948c36eSLisandro Dalcin return _isnan(a) ? PETSC_TRUE : PETSC_FALSE; 116bae46576SBarry Smith } 117bae46576SBarry Smith #else 118d71ae5a4SJacob Faibussowitsch PetscBool PetscIsNanReal(PetscReal a) 119d71ae5a4SJacob Faibussowitsch { 1203948c36eSLisandro Dalcin return (a != a) ? PETSC_TRUE : PETSC_FALSE; 121bae46576SBarry Smith } 122bae46576SBarry Smith #endif 123