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 7e7029fe1SSatish Balay This file is included by petsc.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 16ff73aad6SKris Buschelman extern MPI_Datatype PETSC_DLLEXPORT MPIU_2SCALAR; 17ff73aad6SKris Buschelman extern MPI_Datatype PETSC_DLLEXPORT MPIU_2INT; 18314da920SBarry Smith /* 19f4ccad53SBarry Smith 20f4ccad53SBarry Smith Defines operations that are different for complex and real numbers; 21f4ccad53SBarry Smith note that one cannot really mix the use of complex and real in the same 22f4ccad53SBarry Smith PETSc program. All PETSc objects in one program are built around the object 23ea709b57SSatish Balay PetscScalar which is either always a double or a complex. 24f4ccad53SBarry Smith 25e489efc1SBarry Smith */ 26b36a9721SBarry Smith 2759cb5930SBarry Smith #define PetscExpPassiveScalar(a) PetscExpScalar() 2859cb5930SBarry Smith 29aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 30b7940d39SSatish Balay #if defined(PETSC_CLANGUAGE_CXX) 310bfd3fbfSBarry Smith /* 32b7940d39SSatish Balay C++ support of complex numbers: Original support 330bfd3fbfSBarry Smith */ 34df9b3741SSatish Balay #include <complex> 35adc17e78SSatish Balay 36329f5518SBarry Smith #define PetscRealPart(a) (a).real() 37329f5518SBarry Smith #define PetscImaginaryPart(a) (a).imag() 383f6de6efSSatish Balay #define PetscAbsScalar(a) std::abs(a) 393f6de6efSSatish Balay #define PetscConj(a) std::conj(a) 4018a7d68fSSatish Balay #define PetscSqrtScalar(a) std::sqrt(a) 41184914b5SBarry Smith #define PetscPowScalar(a,b) std::pow(a,b) 42184914b5SBarry Smith #define PetscExpScalar(a) std::exp(a) 4306c1185fSBarry Smith #define PetscLogScalar(a) std::log(a) 44184914b5SBarry Smith #define PetscSinScalar(a) std::sin(a) 45184914b5SBarry Smith #define PetscCosScalar(a) std::cos(a) 460bfd3fbfSBarry Smith 4765460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 484a60b672SMatthew Knepley typedef std::complex<float> PetscScalar; 4965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 504a60b672SMatthew Knepley typedef std::complex<long double> PetscScalar; 5165460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT) 524a60b672SMatthew Knepley typedef std::complex<int> PetscScalar; 534a60b672SMatthew Knepley #else 54ea709b57SSatish Balay typedef std::complex<double> PetscScalar; 554a60b672SMatthew Knepley #endif 56b7940d39SSatish Balay #else 57b7940d39SSatish Balay #include <complex.h> 58b7940d39SSatish Balay 59b7940d39SSatish Balay /* 60b7940d39SSatish Balay C support of complex numbers: Warning it needs a 61b7940d39SSatish Balay C90 compliant compiler to work... 62b7940d39SSatish Balay */ 63b7940d39SSatish Balay 6465460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 6585b47369SMatthew Knepley typedef float complex PetscScalar; 6685b47369SMatthew Knepley 6785b47369SMatthew Knepley #define PetscRealPart(a) crealf(a) 6885b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagf(a) 6985b47369SMatthew Knepley #define PetscAbsScalar(a) cabsf(a) 7085b47369SMatthew Knepley #define PetscConj(a) conjf(a) 7185b47369SMatthew Knepley #define PetscSqrtScalar(a) csqrtf(a) 7285b47369SMatthew Knepley #define PetscPowScalar(a,b) cpowf(a,b) 7385b47369SMatthew Knepley #define PetscExpScalar(a) cexpf(a) 7406c1185fSBarry Smith #define PetscLogScalar(a) clogf(a) 7585b47369SMatthew Knepley #define PetscSinScalar(a) csinf(a) 7685b47369SMatthew Knepley #define PetscCosScalar(a) ccosf(a) 7765460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 7885b47369SMatthew Knepley typedef long double complex PetscScalar; 7985b47369SMatthew Knepley 8085b47369SMatthew Knepley #define PetscRealPart(a) creall(a) 8185b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagl(a) 8285b47369SMatthew Knepley #define PetscAbsScalar(a) cabsl(a) 8385b47369SMatthew Knepley #define PetscConj(a) conjl(a) 8485b47369SMatthew Knepley #define PetscSqrtScalar(a) csqrtl(a) 8585b47369SMatthew Knepley #define PetscPowScalar(a,b) cpowl(a,b) 8685b47369SMatthew Knepley #define PetscExpScalar(a) cexpl(a) 8706c1185fSBarry Smith #define PetscLogScalar(a) clogl(a) 8885b47369SMatthew Knepley #define PetscSinScalar(a) csinl(a) 8985b47369SMatthew Knepley #define PetscCosScalar(a) ccosl(a) 9085b47369SMatthew Knepley 9185b47369SMatthew Knepley #else 9285b47369SMatthew Knepley typedef double complex PetscScalar; 9385b47369SMatthew Knepley 94b7940d39SSatish Balay #define PetscRealPart(a) creal(a) 95b7940d39SSatish Balay #define PetscImaginaryPart(a) cimag(a) 96b7940d39SSatish Balay #define PetscAbsScalar(a) cabs(a) 97b7940d39SSatish Balay #define PetscConj(a) conj(a) 98b7940d39SSatish Balay #define PetscSqrtScalar(a) csqrt(a) 99b7940d39SSatish Balay #define PetscPowScalar(a,b) cpow(a,b) 100b7940d39SSatish Balay #define PetscExpScalar(a) cexp(a) 10106c1185fSBarry Smith #define PetscLogScalar(a) clog(a) 102b7940d39SSatish Balay #define PetscSinScalar(a) csin(a) 103b7940d39SSatish Balay #define PetscCosScalar(a) ccos(a) 104b7940d39SSatish Balay #endif 1054a60b672SMatthew Knepley #endif 106e489efc1SBarry Smith 1072c876bd9SBarry Smith #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) 108*5b126d37SMatthew Knepley extern MPI_Datatype PETSC_DLLEXPORT MPI_C_DOUBLE_COMPLEX; 1092c876bd9SBarry Smith #endif 1102c876bd9SBarry Smith 1112c876bd9SBarry Smith #define MPIU_SCALAR MPI_C_DOUBLE_COMPLEX 11265460251SBarry Smith #if defined(PETSC_USE_SCALAR_MAT_SINGLE) 113762437b8SSatish Balay #define MPIU_MATSCALAR ??Notdone 114762437b8SSatish Balay #else 1152c876bd9SBarry Smith #define MPIU_MATSCALAR MPI_C_DOUBLE_COMPLEX 116762437b8SSatish Balay #endif 117762437b8SSatish Balay 11875567043SBarry Smith 119e489efc1SBarry Smith /* Compiling for real numbers only */ 120e489efc1SBarry Smith #else 12165460251SBarry Smith # if defined(PETSC_USE_SCALAR_SINGLE) 12287828ca2SBarry Smith # define MPIU_SCALAR MPI_FLOAT 12365460251SBarry Smith # elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 124f68b968cSBarry Smith # define MPIU_SCALAR MPI_LONG_DOUBLE 12575567043SBarry Smith # elif defined(PETSC_USE_SCALAR_INT) 12675567043SBarry Smith # define MPIU_SCALAR MPI_INT 12775567043SBarry Smith # elif defined(PETSC_USE_SCALAR_QD_DD) 12875567043SBarry Smith # define MPIU_SCALAR MPIU_QD_DD 12987828ca2SBarry Smith # else 130e489efc1SBarry Smith # define MPIU_SCALAR MPI_DOUBLE 13187828ca2SBarry Smith # endif 13265460251SBarry Smith # if defined(PETSC_USE_SCALAR_MAT_SINGLE) || defined(PETSC_USE_SCALAR_SINGLE) 1333eda8832SBarry Smith # define MPIU_MATSCALAR MPI_FLOAT 13465460251SBarry Smith # elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 135f68b968cSBarry Smith # define MPIU_MATSCALAR MPI_LONG_DOUBLE 13665460251SBarry Smith # elif defined(PETSC_USE_SCALAR_INT) 13703c60df9SBarry Smith # define MPIU_MATSCALAR MPI_INT 13875567043SBarry Smith # elif defined(PETSC_USE_SCALAR_QD_DD) 13975567043SBarry Smith # define MPIU_MATSCALAR MPIU_QD_DD 1403eda8832SBarry Smith # else 1413eda8832SBarry Smith # define MPIU_MATSCALAR MPI_DOUBLE 1423eda8832SBarry Smith # endif 143329f5518SBarry Smith # define PetscRealPart(a) (a) 14475567043SBarry Smith # define PetscImaginaryPart(a) (0.) 145e489efc1SBarry Smith # define PetscAbsScalar(a) (((a)<0.0) ? -(a) : (a)) 146e489efc1SBarry Smith # define PetscConj(a) (a) 14718a7d68fSSatish Balay # define PetscSqrtScalar(a) sqrt(a) 148184914b5SBarry Smith # define PetscPowScalar(a,b) pow(a,b) 149184914b5SBarry Smith # define PetscExpScalar(a) exp(a) 15006c1185fSBarry Smith # define PetscLogScalar(a) log(a) 151184914b5SBarry Smith # define PetscSinScalar(a) sin(a) 152184914b5SBarry Smith # define PetscCosScalar(a) cos(a) 153b0a32e0cSBarry Smith 15465460251SBarry Smith # if defined(PETSC_USE_SCALAR_SINGLE) 155ea709b57SSatish Balay typedef float PetscScalar; 15665460251SBarry Smith # elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 157f68b968cSBarry Smith typedef long double PetscScalar; 15865460251SBarry Smith # elif defined(PETSC_USE_SCALAR_INT) 15903c60df9SBarry Smith typedef int PetscScalar; 16075567043SBarry Smith # elif defined(PETSC_USE_SCALAR_QD_DD) 16175567043SBarry Smith # include "qd/dd_real.h" 16275567043SBarry Smith typedef dd_real PetscScalar; 163b0a32e0cSBarry Smith # else 164ea709b57SSatish Balay typedef double PetscScalar; 165b0a32e0cSBarry Smith # endif 166e489efc1SBarry Smith #endif 167e489efc1SBarry Smith 16865460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 169d7d1e502SBarry Smith # define MPIU_REAL MPI_FLOAT 17065460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 171f68b968cSBarry Smith # define MPIU_REAL MPI_LONG_DOUBLE 17265460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT) 17303c60df9SBarry Smith # define MPIU_REAL MPI_INT 17475567043SBarry Smith #elif defined(PETSC_USE_SCALAR_QD_DD) 17575567043SBarry Smith # define MPIU_REAL MPIU_QD_DD 176d7d1e502SBarry Smith #else 177d7d1e502SBarry Smith # define MPIU_REAL MPI_DOUBLE 178d7d1e502SBarry Smith #endif 179d7d1e502SBarry Smith 18075567043SBarry Smith #if defined(PETSC_USE_SCALAR_QD_DD) 18175567043SBarry Smith extern MPI_Datatype PETSC_DLLEXPORT MPIU_QD_DD; 18275567043SBarry Smith #endif 18375567043SBarry Smith 184da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1) 18526aa1773SMatthew Knepley #define PetscAbs(a) (((a) >= 0) ? (a) : -(a)) 1863f1db9ecSBarry Smith /* 1873f1db9ecSBarry Smith Allows compiling PETSc so that matrix values are stored in 1883f1db9ecSBarry Smith single precision but all other objects still use double 1893f1db9ecSBarry Smith precision. This does not work for complex numbers in that case 1903f1db9ecSBarry Smith it remains double 1913f1db9ecSBarry Smith 1923f1db9ecSBarry Smith EXPERIMENTAL! NOT YET COMPLETELY WORKING 1933f1db9ecSBarry Smith */ 1943f1db9ecSBarry Smith 19565460251SBarry Smith #if defined(PETSC_USE_SCALAR_MAT_SINGLE) 196b400db4cSSatish Balay typedef float MatScalar; 1973f1db9ecSBarry Smith #else 198ea709b57SSatish Balay typedef PetscScalar MatScalar; 19911380375SSatish Balay #endif 2003f1db9ecSBarry Smith 20165460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 202b400db4cSSatish Balay typedef float PetscReal; 20365460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 204f68b968cSBarry Smith typedef long double PetscReal; 20565460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT) 20603c60df9SBarry Smith typedef int PetscReal; 20775567043SBarry Smith #elif defined(PETSC_USE_SCALAR_QD_DD) 20875567043SBarry Smith typedef dd_real PetscReal; 209329f5518SBarry Smith #else 210b400db4cSSatish Balay typedef double PetscReal; 211329f5518SBarry Smith #endif 2123f1db9ecSBarry Smith 213f68b968cSBarry Smith #if defined(PETSC_USE_COMPLEX) 214f68b968cSBarry Smith typedef PetscReal MatReal; 21565460251SBarry Smith #elif defined(PETSC_USE_SCALAR_MAT_SINGLE) || defined(PETSC_USE_SCALAR_SINGLE) 216f68b968cSBarry Smith typedef float MatReal; 217f68b968cSBarry Smith #else 218f68b968cSBarry Smith typedef PetscReal MatReal; 219f68b968cSBarry Smith #endif 220f68b968cSBarry Smith 221f68b968cSBarry Smith 222314da920SBarry Smith /* --------------------------------------------------------------------------*/ 223314da920SBarry Smith 224e489efc1SBarry Smith /* 225e489efc1SBarry Smith Certain objects may be created using either single 226e489efc1SBarry Smith or double precision. 227e489efc1SBarry Smith */ 22875567043SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE, PETSC_SCALAR_QD_DD } PetscScalarPrecision; 229e489efc1SBarry Smith 230e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */ 231ff73aad6SKris Buschelman extern PetscScalar PETSC_DLLEXPORT PETSC_i; 232e489efc1SBarry Smith 233b6a5bde7SBarry Smith /*MC 234b6a5bde7SBarry Smith PetscMin - Returns minimum of two numbers 235b6a5bde7SBarry Smith 236b6a5bde7SBarry Smith Input Parameter: 237b6a5bde7SBarry Smith + v1 - first value to find minimum of 238b6a5bde7SBarry Smith - v2 - second value to find minimum of 239b6a5bde7SBarry Smith 240b6a5bde7SBarry Smith Synopsis: 241b6a5bde7SBarry Smith type PetscMin(type v1,type v2) 242b6a5bde7SBarry Smith 243b6a5bde7SBarry Smith Notes: type can be integer or floating point value 244b6a5bde7SBarry Smith 245b6a5bde7SBarry Smith Level: beginner 246b6a5bde7SBarry Smith 247b6a5bde7SBarry Smith 248b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 249b6a5bde7SBarry Smith 250b6a5bde7SBarry Smith M*/ 251e489efc1SBarry Smith #define PetscMin(a,b) (((a)<(b)) ? (a) : (b)) 252b6a5bde7SBarry Smith 253b6a5bde7SBarry Smith /*MC 254b6a5bde7SBarry Smith PetscMax - Returns maxium of two numbers 255b6a5bde7SBarry Smith 256b6a5bde7SBarry Smith Input Parameter: 257b6a5bde7SBarry Smith + v1 - first value to find maximum of 258b6a5bde7SBarry Smith - v2 - second value to find maximum of 259b6a5bde7SBarry Smith 260b6a5bde7SBarry Smith Synopsis: 261b6a5bde7SBarry Smith type max PetscMax(type v1,type v2) 262b6a5bde7SBarry Smith 263b6a5bde7SBarry Smith Notes: type can be integer or floating point value 264b6a5bde7SBarry Smith 265b6a5bde7SBarry Smith Level: beginner 266b6a5bde7SBarry Smith 267b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr() 268b6a5bde7SBarry Smith 269b6a5bde7SBarry Smith M*/ 270e489efc1SBarry Smith #define PetscMax(a,b) (((a)<(b)) ? (b) : (a)) 271b6a5bde7SBarry Smith 272b6a5bde7SBarry Smith /*MC 273b6a5bde7SBarry Smith PetscAbsInt - Returns the absolute value of an integer 274b6a5bde7SBarry Smith 275b6a5bde7SBarry Smith Input Parameter: 276b6a5bde7SBarry Smith . v1 - the integer 277b6a5bde7SBarry Smith 278b6a5bde7SBarry Smith Synopsis: 279b6a5bde7SBarry Smith int abs PetscAbsInt(int v1) 280b6a5bde7SBarry Smith 281b6a5bde7SBarry Smith 282b6a5bde7SBarry Smith Level: beginner 283b6a5bde7SBarry Smith 284b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr() 285b6a5bde7SBarry Smith 286b6a5bde7SBarry Smith M*/ 287e489efc1SBarry Smith #define PetscAbsInt(a) (((a)<0) ? -(a) : (a)) 288b6a5bde7SBarry Smith 289b6a5bde7SBarry Smith /*MC 290b6a5bde7SBarry Smith PetscAbsReal - Returns the absolute value of an real number 291b6a5bde7SBarry Smith 292b6a5bde7SBarry Smith Input Parameter: 293b6a5bde7SBarry Smith . v1 - the double 294b6a5bde7SBarry Smith 295b6a5bde7SBarry Smith Synopsis: 296b6a5bde7SBarry Smith int abs PetscAbsReal(PetscReal v1) 297b6a5bde7SBarry Smith 298b6a5bde7SBarry Smith 299b6a5bde7SBarry Smith Level: beginner 300b6a5bde7SBarry Smith 301b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr() 302b6a5bde7SBarry Smith 303b6a5bde7SBarry Smith M*/ 304f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0) ? -(a) : (a)) 305b6a5bde7SBarry Smith 306b6a5bde7SBarry Smith /*MC 307b6a5bde7SBarry Smith PetscSqr - Returns the square of a number 308b6a5bde7SBarry Smith 309b6a5bde7SBarry Smith Input Parameter: 310b6a5bde7SBarry Smith . v1 - the value 311b6a5bde7SBarry Smith 312b6a5bde7SBarry Smith Synopsis: 313b6a5bde7SBarry Smith type sqr PetscSqr(type v1) 314b6a5bde7SBarry Smith 315b6a5bde7SBarry Smith Notes: type can be integer or floating point value 316b6a5bde7SBarry Smith 317b6a5bde7SBarry Smith Level: beginner 318b6a5bde7SBarry Smith 319b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal() 320b6a5bde7SBarry Smith 321b6a5bde7SBarry Smith M*/ 3224ebda54eSMatthew Knepley #define PetscSqr(a) ((a)*(a)) 323e489efc1SBarry Smith 324314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 325314da920SBarry Smith /* 32603c60df9SBarry Smith Basic constants - These should be done much better 327314da920SBarry Smith */ 328314da920SBarry Smith #define PETSC_PI 3.14159265358979323846264 329314da920SBarry Smith #define PETSC_DEGREES_TO_RADIANS 0.01745329251994 33071fd2e92SBarry Smith #define PETSC_MAX_INT 2147483647 33171fd2e92SBarry Smith #define PETSC_MIN_INT -2147483647 332e489efc1SBarry Smith 33365460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 3347e032f8bSBarry Smith # define PETSC_MAX 1.e30 3357e032f8bSBarry Smith # define PETSC_MIN -1.e30 336f10639e6SSatish Balay # define PETSC_MACHINE_EPSILON 1.e-7 337f10639e6SSatish Balay # define PETSC_SQRT_MACHINE_EPSILON 3.e-4 338cf6e855fSSatish Balay # define PETSC_SMALL 1.e-5 33965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT) 34003c60df9SBarry Smith # define PETSC_MAX PETSC_MAX_INT 34103c60df9SBarry Smith # define PETSC_MIN PETSC_MIN_INT 34203c60df9SBarry Smith # define PETSC_MACHINE_EPSILON 1 34303c60df9SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1 34403c60df9SBarry Smith # define PETSC_SMALL 0 34575567043SBarry Smith #elif defined(PETSC_USE_SCALAR_QD_DD) 34675567043SBarry Smith # define PETSC_MAX 1.e300 34775567043SBarry Smith # define PETSC_MIN -1.e300 34875567043SBarry Smith # define PETSC_MACHINE_EPSILON 1.e-30 34975567043SBarry Smith # define PETSC_SQRT_MACHINE_EPSILON 1.e-15 35075567043SBarry Smith # define PETSC_SMALL 1.e-25 35182adfdadSBarry Smith #else 3527e032f8bSBarry Smith # define PETSC_MAX 1.e300 3537e032f8bSBarry Smith # define PETSC_MIN -1.e300 354f10639e6SSatish Balay # define PETSC_MACHINE_EPSILON 1.e-14 355f10639e6SSatish Balay # define PETSC_SQRT_MACHINE_EPSILON 1.e-7 356cf6e855fSSatish Balay # define PETSC_SMALL 1.e-10 35782adfdadSBarry Smith #endif 35882adfdadSBarry Smith 359ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMax(PetscReal*,PetscReal*,MPI_Comm); 360ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMin(PetscReal*,PetscReal*,MPI_Comm); 361ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalSum(PetscScalar*,PetscScalar*,MPI_Comm); 3623e523bebSBarry Smith 3630763cb5fSBarry Smith /*MC 3640763cb5fSBarry Smith PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0. 3653e523bebSBarry Smith 3660763cb5fSBarry Smith Input Parameter: 3670763cb5fSBarry Smith . a - the double 3680763cb5fSBarry Smith 3690763cb5fSBarry Smith 3700763cb5fSBarry Smith Notes: uses the C99 standard isinf() and isnan() on systems where they exist. 37183886165SBarry Smith Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile 3720763cb5fSBarry Smith out this form, thus removing the check. 3730763cb5fSBarry Smith 37483672c4dSSatish Balay Level: beginner 37583672c4dSSatish Balay 37683672c4dSSatish Balay M*/ 3779a25a3ccSBarry Smith #if defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN) 378f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a))) 379f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (isinf(a) || isnan(a)) 38062b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN) 381270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H) 382270b8587SSatish Balay #include "float.h" /* windows defines _finite() in float.h */ 383270b8587SSatish Balay #endif 384961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H) 385961faeafSBarry Smith #include "ieeefp.h" /* Solaris prototypes these here */ 386961faeafSBarry Smith #endif 387f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (!_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a))) 388f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (!_finite(a) || _isnan(a)) 3899a25a3ccSBarry Smith #else 390f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) ((a - a) != 0.0) 391f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) ((a - a) != 0.0) 3929a25a3ccSBarry Smith #endif 3939a25a3ccSBarry Smith 3949a25a3ccSBarry Smith 395314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 396e489efc1SBarry Smith /* 397b0a32e0cSBarry Smith PetscLogDouble variables are used to contain double precision numbers 398e489efc1SBarry Smith that are not used in the numerical computations, but rather in logging, 399e489efc1SBarry Smith timing etc. 400e489efc1SBarry Smith */ 401b0a32e0cSBarry Smith typedef double PetscLogDouble; 402b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 403e489efc1SBarry Smith 40487828ca2SBarry Smith #define PassiveReal PetscReal 405ea709b57SSatish Balay #define PassiveScalar PetscScalar 406d3ecb3a7SBarry Smith 407e9fa29b7SSatish Balay 408e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 409e489efc1SBarry Smith #endif 410