xref: /petsc/include/petscmath.h (revision 71fd2e92b2fee25f70818ffc1dca9fc57f8584d7)
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 
107762437b8SSatish Balay extern  MPI_Datatype PETSC_DLLEXPORT MPIU_COMPLEX;
108762437b8SSatish Balay #define MPIU_SCALAR         MPIU_COMPLEX
10965460251SBarry Smith #if defined(PETSC_USE_SCALAR_MAT_SINGLE)
110762437b8SSatish Balay #define MPIU_MATSCALAR        ??Notdone
111762437b8SSatish Balay #else
112762437b8SSatish Balay #define MPIU_MATSCALAR      MPIU_COMPLEX
113762437b8SSatish Balay #endif
114762437b8SSatish Balay 
115e489efc1SBarry Smith /* Compiling for real numbers only */
116e489efc1SBarry Smith #else
11765460251SBarry Smith #  if defined(PETSC_USE_SCALAR_SINGLE)
11887828ca2SBarry Smith #    define MPIU_SCALAR           MPI_FLOAT
11965460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
120f68b968cSBarry Smith #    define MPIU_SCALAR           MPI_LONG_DOUBLE
12103c60df9SBarry Smith #  elif defined(PETSC_INT)
12203c60df9SBarry Smith #    define MPIU_INT              MPI_INT
12387828ca2SBarry Smith #  else
124e489efc1SBarry Smith #    define MPIU_SCALAR           MPI_DOUBLE
12587828ca2SBarry Smith #  endif
12665460251SBarry Smith #  if defined(PETSC_USE_SCALAR_MAT_SINGLE) || defined(PETSC_USE_SCALAR_SINGLE)
1273eda8832SBarry Smith #    define MPIU_MATSCALAR        MPI_FLOAT
12865460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
129f68b968cSBarry Smith #    define MPIU_MATSCALAR        MPI_LONG_DOUBLE
13065460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_INT)
13103c60df9SBarry Smith #    define MPIU_MATSCALAR        MPI_INT
1323eda8832SBarry Smith #  else
1333eda8832SBarry Smith #    define MPIU_MATSCALAR        MPI_DOUBLE
1343eda8832SBarry Smith #  endif
135329f5518SBarry Smith #  define PetscRealPart(a)      (a)
1369b0def1dSBarry Smith #  define PetscImaginaryPart(a) (0)
137e489efc1SBarry Smith #  define PetscAbsScalar(a)     (((a)<0.0)   ? -(a) : (a))
138e489efc1SBarry Smith #  define PetscConj(a)          (a)
13918a7d68fSSatish Balay #  define PetscSqrtScalar(a)    sqrt(a)
140184914b5SBarry Smith #  define PetscPowScalar(a,b)   pow(a,b)
141184914b5SBarry Smith #  define PetscExpScalar(a)     exp(a)
14206c1185fSBarry Smith #  define PetscLogScalar(a)     log(a)
143184914b5SBarry Smith #  define PetscSinScalar(a)     sin(a)
144184914b5SBarry Smith #  define PetscCosScalar(a)     cos(a)
145b0a32e0cSBarry Smith 
14665460251SBarry Smith #  if defined(PETSC_USE_SCALAR_SINGLE)
147ea709b57SSatish Balay   typedef float PetscScalar;
14865460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
149f68b968cSBarry Smith   typedef long double PetscScalar;
15065460251SBarry Smith #  elif defined(PETSC_USE_SCALAR_INT)
15103c60df9SBarry Smith   typedef int PetscScalar;
152b0a32e0cSBarry Smith #  else
153ea709b57SSatish Balay   typedef double PetscScalar;
154b0a32e0cSBarry Smith #  endif
155e489efc1SBarry Smith #endif
156e489efc1SBarry Smith 
15765460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
158d7d1e502SBarry Smith #  define MPIU_REAL   MPI_FLOAT
15965460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
160f68b968cSBarry Smith #  define MPIU_REAL   MPI_LONG_DOUBLE
16165460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
16203c60df9SBarry Smith #  define MPIU_REAL   MPI_INT
163d7d1e502SBarry Smith #else
164d7d1e502SBarry Smith #  define MPIU_REAL   MPI_DOUBLE
165d7d1e502SBarry Smith #endif
166d7d1e502SBarry Smith 
167da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1)
16826aa1773SMatthew Knepley #define PetscAbs(a)  (((a) >= 0) ? (a) : -(a))
1693f1db9ecSBarry Smith /*
1703f1db9ecSBarry Smith        Allows compiling PETSc so that matrix values are stored in
1713f1db9ecSBarry Smith    single precision but all other objects still use double
1723f1db9ecSBarry Smith    precision. This does not work for complex numbers in that case
1733f1db9ecSBarry Smith    it remains double
1743f1db9ecSBarry Smith 
1753f1db9ecSBarry Smith           EXPERIMENTAL! NOT YET COMPLETELY WORKING
1763f1db9ecSBarry Smith */
1773f1db9ecSBarry Smith 
17865460251SBarry Smith #if defined(PETSC_USE_SCALAR_MAT_SINGLE)
179b400db4cSSatish Balay typedef float MatScalar;
1803f1db9ecSBarry Smith #else
181ea709b57SSatish Balay typedef PetscScalar MatScalar;
18211380375SSatish Balay #endif
1833f1db9ecSBarry Smith 
18465460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
185b400db4cSSatish Balay   typedef float PetscReal;
18665460251SBarry Smith #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
187f68b968cSBarry Smith   typedef long double PetscReal;
18865460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
18903c60df9SBarry Smith   typedef int PetscReal;
190329f5518SBarry Smith #else
191b400db4cSSatish Balay   typedef double PetscReal;
192329f5518SBarry Smith #endif
1933f1db9ecSBarry Smith 
194f68b968cSBarry Smith #if defined(PETSC_USE_COMPLEX)
195f68b968cSBarry Smith typedef PetscReal MatReal;
19665460251SBarry Smith #elif defined(PETSC_USE_SCALAR_MAT_SINGLE) || defined(PETSC_USE_SCALAR_SINGLE)
197f68b968cSBarry Smith typedef float MatReal;
198f68b968cSBarry Smith #else
199f68b968cSBarry Smith typedef PetscReal MatReal;
200f68b968cSBarry Smith #endif
201f68b968cSBarry Smith 
202f68b968cSBarry Smith 
203314da920SBarry Smith /* --------------------------------------------------------------------------*/
204314da920SBarry Smith 
205e489efc1SBarry Smith /*
206e489efc1SBarry Smith    Certain objects may be created using either single
207e489efc1SBarry Smith   or double precision.
208e489efc1SBarry Smith */
209f68b968cSBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision;
210e489efc1SBarry Smith 
211e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */
212ff73aad6SKris Buschelman extern  PetscScalar PETSC_DLLEXPORT PETSC_i;
213e489efc1SBarry Smith 
214b6a5bde7SBarry Smith /*MC
215b6a5bde7SBarry Smith    PetscMin - Returns minimum of two numbers
216b6a5bde7SBarry Smith 
217b6a5bde7SBarry Smith    Input Parameter:
218b6a5bde7SBarry Smith +  v1 - first value to find minimum of
219b6a5bde7SBarry Smith -  v2 - second value to find minimum of
220b6a5bde7SBarry Smith 
221b6a5bde7SBarry Smith    Synopsis:
222b6a5bde7SBarry Smith    type PetscMin(type v1,type v2)
223b6a5bde7SBarry Smith 
224b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
225b6a5bde7SBarry Smith 
226b6a5bde7SBarry Smith    Level: beginner
227b6a5bde7SBarry Smith 
228b6a5bde7SBarry Smith 
229b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
230b6a5bde7SBarry Smith 
231b6a5bde7SBarry Smith M*/
232e489efc1SBarry Smith #define PetscMin(a,b)   (((a)<(b)) ?  (a) : (b))
233b6a5bde7SBarry Smith 
234b6a5bde7SBarry Smith /*MC
235b6a5bde7SBarry Smith    PetscMax - Returns maxium of two numbers
236b6a5bde7SBarry Smith 
237b6a5bde7SBarry Smith    Input Parameter:
238b6a5bde7SBarry Smith +  v1 - first value to find maximum of
239b6a5bde7SBarry Smith -  v2 - second value to find maximum of
240b6a5bde7SBarry Smith 
241b6a5bde7SBarry Smith    Synopsis:
242b6a5bde7SBarry Smith    type max PetscMax(type v1,type v2)
243b6a5bde7SBarry Smith 
244b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
245b6a5bde7SBarry Smith 
246b6a5bde7SBarry Smith    Level: beginner
247b6a5bde7SBarry Smith 
248b6a5bde7SBarry Smith .seealso: PetscMin(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
249b6a5bde7SBarry Smith 
250b6a5bde7SBarry Smith M*/
251e489efc1SBarry Smith #define PetscMax(a,b)   (((a)<(b)) ?  (b) : (a))
252b6a5bde7SBarry Smith 
253b6a5bde7SBarry Smith /*MC
254b6a5bde7SBarry Smith    PetscAbsInt - Returns the absolute value of an integer
255b6a5bde7SBarry Smith 
256b6a5bde7SBarry Smith    Input Parameter:
257b6a5bde7SBarry Smith .   v1 - the integer
258b6a5bde7SBarry Smith 
259b6a5bde7SBarry Smith    Synopsis:
260b6a5bde7SBarry Smith    int abs PetscAbsInt(int v1)
261b6a5bde7SBarry Smith 
262b6a5bde7SBarry Smith 
263b6a5bde7SBarry Smith    Level: beginner
264b6a5bde7SBarry Smith 
265b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr()
266b6a5bde7SBarry Smith 
267b6a5bde7SBarry Smith M*/
268e489efc1SBarry Smith #define PetscAbsInt(a)  (((a)<0)   ? -(a) : (a))
269b6a5bde7SBarry Smith 
270b6a5bde7SBarry Smith /*MC
271b6a5bde7SBarry Smith    PetscAbsReal - Returns the absolute value of an real number
272b6a5bde7SBarry Smith 
273b6a5bde7SBarry Smith    Input Parameter:
274b6a5bde7SBarry Smith .   v1 - the double
275b6a5bde7SBarry Smith 
276b6a5bde7SBarry Smith    Synopsis:
277b6a5bde7SBarry Smith    int abs PetscAbsReal(PetscReal v1)
278b6a5bde7SBarry Smith 
279b6a5bde7SBarry Smith 
280b6a5bde7SBarry Smith    Level: beginner
281b6a5bde7SBarry Smith 
282b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr()
283b6a5bde7SBarry Smith 
284b6a5bde7SBarry Smith M*/
285f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0)   ? -(a) : (a))
286b6a5bde7SBarry Smith 
287b6a5bde7SBarry Smith /*MC
288b6a5bde7SBarry Smith    PetscSqr - Returns the square of a number
289b6a5bde7SBarry Smith 
290b6a5bde7SBarry Smith    Input Parameter:
291b6a5bde7SBarry Smith .   v1 - the value
292b6a5bde7SBarry Smith 
293b6a5bde7SBarry Smith    Synopsis:
294b6a5bde7SBarry Smith    type sqr PetscSqr(type v1)
295b6a5bde7SBarry Smith 
296b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
297b6a5bde7SBarry Smith 
298b6a5bde7SBarry Smith    Level: beginner
299b6a5bde7SBarry Smith 
300b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal()
301b6a5bde7SBarry Smith 
302b6a5bde7SBarry Smith M*/
3034ebda54eSMatthew Knepley #define PetscSqr(a)     ((a)*(a))
304e489efc1SBarry Smith 
305314da920SBarry Smith /* ----------------------------------------------------------------------------*/
306314da920SBarry Smith /*
30703c60df9SBarry Smith      Basic constants - These should be done much better
308314da920SBarry Smith */
309314da920SBarry Smith #define PETSC_PI                 3.14159265358979323846264
310314da920SBarry Smith #define PETSC_DEGREES_TO_RADIANS 0.01745329251994
311*71fd2e92SBarry Smith #define PETSC_MAX_INT            2147483647
312*71fd2e92SBarry Smith #define PETSC_MIN_INT            -2147483647
313e489efc1SBarry Smith 
31465460251SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
3157e032f8bSBarry Smith #  define PETSC_MAX                     1.e30
3167e032f8bSBarry Smith #  define PETSC_MIN                    -1.e30
317f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-7
318f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    3.e-4
319cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-5
32065460251SBarry Smith #elif defined(PETSC_USE_SCALAR_INT)
32103c60df9SBarry Smith #  define PETSC_MAX                     PETSC_MAX_INT
32203c60df9SBarry Smith #  define PETSC_MIN                     PETSC_MIN_INT
32303c60df9SBarry Smith #  define PETSC_MACHINE_EPSILON         1
32403c60df9SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1
32503c60df9SBarry Smith #  define PETSC_SMALL                   0
32682adfdadSBarry Smith #else
3277e032f8bSBarry Smith #  define PETSC_MAX                     1.e300
3287e032f8bSBarry Smith #  define PETSC_MIN                    -1.e300
329f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-14
330f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    1.e-7
331cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
33282adfdadSBarry Smith #endif
33382adfdadSBarry Smith 
334ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMax(PetscReal*,PetscReal*,MPI_Comm);
335ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalMin(PetscReal*,PetscReal*,MPI_Comm);
336ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGlobalSum(PetscScalar*,PetscScalar*,MPI_Comm);
3373e523bebSBarry Smith 
3380763cb5fSBarry Smith /*MC
3390763cb5fSBarry Smith       PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.
3403e523bebSBarry Smith 
3410763cb5fSBarry Smith     Input Parameter:
3420763cb5fSBarry Smith .     a - the double
3430763cb5fSBarry Smith 
3440763cb5fSBarry Smith 
3450763cb5fSBarry Smith      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
34683886165SBarry Smith       Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile
3470763cb5fSBarry Smith       out this form, thus removing the check.
3480763cb5fSBarry Smith 
34983672c4dSSatish Balay      Level: beginner
35083672c4dSSatish Balay 
35183672c4dSSatish Balay M*/
3529a25a3ccSBarry Smith #if defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
353f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a)))
354f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (isinf(a) || isnan(a))
35562b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
356270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H)
357270b8587SSatish Balay #include "float.h"  /* windows defines _finite() in float.h */
358270b8587SSatish Balay #endif
359961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H)
360961faeafSBarry Smith #include "ieeefp.h"  /* Solaris prototypes these here */
361961faeafSBarry Smith #endif
362f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) (!_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a)))
363f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) (!_finite(a) || _isnan(a))
3649a25a3ccSBarry Smith #else
365f66fdb6dSSatish Balay #define PetscIsInfOrNanScalar(a) ((a - a) != 0.0)
366f66fdb6dSSatish Balay #define PetscIsInfOrNanReal(a) ((a - a) != 0.0)
3679a25a3ccSBarry Smith #endif
3689a25a3ccSBarry Smith 
3699a25a3ccSBarry Smith 
370314da920SBarry Smith /* ----------------------------------------------------------------------------*/
371e489efc1SBarry Smith /*
372b0a32e0cSBarry Smith     PetscLogDouble variables are used to contain double precision numbers
373e489efc1SBarry Smith   that are not used in the numerical computations, but rather in logging,
374e489efc1SBarry Smith   timing etc.
375e489efc1SBarry Smith */
376b0a32e0cSBarry Smith typedef double PetscLogDouble;
377b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
378e489efc1SBarry Smith 
37987828ca2SBarry Smith #define PassiveReal   PetscReal
380ea709b57SSatish Balay #define PassiveScalar PetscScalar
381d3ecb3a7SBarry Smith 
382e9fa29b7SSatish Balay 
383e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
384e489efc1SBarry Smith #endif
385