From e25630f3d214896c515b914f68a51f2d2bca23d1 Mon Sep 17 00:00:00 2001
From: Martin Nolte <mnolte@dune-project.org>
Date: Fri, 22 Jan 2010 19:18:08 +0000
Subject: [PATCH] if we move gmp.m4 to dune-common, we should also move
 gmpfield.hh

[[Imported from SVN: r5853]]
---
 dune/common/Makefile.am |  3 +-
 dune/common/gmpfield.hh | 95 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 dune/common/gmpfield.hh

diff --git a/dune/common/Makefile.am b/dune/common/Makefile.am
index 24b0d249f..bbb16aa73 100644
--- a/dune/common/Makefile.am
+++ b/dune/common/Makefile.am
@@ -22,7 +22,8 @@ commoninclude_HEADERS = alignment.hh array.hh \
   bartonnackmanifcheck.hh binaryfunctions.hh lru.hh fassign.hh \
   static_assert.hh smallobject.hh version.hh \
   float_cmp.cc float_cmp.hh nullptr.hh \
-  forloop.hh function.hh interfaces.hh
+  forloop.hh function.hh interfaces.hh \
+  gmpfield.hh
 
 if EXPRESSIONTEMPLATES
 commoninclude_HEADERS += exprtmpl.hh exprtmpl/scalar.inc exprtmpl/exprexpr.inc
diff --git a/dune/common/gmpfield.hh b/dune/common/gmpfield.hh
new file mode 100644
index 000000000..5b53ad1fd
--- /dev/null
+++ b/dune/common/gmpfield.hh
@@ -0,0 +1,95 @@
+// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vi: set et ts=4 sw=2 sts=2:
+#ifndef DUNE_GMPFIELD_HH
+#define DUNE_GMPFIELD_HH
+
+#include <iostream>
+
+#if HAVE_GMP
+
+#include <gmpxx.h>
+
+namespace Dune
+{
+
+  template< unsigned int precision >
+  class GMPField
+    : public mpf_class
+  {
+    typedef mpf_class Base;
+
+  public:
+    GMPField ()
+      : Base(0,precision)
+    {}
+
+    template< class T >
+    GMPField ( const T &v )
+      : Base( v,precision )
+    {}
+
+    /*
+       GMPField &operator=(const GMPField &other)
+       {
+       Base(*this) = Base(other);
+       return *this;
+       }
+     */
+  };
+
+
+
+  template< unsigned int precision >
+  inline GMPField< precision >
+  operator+ ( const GMPField< precision > &a, const GMPField< precision > &b )
+  {
+    typedef mpf_class F;
+    return ((const F &)a + (const F &)b);
+  }
+
+  template< unsigned int precision >
+  inline GMPField< precision >
+  operator- ( const GMPField< precision > &a, const GMPField< precision > &b )
+  {
+    typedef mpf_class F;
+    return ((const F &)a - (const F &)b);
+  }
+
+  template< unsigned int precision >
+  inline GMPField< precision >
+  operator- ( const GMPField< precision > &a )
+  {
+    typedef mpf_class F;
+    return -((const F &)a);
+  }
+
+  template< unsigned int precision >
+  inline GMPField< precision >
+  operator* ( const GMPField< precision > &a, const GMPField< precision > &b )
+  {
+    typedef mpf_class F;
+    return ((const F &)a * (const F &)b);
+  }
+
+  template< unsigned int precision >
+  inline GMPField< precision >
+  operator/ ( const GMPField< precision > &a, const GMPField< precision > &b )
+  {
+    typedef mpf_class F;
+    return ((const F &)a / (const F &)b);
+  }
+
+
+
+  template< unsigned int precision >
+  inline std::ostream &
+  operator<< ( std::ostream &out, const GMPField< precision > &value )
+  {
+    return out << value.get_d();
+  }
+
+}
+
+#endif // HAVE_GMP
+
+#endif // #ifndef DUNE_MULTIPRECISION_HH
-- 
GitLab