00001
00002
00003 #ifndef DUNE_MATH_HH
00004 #define DUNE_MATH_HH
00005
00010 #include <cmath>
00011 #include <complex>
00012
00013 namespace Dune
00014 {
00015
00023 template< class Field >
00024 struct MathematicalConstants;
00025
00036 template< class T >
00037 struct StandardMathematicalConstants
00038 {
00039 static T e ()
00040 {
00041 static const T e = std::exp( T( 1 ) );
00042 return e;
00043 }
00044
00045 static T pi ()
00046 {
00047 static const T pi = std::acos( T( -1 ) );
00048 return pi;
00049 }
00050 };
00051
00052
00053 #ifndef DOXYGEN
00054
00055
00056
00057 template<>
00058 struct MathematicalConstants< float >
00059 : public StandardMathematicalConstants< float >
00060 {};
00061
00062
00063
00064
00065
00066
00067 template<>
00068 struct MathematicalConstants< double >
00069 : public StandardMathematicalConstants< double >
00070 {};
00071
00072
00073
00074
00075
00076
00077 template<>
00078 struct MathematicalConstants< long double >
00079 : public StandardMathematicalConstants< long double >
00080 {};
00081 #endif // DOXYGEN
00082
00083
00085 template <int m>
00086 struct Factorial
00087 {
00089 enum { factorial = m * Factorial<m-1>::factorial };
00090 };
00091
00093 template <>
00094 struct Factorial<0>
00095 {
00096
00097 enum { factorial = 1 };
00098 };
00099
00101
00102 template<class K>
00103 inline K conjugateComplex (const K& x)
00104 {
00105 return x;
00106 }
00107
00108 #ifndef DOXYGEN
00109
00110 template<class K>
00111 inline std::complex<K> conjugateComplex (const std::complex<K>& c)
00112 {
00113 return std::complex<K>(c.real(),-c.imag());
00114 }
00115 #endif
00116
00118 template <class T>
00119 int sign(const T& val)
00120 {
00121 return (val < 0 ? -1 : 1);
00122 }
00123
00124 }
00125
00126 #endif // #ifndef DUNE_MATH_HH