xref: /petsc/include/petscmath.h (revision ea345e14a8d04e783ca66ed973b6c768f91d6e89)
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()
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 
49ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
504a60b672SMatthew Knepley typedef std::complex<float> PetscScalar;
51ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
521093a601SBarry Smith typedef std::complex<double> PetscScalar;
53ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE)
544a60b672SMatthew Knepley typedef std::complex<long double> PetscScalar;
55ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
56b7940d39SSatish Balay 
571b65fc54SMatthew G Knepley #else /* PETSC_CLANGUAGE_CXX */
581093a601SBarry Smith /*  C support of complex numbers: Requires C99 compliant compiler*/
591093a601SBarry Smith #include <complex.h>
60b7940d39SSatish Balay 
61ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_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 
75ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_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 
89ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_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 
103ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
1041b65fc54SMatthew G Knepley #endif /* PETSC_CLANGUAGE_CXX */
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;
1091b65fc54SMatthew G Knepley #endif /* PETSC_HAVE_MPI_C_DOUBLE_COMPLEX */
1102c876bd9SBarry Smith 
111ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
112a83b8d76SBarry Smith #define MPIU_SCALAR MPI_C_COMPLEX
113ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
1142c876bd9SBarry Smith #define MPIU_SCALAR MPI_C_DOUBLE_COMPLEX
115ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE)
1161093a601SBarry Smith #define MPIU_SCALAR error
117ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
11875567043SBarry Smith 
1191093a601SBarry Smith /*
1201093a601SBarry Smith     real number definitions
1211093a601SBarry Smith  */
1221b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */
123ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
12487828ca2SBarry Smith #define MPIU_SCALAR           MPI_FLOAT
1251093a601SBarry Smith typedef float PetscScalar;
126ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
1271093a601SBarry Smith #define MPIU_SCALAR           MPI_DOUBLE
1281093a601SBarry Smith typedef double PetscScalar;
129ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE)
130f68b968cSBarry Smith #define MPIU_SCALAR           MPI_LONG_DOUBLE
1311093a601SBarry Smith typedef long double PetscScalar;
132ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
133c90a1750SBarry Smith extern MPI_Datatype MPIU___FLOAT128;
134c90a1750SBarry Smith #define MPIU_SCALAR MPIU___FLOAT128
1350d0cc1b5SBarry Smith typedef __float128 PetscScalar;
136ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
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)
141ce63c4c1SBarry Smith #if !defined(PETSC_USE_REAL___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)
148ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */
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)
156ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */
157b0a32e0cSBarry Smith 
1581b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */
159e489efc1SBarry Smith 
160ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
161d7d1e502SBarry Smith #define MPIU_REAL   MPI_FLOAT
1621093a601SBarry Smith typedef float PetscReal;
163ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
1641093a601SBarry Smith #define MPIU_REAL   MPI_DOUBLE
1651093a601SBarry Smith typedef double PetscReal;
166ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_LONG_DOUBLE)
167f68b968cSBarry Smith #define MPIU_REAL   MPI_LONG_DOUBLE
1681093a601SBarry Smith typedef long double PetscReal;
169ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
170c90a1750SBarry Smith #define MPIU_REAL MPIU___FLOAT128
1710d0cc1b5SBarry Smith typedef __float128 PetscReal;
172ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
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 /*
291d34fcf5fSBarry Smith      Basic constants
292314da920SBarry Smith */
293ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128)
294d34fcf5fSBarry Smith #define PETSC_PI                 M_PIq
295d34fcf5fSBarry Smith #elif defined(M_PI)
296d34fcf5fSBarry Smith #define PETSC_PI                 M_PI
297d34fcf5fSBarry Smith #else
298314da920SBarry Smith #define PETSC_PI                 3.14159265358979323846264
299d34fcf5fSBarry Smith #endif
300d34fcf5fSBarry Smith 
301d34fcf5fSBarry Smith 
30271fd2e92SBarry Smith #define PETSC_MAX_INT            2147483647
30371fd2e92SBarry Smith #define PETSC_MIN_INT            -2147483647
304e489efc1SBarry Smith 
305ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
306d34fcf5fSBarry Smith #if defined(MAXFLOAT)
307*ea345e14SBarry Smith #  define PETSC_MAX_REAL                 MAXFLOAT
308d34fcf5fSBarry Smith #else
309*ea345e14SBarry Smith #  define PETSC_MAX_REAL                1.e30
310d34fcf5fSBarry Smith #endif
311*ea345e14SBarry Smith #  define PETSC_MIN_REAL                -PETSC_MAX_REAL
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
315ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
316*ea345e14SBarry Smith #  define PETSC_MAX_REAL                1.e300
317*ea345e14SBarry Smith #  define PETSC_MIN_REAL                -PETSC_MAX_REAL
318f10639e6SSatish Balay #  define PETSC_MACHINE_EPSILON         1.e-14
319f10639e6SSatish Balay #  define PETSC_SQRT_MACHINE_EPSILON    1.e-7
320cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
321ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
322*ea345e14SBarry Smith #  define PETSC_MAX_REAL                FLT128_MAX
323ce63c4c1SBarry Smith #  define PETSC_MIN_REAL                -FLT128_MAX
324d34fcf5fSBarry Smith #  define PETSC_MACHINE_EPSILON         FLT128_EPSILON
325d34fcf5fSBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1.38777878078e-17
326d34fcf5fSBarry Smith #  define PETSC_SMALL                   1.e-20
32782adfdadSBarry Smith #endif
32882adfdadSBarry Smith 
3299cf09972SJed Brown #if defined PETSC_HAVE_ADIC
3309cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */
3317087cfbeSBarry Smith extern PetscErrorCode  PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*);
3327087cfbeSBarry Smith extern PetscErrorCode  PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*);
3337087cfbeSBarry Smith extern PetscErrorCode  PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*);
3349cf09972SJed Brown #endif
3353e523bebSBarry Smith 
3360763cb5fSBarry Smith /*MC
3370763cb5fSBarry Smith       PetscIsInfOrNan - Returns 1 if the input double has an infinity for Not-a-number (Nan) value, otherwise 0.
3383e523bebSBarry Smith 
3390763cb5fSBarry Smith     Input Parameter:
3400763cb5fSBarry Smith .     a - the double
3410763cb5fSBarry Smith 
3420763cb5fSBarry Smith 
3430763cb5fSBarry Smith      Notes: uses the C99 standard isinf() and isnan() on systems where they exist.
34483886165SBarry Smith       Otherwises uses ( (a - a) != 0.0), note that some optimizing compiles compile
3450763cb5fSBarry Smith       out this form, thus removing the check.
3460763cb5fSBarry Smith 
34783672c4dSSatish Balay      Level: beginner
34883672c4dSSatish Balay 
34983672c4dSSatish Balay M*/
350ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128)
351a06653b4SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
352a06653b4SBarry Smith   return isinfq(PetscAbsScalar(a)) || isnanq(PetscAbsScalar(a));
353a06653b4SBarry Smith }
354a06653b4SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
355a06653b4SBarry Smith   return isinfq(a) || isnanq(a);
356a06653b4SBarry Smith }
357a06653b4SBarry Smith #elif defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
35862cbcd01SMatthew G Knepley PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
35962cbcd01SMatthew G Knepley   return isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a));
36062cbcd01SMatthew G Knepley }
36162cbcd01SMatthew G Knepley PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
36262cbcd01SMatthew G Knepley   return isinf(a) || isnan(a);
36362cbcd01SMatthew G Knepley }
36462b4c0b3SBarry Smith #elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
365270b8587SSatish Balay #if defined(PETSC_HAVE_FLOAT_H)
36698725619SBarry Smith #include "float.h"  /* Microsoft Windows defines _finite() in float.h */
367270b8587SSatish Balay #endif
368961faeafSBarry Smith #if defined(PETSC_HAVE_IEEEFP_H)
369961faeafSBarry Smith #include "ieeefp.h"  /* Solaris prototypes these here */
370961faeafSBarry Smith #endif
37198725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
37298725619SBarry Smith   return !_finite(PetscAbsScalar(a)) || _isnan(PetscAbsScalar(a));
37398725619SBarry Smith }
37498725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
37598725619SBarry Smith   return !_finite(a) || _isnan(a);
37698725619SBarry Smith }
3779a25a3ccSBarry Smith #else
37898725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
37998725619SBarry Smith   return  ((a - a) != 0.0);
38098725619SBarry Smith }
38198725619SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanReal(PetscReal a) {
38298725619SBarry Smith   return ((a - a) != 0.0);
38398725619SBarry Smith }
3849a25a3ccSBarry Smith #endif
3859a25a3ccSBarry Smith 
3869a25a3ccSBarry Smith 
387314da920SBarry Smith /* ----------------------------------------------------------------------------*/
388e489efc1SBarry Smith /*
389b0a32e0cSBarry Smith     PetscLogDouble variables are used to contain double precision numbers
390e489efc1SBarry Smith   that are not used in the numerical computations, but rather in logging,
391e489efc1SBarry Smith   timing etc.
392e489efc1SBarry Smith */
393b0a32e0cSBarry Smith typedef double PetscLogDouble;
394b9617806SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
395e489efc1SBarry Smith 
39687828ca2SBarry Smith #define PassiveReal   PetscReal
397ea709b57SSatish Balay #define PassiveScalar PetscScalar
398d3ecb3a7SBarry Smith 
39998725619SBarry Smith /*
40098725619SBarry Smith     These macros are currently hardwired to match the regular data types, so there is no support for a different
40198725619SBarry Smith     MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again.
40298725619SBarry Smith  */
40398725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR
40498725619SBarry Smith typedef PetscScalar MatScalar;
40598725619SBarry Smith typedef PetscReal MatReal;
40698725619SBarry Smith 
407e9fa29b7SSatish Balay 
408e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
409e489efc1SBarry Smith #endif
410