Actual source code: slepcmath.h
1: /*
2: SLEPc mathematics include file. Defines basic operations and functions.
3: This file is included by slepcsys.h and should not be used directly.
5: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6: SLEPc - Scalable Library for Eigenvalue Problem Computations
7: Copyright (c) 2002-2013, Universitat Politecnica de Valencia, Spain
9: This file is part of SLEPc.
11: SLEPc is free software: you can redistribute it and/or modify it under the
12: terms of version 3 of the GNU Lesser General Public License as published by
13: the Free Software Foundation.
15: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
16: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
18: more details.
20: You should have received a copy of the GNU Lesser General Public License
21: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
22: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23: */
28: /*
29: Default tolerance for the different solvers, depending on the precision
30: */
31: #if defined(PETSC_USE_REAL_SINGLE)
32: # define SLEPC_DEFAULT_TOL 1e-6
33: #elif defined(PETSC_USE_REAL_DOUBLE)
34: # define SLEPC_DEFAULT_TOL 1e-8
35: #elif defined(PETSC_USE_REAL___FLOAT128)
36: # define SLEPC_DEFAULT_TOL 1e-16
37: #else
38: # define SLEPC_DEFAULT_TOL 1e-7
39: #endif
41: /*E
42: SlepcFunction - Used to specify a mathematical function
44: Note:
45: Currently available functions:
46: . SLEPC_FUNCTION_EXP - exponential
48: Level: beginner
49: E*/
50: typedef enum { SLEPC_FUNCTION_NONE=0,
51: SLEPC_FUNCTION_EXP,
52: SLEPC_FUNCTION_LAST } SlepcFunction;
54: /*@C
55: SlepcAbs - Returns sqrt(x**2+y**2), taking care not to cause unnecessary
56: overflow. It is based on LAPACK's DLAPY2.
58: Not Collective
60: Input parameters:
61: . x,y - the real numbers
63: Output parameter:
64: . return - the result
66: Note:
67: This function is not available from Fortran.
69: Level: developer
70: @*/
71: PETSC_STATIC_INLINE PetscReal SlepcAbs(PetscReal x,PetscReal y)
72: {
73: PetscReal w,z,t,xabs=PetscAbs(x),yabs=PetscAbs(y);
75: w = PetscMax(xabs,yabs);
76: z = PetscMin(xabs,yabs);
77: if (z == 0.0) return w;
78: t = z/w;
79: return w*PetscSqrtReal(1.0+t*t);
80: }
82: /*MC
83: SlepcAbsEigenvalue - Returns the absolute value of a complex number given
84: its real and imaginary parts.
86: Synopsis:
87: PetscReal SlepcAbsEigenvalue(PetscScalar x,PetscScalar y)
89: Not Collective
91: Input parameters:
92: + x - the real part of the complex number
93: - y - the imaginary part of the complex number
95: Notes:
96: This function computes sqrt(x**2+y**2), taking care not to cause unnecessary
97: overflow. It is based on LAPACK's DLAPY2.
99: This function is not available from Fortran.
101: Level: developer
102: M*/
103: #if !defined(PETSC_USE_COMPLEX)
104: #define SlepcAbsEigenvalue(x,y) SlepcAbs(x,y)
105: #else
106: #define SlepcAbsEigenvalue(x,y) PetscAbsScalar(x)
107: #endif
109: #endif