xref: /petsc/include/petscmath.h (revision 314da920dddea2a1b0ac7751fbf5bde644db819e)
1 /* $Id: petscmath.h,v 1.1 1997/08/29 20:00:06 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     Defines operations that are different for complex and real numbers
16 */
17 #if defined(PETSC_COMPLEX)
18 #if defined(HAVE_NONSTANDARD_COMPLEX_H)
19 #include HAVE_NONSTANDARD_COMPLEX_H
20 #else
21 #include <complex.h>
22 #endif
23 extern  MPI_Datatype      MPIU_COMPLEX;
24 #define MPIU_SCALAR       MPIU_COMPLEX
25 #define PetscReal(a)      real(a)
26 #define PetscImaginary(a) imag(a)
27 #define PetscAbsScalar(a) abs(a)
28 #define PetscConj(a)      conj(a)
29 /*
30   The new complex class for GNU C++ is based on templates and is not backward
31   compatible with all previous complex class libraries.
32 */
33 #if defined(USES_TEMPLATED_COMPLEX)
34 #define Scalar            complex<double>
35 #else
36 #define Scalar            complex
37 #endif
38 
39 /* Compiling for real numbers only */
40 #else
41 #define MPIU_SCALAR       MPI_DOUBLE
42 #define PetscReal(a)      (a)
43 #define PetscImaginary(a) (a)
44 #define PetscAbsScalar(a) ( ((a)<0.0)   ? -(a) : (a) )
45 #define Scalar            double
46 #define PetscConj(a)      (a)
47 #endif
48 
49 /* --------------------------------------------------------------------------*/
50 
51 /*
52    Certain objects may be created using either single
53   or double precision.
54 */
55 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision;
56 
57 /* PETSC_i is the imaginary number, i */
58 extern  Scalar            PETSC_i;
59 
60 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
61 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
62 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
63 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
64 
65 /* ----------------------------------------------------------------------------*/
66 /*
67      Basic constants
68 */
69 #define PETSC_PI                 3.14159265358979323846264
70 #define PETSC_DEGREES_TO_RADIANS 0.01745329251994
71 #define PETSC_MAX                1.e300
72 #define PETSC_MIN                -1.e300
73 
74 /* ----------------------------------------------------------------------------*/
75 /*
76     PLogDouble variables are used to contain double precision numbers
77   that are not used in the numerical computations, but rather in logging,
78   timing etc.
79 */
80 typedef double PLogDouble;
81 /*
82       Once PETSc is compiling with a ADIC enhanced version of MPI
83    we will create a new MPI_Datatype for the inactive double variables.
84 */
85 #if defined(AD_DERIV_H)
86 /* extern  MPI_Datatype  MPIU_PLOGDOUBLE; */
87 #else
88 #if !defined(PETSC_USING_MPIUNI)
89 #define MPIU_PLOGDOUBLE MPI_DOUBLE
90 #endif
91 #endif
92 
93 
94 #endif
95