10c567f5aSSatish Balay #define PETSC_SKIP_COMPLEX 2532fbc7fSSatish Balay #include <petscsys.h> 3532fbc7fSSatish Balay /*@C 40c567f5aSSatish Balay PetscIsNormalReal - Returns PETSC_TRUE if the input value satisfies isnormal() 5532fbc7fSSatish Balay 6532fbc7fSSatish Balay Input Parameter: 78b49ba18SBarry Smith . a - the PetscReal Value 8532fbc7fSSatish Balay 9*95452b02SPatrick Sanan Notes: 10*95452b02SPatrick Sanan uses the C99 standard isnormal() on systems where they exist. 118b49ba18SBarry Smith Uses isnormalq() with __float128 128b49ba18SBarry Smith Otherwises always returns true 138b49ba18SBarry Smith 148b49ba18SBarry Smith Level: beginner 158b49ba18SBarry Smith @*/ 16570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 178b49ba18SBarry Smith PetscBool PetscIsNormalReal(PetscReal a) 188b49ba18SBarry Smith { 198fa295daSBarry Smith return PETSC_TRUE; 208b49ba18SBarry Smith } 218b49ba18SBarry Smith #elif defined(PETSC_HAVE_ISNORMAL) 228b49ba18SBarry Smith PetscBool PetscIsNormalReal(PetscReal a) 238b49ba18SBarry Smith { 24bb88209dSBarry Smith return isnormal(a) ? PETSC_TRUE : PETSC_FALSE; 258b49ba18SBarry Smith } 268b49ba18SBarry Smith #else 278b49ba18SBarry Smith PetscBool PetscIsNormalReal(PetscReal a) 288b49ba18SBarry Smith { 298b49ba18SBarry Smith return PETSC_TRUE; 308b49ba18SBarry Smith } 318b49ba18SBarry Smith #endif 328b49ba18SBarry Smith 338b49ba18SBarry Smith /*@C 349f4f8022SLisandro Dalcin PetscIsInfReal - Returns whether the input is an infinity value. 358b49ba18SBarry Smith 368b49ba18SBarry Smith Input Parameter: 378b49ba18SBarry Smith . a - the floating point number 38532fbc7fSSatish Balay 39*95452b02SPatrick Sanan Notes: 40*95452b02SPatrick Sanan uses the C99 standard isinf() on systems where it exists. 419f4f8022SLisandro Dalcin Otherwises uses (a && a/2 == a), note that some optimizing compiles compile 42532fbc7fSSatish Balay out this form, thus removing the check. 43532fbc7fSSatish Balay 44532fbc7fSSatish Balay Level: beginner 45532fbc7fSSatish Balay @*/ 46532fbc7fSSatish Balay #if defined(PETSC_USE_REAL___FLOAT128) 479f4f8022SLisandro Dalcin PetscBool PetscIsInfReal(PetscReal a) 48f48dab2eSKarl Rupp { 499f4f8022SLisandro Dalcin return isinfq(a) ? PETSC_TRUE : PETSC_FALSE; 50532fbc7fSSatish Balay } 519f4f8022SLisandro Dalcin #elif defined(PETSC_HAVE_ISINF) 529f4f8022SLisandro Dalcin PetscBool PetscIsInfReal(PetscReal a) 53f48dab2eSKarl Rupp { 549f4f8022SLisandro Dalcin return isinf(a) ? PETSC_TRUE : PETSC_FALSE; 55532fbc7fSSatish Balay } 569f4f8022SLisandro Dalcin #elif defined(PETSC_HAVE__FINITE) 57532fbc7fSSatish Balay #if defined(PETSC_HAVE_FLOAT_H) 58aaa7dc30SBarry Smith #include <float.h> /* Microsoft Windows defines _finite() in float.h */ 59532fbc7fSSatish Balay #endif 60532fbc7fSSatish Balay #if defined(PETSC_HAVE_IEEEFP_H) 61aaa7dc30SBarry Smith #include <ieeefp.h> /* Solaris prototypes these here */ 62532fbc7fSSatish Balay #endif 639f4f8022SLisandro Dalcin PetscBool PetscIsInfReal(PetscReal a) 64f48dab2eSKarl Rupp { 659f4f8022SLisandro Dalcin return !_finite(a) ? PETSC_TRUE : PETSC_FALSE; 66532fbc7fSSatish Balay } 67532fbc7fSSatish Balay #else 68609837fcSLisandro Dalcin PetscBool PetscIsInfReal(PetscReal a) 69f48dab2eSKarl Rupp { 709f4f8022SLisandro Dalcin return (a && a/2 == a) ? PETSC_TRUE : PETSC_FALSE; 71532fbc7fSSatish Balay } 72532fbc7fSSatish Balay #endif 73532fbc7fSSatish Balay 74bae46576SBarry Smith /*@C 753948c36eSLisandro Dalcin PetscIsNanReal - Returns whether the input is a Not-a-Number (NaN) value. 76bae46576SBarry Smith 77bae46576SBarry Smith Input Parameter: 78bae46576SBarry Smith . a - the floating point number 79bae46576SBarry Smith 80*95452b02SPatrick Sanan Notes: 81*95452b02SPatrick Sanan uses the C99 standard isnan() on systems where it exists. 823948c36eSLisandro Dalcin Otherwises uses (a != a), note that some optimizing compiles compile 83bae46576SBarry Smith out this form, thus removing the check. 84bae46576SBarry Smith 85bae46576SBarry Smith Level: beginner 86bae46576SBarry Smith @*/ 87bae46576SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 883948c36eSLisandro Dalcin PetscBool PetscIsNanReal(PetscReal a) 89bae46576SBarry Smith { 903948c36eSLisandro Dalcin return isnanq(a) ? PETSC_TRUE : PETSC_FALSE; 91bae46576SBarry Smith } 923948c36eSLisandro Dalcin #elif defined(PETSC_HAVE_ISNAN) 933948c36eSLisandro Dalcin PetscBool PetscIsNanReal(PetscReal a) 94bae46576SBarry Smith { 953948c36eSLisandro Dalcin return isnan(a) ? PETSC_TRUE : PETSC_FALSE; 96bae46576SBarry Smith } 973948c36eSLisandro Dalcin #elif defined(PETSC_HAVE__ISNAN) 98bae46576SBarry Smith #if defined(PETSC_HAVE_FLOAT_H) 993948c36eSLisandro Dalcin #include <float.h> /* Microsoft Windows defines _isnan() in float.h */ 100bae46576SBarry Smith #endif 101bae46576SBarry Smith #if defined(PETSC_HAVE_IEEEFP_H) 102bae46576SBarry Smith #include <ieeefp.h> /* Solaris prototypes these here */ 103bae46576SBarry Smith #endif 1043948c36eSLisandro Dalcin PetscBool PetscIsNanReal(PetscReal a) 105bae46576SBarry Smith { 1063948c36eSLisandro Dalcin return _isnan(a) ? PETSC_TRUE : PETSC_FALSE; 107bae46576SBarry Smith } 108bae46576SBarry Smith #else 109609837fcSLisandro Dalcin PetscBool PetscIsNanReal(PetscReal a) 110bae46576SBarry Smith { 1113948c36eSLisandro Dalcin return (a != a) ? PETSC_TRUE : PETSC_FALSE; 112bae46576SBarry Smith } 113bae46576SBarry Smith #endif 114