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