Dune Core Modules (2.6.0)

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 
13 namespace Dune
14 {
15 
23  template< class Field >
25 
36  template< class T >
38  {
39  static const T e ()
40  {
41  using std::exp;
42  static const T e = exp( T( 1 ) );
43  return e;
44  }
45 
46  static const T pi ()
47  {
48  using std::acos;
49  static const T pi = acos( T( -1 ) );
50  return pi;
51  }
52  };
53 
54 
55 #ifndef DOXYGEN
56  // MathematicalConstants for float
57  // -------------------------------
58 
59  template<>
60  struct MathematicalConstants< float >
61  : public StandardMathematicalConstants< float >
62  {};
63 
64 
65 
66  // MathematicalConstants for double
67  // --------------------------------
68 
69  template<>
70  struct MathematicalConstants< double >
71  : public StandardMathematicalConstants< double >
72  {};
73 
74 
75 
76  // MathematicalConstants for long double
77  // -------------------------------------
78 
79  template<>
80  struct MathematicalConstants< long double >
81  : public StandardMathematicalConstants< long double >
82  {};
83 #endif // DOXYGEN
84 
85 
87  template <int m>
88  struct Factorial
89  {
91  enum { factorial = m * Factorial<m-1>::factorial };
92  };
93 
95  template <>
96  struct Factorial<0>
97  {
98  // 0! = 1
99  enum { factorial = 1 };
100  };
101 
103  // conjugate complex does nothing for non-complex types
104  template<class K>
105  inline K conjugateComplex (const K& x)
106  {
107  return x;
108  }
109 
110 #ifndef DOXYGEN
111  // specialization for complex
112  template<class K>
113  inline std::complex<K> conjugateComplex (const std::complex<K>& c)
114  {
115  return std::complex<K>(c.real(),-c.imag());
116  }
117 #endif
118 
120  template <class T>
121  int sign(const T& val)
122  {
123  return (val < 0 ? -1 : 1);
124  }
125 
126 }
127 
128 #endif // #ifndef DUNE_MATH_HH
Dune namespace.
Definition: alignedallocator.hh:10
int sign(const T &val)
Return the sign of the value.
Definition: math.hh:121
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:105
Calculates the factorial of m at compile time.
Definition: math.hh:89
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.80.0 (Apr 27, 22:29, 2024)