xref: /petsc/include/petscmath.h (revision 3351b39492aff2651e4a5b0633baeb4ef1c9c887)
1e489efc1SBarry Smith /*
2314da920SBarry Smith 
3314da920SBarry Smith       PETSc mathematics include file. Defines certain basic mathematical
4a5057860SBarry Smith     constants and functions for working with single, double, and quad precision
5a5057860SBarry Smith     floating point numbers as well as complex single and double.
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>
140a5f7794SBarry Smith 
15014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_2SCALAR;
16014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_2INT;
17c90a1750SBarry Smith 
18314da920SBarry Smith /*
19f4ccad53SBarry Smith 
20f4ccad53SBarry Smith      Defines operations that are different for complex and real numbers;
21a5057860SBarry Smith    note that one cannot 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
2398725619SBarry Smith    PetscScalar which is either always a real or a complex.
24f4ccad53SBarry Smith 
25e489efc1SBarry Smith */
26b36a9721SBarry Smith 
2759cb5930SBarry Smith #define PetscExpPassiveScalar(a) PetscExpScalar()
28c1d390e3SJed Brown #if defined(PETSC_USE_REAL_SINGLE)
29c1d390e3SJed Brown #define MPIU_REAL   MPI_FLOAT
30c1d390e3SJed Brown typedef float PetscReal;
318f1a2a5eSBarry Smith #define PetscSqrtReal(a)    sqrt(a)
32c1d390e3SJed Brown #elif defined(PETSC_USE_REAL_DOUBLE)
33c1d390e3SJed Brown #define MPIU_REAL   MPI_DOUBLE
34c1d390e3SJed Brown typedef double PetscReal;
358f1a2a5eSBarry Smith #define PetscSqrtReal(a)    sqrt(a)
36c1d390e3SJed Brown #elif defined(PETSC_USE_REAL___FLOAT128)
37574fde7bSSatish Balay #if defined(__cplusplus)
38574fde7bSSatish Balay extern "C" {
39574fde7bSSatish Balay #endif
40574fde7bSSatish Balay #include <quadmath.h>
41574fde7bSSatish Balay #if defined(__cplusplus)
42574fde7bSSatish Balay }
43574fde7bSSatish Balay #endif
44c1d390e3SJed Brown #define MPIU_REAL MPIU___FLOAT128
45c1d390e3SJed Brown typedef __float128 PetscReal;
468f1a2a5eSBarry Smith #define PetscSqrtReal(a)    sqrtq(a)
47c1d390e3SJed Brown #endif /* PETSC_USE_REAL_* */
4859cb5930SBarry Smith 
491093a601SBarry Smith /*
501093a601SBarry Smith     Complex number definitions
511093a601SBarry Smith  */
5250f81f78SJed Brown #if defined(PETSC_CLANGUAGE_CXX) && defined(PETSC_HAVE_CXX_COMPLEX)
5350f81f78SJed Brown #define PETSC_HAVE_COMPLEX 1
541093a601SBarry Smith /* C++ support of complex number */
55debe9ee2SPaul Mullowney #if defined(PETSC_HAVE_CUSP)
56debe9ee2SPaul Mullowney #define complexlib cusp
579ae82921SPaul Mullowney #include <cusp/complex.h>
58debe9ee2SPaul Mullowney #else
59debe9ee2SPaul Mullowney #define complexlib std
60debe9ee2SPaul Mullowney #include <complex>
619ae82921SPaul Mullowney #endif
62b7940d39SSatish Balay 
6350f81f78SJed Brown #define PetscRealPartComplex(a)      (a).real()
6450f81f78SJed Brown #define PetscImaginaryPartComplex(a) (a).imag()
6550f81f78SJed Brown #define PetscAbsComplex(a)           complexlib::abs(a)
6650f81f78SJed Brown #define PetscConjComplex(a)          complexlib::conj(a)
6750f81f78SJed Brown #define PetscSqrtComplex(a)          complexlib::sqrt(a)
6850f81f78SJed Brown #define PetscPowComplex(a,b)         complexlib::pow(a,b)
6950f81f78SJed Brown #define PetscExpComplex(a)           complexlib::exp(a)
7050f81f78SJed Brown #define PetscLogComplex(a)           complexlib::log(a)
7150f81f78SJed Brown #define PetscSinComplex(a)           complexlib::sin(a)
7250f81f78SJed Brown #define PetscCosComplex(a)           complexlib::cos(a)
73debe9ee2SPaul Mullowney 
74debe9ee2SPaul Mullowney #if defined(PETSC_USE_REAL_SINGLE)
7550f81f78SJed Brown typedef complexlib::complex<float> PetscComplex;
76debe9ee2SPaul Mullowney #elif defined(PETSC_USE_REAL_DOUBLE)
7750f81f78SJed Brown typedef complexlib::complex<double> PetscComplex;
788c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128)
7950f81f78SJed Brown typedef complexlib::complex<__float128> PetscComplex; /* Notstandard and not expected to work, use __complex128 */
80debe9ee2SPaul Mullowney #endif  /* PETSC_USE_REAL_ */
81debe9ee2SPaul Mullowney 
8250f81f78SJed Brown #elif defined(PETSC_CLANGUAGE_C) && defined(PETSC_HAVE_C99_COMPLEX)
8350f81f78SJed Brown #define PETSC_HAVE_COMPLEX 1
84b7940d39SSatish Balay 
8550f81f78SJed Brown /* Use C99 _Complex for the type. Do not include complex.h by default to define "complex" because of symbol conflicts in Hypre. */
8650f81f78SJed Brown /* Compilation units that can safely use complex should define PETSC_DESIRE_COMPLEX before including any headers */
8750f81f78SJed Brown #if defined(PETSC_USE_COMPLEX) || defined(PETSC_DESIRE_COMPLEX)
88519e2a1fSPaul Mullowney #include <complex.h>
8950f81f78SJed Brown #endif
90519e2a1fSPaul Mullowney 
91ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
9250f81f78SJed Brown typedef float _Complex PetscComplex;
9385b47369SMatthew Knepley 
9450f81f78SJed Brown #define PetscRealPartComplex(a)      crealf(a)
9550f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagf(a)
9650f81f78SJed Brown #define PetscAbsComplex(a)           cabsf(a)
9750f81f78SJed Brown #define PetscConjComplex(a)          conjf(a)
9850f81f78SJed Brown #define PetscSqrtComplex(a)          csqrtf(a)
9950f81f78SJed Brown #define PetscPowComplex(a,b)         cpowf(a,b)
10050f81f78SJed Brown #define PetscExpComplex(a)           cexpf(a)
10150f81f78SJed Brown #define PetscLogComplex(a)           clogf(a)
10250f81f78SJed Brown #define PetscSinComplex(a)           csinf(a)
10350f81f78SJed Brown #define PetscCosComplex(a)           ccosf(a)
1041093a601SBarry Smith 
105ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
10650f81f78SJed Brown typedef double _Complex PetscComplex;
1071093a601SBarry Smith 
10850f81f78SJed Brown #define PetscRealPartComplex(a)      creal(a)
10950f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimag(a)
11050f81f78SJed Brown #define PetscAbsComplex(a)           cabs(a)
11150f81f78SJed Brown #define PetscConjComplex(a)          conj(a)
11250f81f78SJed Brown #define PetscSqrtComplex(a)          csqrt(a)
11350f81f78SJed Brown #define PetscPowComplex(a,b)         cpow(a,b)
11450f81f78SJed Brown #define PetscExpComplex(a)           cexp(a)
11550f81f78SJed Brown #define PetscLogComplex(a)           clog(a)
11650f81f78SJed Brown #define PetscSinComplex(a)           csin(a)
11750f81f78SJed Brown #define PetscCosComplex(a)           ccos(a)
1181093a601SBarry Smith 
1198c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128)
12050f81f78SJed Brown typedef __complex128 PetscComplex;
1218c764dc5SJose Roman PETSC_EXTERN MPI_Datatype MPIU___FLOAT128;
1228c764dc5SJose Roman PETSC_EXTERN MPI_Datatype MPIU___COMPLEX128;
1238c764dc5SJose Roman 
12450f81f78SJed Brown #define PetscRealPartComplex(a)      crealq(a)
12550f81f78SJed Brown #define PetscImaginaryPartComplex(a) cimagq(a)
12650f81f78SJed Brown #define PetscAbsComplex(a)           cabsq(a)
12750f81f78SJed Brown #define PetscConjComplex(a)          conjq(a)
12850f81f78SJed Brown #define PetscSqrtComplex(a)          csqrtq(a)
12950f81f78SJed Brown #define PetscPowComplex(a,b)         cpowq(a,b)
13050f81f78SJed Brown #define PetscExpComplex(a)           cexpq(a)
13150f81f78SJed Brown #define PetscLogComplex(a)           clogq(a)
13250f81f78SJed Brown #define PetscSinComplex(a)           csinq(a)
13350f81f78SJed Brown #define PetscCosComplex(a)           ccosq(a)
134ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
13550f81f78SJed Brown #elif defined(PETSC_USE_COMPLEX)
13650f81f78SJed Brown #error "PETSc was configured --with-scalar-type=complex, but a language-appropriate complex library is not available"
1371b65fc54SMatthew G Knepley #endif /* PETSC_CLANGUAGE_CXX */
138e489efc1SBarry Smith 
13970da9c3bSJed Brown #if defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
140500d8756SSatish Balay #define MPIU_C_DOUBLE_COMPLEX MPI_C_DOUBLE_COMPLEX
141500d8756SSatish Balay #define MPIU_C_COMPLEX MPI_C_COMPLEX
14270da9c3bSJed Brown #else
143014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_DOUBLE_COMPLEX;
144014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_COMPLEX;
1451b65fc54SMatthew G Knepley #endif /* PETSC_HAVE_MPI_C_DOUBLE_COMPLEX */
1462c876bd9SBarry Smith 
14750f81f78SJed Brown #if defined(PETSC_USE_COMPLEX)
14850f81f78SJed Brown typedef PetscComplex PetscScalar;
14950f81f78SJed Brown #define PetscRealPart(a)      PetscRealPartComplex(a)
15050f81f78SJed Brown #define PetscImaginaryPart(a) PetscImaginaryPartComplex(a)
15150f81f78SJed Brown #define PetscAbsScalar(a)     PetscAbsComplex(a)
15250f81f78SJed Brown #define PetscConj(a)          PetscConjComplex(a)
15350f81f78SJed Brown #define PetscSqrtScalar(a)    PetscSqrtComplex(a)
15450f81f78SJed Brown #define PetscPowScalar(a,b)   PetscPowComplex(a,b)
15550f81f78SJed Brown #define PetscExpScalar(a)     PetscExpComplex(a)
15650f81f78SJed Brown #define PetscLogScalar(a)     PetscLogComplex(a)
15750f81f78SJed Brown #define PetscSinScalar(a)     PetscSinComplex(a)
15850f81f78SJed Brown #define PetscCosScalar(a)     PetscCosComplex(a)
15950f81f78SJed Brown 
160ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
161500d8756SSatish Balay #define MPIU_SCALAR MPIU_C_COMPLEX
162ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
163500d8756SSatish Balay #define MPIU_SCALAR MPIU_C_DOUBLE_COMPLEX
164*3351b394SSatish Balay #elif defined(PETSC_USE_REAL___FLOAT128)
165*3351b394SSatish Balay #define MPIU_SCALAR MPIU___COMPLEX128
166ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
16775567043SBarry Smith 
1681093a601SBarry Smith /*
1691093a601SBarry Smith     real number definitions
1701093a601SBarry Smith  */
1711b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */
172ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
17387828ca2SBarry Smith #define MPIU_SCALAR           MPI_FLOAT
1741093a601SBarry Smith typedef float PetscScalar;
175ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
1761093a601SBarry Smith #define MPIU_SCALAR           MPI_DOUBLE
1771093a601SBarry Smith typedef double PetscScalar;
178ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
179014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU___FLOAT128;
180c90a1750SBarry Smith #define MPIU_SCALAR MPIU___FLOAT128
1810d0cc1b5SBarry Smith typedef __float128 PetscScalar;
182ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
183329f5518SBarry Smith #define PetscRealPart(a)      (a)
184c1d390e3SJed Brown #define PetscImaginaryPart(a) ((PetscReal)0.)
185c1d390e3SJed Brown PETSC_STATIC_INLINE PetscReal PetscAbsScalar(PetscScalar a) {return a < 0.0 ? -a : a;}
186e489efc1SBarry Smith #define PetscConj(a)          (a)
187ce63c4c1SBarry Smith #if !defined(PETSC_USE_REAL___FLOAT128)
18818a7d68fSSatish Balay #define PetscSqrtScalar(a)    sqrt(a)
189184914b5SBarry Smith #define PetscPowScalar(a,b)   pow(a,b)
190184914b5SBarry Smith #define PetscExpScalar(a)     exp(a)
19106c1185fSBarry Smith #define PetscLogScalar(a)     log(a)
192184914b5SBarry Smith #define PetscSinScalar(a)     sin(a)
193184914b5SBarry Smith #define PetscCosScalar(a)     cos(a)
194ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */
1950d0cc1b5SBarry Smith #define PetscSqrtScalar(a)    sqrtq(a)
1960d0cc1b5SBarry Smith #define PetscPowScalar(a,b)   powq(a,b)
1970d0cc1b5SBarry Smith #define PetscExpScalar(a)     expq(a)
1980d0cc1b5SBarry Smith #define PetscLogScalar(a)     logq(a)
1990d0cc1b5SBarry Smith #define PetscSinScalar(a)     sinq(a)
2000d0cc1b5SBarry Smith #define PetscCosScalar(a)     cosq(a)
201ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */
202b0a32e0cSBarry Smith 
2031b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */
204e489efc1SBarry Smith 
205da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1)
20626aa1773SMatthew Knepley #define PetscAbs(a)  (((a) >= 0) ? (a) : -(a))
2073f1db9ecSBarry Smith 
208314da920SBarry Smith /* --------------------------------------------------------------------------*/
209314da920SBarry Smith 
210e489efc1SBarry Smith /*
211f22f69f0SBarry Smith    Certain objects may be created using either single or double precision.
212f22f69f0SBarry Smith    This is currently not used.
213e489efc1SBarry Smith */
214557d4da8SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision;
215e489efc1SBarry Smith 
21650f81f78SJed Brown #if defined(PETSC_HAVE_COMPLEX)
217e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */
21850f81f78SJed Brown PETSC_EXTERN PetscComplex PETSC_i;
21950f81f78SJed Brown #endif
220e489efc1SBarry Smith 
221b6a5bde7SBarry Smith /*MC
222b6a5bde7SBarry Smith    PetscMin - Returns minimum of two numbers
223b6a5bde7SBarry Smith 
224eca87e8dSBarry Smith    Synopsis:
225eca87e8dSBarry Smith    type PetscMin(type v1,type v2)
226eca87e8dSBarry Smith 
227eca87e8dSBarry Smith    Not Collective
228eca87e8dSBarry Smith 
229b6a5bde7SBarry Smith    Input Parameter:
230b6a5bde7SBarry Smith +  v1 - first value to find minimum of
231b6a5bde7SBarry Smith -  v2 - second value to find minimum of
232b6a5bde7SBarry Smith 
233b6a5bde7SBarry Smith 
234b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
235b6a5bde7SBarry Smith 
236b6a5bde7SBarry Smith    Level: beginner
237b6a5bde7SBarry Smith 
238b6a5bde7SBarry Smith 
239d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
240b6a5bde7SBarry Smith 
241b6a5bde7SBarry Smith M*/
242e489efc1SBarry Smith #define PetscMin(a,b)   (((a)<(b)) ?  (a) : (b))
243b6a5bde7SBarry Smith 
244b6a5bde7SBarry Smith /*MC
245b6a5bde7SBarry Smith    PetscMax - Returns maxium of two numbers
246b6a5bde7SBarry Smith 
247eca87e8dSBarry Smith    Synopsis:
248eca87e8dSBarry Smith    type max PetscMax(type v1,type v2)
249eca87e8dSBarry Smith 
250eca87e8dSBarry Smith    Not Collective
251eca87e8dSBarry Smith 
252b6a5bde7SBarry Smith    Input Parameter:
253b6a5bde7SBarry Smith +  v1 - first value to find maximum of
254b6a5bde7SBarry Smith -  v2 - second value to find maximum of
255b6a5bde7SBarry Smith 
256b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
257b6a5bde7SBarry Smith 
258b6a5bde7SBarry Smith    Level: beginner
259b6a5bde7SBarry Smith 
260d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
261b6a5bde7SBarry Smith 
262b6a5bde7SBarry Smith M*/
263e489efc1SBarry Smith #define PetscMax(a,b)   (((a)<(b)) ?  (b) : (a))
264b6a5bde7SBarry Smith 
265b6a5bde7SBarry Smith /*MC
266d9a4bb16SJed Brown    PetscClipInterval - Returns a number clipped to be within an interval
267d9a4bb16SJed Brown 
268d9a4bb16SJed Brown    Synopsis:
269d9a4bb16SJed Brown    type clip PetscClipInterval(type x,type a,type b)
270d9a4bb16SJed Brown 
271d9a4bb16SJed Brown    Not Collective
272d9a4bb16SJed Brown 
273d9a4bb16SJed Brown    Input Parameter:
274d9a4bb16SJed Brown +  x - value to use if within interval (a,b)
275d9a4bb16SJed Brown .  a - lower end of interval
276d9a4bb16SJed Brown -  b - upper end of interval
277d9a4bb16SJed Brown 
278d9a4bb16SJed Brown    Notes: type can be integer or floating point value
279d9a4bb16SJed Brown 
280d9a4bb16SJed Brown    Level: beginner
281d9a4bb16SJed Brown 
282d9a4bb16SJed Brown .seealso: PetscMin(), PetscMax(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
283d9a4bb16SJed Brown 
284d9a4bb16SJed Brown M*/
285d9a4bb16SJed Brown #define PetscClipInterval(x,a,b)   (PetscMax((a),PetscMin((x),(b))))
286d9a4bb16SJed Brown 
287d9a4bb16SJed Brown /*MC
288b6a5bde7SBarry Smith    PetscAbsInt - Returns the absolute value of an integer
289b6a5bde7SBarry Smith 
290b6a5bde7SBarry Smith    Synopsis:
291b6a5bde7SBarry Smith    int abs PetscAbsInt(int v1)
292b6a5bde7SBarry Smith 
293eca87e8dSBarry Smith    Not Collective
294eca87e8dSBarry Smith 
295eca87e8dSBarry Smith    Input Parameter:
296eca87e8dSBarry Smith .   v1 - the integer
297b6a5bde7SBarry Smith 
298b6a5bde7SBarry Smith    Level: beginner
299b6a5bde7SBarry Smith 
300b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr()
301b6a5bde7SBarry Smith 
302b6a5bde7SBarry Smith M*/
303e489efc1SBarry Smith #define PetscAbsInt(a)  (((a)<0)   ? -(a) : (a))
304b6a5bde7SBarry Smith 
305b6a5bde7SBarry Smith /*MC
306b6a5bde7SBarry Smith    PetscAbsReal - Returns the absolute value of an real number
307b6a5bde7SBarry Smith 
308eca87e8dSBarry Smith    Synopsis:
309eca87e8dSBarry Smith    Real abs PetscAbsReal(PetscReal v1)
310eca87e8dSBarry Smith 
311eca87e8dSBarry Smith    Not Collective
312eca87e8dSBarry Smith 
313b6a5bde7SBarry Smith    Input Parameter:
314b6a5bde7SBarry Smith .   v1 - the double
315b6a5bde7SBarry Smith 
316b6a5bde7SBarry Smith 
317b6a5bde7SBarry Smith    Level: beginner
318b6a5bde7SBarry Smith 
319b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr()
320b6a5bde7SBarry Smith 
321b6a5bde7SBarry Smith M*/
322f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0)   ? -(a) : (a))
323b6a5bde7SBarry Smith 
324b6a5bde7SBarry Smith /*MC
325b6a5bde7SBarry Smith    PetscSqr - Returns the square of a number
326b6a5bde7SBarry Smith 
327b6a5bde7SBarry Smith    Synopsis:
328b6a5bde7SBarry Smith    type sqr PetscSqr(type v1)
329b6a5bde7SBarry Smith 
330eca87e8dSBarry Smith    Not Collective
331eca87e8dSBarry Smith 
332eca87e8dSBarry Smith    Input Parameter:
333eca87e8dSBarry Smith .   v1 - the value
334eca87e8dSBarry Smith 
335b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
336b6a5bde7SBarry Smith 
337b6a5bde7SBarry Smith    Level: beginner
338b6a5bde7SBarry Smith 
339b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal()
340b6a5bde7SBarry Smith 
341b6a5bde7SBarry Smith M*/
3424ebda54eSMatthew Knepley #define PetscSqr(a)     ((a)*(a))
343e489efc1SBarry Smith 
344314da920SBarry Smith /* ----------------------------------------------------------------------------*/
345314da920SBarry Smith /*
346d34fcf5fSBarry Smith      Basic constants
347314da920SBarry Smith */
348ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128)
349d34fcf5fSBarry Smith #define PETSC_PI                 M_PIq
350d34fcf5fSBarry Smith #elif defined(M_PI)
351d34fcf5fSBarry Smith #define PETSC_PI                 M_PI
352d34fcf5fSBarry Smith #else
353faa6e9b0SMatthew G Knepley #define PETSC_PI                 3.14159265358979323846264338327950288419716939937510582
354d34fcf5fSBarry Smith #endif
355d34fcf5fSBarry Smith 
356ab824b78SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
35771fd2e92SBarry Smith #define PETSC_MAX_INT            2147483647
358ab824b78SBarry Smith #define PETSC_MIN_INT            (-PETSC_MAX_INT - 1)
359ab824b78SBarry Smith #else
360ab824b78SBarry Smith #define PETSC_MAX_INT            9223372036854775807L
361ab824b78SBarry Smith #define PETSC_MIN_INT            (-PETSC_MAX_INT - 1)
362ab824b78SBarry Smith #endif
363e489efc1SBarry Smith 
364ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
365ab824b78SBarry Smith #  define PETSC_MAX_REAL                3.40282346638528860e+38F
366ea345e14SBarry Smith #  define PETSC_MIN_REAL                -PETSC_MAX_REAL
36782a7e548SBarry Smith #  define PETSC_MACHINE_EPSILON         1.19209290e-07F
36882a7e548SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    3.45266983e-04F
369cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-5
370ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
371ab824b78SBarry Smith #  define PETSC_MAX_REAL                1.7976931348623157e+308
372ea345e14SBarry Smith #  define PETSC_MIN_REAL                -PETSC_MAX_REAL
37382a7e548SBarry Smith #  define PETSC_MACHINE_EPSILON         2.2204460492503131e-16
37482a7e548SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1.490116119384766e-08
375cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
376ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
377ea345e14SBarry Smith #  define PETSC_MAX_REAL                FLT128_MAX
378ce63c4c1SBarry Smith #  define PETSC_MIN_REAL                -FLT128_MAX
379d34fcf5fSBarry Smith #  define PETSC_MACHINE_EPSILON         FLT128_EPSILON
380d34fcf5fSBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1.38777878078e-17
381d34fcf5fSBarry Smith #  define PETSC_SMALL                   1.e-20
38282adfdadSBarry Smith #endif
38382adfdadSBarry Smith 
3849cf09972SJed Brown #if defined PETSC_HAVE_ADIC
3859cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */
386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*);
387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*);
388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*);
3899cf09972SJed Brown #endif
3903e523bebSBarry Smith 
391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanScalar(PetscScalar);
392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanReal(PetscReal);
3939a25a3ccSBarry Smith 
394314da920SBarry Smith /* ----------------------------------------------------------------------------*/
39587828ca2SBarry Smith #define PassiveReal   PetscReal
396ea709b57SSatish Balay #define PassiveScalar PetscScalar
397d3ecb3a7SBarry Smith 
39898725619SBarry Smith /*
39998725619SBarry Smith     These macros are currently hardwired to match the regular data types, so there is no support for a different
40098725619SBarry Smith     MatScalar from PetscScalar. We left the MatScalar in the source just in case we use it again.
40198725619SBarry Smith  */
40298725619SBarry Smith #define MPIU_MATSCALAR MPIU_SCALAR
40398725619SBarry Smith typedef PetscScalar MatScalar;
40498725619SBarry Smith typedef PetscReal MatReal;
40598725619SBarry Smith 
406e9fa29b7SSatish Balay 
407e489efc1SBarry Smith #endif
408