1e489efc1SBarry Smith /* 2314da920SBarry Smith 3314da920SBarry Smith PETSc mathematics include file. Defines certain basic mathematical 4314da920SBarry Smith constants and functions for working with single and double precision 5314da920SBarry Smith floating point numbers as well as complex and integers. 6314da920SBarry Smith 7d382aafbSBarry Smith This file is included by petscsys.h and should not be used directly. 8e7029fe1SSatish Balay 9e489efc1SBarry Smith */ 10e489efc1SBarry Smith 11488ecbafSBarry Smith #if !defined(__PETSCMATH_H) 12488ecbafSBarry Smith #define __PETSCMATH_H 130a5f7794SBarry Smith #include <math.h> 14e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 150a5f7794SBarry Smith 167087cfbeSBarry Smith extern MPI_Datatype MPIU_2SCALAR; 177087cfbeSBarry Smith extern MPI_Datatype MPIU_2INT; 18c90a1750SBarry Smith 19314da920SBarry Smith /* 20f4ccad53SBarry Smith 21f4ccad53SBarry Smith Defines operations that are different for complex and real numbers; 22f4ccad53SBarry Smith note that one cannot really mix the use of complex and real in the same 23f4ccad53SBarry Smith PETSc program. All PETSc objects in one program are built around the object 2498725619SBarry Smith PetscScalar which is either always a real or a complex. 25f4ccad53SBarry Smith 26e489efc1SBarry Smith */ 27b36a9721SBarry Smith 2859cb5930SBarry Smith #define PetscExpPassiveScalar(a) PetscExpScalar() 29*c1d390e3SJed Brown #if defined(PETSC_USE_REAL_SINGLE) 30*c1d390e3SJed Brown #define MPIU_REAL MPI_FLOAT 31*c1d390e3SJed Brown typedef float PetscReal; 32*c1d390e3SJed Brown #elif defined(PETSC_USE_REAL_DOUBLE) 33*c1d390e3SJed Brown #define MPIU_REAL MPI_DOUBLE 34*c1d390e3SJed Brown typedef double PetscReal; 35*c1d390e3SJed Brown #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 36*c1d390e3SJed Brown #define MPIU_REAL MPI_LONG_DOUBLE 37*c1d390e3SJed Brown typedef long double PetscReal; 38*c1d390e3SJed Brown #elif defined(PETSC_USE_REAL___FLOAT128) 39*c1d390e3SJed Brown #define MPIU_REAL MPIU___FLOAT128 40*c1d390e3SJed Brown typedef __float128 PetscReal; 41*c1d390e3SJed Brown #endif /* PETSC_USE_REAL_* */ 4259cb5930SBarry Smith 431093a601SBarry Smith /* 441093a601SBarry Smith Complex number definitions 451093a601SBarry Smith */ 46aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 47b7940d39SSatish Balay #if defined(PETSC_CLANGUAGE_CXX) 481093a601SBarry Smith /* C++ support of complex number */ 49df9b3741SSatish Balay #include <complex> 50adc17e78SSatish Balay 51329f5518SBarry Smith #define PetscRealPart(a) (a).real() 52329f5518SBarry Smith #define PetscImaginaryPart(a) (a).imag() 533f6de6efSSatish Balay #define PetscAbsScalar(a) std::abs(a) 543f6de6efSSatish Balay #define PetscConj(a) std::conj(a) 5518a7d68fSSatish Balay #define PetscSqrtScalar(a) std::sqrt(a) 56184914b5SBarry Smith #define PetscPowScalar(a,b) std::pow(a,b) 57184914b5SBarry Smith #define PetscExpScalar(a) std::exp(a) 5806c1185fSBarry Smith #define PetscLogScalar(a) std::log(a) 59184914b5SBarry Smith #define PetscSinScalar(a) std::sin(a) 60184914b5SBarry Smith #define PetscCosScalar(a) std::cos(a) 610bfd3fbfSBarry Smith 62ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 634a60b672SMatthew Knepley typedef std::complex<float> PetscScalar; 64ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 651093a601SBarry Smith typedef std::complex<double> PetscScalar; 66ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 674a60b672SMatthew Knepley typedef std::complex<long double> PetscScalar; 68ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 69b7940d39SSatish Balay 701b65fc54SMatthew G Knepley #else /* PETSC_CLANGUAGE_CXX */ 711093a601SBarry Smith /* C support of complex numbers: Requires C99 compliant compiler*/ 721093a601SBarry Smith #include <complex.h> 73b7940d39SSatish Balay 74ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 7585b47369SMatthew Knepley typedef float complex PetscScalar; 7685b47369SMatthew Knepley 7785b47369SMatthew Knepley #define PetscRealPart(a) crealf(a) 7885b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagf(a) 7985b47369SMatthew Knepley #define PetscAbsScalar(a) cabsf(a) 8085b47369SMatthew Knepley #define PetscConj(a) conjf(a) 8185b47369SMatthew Knepley #define PetscSqrtScalar(a) csqrtf(a) 8285b47369SMatthew Knepley #define PetscPowScalar(a,b) cpowf(a,b) 8385b47369SMatthew Knepley #define PetscExpScalar(a) cexpf(a) 8406c1185fSBarry Smith #define PetscLogScalar(a) clogf(a) 8585b47369SMatthew Knepley #define PetscSinScalar(a) csinf(a) 8685b47369SMatthew Knepley #define PetscCosScalar(a) ccosf(a) 871093a601SBarry Smith 88ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 891093a601SBarry Smith typedef double complex PetscScalar; 901093a601SBarry Smith 911093a601SBarry Smith #define PetscRealPart(a) creal(a) 921093a601SBarry Smith #define PetscImaginaryPart(a) cimag(a) 931093a601SBarry Smith #define PetscAbsScalar(a) cabs(a) 941093a601SBarry Smith #define PetscConj(a) conj(a) 951093a601SBarry Smith #define PetscSqrtScalar(a) csqrt(a) 961093a601SBarry Smith #define PetscPowScalar(a,b) cpow(a,b) 971093a601SBarry Smith #define PetscExpScalar(a) cexp(a) 981093a601SBarry Smith #define PetscLogScalar(a) clog(a) 991093a601SBarry Smith #define PetscSinScalar(a) csin(a) 1001093a601SBarry Smith #define PetscCosScalar(a) ccos(a) 1011093a601SBarry Smith 102ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 10385b47369SMatthew Knepley typedef long double complex PetscScalar; 10485b47369SMatthew Knepley 10585b47369SMatthew Knepley #define PetscRealPart(a) creall(a) 10685b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagl(a) 10785b47369SMatthew Knepley #define PetscAbsScalar(a) cabsl(a) 10885b47369SMatthew Knepley #define PetscConj(a) conjl(a) 10985b47369SMatthew Knepley #define PetscSqrtScalar(a) csqrtl(a) 11085b47369SMatthew Knepley #define PetscPowScalar(a,b) cpowl(a,b) 11185b47369SMatthew Knepley #define PetscExpScalar(a) cexpl(a) 11206c1185fSBarry Smith #define PetscLogScalar(a) clogl(a) 11385b47369SMatthew Knepley #define PetscSinScalar(a) csinl(a) 11485b47369SMatthew Knepley #define PetscCosScalar(a) ccosl(a) 11585b47369SMatthew Knepley 116ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 1171b65fc54SMatthew G Knepley #endif /* PETSC_CLANGUAGE_CXX */ 118e489efc1SBarry Smith 1192c876bd9SBarry Smith #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) 1207087cfbeSBarry Smith extern MPI_Datatype MPI_C_DOUBLE_COMPLEX; 1217087cfbeSBarry Smith extern MPI_Datatype MPI_C_COMPLEX; 1221b65fc54SMatthew G Knepley #endif /* PETSC_HAVE_MPI_C_DOUBLE_COMPLEX */ 1232c876bd9SBarry Smith 124ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 125a83b8d76SBarry Smith #define MPIU_SCALAR MPI_C_COMPLEX 126ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 1272c876bd9SBarry Smith #define MPIU_SCALAR MPI_C_DOUBLE_COMPLEX 128ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 1291093a601SBarry Smith #define MPIU_SCALAR error 130ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 13175567043SBarry Smith 1321093a601SBarry Smith /* 1331093a601SBarry Smith real number definitions 1341093a601SBarry Smith */ 1351b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */ 136ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 13787828ca2SBarry Smith #define MPIU_SCALAR MPI_FLOAT 1381093a601SBarry Smith typedef float PetscScalar; 139ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 1401093a601SBarry Smith #define MPIU_SCALAR MPI_DOUBLE 1411093a601SBarry Smith typedef double PetscScalar; 142ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 143f68b968cSBarry Smith #define MPIU_SCALAR MPI_LONG_DOUBLE 1441093a601SBarry Smith typedef long double PetscScalar; 145ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 146c90a1750SBarry Smith extern MPI_Datatype MPIU___FLOAT128; 147c90a1750SBarry Smith #define MPIU_SCALAR MPIU___FLOAT128 1480d0cc1b5SBarry Smith typedef __float128 PetscScalar; 149ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */ 150329f5518SBarry Smith #define PetscRealPart(a) (a) 151*c1d390e3SJed Brown #define PetscImaginaryPart(a) ((PetscReal)0.) 152*c1d390e3SJed Brown PETSC_STATIC_INLINE PetscReal PetscAbsScalar(PetscScalar a) {return a < 0.0 ? -a : a;} 153e489efc1SBarry Smith #define PetscConj(a) (a) 154ce63c4c1SBarry Smith #if !defined(PETSC_USE_REAL___FLOAT128) 15518a7d68fSSatish Balay #define PetscSqrtScalar(a) sqrt(a) 156184914b5SBarry Smith #define PetscPowScalar(a,b) pow(a,b) 157184914b5SBarry Smith #define PetscExpScalar(a) exp(a) 15806c1185fSBarry Smith #define PetscLogScalar(a) log(a) 159184914b5SBarry Smith #define PetscSinScalar(a) sin(a) 160184914b5SBarry Smith #define PetscCosScalar(a) cos(a) 161ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */ 1620d0cc1b5SBarry Smith #include <quadmath.h> 1630d0cc1b5SBarry Smith #define PetscSqrtScalar(a) sqrtq(a) 1640d0cc1b5SBarry Smith #define PetscPowScalar(a,b) powq(a,b) 1650d0cc1b5SBarry Smith #define PetscExpScalar(a) expq(a) 1660d0cc1b5SBarry Smith #define PetscLogScalar(a) logq(a) 1670d0cc1b5SBarry Smith #define PetscSinScalar(a) sinq(a) 1680d0cc1b5SBarry Smith #define PetscCosScalar(a) cosq(a) 169ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */ 170b0a32e0cSBarry Smith 1711b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */ 172e489efc1SBarry Smith 173da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1) 17426aa1773SMatthew Knepley #define PetscAbs(a) (((a) >= 0) ? (a) : -(a)) 1753f1db9ecSBarry Smith 176314da920SBarry Smith /* --------------------------------------------------------------------------*/ 177314da920SBarry Smith 178e489efc1SBarry Smith /* 179f22f69f0SBarry Smith Certain objects may be created using either single or double precision. 180f22f69f0SBarry Smith This is currently not used. 181e489efc1SBarry Smith */ 182557d4da8SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision; 183e489efc1SBarry Smith 184e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */ 1857087cfbeSBarry Smith extern PetscScalar PETSC_i; 186e489efc1SBarry Smith 187b6a5bde7SBarry Smith /*MC 188b6a5bde7SBarry Smith PetscMin - Returns minimum of two numbers 189b6a5bde7SBarry Smith 190eca87e8dSBarry Smith Synopsis: 191eca87e8dSBarry Smith type PetscMin(type v1,type v2) 192eca87e8dSBarry Smith 193eca87e8dSBarry Smith Not Collective 194eca87e8dSBarry Smith 195b6a5bde7SBarry Smith Input Parameter: 196b6a5bde7SBarry Smith + v1 - first value to find minimum of 197b6a5bde7SBarry Smith - v2 - second value to find minimum of 198b6a5bde7SBarry Smith 199b6a5bde7SBarry Smith 200b6a5bde7SBarry Smith Notes: type can be integer or floating point value 201b6a5bde7SBarry Smith 202b6a5bde7SBarry Smith Level: beginner 203b6a5bde7SBarry Smith 204b6a5bde7SBarry Smith 205b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 206b6a5bde7SBarry Smith 207b6a5bde7SBarry Smith M*/ 208e489efc1SBarry Smith #define PetscMin(a,b) (((a)<(b)) ? (a) : (b)) 209b6a5bde7SBarry Smith 210b6a5bde7SBarry Smith /*MC 211b6a5bde7SBarry Smith PetscMax - Returns maxium of two numbers 212b6a5bde7SBarry Smith 213eca87e8dSBarry Smith Synopsis: 214eca87e8dSBarry Smith type max PetscMax(type v1,type v2) 215eca87e8dSBarry Smith 216eca87e8dSBarry Smith Not Collective 217eca87e8dSBarry Smith 218b6a5bde7SBarry Smith Input Parameter: 219b6a5bde7SBarry Smith + v1 - first value to find maximum of 220b6a5bde7SBarry Smith - v2 - second value to find maximum of 221b6a5bde7SBarry Smith 222b6a5bde7SBarry Smith Notes: type can be integer or floating point value 223b6a5bde7SBarry Smith 224b6a5bde7SBarry Smith Level: beginner 225b6a5bde7SBarry Smith 226b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 227b6a5bde7SBarry Smith 228b6a5bde7SBarry Smith M*/ 229e489efc1SBarry Smith #define PetscMax(a,b) (((a)<(b)) ? (b) : (a)) 230b6a5bde7SBarry Smith 231b6a5bde7SBarry Smith /*MC 232b6a5bde7SBarry Smith PetscAbsInt - Returns the absolute value of an integer 233b6a5bde7SBarry Smith 234b6a5bde7SBarry Smith Synopsis: 235b6a5bde7SBarry Smith int abs PetscAbsInt(int v1) 236b6a5bde7SBarry Smith 237eca87e8dSBarry Smith Not Collective 238eca87e8dSBarry Smith 239eca87e8dSBarry Smith Input Parameter: 240eca87e8dSBarry Smith . v1 - the integer 241b6a5bde7SBarry Smith 242b6a5bde7SBarry Smith Level: beginner 243b6a5bde7SBarry Smith 244b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr() 245b6a5bde7SBarry Smith 246b6a5bde7SBarry Smith M*/ 247e489efc1SBarry Smith #define PetscAbsInt(a) (((a)<0) ? -(a) : (a)) 248b6a5bde7SBarry Smith 249b6a5bde7SBarry Smith /*MC 250b6a5bde7SBarry Smith PetscAbsReal - Returns the absolute value of an real number 251b6a5bde7SBarry Smith 252eca87e8dSBarry Smith Synopsis: 253eca87e8dSBarry Smith Real abs PetscAbsReal(PetscReal v1) 254eca87e8dSBarry Smith 255eca87e8dSBarry Smith Not Collective 256eca87e8dSBarry Smith 257b6a5bde7SBarry Smith Input Parameter: 258b6a5bde7SBarry Smith . v1 - the double 259b6a5bde7SBarry Smith 260b6a5bde7SBarry Smith 261b6a5bde7SBarry Smith Level: beginner 262b6a5bde7SBarry Smith 263b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr() 264b6a5bde7SBarry Smith 265b6a5bde7SBarry Smith M*/ 266f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0) ? -(a) : (a)) 267b6a5bde7SBarry Smith 268b6a5bde7SBarry Smith /*MC 269b6a5bde7SBarry Smith PetscSqr - Returns the square of a number 270b6a5bde7SBarry Smith 271b6a5bde7SBarry Smith Synopsis: 272b6a5bde7SBarry Smith type sqr PetscSqr(type v1) 273b6a5bde7SBarry Smith 274eca87e8dSBarry Smith Not Collective 275eca87e8dSBarry Smith 276eca87e8dSBarry Smith Input Parameter: 277eca87e8dSBarry Smith . v1 - the value 278eca87e8dSBarry Smith 279b6a5bde7SBarry Smith Notes: type can be integer or floating point value 280b6a5bde7SBarry Smith 281b6a5bde7SBarry Smith Level: beginner 282b6a5bde7SBarry Smith 283b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal() 284b6a5bde7SBarry Smith 285b6a5bde7SBarry Smith M*/ 2864ebda54eSMatthew Knepley #define PetscSqr(a) ((a)*(a)) 287e489efc1SBarry Smith 288314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 289314da920SBarry Smith /* 290d34fcf5fSBarry Smith Basic constants 291314da920SBarry Smith */ 292ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 293d34fcf5fSBarry Smith #define PETSC_PI M_PIq 294d34fcf5fSBarry Smith #elif defined(M_PI) 295d34fcf5fSBarry Smith #define PETSC_PI M_PI 296d34fcf5fSBarry Smith #else 297314da920SBarry Smith #define PETSC_PI 3.14159265358979323846264 298d34fcf5fSBarry Smith #endif 299d34fcf5fSBarry Smith 300d34fcf5fSBarry Smith 30171fd2e92SBarry Smith #define PETSC_MAX_INT 2147483647 30271fd2e92SBarry Smith #define PETSC_MIN_INT -2147483647 303e489efc1SBarry Smith 304ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 305d34fcf5fSBarry Smith #if defined(MAXFLOAT) 306ea345e14SBarry Smith # define PETSC_MAX_REAL MAXFLOAT 307d34fcf5fSBarry Smith #else 308ea345e14SBarry Smith # define PETSC_MAX_REAL 1.e30 309d34fcf5fSBarry Smith #endif 310ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 311f10639e6SSatish Balay # define PETSC_MACHINE_EPSILON 1.e-7 312f10639e6SSatish Balay # define PETSC_SQRT_MACHINE_EPSILON 3.e-4 313cf6e855fSSatish Balay # define PETSC_SMALL 1.e-5 314ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 315ea345e14SBarry Smith # define PETSC_MAX_REAL 1.e300 316ea345e14SBarry Smith # define PETSC_MIN_REAL -PETSC_MAX_REAL 317f10639e6SSatish Balay # define PETSC_MACHINE_EPSILON 1.e-14 318f10639e6SSatish Balay # define PETSC_SQRT_MACHINE_EPSILON 1.e-7 319cf6e855fSSatish Balay # define PETSC_SMALL 1.e-10 320513dbe71SLisandro Dalcin #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 321513dbe71SLisandro Dalcin # define PETSC_MAX_REAL 1.e4900L 322513dbe71SLisandro Dalcin # define PETSC_MIN_REAL -PETSC_MAX_REAL 323513dbe71SLisandro Dalcin # define PETSC_MACHINE_EPSILON 1.e-18 324513dbe71SLisandro Dalcin # define PETSC_SQRT_MACHINE_EPSILON 1.e-9 325513dbe71SLisandro Dalcin # define PETSC_SMALL 1.e-13 326ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 327ea345e14SBarry Smith # define PETSC_MAX_REAL FLT128_MAX 328ce63c4c1SBarry Smith # define PETSC_MIN_REAL -FLT128_MAX 329d34fcf5fSBarry Smith # define PETSC_MACHINE_EPSILON FLT128_EPSILON 330d34fcf5fSBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.38777878078e-17 331d34fcf5fSBarry Smith # define PETSC_SMALL 1.e-20 33282adfdadSBarry Smith #endif 33382adfdadSBarry Smith 3349cf09972SJed Brown #if defined PETSC_HAVE_ADIC 3359cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */ 3367087cfbeSBarry Smith extern PetscErrorCode PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*); 3377087cfbeSBarry Smith extern PetscErrorCode PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*); 3387087cfbeSBarry Smith extern PetscErrorCode PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*); 3399cf09972SJed Brown #endif 3403e523bebSBarry Smith 3410763cb5fSBarry Smith /*MC 3420763cb5fSBarry Smith PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0. 3433e523bebSBarry Smith 3440763cb5fSBarry Smith Input Parameter: 3450763cb5fSBarry Smith . a - the double 3460763cb5fSBarry Smith 3470763cb5fSBarry Smith 3480763cb5fSBarry Smith Notes: uses the C99 standard isinf() and isnan() on systems where they exist. 34983886165SBarry Smith Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile 3500763cb5fSBarry Smith out this form, thus removing the check. 3510763cb5fSBarry Smith 35283672c4dSSatish Balay Level: beginner 35383672c4dSSatish Balay 35483672c4dSSatish Balay M*/ 355ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 356a06653b4SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) { 357a06653b4SBarry Smith return isinfq(PetscAbsScalar(a)) || isnanq(PetscAbsScalar(a)); 358a06653b4SBarry Smith } 359a06653b4SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) { 360a06653b4SBarry Smith return isinfq(a) || isnanq(a); 361a06653b4SBarry Smith } 362380a9c49SSatish Balay #elif defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN) && !defined(_GLIBCXX_CMATH) 36362cbcd01SMatthew G Knepley PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) { 36462cbcd01SMatthew G Knepley return isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a)); 36562cbcd01SMatthew G Knepley } 36662cbcd01SMatthew G Knepley PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) { 36762cbcd01SMatthew G Knepley return isinf(a) || isnan(a); 36862cbcd01SMatthew G Knepley } 36962b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN) 370270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H) 37198725619SBarry Smith #include "float.h" /* Microsoft Windows defines _finite() in float.h */ 372270b8587SSatish Balay #endif 373961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H) 374961faeafSBarry Smith #include "ieeefp.h" /* Solaris prototypes these here */ 375961faeafSBarry Smith #endif 37698725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) { 37798725619SBarry Smith return !_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a)); 37898725619SBarry Smith } 37998725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) { 38098725619SBarry Smith return !_finite(a) || _isnan(a); 38198725619SBarry Smith } 3829a25a3ccSBarry Smith #else 38398725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) { 384d4a378daSJed Brown return ((a - a) != (PetscScalar)0); 38598725619SBarry Smith } 38698725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) { 387d4a378daSJed Brown return ((a - a) != 0); 38898725619SBarry Smith } 3899a25a3ccSBarry Smith #endif 3909a25a3ccSBarry Smith 3919a25a3ccSBarry Smith 392314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 393e489efc1SBarry Smith /* 394b0a32e0cSBarry Smith PetscLogDouble variables are used to contain double precision numbers 395e489efc1SBarry Smith that are not used in the numerical computations, but rather in logging, 396e489efc1SBarry Smith timing etc. 397e489efc1SBarry Smith */ 398b0a32e0cSBarry Smith typedef double PetscLogDouble; 399b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 400e489efc1SBarry Smith 40187828ca2SBarry Smith #define PassiveReal PetscReal 402ea709b57SSatish Balay #define PassiveScalar PetscScalar 403d3ecb3a7SBarry Smith 40498725619SBarry Smith /* 40598725619SBarry Smith These macros are currently hardwired to match the regular data types, so there is no support for a different 40698725619SBarry Smith MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again. 40798725619SBarry Smith */ 40898725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR 40998725619SBarry Smith typedef PetscScalar MatScalar; 41098725619SBarry Smith typedef PetscReal MatReal; 41198725619SBarry Smith 412e9fa29b7SSatish Balay 413e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 414e489efc1SBarry Smith #endif 415