xref: /petsc/include/petscmath.h (revision 9f20b660d02539fde000fba3938457fb1d96a99f)
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)
53*9f20b660SSatish Balay #if defined(PETSC_USE_COMPLEX) || defined(PETSC_DESIRE_COMPLEX)
5450f81f78SJed Brown #define PETSC_HAVE_COMPLEX 1
551093a601SBarry Smith /* C++ support of complex number */
56debe9ee2SPaul Mullowney #if defined(PETSC_HAVE_CUSP)
57debe9ee2SPaul Mullowney #define complexlib cusp
589ae82921SPaul Mullowney #include <cusp/complex.h>
59debe9ee2SPaul Mullowney #else
60debe9ee2SPaul Mullowney #define complexlib std
61debe9ee2SPaul Mullowney #include <complex>
629ae82921SPaul Mullowney #endif
63b7940d39SSatish Balay 
6450f81f78SJed Brown #define PetscRealPartComplex(a)      (a).real()
6550f81f78SJed Brown #define PetscImaginaryPartComplex(a) (a).imag()
6650f81f78SJed Brown #define PetscAbsComplex(a)           complexlib::abs(a)
6750f81f78SJed Brown #define PetscConjComplex(a)          complexlib::conj(a)
6850f81f78SJed Brown #define PetscSqrtComplex(a)          complexlib::sqrt(a)
6950f81f78SJed Brown #define PetscPowComplex(a,b)         complexlib::pow(a,b)
7050f81f78SJed Brown #define PetscExpComplex(a)           complexlib::exp(a)
7150f81f78SJed Brown #define PetscLogComplex(a)           complexlib::log(a)
7250f81f78SJed Brown #define PetscSinComplex(a)           complexlib::sin(a)
7350f81f78SJed Brown #define PetscCosComplex(a)           complexlib::cos(a)
74debe9ee2SPaul Mullowney 
75debe9ee2SPaul Mullowney #if defined(PETSC_USE_REAL_SINGLE)
7650f81f78SJed Brown typedef complexlib::complex<float> PetscComplex;
77debe9ee2SPaul Mullowney #elif defined(PETSC_USE_REAL_DOUBLE)
7850f81f78SJed Brown typedef complexlib::complex<double> PetscComplex;
798c764dc5SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128)
8050f81f78SJed Brown typedef complexlib::complex<__float128> PetscComplex; /* Notstandard and not expected to work, use __complex128 */
81debe9ee2SPaul Mullowney #endif  /* PETSC_USE_REAL_ */
82*9f20b660SSatish Balay #endif  /* PETSC_USE_COMPLEX && PETSC_DESIRE_COMPLEX */
83debe9ee2SPaul Mullowney 
8450f81f78SJed Brown #elif defined(PETSC_CLANGUAGE_C) && defined(PETSC_HAVE_C99_COMPLEX)
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)
88*9f20b660SSatish Balay #define PETSC_HAVE_COMPLEX 1
89519e2a1fSPaul Mullowney #include <complex.h>
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"
137*9f20b660SSatish Balay #endif /* PETSC_USE_COMPLEX || PETSC_DESIRE_COMPLEX */
138*9f20b660SSatish Balay #endif /* (PETSC_CLANGUAGE_CXX && PETSC_HAVE_CXX_COMPLEX) else-if (PETSC_CLANGUAGE_C && PETSC_HAVE_C99_COMPLEX) */
139e489efc1SBarry Smith 
14070da9c3bSJed Brown #if defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
141500d8756SSatish Balay #define MPIU_C_DOUBLE_COMPLEX MPI_C_DOUBLE_COMPLEX
142500d8756SSatish Balay #define MPIU_C_COMPLEX MPI_C_COMPLEX
14370da9c3bSJed Brown #else
144014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_DOUBLE_COMPLEX;
145014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU_C_COMPLEX;
1461b65fc54SMatthew G Knepley #endif /* PETSC_HAVE_MPI_C_DOUBLE_COMPLEX */
1472c876bd9SBarry Smith 
14850f81f78SJed Brown #if defined(PETSC_USE_COMPLEX)
14950f81f78SJed Brown typedef PetscComplex PetscScalar;
15050f81f78SJed Brown #define PetscRealPart(a)      PetscRealPartComplex(a)
15150f81f78SJed Brown #define PetscImaginaryPart(a) PetscImaginaryPartComplex(a)
15250f81f78SJed Brown #define PetscAbsScalar(a)     PetscAbsComplex(a)
15350f81f78SJed Brown #define PetscConj(a)          PetscConjComplex(a)
15450f81f78SJed Brown #define PetscSqrtScalar(a)    PetscSqrtComplex(a)
15550f81f78SJed Brown #define PetscPowScalar(a,b)   PetscPowComplex(a,b)
15650f81f78SJed Brown #define PetscExpScalar(a)     PetscExpComplex(a)
15750f81f78SJed Brown #define PetscLogScalar(a)     PetscLogComplex(a)
15850f81f78SJed Brown #define PetscSinScalar(a)     PetscSinComplex(a)
15950f81f78SJed Brown #define PetscCosScalar(a)     PetscCosComplex(a)
16050f81f78SJed Brown 
161ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
162500d8756SSatish Balay #define MPIU_SCALAR MPIU_C_COMPLEX
163ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
164500d8756SSatish Balay #define MPIU_SCALAR MPIU_C_DOUBLE_COMPLEX
1653351b394SSatish Balay #elif defined(PETSC_USE_REAL___FLOAT128)
1663351b394SSatish Balay #define MPIU_SCALAR MPIU___COMPLEX128
167ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
16875567043SBarry Smith 
1691093a601SBarry Smith /*
1701093a601SBarry Smith     real number definitions
1711093a601SBarry Smith  */
1721b65fc54SMatthew G Knepley #else /* PETSC_USE_COMPLEX */
173ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
17487828ca2SBarry Smith #define MPIU_SCALAR           MPI_FLOAT
1751093a601SBarry Smith typedef float PetscScalar;
176ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
1771093a601SBarry Smith #define MPIU_SCALAR           MPI_DOUBLE
1781093a601SBarry Smith typedef double PetscScalar;
179ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
180014dd563SJed Brown PETSC_EXTERN MPI_Datatype MPIU___FLOAT128;
181c90a1750SBarry Smith #define MPIU_SCALAR MPIU___FLOAT128
1820d0cc1b5SBarry Smith typedef __float128 PetscScalar;
183ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL_* */
184329f5518SBarry Smith #define PetscRealPart(a)      (a)
185c1d390e3SJed Brown #define PetscImaginaryPart(a) ((PetscReal)0.)
186c1d390e3SJed Brown PETSC_STATIC_INLINE PetscReal PetscAbsScalar(PetscScalar a) {return a < 0.0 ? -a : a;}
187e489efc1SBarry Smith #define PetscConj(a)          (a)
188ce63c4c1SBarry Smith #if !defined(PETSC_USE_REAL___FLOAT128)
18918a7d68fSSatish Balay #define PetscSqrtScalar(a)    sqrt(a)
190184914b5SBarry Smith #define PetscPowScalar(a,b)   pow(a,b)
191184914b5SBarry Smith #define PetscExpScalar(a)     exp(a)
19206c1185fSBarry Smith #define PetscLogScalar(a)     log(a)
193184914b5SBarry Smith #define PetscSinScalar(a)     sin(a)
194184914b5SBarry Smith #define PetscCosScalar(a)     cos(a)
195ce63c4c1SBarry Smith #else /* PETSC_USE_REAL___FLOAT128 */
1960d0cc1b5SBarry Smith #define PetscSqrtScalar(a)    sqrtq(a)
1970d0cc1b5SBarry Smith #define PetscPowScalar(a,b)   powq(a,b)
1980d0cc1b5SBarry Smith #define PetscExpScalar(a)     expq(a)
1990d0cc1b5SBarry Smith #define PetscLogScalar(a)     logq(a)
2000d0cc1b5SBarry Smith #define PetscSinScalar(a)     sinq(a)
2010d0cc1b5SBarry Smith #define PetscCosScalar(a)     cosq(a)
202ce63c4c1SBarry Smith #endif /* PETSC_USE_REAL___FLOAT128 */
203b0a32e0cSBarry Smith 
2041b65fc54SMatthew G Knepley #endif /* PETSC_USE_COMPLEX */
205e489efc1SBarry Smith 
206da9b6338SBarry Smith #define PetscSign(a) (((a) >= 0) ? ((a) == 0 ? 0 : 1) : -1)
20726aa1773SMatthew Knepley #define PetscAbs(a)  (((a) >= 0) ? (a) : -(a))
2083f1db9ecSBarry Smith 
209314da920SBarry Smith /* --------------------------------------------------------------------------*/
210314da920SBarry Smith 
211e489efc1SBarry Smith /*
212f22f69f0SBarry Smith    Certain objects may be created using either single or double precision.
213f22f69f0SBarry Smith    This is currently not used.
214e489efc1SBarry Smith */
215557d4da8SBarry Smith typedef enum { PETSC_SCALAR_DOUBLE,PETSC_SCALAR_SINGLE, PETSC_SCALAR_LONG_DOUBLE } PetscScalarPrecision;
216e489efc1SBarry Smith 
21750f81f78SJed Brown #if defined(PETSC_HAVE_COMPLEX)
218e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */
21950f81f78SJed Brown PETSC_EXTERN PetscComplex PETSC_i;
22050f81f78SJed Brown #endif
221e489efc1SBarry Smith 
222b6a5bde7SBarry Smith /*MC
223b6a5bde7SBarry Smith    PetscMin - Returns minimum of two numbers
224b6a5bde7SBarry Smith 
225eca87e8dSBarry Smith    Synopsis:
226eca87e8dSBarry Smith    type PetscMin(type v1,type v2)
227eca87e8dSBarry Smith 
228eca87e8dSBarry Smith    Not Collective
229eca87e8dSBarry Smith 
230b6a5bde7SBarry Smith    Input Parameter:
231b6a5bde7SBarry Smith +  v1 - first value to find minimum of
232b6a5bde7SBarry Smith -  v2 - second value to find minimum of
233b6a5bde7SBarry Smith 
234b6a5bde7SBarry Smith 
235b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
236b6a5bde7SBarry Smith 
237b6a5bde7SBarry Smith    Level: beginner
238b6a5bde7SBarry Smith 
239b6a5bde7SBarry Smith 
240d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
241b6a5bde7SBarry Smith 
242b6a5bde7SBarry Smith M*/
243e489efc1SBarry Smith #define PetscMin(a,b)   (((a)<(b)) ?  (a) : (b))
244b6a5bde7SBarry Smith 
245b6a5bde7SBarry Smith /*MC
246b6a5bde7SBarry Smith    PetscMax - Returns maxium of two numbers
247b6a5bde7SBarry Smith 
248eca87e8dSBarry Smith    Synopsis:
249eca87e8dSBarry Smith    type max PetscMax(type v1,type v2)
250eca87e8dSBarry Smith 
251eca87e8dSBarry Smith    Not Collective
252eca87e8dSBarry Smith 
253b6a5bde7SBarry Smith    Input Parameter:
254b6a5bde7SBarry Smith +  v1 - first value to find maximum of
255b6a5bde7SBarry Smith -  v2 - second value to find maximum of
256b6a5bde7SBarry Smith 
257b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
258b6a5bde7SBarry Smith 
259b6a5bde7SBarry Smith    Level: beginner
260b6a5bde7SBarry Smith 
261d9a4bb16SJed Brown .seealso: PetscMin(), PetscClipInterval(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
262b6a5bde7SBarry Smith 
263b6a5bde7SBarry Smith M*/
264e489efc1SBarry Smith #define PetscMax(a,b)   (((a)<(b)) ?  (b) : (a))
265b6a5bde7SBarry Smith 
266b6a5bde7SBarry Smith /*MC
267d9a4bb16SJed Brown    PetscClipInterval - Returns a number clipped to be within an interval
268d9a4bb16SJed Brown 
269d9a4bb16SJed Brown    Synopsis:
270d9a4bb16SJed Brown    type clip PetscClipInterval(type x,type a,type b)
271d9a4bb16SJed Brown 
272d9a4bb16SJed Brown    Not Collective
273d9a4bb16SJed Brown 
274d9a4bb16SJed Brown    Input Parameter:
275d9a4bb16SJed Brown +  x - value to use if within interval (a,b)
276d9a4bb16SJed Brown .  a - lower end of interval
277d9a4bb16SJed Brown -  b - upper end of interval
278d9a4bb16SJed Brown 
279d9a4bb16SJed Brown    Notes: type can be integer or floating point value
280d9a4bb16SJed Brown 
281d9a4bb16SJed Brown    Level: beginner
282d9a4bb16SJed Brown 
283d9a4bb16SJed Brown .seealso: PetscMin(), PetscMax(), PetscAbsInt(), PetscAbsReal(), PetscSqr()
284d9a4bb16SJed Brown 
285d9a4bb16SJed Brown M*/
286d9a4bb16SJed Brown #define PetscClipInterval(x,a,b)   (PetscMax((a),PetscMin((x),(b))))
287d9a4bb16SJed Brown 
288d9a4bb16SJed Brown /*MC
289b6a5bde7SBarry Smith    PetscAbsInt - Returns the absolute value of an integer
290b6a5bde7SBarry Smith 
291b6a5bde7SBarry Smith    Synopsis:
292b6a5bde7SBarry Smith    int abs PetscAbsInt(int v1)
293b6a5bde7SBarry Smith 
294eca87e8dSBarry Smith    Not Collective
295eca87e8dSBarry Smith 
296eca87e8dSBarry Smith    Input Parameter:
297eca87e8dSBarry Smith .   v1 - the integer
298b6a5bde7SBarry Smith 
299b6a5bde7SBarry Smith    Level: beginner
300b6a5bde7SBarry Smith 
301b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsReal(), PetscSqr()
302b6a5bde7SBarry Smith 
303b6a5bde7SBarry Smith M*/
304e489efc1SBarry Smith #define PetscAbsInt(a)  (((a)<0)   ? -(a) : (a))
305b6a5bde7SBarry Smith 
306b6a5bde7SBarry Smith /*MC
307b6a5bde7SBarry Smith    PetscAbsReal - Returns the absolute value of an real number
308b6a5bde7SBarry Smith 
309eca87e8dSBarry Smith    Synopsis:
310eca87e8dSBarry Smith    Real abs PetscAbsReal(PetscReal v1)
311eca87e8dSBarry Smith 
312eca87e8dSBarry Smith    Not Collective
313eca87e8dSBarry Smith 
314b6a5bde7SBarry Smith    Input Parameter:
315b6a5bde7SBarry Smith .   v1 - the double
316b6a5bde7SBarry Smith 
317b6a5bde7SBarry Smith 
318b6a5bde7SBarry Smith    Level: beginner
319b6a5bde7SBarry Smith 
320b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscSqr()
321b6a5bde7SBarry Smith 
322b6a5bde7SBarry Smith M*/
323f6275e2eSBarry Smith #define PetscAbsReal(a) (((a)<0)   ? -(a) : (a))
324b6a5bde7SBarry Smith 
325b6a5bde7SBarry Smith /*MC
326b6a5bde7SBarry Smith    PetscSqr - Returns the square of a number
327b6a5bde7SBarry Smith 
328b6a5bde7SBarry Smith    Synopsis:
329b6a5bde7SBarry Smith    type sqr PetscSqr(type v1)
330b6a5bde7SBarry Smith 
331eca87e8dSBarry Smith    Not Collective
332eca87e8dSBarry Smith 
333eca87e8dSBarry Smith    Input Parameter:
334eca87e8dSBarry Smith .   v1 - the value
335eca87e8dSBarry Smith 
336b6a5bde7SBarry Smith    Notes: type can be integer or floating point value
337b6a5bde7SBarry Smith 
338b6a5bde7SBarry Smith    Level: beginner
339b6a5bde7SBarry Smith 
340b6a5bde7SBarry Smith .seealso: PetscMax(), PetscMin(), PetscAbsInt(), PetscAbsReal()
341b6a5bde7SBarry Smith 
342b6a5bde7SBarry Smith M*/
3434ebda54eSMatthew Knepley #define PetscSqr(a)     ((a)*(a))
344e489efc1SBarry Smith 
345314da920SBarry Smith /* ----------------------------------------------------------------------------*/
346314da920SBarry Smith /*
347d34fcf5fSBarry Smith      Basic constants
348314da920SBarry Smith */
349ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128)
350d34fcf5fSBarry Smith #define PETSC_PI                 M_PIq
351d34fcf5fSBarry Smith #elif defined(M_PI)
352d34fcf5fSBarry Smith #define PETSC_PI                 M_PI
353d34fcf5fSBarry Smith #else
354faa6e9b0SMatthew G Knepley #define PETSC_PI                 3.14159265358979323846264338327950288419716939937510582
355d34fcf5fSBarry Smith #endif
356d34fcf5fSBarry Smith 
357ab824b78SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
35871fd2e92SBarry Smith #define PETSC_MAX_INT            2147483647
359ab824b78SBarry Smith #define PETSC_MIN_INT            (-PETSC_MAX_INT - 1)
360ab824b78SBarry Smith #else
361ab824b78SBarry Smith #define PETSC_MAX_INT            9223372036854775807L
362ab824b78SBarry Smith #define PETSC_MIN_INT            (-PETSC_MAX_INT - 1)
363ab824b78SBarry Smith #endif
364e489efc1SBarry Smith 
365ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
366ab824b78SBarry Smith #  define PETSC_MAX_REAL                3.40282346638528860e+38F
367ea345e14SBarry Smith #  define PETSC_MIN_REAL                -PETSC_MAX_REAL
36882a7e548SBarry Smith #  define PETSC_MACHINE_EPSILON         1.19209290e-07F
36982a7e548SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    3.45266983e-04F
370cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-5
371ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
372ab824b78SBarry Smith #  define PETSC_MAX_REAL                1.7976931348623157e+308
373ea345e14SBarry Smith #  define PETSC_MIN_REAL                -PETSC_MAX_REAL
37482a7e548SBarry Smith #  define PETSC_MACHINE_EPSILON         2.2204460492503131e-16
37582a7e548SBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1.490116119384766e-08
376cf6e855fSSatish Balay #  define PETSC_SMALL                   1.e-10
377ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
378ea345e14SBarry Smith #  define PETSC_MAX_REAL                FLT128_MAX
379ce63c4c1SBarry Smith #  define PETSC_MIN_REAL                -FLT128_MAX
380d34fcf5fSBarry Smith #  define PETSC_MACHINE_EPSILON         FLT128_EPSILON
381d34fcf5fSBarry Smith #  define PETSC_SQRT_MACHINE_EPSILON    1.38777878078e-17
382d34fcf5fSBarry Smith #  define PETSC_SMALL                   1.e-20
38382adfdadSBarry Smith #endif
38482adfdadSBarry Smith 
3859cf09972SJed Brown #if defined PETSC_HAVE_ADIC
3869cf09972SJed Brown /* Use MPI_Allreduce when ADIC is not available. */
387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMax(MPI_Comm, const PetscReal*,PetscReal*);
388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalMin(MPI_Comm, const PetscReal*,PetscReal*);
389014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGlobalSum(MPI_Comm, const PetscScalar*,PetscScalar*);
3909cf09972SJed Brown #endif
3913e523bebSBarry Smith 
392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanScalar(PetscScalar);
393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIsInfOrNanReal(PetscReal);
3949a25a3ccSBarry Smith 
395314da920SBarry 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 
408e489efc1SBarry Smith #endif
409