/usr/include/dune/common/math.hh is in libdune-common-dev 2.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MATH_HH
#define DUNE_MATH_HH
/** \file
* \brief Some useful basic math stuff
*/
#include <cmath>
#include <complex>
namespace Dune
{
/**
\brief Provides commonly used mathematical constants.
a struct that is specialized for types repesenting real or complex
numbers. I provides commonly used mathematical constants with the
required accuary for the specified type.
*/
template< class Field >
struct MathematicalConstants;
/**
\brief Standard implementation of MathematicalConstants.
This implementation will work with all built-in floating point
types. It provides
* e as std::exp(1.0)
* pi as std::acos(-1.0)
*/
template< class T >
struct StandardMathematicalConstants
{
static T e ()
{
static const T e = std::exp( T( 1 ) );
return e;
}
static T pi ()
{
static const T pi = std::acos( T( -1 ) );
return pi;
}
};
#ifndef DOXYGEN
// MathematicalConstants for float
// -------------------------------
template<>
struct MathematicalConstants< float >
: public StandardMathematicalConstants< float >
{};
// MathematicalConstants for double
// --------------------------------
template<>
struct MathematicalConstants< double >
: public StandardMathematicalConstants< double >
{};
// MathematicalConstants for long double
// -------------------------------------
template<>
struct MathematicalConstants< long double >
: public StandardMathematicalConstants< long double >
{};
#endif // DOXYGEN
//! Calculates the factorial of m at compile time
template <int m>
struct Factorial
{
//! factorial stores m!
enum { factorial = m * Factorial<m-1>::factorial };
};
//! end of recursion of factorial via specialization
template <>
struct Factorial<0>
{
// 0! = 1
enum { factorial = 1 };
};
//! compute conjugate complex of x
// conjugate complex does nothing for non-complex types
template<class K>
inline K conjugateComplex (const K& x)
{
return x;
}
#ifndef DOXYGEN
// specialization for complex
template<class K>
inline std::complex<K> conjugateComplex (const std::complex<K>& c)
{
return std::complex<K>(c.real(),-c.imag());
}
#endif
//! Return the sign of the value
template <class T>
int sign(const T& val)
{
return (val < 0 ? -1 : 1);
}
}
#endif // #ifndef DUNE_MATH_HH
|