xref: /petsc/include/petscmath.h (revision c90a1750bdbee6915dd9fc4c3be647ac513fbcb1)
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;
18*c90a1750SBarry 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()
2959cb5930SBarry Smith 
301093a601SBarry Smith /*
311093a601SBarry Smith     Complex number definitions
321093a601SBarry Smith  */
33aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
34b7940d39SSatish Balay #if defined(PETSC_CLANGUAGE_CXX)
351093a601SBarry Smith /* C++ support of complex number */
36df9b3741SSatish Balay #include <complex>
37adc17e78SSatish Balay 
38329f5518SBarry Smith #define PetscRealPart(a)      (a).real()
39329f5518SBarry Smith #define PetscImaginaryPart(a) (a).imag()
403f6de6efSSatish Balay #define PetscAbsScalar(a)     std::abs(a)
413f6de6efSSatish Balay #define PetscConj(a)          std::conj(a)
4218a7d68fSSatish Balay #define PetscSqrtScalar(a)    std::sqrt(a)
43184914b5SBarry Smith #define PetscPowScalar(a,b)   std::pow(a,b)
44184914b5SBarry Smith #define PetscExpScalar(a)     std::exp(a)
4506c1185fSBarry Smith #define PetscLogScalar(a)     std::log(a)
46184914b5SBarry Smith #define PetscSinScalar(a)     std::sin(a)
47184914b5SBarry Smith #define PetscCosScalar(a)     std::cos(a)
480bfd3fbfSBarry Smith 
4965460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
504a60b672SMatthew Knepley typedef std::complex<float> PetscScalar;
511093a601SBarry Smith #elif defined(PETSC_USE_SCALAR_DOUBLE)
521093a601SBarry Smith typedef std::complex<double> PetscScalar;
5365460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
544a60b672SMatthew Knepley typedef std::complex<long double> PetscScalar;
554a60b672SMatthew Knepley #endif
56b7940d39SSatish Balay 
571093a601SBarry Smith #else
581093a601SBarry Smith /*  C support of complex numbers: Requires C99 compliant compiler*/
591093a601SBarry Smith #include <complex.h>
60b7940d39SSatish Balay 
6165460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
6285b47369SMatthew Knepley typedef float complex PetscScalar;
6385b47369SMatthew Knepley 
6485b47369SMatthew Knepley #define PetscRealPart(a)      crealf(a)
6585b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagf(a)
6685b47369SMatthew Knepley #define PetscAbsScalar(a)     cabsf(a)
6785b47369SMatthew Knepley #define PetscConj(a)          conjf(a)
6885b47369SMatthew Knepley #define PetscSqrtScalar(a)    csqrtf(a)
6985b47369SMatthew Knepley #define PetscPowScalar(a,b)   cpowf(a,b)
7085b47369SMatthew Knepley #define PetscExpScalar(a)     cexpf(a)
7106c1185fSBarry Smith #define PetscLogScalar(a)     clogf(a)
7285b47369SMatthew Knepley #define PetscSinScalar(a)     csinf(a)
7385b47369SMatthew Knepley #define PetscCosScalar(a)     ccosf(a)
741093a601SBarry Smith 
751093a601SBarry Smith #elif defined(PETSC_USE_SCALAR_DOUBLE)
761093a601SBarry Smith typedef double complex PetscScalar;
771093a601SBarry Smith 
781093a601SBarry Smith #define PetscRealPart(a)      creal(a)
791093a601SBarry Smith #define PetscImaginaryPart(a) cimag(a)
801093a601SBarry Smith #define PetscAbsScalar(a)     cabs(a)
811093a601SBarry Smith #define PetscConj(a)          conj(a)
821093a601SBarry Smith #define PetscSqrtScalar(a)    csqrt(a)
831093a601SBarry Smith #define PetscPowScalar(a,b)   cpow(a,b)
841093a601SBarry Smith #define PetscExpScalar(a)     cexp(a)
851093a601SBarry Smith #define PetscLogScalar(a)     clog(a)
861093a601SBarry Smith #define PetscSinScalar(a)     csin(a)
871093a601SBarry Smith #define PetscCosScalar(a)     ccos(a)
881093a601SBarry Smith 
8965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
9085b47369SMatthew Knepley typedef long double complex PetscScalar;
9185b47369SMatthew Knepley 
9285b47369SMatthew Knepley #define PetscRealPart(a)      creall(a)
9385b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagl(a)
9485b47369SMatthew Knepley #define PetscAbsScalar(a)     cabsl(a)
9585b47369SMatthew Knepley #define PetscConj(a)          conjl(a)
9685b47369SMatthew Knepley #define PetscSqrtScalar(a)    csqrtl(a)
9785b47369SMatthew Knepley #define PetscPowScalar(a,b)   cpowl(a,b)
9885b47369SMatthew Knepley #define PetscExpScalar(a)     cexpl(a)
9906c1185fSBarry Smith #define PetscLogScalar(a)     clogl(a)
10085b47369SMatthew Knepley #define PetscSinScalar(a)     csinl(a)
10185b47369SMatthew Knepley #define PetscCosScalar(a)     ccosl(a)
10285b47369SMatthew Knepley 
103b7940d39SSatish Balay #endif
1044a60b672SMatthew Knepley #endif
105e489efc1SBarry Smith 
1062c876bd9SBarry Smith #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
1077087cfbeSBarry Smith extern  MPI_Datatype  MPI_C_DOUBLE_COMPLEX;
1087087cfbeSBarry Smith extern  MPI_Datatype  MPI_C_COMPLEX;
1092c876bd9SBarry Smith #endif
1102c876bd9SBarry Smith 
111a83b8d76SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
112a83b8d76SBarry Smith #define MPIU_SCALAR MPI_C_COMPLEX
1131093a601SBarry Smith #elif defined(PETSC_USE_SCALAR_DOUBLE)
1142c876bd9SBarry Smith #define MPIU_SCALAR MPI_C_DOUBLE_COMPLEX
1151093a601SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
1161093a601SBarry Smith #define MPIU_SCALAR error
117a83b8d76SBarry Smith #endif
11875567043SBarry Smith 
1191093a601SBarry Smith /*
1201093a601SBarry Smith     real number definitions
1211093a601SBarry Smith  */
122e489efc1SBarry Smith #else
12365460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
12487828ca2SBarry Smith #define MPIU_SCALAR           MPI_FLOAT
1251093a601SBarry Smith typedef float PetscScalar;
1261093a601SBarry Smith #elif defined(PETSC_USE_SCALAR_DOUBLE)
1271093a601SBarry Smith #define MPIU_SCALAR           MPI_DOUBLE
1281093a601SBarry Smith typedef double PetscScalar;
12965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
130f68b968cSBarry Smith #define MPIU_SCALAR           MPI_LONG_DOUBLE
1311093a601SBarry Smith typedef long double PetscScalar;
1320d0cc1b5SBarry Smith #elif defined(PETSC_USE_SCALAR___FLOAT128)
133*c90a1750SBarry Smith extern MPI_Datatype MPIU___FLOAT128;
134*c90a1750SBarry Smith #define MPIU_SCALAR MPIU___FLOAT128
1350d0cc1b5SBarry Smith typedef __float128 PetscScalar;
13687828ca2SBarry Smith #endif
137329f5518SBarry Smith #define PetscRealPart(a)      (a)
13875567043SBarry Smith #define PetscImaginaryPart(a) (0.)
139e489efc1SBarry Smith #define PetscAbsScalar(a)     (((a)<0.0)   ? -(a) : (a))
140e489efc1SBarry Smith #define PetscConj(a)          (a)
1410d0cc1b5SBarry Smith #if !defined(PETSC_USE_SCALAR___FLOAT128)
14218a7d68fSSatish Balay #define PetscSqrtScalar(a)    sqrt(a)
143184914b5SBarry Smith #define PetscPowScalar(a,b)   pow(a,b)
144184914b5SBarry Smith #define PetscExpScalar(a)     exp(a)
14506c1185fSBarry Smith #define PetscLogScalar(a)     log(a)
146184914b5SBarry Smith #define PetscSinScalar(a)     sin(a)
147184914b5SBarry Smith #define PetscCosScalar(a)     cos(a)
1480d0cc1b5SBarry Smith #else
1490d0cc1b5SBarry Smith #include <quadmath.h>
1500d0cc1b5SBarry Smith #define PetscSqrtScalar(a)    sqrtq(a)
1510d0cc1b5SBarry Smith #define PetscPowScalar(a,b)   powq(a,b)
1520d0cc1b5SBarry Smith #define PetscExpScalar(a)     expq(a)
1530d0cc1b5SBarry Smith #define PetscLogScalar(a)     logq(a)
1540d0cc1b5SBarry Smith #define PetscSinScalar(a)     sinq(a)
1550d0cc1b5SBarry Smith #define PetscCosScalar(a)     cosq(a)
1560d0cc1b5SBarry Smith #endif
157b0a32e0cSBarry Smith 
158e489efc1SBarry Smith #endif
159e489efc1SBarry Smith 
16065460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
161d7d1e502SBarry Smith #define MPIU_REAL   MPI_FLOAT
1621093a601SBarry Smith typedef float PetscReal;
1631093a601SBarry Smith #elif defined(PETSC_USE_SCALAR_DOUBLE)
1641093a601SBarry Smith #define MPIU_REAL   MPI_DOUBLE
1651093a601SBarry Smith typedef double PetscReal;
16665460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
167f68b968cSBarry Smith #define MPIU_REAL   MPI_LONG_DOUBLE
1681093a601SBarry Smith typedef long double PetscReal;
1690d0cc1b5SBarry Smith #elif defined(PETSC_USE_SCALAR___FLOAT128)
170*c90a1750SBarry Smith #define MPIU_REAL MPIU___FLOAT128
1710d0cc1b5SBarry Smith typedef __float128 PetscReal;
172d7d1e502SBarry Smith #endif
173d7d1e502SBarry Smith 
174da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1)
17526aa1773SMatthew Knepley #define PetscAbs(a)  (((a) >= 0) ? (a) : -(a))
1763f1db9ecSBarry Smith 
177314da920SBarry Smith /* --------------------------------------------------------------------------*/
178314da920SBarry Smith 
179e489efc1SBarry Smith /*
180f22f69f0SBarry Smith    Certain objects may be created using either single or double precision.
181f22f69f0SBarry Smith    This is currently not used.
182e489efc1SBarry Smith */
183557d4da8SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision;
184e489efc1SBarry Smith 
185e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */
1867087cfbeSBarry Smith extern  PetscScalar  PETSC_i;
187e489efc1SBarry Smith 
188b6a5bde7SBarry Smith /*MC
189b6a5bde7SBarry Smith    PetscMin - Returns minimum of two numbers
190b6a5bde7SBarry Smith 
191eca87e8dSBarry Smith    Synopsis:
192eca87e8dSBarry Smith    type PetscMin(type v1,type v2)
193eca87e8dSBarry Smith 
194eca87e8dSBarry Smith    Not Collective
195eca87e8dSBarry Smith 
196b6a5bde7SBarry Smith    Input Parameter:
197b6a5bde7SBarry Smith +  v1 - first value to find minimum of
198b6a5bde7SBarry Smith -  v2 - second value to find minimum of
199b6a5bde7SBarry Smith 
200b6a5bde7SBarry Smith 
201b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
202b6a5bde7SBarry Smith 
203b6a5bde7SBarry Smith    Level: beginner
204b6a5bde7SBarry Smith 
205b6a5bde7SBarry Smith 
206b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
207b6a5bde7SBarry Smith 
208b6a5bde7SBarry Smith M*/
209e489efc1SBarry Smith #define PetscMin(a,b)   (((a)<(b)) ?  (a) : (b))
210b6a5bde7SBarry Smith 
211b6a5bde7SBarry Smith /*MC
212b6a5bde7SBarry Smith    PetscMax - Returns maxium of two numbers
213b6a5bde7SBarry Smith 
214eca87e8dSBarry Smith    Synopsis:
215eca87e8dSBarry Smith    type max PetscMax(type v1,type v2)
216eca87e8dSBarry Smith 
217eca87e8dSBarry Smith    Not Collective
218eca87e8dSBarry Smith 
219b6a5bde7SBarry Smith    Input Parameter:
220b6a5bde7SBarry Smith +  v1 - first value to find maximum of
221b6a5bde7SBarry Smith -  v2 - second value to find maximum of
222b6a5bde7SBarry Smith 
223b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
224b6a5bde7SBarry Smith 
225b6a5bde7SBarry Smith    Level: beginner
226b6a5bde7SBarry Smith 
227b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
228b6a5bde7SBarry Smith 
229b6a5bde7SBarry Smith M*/
230e489efc1SBarry Smith #define PetscMax(a,b)   (((a)<(b)) ?  (b) : (a))
231b6a5bde7SBarry Smith 
232b6a5bde7SBarry Smith /*MC
233b6a5bde7SBarry Smith    PetscAbsInt - Returns the absolute value of an integer
234b6a5bde7SBarry Smith 
235b6a5bde7SBarry Smith    Synopsis:
236b6a5bde7SBarry Smith    int abs PetscAbsInt(int v1)
237b6a5bde7SBarry Smith 
238eca87e8dSBarry Smith    Not Collective
239eca87e8dSBarry Smith 
240eca87e8dSBarry Smith    Input Parameter:
241eca87e8dSBarry Smith .   v1 - the integer
242b6a5bde7SBarry Smith 
243b6a5bde7SBarry Smith    Level: beginner
244b6a5bde7SBarry Smith 
245b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr()
246b6a5bde7SBarry Smith 
247b6a5bde7SBarry Smith M*/
248e489efc1SBarry Smith #define PetscAbsInt(a)  (((a)<0)   ? -(a) : (a))
249b6a5bde7SBarry Smith 
250b6a5bde7SBarry Smith /*MC
251b6a5bde7SBarry Smith    PetscAbsReal - Returns the absolute value of an real number
252b6a5bde7SBarry Smith 
253eca87e8dSBarry Smith    Synopsis:
254eca87e8dSBarry Smith    Real abs PetscAbsReal(PetscReal v1)
255eca87e8dSBarry Smith 
256eca87e8dSBarry Smith    Not Collective
257eca87e8dSBarry Smith 
258b6a5bde7SBarry Smith    Input Parameter:
259b6a5bde7SBarry Smith .   v1 - the double
260b6a5bde7SBarry Smith 
261b6a5bde7SBarry Smith 
262b6a5bde7SBarry Smith    Level: beginner
263b6a5bde7SBarry Smith 
264b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr()
265b6a5bde7SBarry Smith 
266b6a5bde7SBarry Smith M*/
267f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0)   ? -(a) : (a))
268b6a5bde7SBarry Smith 
269b6a5bde7SBarry Smith /*MC
270b6a5bde7SBarry Smith    PetscSqr - Returns the square of a number
271b6a5bde7SBarry Smith 
272b6a5bde7SBarry Smith    Synopsis:
273b6a5bde7SBarry Smith    type sqr PetscSqr(type v1)
274b6a5bde7SBarry Smith 
275eca87e8dSBarry Smith    Not Collective
276eca87e8dSBarry Smith 
277eca87e8dSBarry Smith    Input Parameter:
278eca87e8dSBarry Smith .   v1 - the value
279eca87e8dSBarry Smith 
280b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
281b6a5bde7SBarry Smith 
282b6a5bde7SBarry Smith    Level: beginner
283b6a5bde7SBarry Smith 
284b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal()
285b6a5bde7SBarry Smith 
286b6a5bde7SBarry Smith M*/
2874ebda54eSMatthew Knepley #define PetscSqr(a)     ((a)*(a))
288e489efc1SBarry Smith 
289314da920SBarry Smith /* ----------------------------------------------------------------------------*/
290314da920SBarry Smith /*
29103c60df9SBarry Smith      Basic constants - These should be done much better
292314da920SBarry Smith */
293314da920SBarry Smith #define PETSC_PI                 3.14159265358979323846264
294314da920SBarry Smith #define PETSC_DEGREES_TO_RADIANS 0.01745329251994
29571fd2e92SBarry Smith #define PETSC_MAX_INT            2147483647
29671fd2e92SBarry Smith #define PETSC_MIN_INT            -2147483647
297e489efc1SBarry Smith 
29865460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
2997e032f8bSBarry Smith #  define PETSC_MAX                     1.e30
3007e032f8bSBarry Smith #  define PETSC_MIN                    -1.e30
301f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-7
302f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    3.e-4
303cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-5
30482adfdadSBarry Smith #else
3057e032f8bSBarry Smith #  define PETSC_MAX                     1.e300
3067e032f8bSBarry Smith #  define PETSC_MIN                    -1.e300
307f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-14
308f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    1.e-7
309cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
31082adfdadSBarry Smith #endif
31182adfdadSBarry Smith 
3129cf09972SJed Brown #if defined PETSC_HAVE_ADIC
3139cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */
3147087cfbeSBarry Smith extern PetscErrorCode  PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*);
3157087cfbeSBarry Smith extern PetscErrorCode  PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*);
3167087cfbeSBarry Smith extern PetscErrorCode  PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*);
3179cf09972SJed Brown #endif
3183e523bebSBarry Smith 
3190763cb5fSBarry Smith /*MC
3200763cb5fSBarry Smith       PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.
3213e523bebSBarry Smith 
3220763cb5fSBarry Smith     Input Parameter:
3230763cb5fSBarry Smith .     a - the double
3240763cb5fSBarry Smith 
3250763cb5fSBarry Smith 
3260763cb5fSBarry Smith      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
32783886165SBarry Smith       Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile
3280763cb5fSBarry Smith       out this form, thus removing the check.
3290763cb5fSBarry Smith 
33083672c4dSSatish Balay      Level: beginner
33183672c4dSSatish Balay 
33283672c4dSSatish Balay M*/
3339a25a3ccSBarry Smith #if defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
33462cbcd01SMatthew G Knepley PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
33562cbcd01SMatthew G Knepley   return isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a));
33662cbcd01SMatthew G Knepley }
33762cbcd01SMatthew G Knepley PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
33862cbcd01SMatthew G Knepley   return isinf(a) || isnan(a);
33962cbcd01SMatthew G Knepley }
34062b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
341270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H)
34298725619SBarry Smith #include "float.h"  /* Microsoft Windows defines _finite() in float.h */
343270b8587SSatish Balay #endif
344961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H)
345961faeafSBarry Smith #include "ieeefp.h"  /* Solaris prototypes these here */
346961faeafSBarry Smith #endif
34798725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
34898725619SBarry Smith   return !_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a));
34998725619SBarry Smith }
35098725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
35198725619SBarry Smith   return !_finite(a) || _isnan(a);
35298725619SBarry Smith }
3539a25a3ccSBarry Smith #else
35498725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
35598725619SBarry Smith   return  ((a - a) != 0.0);
35698725619SBarry Smith }
35798725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
35898725619SBarry Smith   return ((a - a) != 0.0);
35998725619SBarry Smith }
3609a25a3ccSBarry Smith #endif
3619a25a3ccSBarry Smith 
3629a25a3ccSBarry Smith 
363314da920SBarry Smith /* ----------------------------------------------------------------------------*/
364e489efc1SBarry Smith /*
365b0a32e0cSBarry Smith     PetscLogDouble variables are used to contain double precision numbers
366e489efc1SBarry Smith   that are not used in the numerical computations, but rather in logging,
367e489efc1SBarry Smith   timing etc.
368e489efc1SBarry Smith */
369b0a32e0cSBarry Smith typedef double PetscLogDouble;
370b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
371e489efc1SBarry Smith 
37287828ca2SBarry Smith #define PassiveReal   PetscReal
373ea709b57SSatish Balay #define PassiveScalar PetscScalar
374d3ecb3a7SBarry Smith 
37598725619SBarry Smith /*
37698725619SBarry Smith     These macros are currently hardwired to match the regular data types, so there is no support for a different
37798725619SBarry Smith     MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again.
37898725619SBarry Smith  */
37998725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR
38098725619SBarry Smith typedef PetscScalar MatScalar;
38198725619SBarry Smith typedef PetscReal MatReal;
38298725619SBarry Smith 
383e9fa29b7SSatish Balay 
384e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
385e489efc1SBarry Smith #endif
386