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