Dune Core Modules (2.4.1)

math.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_MATH_HH
4#define DUNE_MATH_HH
5
10#include <cmath>
11#include <complex>
12
13namespace Dune
14{
15
23 template< class Field >
25
36 template< class T >
38 {
39 static T e ()
40 {
41 static const T e = std::exp( T( 1 ) );
42 return e;
43 }
44
45 static T pi ()
46 {
47 static const T pi = std::acos( T( -1 ) );
48 return pi;
49 }
50 };
51
52
53#ifndef DOXYGEN
54 // MathematicalConstants for float
55 // -------------------------------
56
57 template<>
58 struct MathematicalConstants< float >
59 : public StandardMathematicalConstants< float >
60 {};
61
62
63
64 // MathematicalConstants for double
65 // --------------------------------
66
67 template<>
68 struct MathematicalConstants< double >
69 : public StandardMathematicalConstants< double >
70 {};
71
72
73
74 // MathematicalConstants for long double
75 // -------------------------------------
76
77 template<>
78 struct MathematicalConstants< long double >
79 : public StandardMathematicalConstants< long double >
80 {};
81#endif // DOXYGEN
82
83
85 template <int m>
86 struct Factorial
87 {
89 enum { factorial = m * Factorial<m-1>::factorial };
90 };
91
93 template <>
94 struct Factorial<0>
95 {
96 // 0! = 1
97 enum { factorial = 1 };
98 };
99
101 // conjugate complex does nothing for non-complex types
102 template<class K>
103 inline K conjugateComplex (const K& x)
104 {
105 return x;
106 }
107
108#ifndef DOXYGEN
109 // specialization for complex
110 template<class K>
111 inline std::complex<K> conjugateComplex (const std::complex<K>& c)
112 {
113 return std::complex<K>(c.real(),-c.imag());
114 }
115#endif
116
118 template <class T>
119 int sign(const T& val)
120 {
121 return (val < 0 ? -1 : 1);
122 }
123
124}
125
126#endif // #ifndef DUNE_MATH_HH
Dune namespace.
Definition: alignment.hh:10
int sign(const T &val)
Return the sign of the value.
Definition: math.hh:119
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
Calculates the factorial of m at compile time.
Definition: math.hh:87
Provides commonly used mathematical constants.
Definition: math.hh:24
Standard implementation of MathematicalConstants.
Definition: math.hh:38
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)