xref: /petsc/include/petscmath.h (revision 961faeaf5c95602f2cfffa72352c76a1c9c4fd4c)
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)
43184914b5SBarry Smith #define PetscSinScalar(a)     std::sin(a)
44184914b5SBarry Smith #define PetscCosScalar(a)     std::cos(a)
450bfd3fbfSBarry Smith 
464a60b672SMatthew Knepley #if defined(PETSC_USE_SINGLE)
474a60b672SMatthew Knepley typedef std::complex<float> PetscScalar;
484a60b672SMatthew Knepley #elif defined(PETSC_USE_LONG_DOUBLE)
494a60b672SMatthew Knepley typedef std::complex<long double> PetscScalar;
504a60b672SMatthew Knepley #elif defined(PETSC_USE_INT)
514a60b672SMatthew Knepley typedef std::complex<int> PetscScalar;
524a60b672SMatthew Knepley #else
53ea709b57SSatish Balay typedef std::complex<double> PetscScalar;
544a60b672SMatthew Knepley #endif
55b7940d39SSatish Balay #else
56b7940d39SSatish Balay #include <complex.h>
57b7940d39SSatish Balay 
58b7940d39SSatish Balay /*
59b7940d39SSatish Balay    C support of complex numbers: Warning it needs a
60b7940d39SSatish Balay    C90 compliant compiler to work...
61b7940d39SSatish Balay  */
62b7940d39SSatish Balay 
6385b47369SMatthew Knepley #if defined(PETSC_USE_SINGLE)
6485b47369SMatthew Knepley typedef float complex PetscScalar;
6585b47369SMatthew Knepley 
6685b47369SMatthew Knepley #define PetscRealPart(a)      crealf(a)
6785b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagf(a)
6885b47369SMatthew Knepley #define PetscAbsScalar(a)     cabsf(a)
6985b47369SMatthew Knepley #define PetscConj(a)          conjf(a)
7085b47369SMatthew Knepley #define PetscSqrtScalar(a)    csqrtf(a)
7185b47369SMatthew Knepley #define PetscPowScalar(a,b)   cpowf(a,b)
7285b47369SMatthew Knepley #define PetscExpScalar(a)     cexpf(a)
7385b47369SMatthew Knepley #define PetscSinScalar(a)     csinf(a)
7485b47369SMatthew Knepley #define PetscCosScalar(a)     ccosf(a)
7585b47369SMatthew Knepley #elif defined(PETSC_USE_LONG_DOUBLE)
7685b47369SMatthew Knepley typedef long double complex PetscScalar;
7785b47369SMatthew Knepley 
7885b47369SMatthew Knepley #define PetscRealPart(a)      creall(a)
7985b47369SMatthew Knepley #define PetscImaginaryPart(a) cimagl(a)
8085b47369SMatthew Knepley #define PetscAbsScalar(a)     cabsl(a)
8185b47369SMatthew Knepley #define PetscConj(a)          conjl(a)
8285b47369SMatthew Knepley #define PetscSqrtScalar(a)    csqrtl(a)
8385b47369SMatthew Knepley #define PetscPowScalar(a,b)   cpowl(a,b)
8485b47369SMatthew Knepley #define PetscExpScalar(a)     cexpl(a)
8585b47369SMatthew Knepley #define PetscSinScalar(a)     csinl(a)
8685b47369SMatthew Knepley #define PetscCosScalar(a)     ccosl(a)
8785b47369SMatthew Knepley 
8885b47369SMatthew Knepley #else
8985b47369SMatthew Knepley typedef double complex PetscScalar;
9085b47369SMatthew Knepley 
91b7940d39SSatish Balay #define PetscRealPart(a)      creal(a)
92b7940d39SSatish Balay #define PetscImaginaryPart(a) cimag(a)
93b7940d39SSatish Balay #define PetscAbsScalar(a)     cabs(a)
94b7940d39SSatish Balay #define PetscConj(a)          conj(a)
95b7940d39SSatish Balay #define PetscSqrtScalar(a)    csqrt(a)
96b7940d39SSatish Balay #define PetscPowScalar(a,b)   cpow(a,b)
97b7940d39SSatish Balay #define PetscExpScalar(a)     cexp(a)
98b7940d39SSatish Balay #define PetscSinScalar(a)     csin(a)
99b7940d39SSatish Balay #define PetscCosScalar(a)     ccos(a)
100b7940d39SSatish Balay #endif
1014a60b672SMatthew Knepley #endif
102e489efc1SBarry Smith 
103762437b8SSatish Balay extern  MPI_Datatype PETSC_DLLEXPORT MPIU_COMPLEX;
104762437b8SSatish Balay #define MPIU_SCALAR         MPIU_COMPLEX
105762437b8SSatish Balay #if defined(PETSC_USE_MAT_SINGLE)
106762437b8SSatish Balay #define MPIU_MATSCALAR        ??Notdone
107762437b8SSatish Balay #else
108762437b8SSatish Balay #define MPIU_MATSCALAR      MPIU_COMPLEX
109762437b8SSatish Balay #endif
110762437b8SSatish Balay 
111e489efc1SBarry Smith /* Compiling for real numbers only */
112e489efc1SBarry Smith #else
11387828ca2SBarry Smith #  if defined(PETSC_USE_SINGLE)
11487828ca2SBarry Smith #    define MPIU_SCALAR           MPI_FLOAT
115f68b968cSBarry Smith #  elif defined(PETSC_USE_LONG_DOUBLE)
116f68b968cSBarry Smith #    define MPIU_SCALAR           MPI_LONG_DOUBLE
11703c60df9SBarry Smith #  elif defined(PETSC_INT)
11803c60df9SBarry Smith #    define MPIU_INT              MPI_INT
11987828ca2SBarry Smith #  else
120e489efc1SBarry Smith #    define MPIU_SCALAR           MPI_DOUBLE
12187828ca2SBarry Smith #  endif
12287828ca2SBarry Smith #  if defined(PETSC_USE_MAT_SINGLE) || defined(PETSC_USE_SINGLE)
1233eda8832SBarry Smith #    define MPIU_MATSCALAR        MPI_FLOAT
124f68b968cSBarry Smith #  elif defined(PETSC_USE_LONG_DOUBLE)
125f68b968cSBarry Smith #    define MPIU_MATSCALAR        MPI_LONG_DOUBLE
12603c60df9SBarry Smith #  elif defined(PETSC_USE_INT)
12703c60df9SBarry Smith #    define MPIU_MATSCALAR        MPI_INT
1283eda8832SBarry Smith #  else
1293eda8832SBarry Smith #    define MPIU_MATSCALAR        MPI_DOUBLE
1303eda8832SBarry Smith #  endif
131329f5518SBarry Smith #  define PetscRealPart(a)      (a)
1329b0def1dSBarry Smith #  define PetscImaginaryPart(a) (0)
133e489efc1SBarry Smith #  define PetscAbsScalar(a)     (((a)<0.0)   ? -(a) : (a))
134e489efc1SBarry Smith #  define PetscConj(a)          (a)
13518a7d68fSSatish Balay #  define PetscSqrtScalar(a)    sqrt(a)
136184914b5SBarry Smith #  define PetscPowScalar(a,b)   pow(a,b)
137184914b5SBarry Smith #  define PetscExpScalar(a)     exp(a)
138184914b5SBarry Smith #  define PetscSinScalar(a)     sin(a)
139184914b5SBarry Smith #  define PetscCosScalar(a)     cos(a)
140b0a32e0cSBarry Smith 
141b0a32e0cSBarry Smith #  if defined(PETSC_USE_SINGLE)
142ea709b57SSatish Balay   typedef float PetscScalar;
143f68b968cSBarry Smith #  elif defined(PETSC_USE_LONG_DOUBLE)
144f68b968cSBarry Smith   typedef long double PetscScalar;
14503c60df9SBarry Smith #  elif defined(PETSC_USE_INT)
14603c60df9SBarry Smith   typedef int PetscScalar;
147b0a32e0cSBarry Smith #  else
148ea709b57SSatish Balay   typedef double PetscScalar;
149b0a32e0cSBarry Smith #  endif
150e489efc1SBarry Smith #endif
151e489efc1SBarry Smith 
152d7d1e502SBarry Smith #if defined(PETSC_USE_SINGLE)
153d7d1e502SBarry Smith #  define MPIU_REAL   MPI_FLOAT
154f68b968cSBarry Smith #elif defined(PETSC_USE_LONG_DOUBLE)
155f68b968cSBarry Smith #  define MPIU_REAL   MPI_LONG_DOUBLE
15603c60df9SBarry Smith #elif defined(PETSC_USE_INT)
15703c60df9SBarry Smith #  define MPIU_REAL   MPI_INT
158d7d1e502SBarry Smith #else
159d7d1e502SBarry Smith #  define MPIU_REAL   MPI_DOUBLE
160d7d1e502SBarry Smith #endif
161d7d1e502SBarry Smith 
162da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1)
16326aa1773SMatthew Knepley #define PetscAbs(a)  (((a) >= 0) ? (a) : -(a))
1643f1db9ecSBarry Smith /*
1653f1db9ecSBarry Smith        Allows compiling PETSc so that matrix values are stored in
1663f1db9ecSBarry Smith    single precision but all other objects still use double
1673f1db9ecSBarry Smith    precision. This does not work for complex numbers in that case
1683f1db9ecSBarry Smith    it remains double
1693f1db9ecSBarry Smith 
1703f1db9ecSBarry Smith           EXPERIMENTAL! NOT YET COMPLETELY WORKING
1713f1db9ecSBarry Smith */
1723f1db9ecSBarry Smith 
17311380375SSatish Balay #if defined(PETSC_USE_MAT_SINGLE)
174b400db4cSSatish Balay typedef float MatScalar;
1753f1db9ecSBarry Smith #else
176ea709b57SSatish Balay typedef PetscScalar MatScalar;
17711380375SSatish Balay #endif
1783f1db9ecSBarry Smith 
179329f5518SBarry Smith #if defined(PETSC_USE_SINGLE)
180b400db4cSSatish Balay   typedef float PetscReal;
181f68b968cSBarry Smith #elif defined(PETSC_USE_LONG_DOUBLE)
182f68b968cSBarry Smith   typedef long double PetscReal;
18303c60df9SBarry Smith #elif defined(PETSC_USE_INT)
18403c60df9SBarry Smith   typedef int PetscReal;
185329f5518SBarry Smith #else
186b400db4cSSatish Balay   typedef double PetscReal;
187329f5518SBarry Smith #endif
1883f1db9ecSBarry Smith 
189f68b968cSBarry Smith #if defined(PETSC_USE_COMPLEX)
190f68b968cSBarry Smith typedef PetscReal MatReal;
191f68b968cSBarry Smith #elif defined(PETSC_USE_MAT_SINGLE) || defined(PETSC_USE_SINGLE)
192f68b968cSBarry Smith typedef float MatReal;
193f68b968cSBarry Smith #else
194f68b968cSBarry Smith typedef PetscReal MatReal;
195f68b968cSBarry Smith #endif
196f68b968cSBarry Smith 
197f68b968cSBarry Smith 
198314da920SBarry Smith /* --------------------------------------------------------------------------*/
199314da920SBarry Smith 
200e489efc1SBarry Smith /*
201e489efc1SBarry Smith    Certain objects may be created using either single
202e489efc1SBarry Smith   or double precision.
203e489efc1SBarry Smith */
204f68b968cSBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision;
205e489efc1SBarry Smith 
206e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */
207ff73aad6SKris Buschelman extern  PetscScalar PETSC_DLLEXPORT PETSC_i;
208e489efc1SBarry Smith 
209b6a5bde7SBarry Smith /*MC
210b6a5bde7SBarry Smith    PetscMin - Returns minimum of two numbers
211b6a5bde7SBarry Smith 
212b6a5bde7SBarry Smith    Input Parameter:
213b6a5bde7SBarry Smith +  v1 - first value to find minimum of
214b6a5bde7SBarry Smith -  v2 - second value to find minimum of
215b6a5bde7SBarry Smith 
216b6a5bde7SBarry Smith    Synopsis:
217b6a5bde7SBarry Smith    type PetscMin(type v1,type v2)
218b6a5bde7SBarry Smith 
219b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
220b6a5bde7SBarry Smith 
221b6a5bde7SBarry Smith    Level: beginner
222b6a5bde7SBarry Smith 
223b6a5bde7SBarry Smith 
224b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
225b6a5bde7SBarry Smith 
226b6a5bde7SBarry Smith M*/
227e489efc1SBarry Smith #define PetscMin(a,b)   (((a)<(b)) ?  (a) : (b))
228b6a5bde7SBarry Smith 
229b6a5bde7SBarry Smith /*MC
230b6a5bde7SBarry Smith    PetscMax - Returns maxium of two numbers
231b6a5bde7SBarry Smith 
232b6a5bde7SBarry Smith    Input Parameter:
233b6a5bde7SBarry Smith +  v1 - first value to find maximum of
234b6a5bde7SBarry Smith -  v2 - second value to find maximum of
235b6a5bde7SBarry Smith 
236b6a5bde7SBarry Smith    Synopsis:
237b6a5bde7SBarry Smith    type max PetscMax(type v1,type v2)
238b6a5bde7SBarry Smith 
239b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
240b6a5bde7SBarry Smith 
241b6a5bde7SBarry Smith    Level: beginner
242b6a5bde7SBarry Smith 
243b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
244b6a5bde7SBarry Smith 
245b6a5bde7SBarry Smith M*/
246e489efc1SBarry Smith #define PetscMax(a,b)   (((a)<(b)) ?  (b) : (a))
247b6a5bde7SBarry Smith 
248b6a5bde7SBarry Smith /*MC
249b6a5bde7SBarry Smith    PetscAbsInt - Returns the absolute value of an integer
250b6a5bde7SBarry Smith 
251b6a5bde7SBarry Smith    Input Parameter:
252b6a5bde7SBarry Smith .   v1 - the integer
253b6a5bde7SBarry Smith 
254b6a5bde7SBarry Smith    Synopsis:
255b6a5bde7SBarry Smith    int abs PetscAbsInt(int v1)
256b6a5bde7SBarry Smith 
257b6a5bde7SBarry Smith 
258b6a5bde7SBarry Smith    Level: beginner
259b6a5bde7SBarry Smith 
260b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr()
261b6a5bde7SBarry Smith 
262b6a5bde7SBarry Smith M*/
263e489efc1SBarry Smith #define PetscAbsInt(a)  (((a)<0)   ? -(a) : (a))
264b6a5bde7SBarry Smith 
265b6a5bde7SBarry Smith /*MC
266b6a5bde7SBarry Smith    PetscAbsReal - Returns the absolute value of an real number
267b6a5bde7SBarry Smith 
268b6a5bde7SBarry Smith    Input Parameter:
269b6a5bde7SBarry Smith .   v1 - the double
270b6a5bde7SBarry Smith 
271b6a5bde7SBarry Smith    Synopsis:
272b6a5bde7SBarry Smith    int abs PetscAbsReal(PetscReal v1)
273b6a5bde7SBarry Smith 
274b6a5bde7SBarry Smith 
275b6a5bde7SBarry Smith    Level: beginner
276b6a5bde7SBarry Smith 
277b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr()
278b6a5bde7SBarry Smith 
279b6a5bde7SBarry Smith M*/
280f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0)   ? -(a) : (a))
281b6a5bde7SBarry Smith 
282b6a5bde7SBarry Smith /*MC
283b6a5bde7SBarry Smith    PetscSqr - Returns the square of a number
284b6a5bde7SBarry Smith 
285b6a5bde7SBarry Smith    Input Parameter:
286b6a5bde7SBarry Smith .   v1 - the value
287b6a5bde7SBarry Smith 
288b6a5bde7SBarry Smith    Synopsis:
289b6a5bde7SBarry Smith    type sqr PetscSqr(type v1)
290b6a5bde7SBarry Smith 
291b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
292b6a5bde7SBarry Smith 
293b6a5bde7SBarry Smith    Level: beginner
294b6a5bde7SBarry Smith 
295b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal()
296b6a5bde7SBarry Smith 
297b6a5bde7SBarry Smith M*/
2984ebda54eSMatthew Knepley #define PetscSqr(a)     ((a)*(a))
299e489efc1SBarry Smith 
300314da920SBarry Smith /* ----------------------------------------------------------------------------*/
301314da920SBarry Smith /*
30203c60df9SBarry Smith      Basic constants - These should be done much better
303314da920SBarry Smith */
304314da920SBarry Smith #define PETSC_PI                 3.14159265358979323846264
305314da920SBarry Smith #define PETSC_DEGREES_TO_RADIANS 0.01745329251994
306f10639e6SSatish Balay #define PETSC_MAX_INT            1000000000
307f10639e6SSatish Balay #define PETSC_MIN_INT            -1000000000
308e489efc1SBarry Smith 
30982adfdadSBarry Smith #if defined(PETSC_USE_SINGLE)
3107e032f8bSBarry Smith #  define PETSC_MAX                     1.e30
3117e032f8bSBarry Smith #  define PETSC_MIN                    -1.e30
312f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-7
313f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    3.e-4
314cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-5
31503c60df9SBarry Smith #elif defined(PETSC_USE_INT)
31603c60df9SBarry Smith #  define PETSC_MAX                     PETSC_MAX_INT
31703c60df9SBarry Smith #  define PETSC_MIN                     PETSC_MIN_INT
31803c60df9SBarry Smith #  define PETSC_MACHINE_EPSILON         1
31903c60df9SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1
32003c60df9SBarry Smith #  define PETSC_SMALL                   0
32182adfdadSBarry Smith #else
3227e032f8bSBarry Smith #  define PETSC_MAX                     1.e300
3237e032f8bSBarry Smith #  define PETSC_MIN                    -1.e300
324f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-14
325f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    1.e-7
326cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
32782adfdadSBarry Smith #endif
32882adfdadSBarry Smith 
329ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMax(PetscReal*,PetscReal*,MPI_Comm);
330ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMin(PetscReal*,PetscReal*,MPI_Comm);
331ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalSum(PetscScalar*,PetscScalar*,MPI_Comm);
3323e523bebSBarry Smith 
3330763cb5fSBarry Smith /*MC
3340763cb5fSBarry Smith       PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.
3353e523bebSBarry Smith 
3360763cb5fSBarry Smith     Input Parameter:
3370763cb5fSBarry Smith .     a - the double
3380763cb5fSBarry Smith 
3390763cb5fSBarry Smith 
3400763cb5fSBarry Smith      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
34183886165SBarry Smith       Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile
3420763cb5fSBarry Smith       out this form, thus removing the check.
3430763cb5fSBarry Smith 
34483672c4dSSatish Balay      Level: beginner
34583672c4dSSatish Balay 
34683672c4dSSatish Balay M*/
3479a25a3ccSBarry Smith #if defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
348f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a)))
349f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (isinf(a) || isnan(a))
35062b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
351270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H)
352270b8587SSatish Balay #include "float.h"  /* windows defines _finite() in float.h */
353270b8587SSatish Balay #endif
354*961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H)
355*961faeafSBarry Smith #include "ieeefp.h"  /* Solaris prototypes these here */
356*961faeafSBarry Smith #endif
357f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (!_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a)))
358f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (!_finite(a) || _isnan(a))
3599a25a3ccSBarry Smith #else
360f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) ((a - a) != 0.0)
361f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) ((a - a) != 0.0)
3629a25a3ccSBarry Smith #endif
3639a25a3ccSBarry Smith 
3649a25a3ccSBarry Smith 
365314da920SBarry Smith /* ----------------------------------------------------------------------------*/
366e489efc1SBarry Smith /*
367b0a32e0cSBarry Smith     PetscLogDouble variables are used to contain double precision numbers
368e489efc1SBarry Smith   that are not used in the numerical computations, but rather in logging,
369e489efc1SBarry Smith   timing etc.
370e489efc1SBarry Smith */
371b0a32e0cSBarry Smith typedef double PetscLogDouble;
372b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
373e489efc1SBarry Smith 
37487828ca2SBarry Smith #define PassiveReal   PetscReal
375ea709b57SSatish Balay #define PassiveScalar PetscScalar
376d3ecb3a7SBarry Smith 
377e9fa29b7SSatish Balay 
378e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
379e489efc1SBarry Smith #endif
380