From 47e26527a1f459675220ecc9a3934fcab8833457 Mon Sep 17 00:00:00 2001 From: Martin Nolte <mnolte@dune-project.org> Date: Wed, 4 May 2011 10:43:51 +0000 Subject: [PATCH] A first implementation of Mathematical Constants (for discussion) [[Imported from SVN: r6436]] --- dune/common/Makefile.am | 1 + dune/common/math.hh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 dune/common/math.hh diff --git a/dune/common/Makefile.am b/dune/common/Makefile.am index 47698d843..62c9109ab 100644 --- a/dune/common/Makefile.am +++ b/dune/common/Makefile.am @@ -57,6 +57,7 @@ commoninclude_HEADERS = \ iteratorfacades.hh \ lcm.hh \ lru.hh \ + math.hh \ matvectraits.hh \ misc.hh \ mpicollectivecommunication.hh \ diff --git a/dune/common/math.hh b/dune/common/math.hh new file mode 100644 index 000000000..9dd578c18 --- /dev/null +++ b/dune/common/math.hh @@ -0,0 +1,40 @@ +// -*- 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 + +#include <cmath> + +namespace Dune +{ + + template< class Field > + struct MathematicalConstants; + + + + // MathematicalConstants for double + // -------------------------------- + + template<> + struct MathematicalConstants< double > + { + static double e () { return std::exp( 1.0 ); } + static double pi () { return std::acos( -1.0 ); } + }; + + + + // MathematicalConstants for float + // ------------------------------- + + template<> + struct MathematicalConstants< float > + { + static float e () { return std::exp( 1.0f ); } + static float pi () { return std::acos( -1.0f ); } + }; + +} + +#endif // #ifndef DUNE_MATH_HH -- GitLab