xref: /petsc/include/petscmath.h (revision 0752156a28ac8f8e9dfaef7ce98457a01bf27fb6)
1 /* $Id: petscmath.h,v 1.2 1997/08/29 20:31:53 bsmith Exp bsmith $ */
2 /*
3 
4       PETSc mathematics include file. Defines certain basic mathematical
5     constants and functions for working with single and double precision
6     floating point numbers as well as complex and integers.
7 
8 */
9 #if !defined(__PETSCMATH_PACKAGE)
10 #define __PETSCMAT_PACKAGE
11 
12 #include "petsc.h"
13 
14 /*
15 
16      Defines operations that are different for complex and real numbers;
17    note that one cannot really mix the use of complex and real in the same
18    PETSc program. All PETSc objects in one program are built around the object
19    Scalar which is either always a double or a complex.
20 
21 */
22 #if defined(PETSC_COMPLEX)
23 #if defined(HAVE_NONSTANDARD_COMPLEX_H)
24 #include HAVE_NONSTANDARD_COMPLEX_H
25 #else
26 #include <complex.h>
27 #endif
28 extern  MPI_Datatype      MPIU_COMPLEX;
29 #define MPIU_SCALAR       MPIU_COMPLEX
30 #define PetscReal(a)      real(a)
31 #define PetscImaginary(a) imag(a)
32 #define PetscAbsScalar(a) abs(a)
33 #define PetscConj(a)      conj(a)
34 /*
35   The new complex class for GNU C++ is based on templates and is not backward
36   compatible with all previous complex class libraries.
37 */
38 #if defined(USES_TEMPLATED_COMPLEX)
39 #define Scalar            complex<double>
40 #else
41 #define Scalar            complex
42 #endif
43 
44 /* Compiling for real numbers only */
45 #else
46 #define MPIU_SCALAR       MPI_DOUBLE
47 #define PetscReal(a)      (a)
48 #define PetscImaginary(a) (a)
49 #define PetscAbsScalar(a) ( ((a)<0.0)   ? -(a) : (a) )
50 #define Scalar            double
51 #define PetscConj(a)      (a)
52 #endif
53 
54 /* --------------------------------------------------------------------------*/
55 
56 /*
57    Certain objects may be created using either single
58   or double precision.
59 */
60 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision;
61 
62 /* PETSC_i is the imaginary number, i */
63 extern  Scalar            PETSC_i;
64 
65 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
66 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
67 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
68 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
69 
70 /* ----------------------------------------------------------------------------*/
71 /*
72      Basic constants
73 */
74 #define PETSC_PI                 3.14159265358979323846264
75 #define PETSC_DEGREES_TO_RADIANS 0.01745329251994
76 #define PETSC_MAX                1.e300
77 #define PETSC_MIN                -1.e300
78 
79 /* ----------------------------------------------------------------------------*/
80 /*
81     PLogDouble variables are used to contain double precision numbers
82   that are not used in the numerical computations, but rather in logging,
83   timing etc.
84 */
85 typedef double PLogDouble;
86 /*
87       Once PETSc is compiling with a ADIC enhanced version of MPI
88    we will create a new MPI_Datatype for the inactive double variables.
89 */
90 #if defined(AD_DERIV_H)
91 /* extern  MPI_Datatype  MPIU_PLOGDOUBLE; */
92 #else
93 #if !defined(PETSC_USING_MPIUNI)
94 #define MPIU_PLOGDOUBLE MPI_DOUBLE
95 #endif
96 #endif
97 
98 
99 #endif
100