dune-common  2.3.1
gmpfield.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_GMPFIELD_HH
4 #define DUNE_GMPFIELD_HH
5 
10 #include <iostream>
11 
12 #if HAVE_GMP
13 
14 #include <gmpxx.h>
15 
16 namespace Dune
17 {
18 
19  template< unsigned int precision >
20  class GMPField
21  : public mpf_class
22  {
23  typedef mpf_class Base;
24 
25  public:
26  GMPField ()
27  : Base(0,precision)
28  {}
29 
30  template< class T >
31  GMPField ( const T &v )
32  : Base( v,precision )
33  {}
34 
35  /*
36  GMPField &operator=(const GMPField &other)
37  {
38  Base(*this) = Base(other);
39  return *this;
40  }
41  */
42 
43  // type conversion operators
44  operator double () const
45  {
46  return this->get_d();
47  }
48 
49  operator float () const
50  {
51  return this->get_d();
52  }
53  };
54 
55 
56 
57  template< unsigned int precision >
58  inline GMPField< precision >
59  operator+ ( const GMPField< precision > &a, const GMPField< precision > &b )
60  {
61  typedef mpf_class F;
62  return ((const F &)a + (const F &)b);
63  }
64 
65  template< unsigned int precision >
66  inline GMPField< precision >
67  operator- ( const GMPField< precision > &a, const GMPField< precision > &b )
68  {
69  typedef mpf_class F;
70  return ((const F &)a - (const F &)b);
71  }
72 
73  template< unsigned int precision >
74  inline GMPField< precision >
75  operator- ( const GMPField< precision > &a )
76  {
77  typedef mpf_class F;
78  return -((const F &)a);
79  }
80 
81  template< unsigned int precision >
82  inline GMPField< precision >
83  operator* ( const GMPField< precision > &a, const GMPField< precision > &b )
84  {
85  typedef mpf_class F;
86  return ((const F &)a * (const F &)b);
87  }
88 
89  template< unsigned int precision >
90  inline GMPField< precision >
91  operator/ ( const GMPField< precision > &a, const GMPField< precision > &b )
92  {
93  typedef mpf_class F;
94  return ((const F &)a / (const F &)b);
95  }
96 
97 
98 
99  template< unsigned int precision >
100  inline std::ostream &
101  operator<< ( std::ostream &out, const GMPField< precision > &value )
102  {
103  return out << static_cast<const mpf_class&>(value);
104  }
105 
106 }
107 
108 namespace std
109 {
110 
111  template< unsigned int precision >
112  inline Dune::GMPField< precision >
113  sqrt ( const Dune::GMPField< precision > &a )
114  {
115  return Dune::GMPField< precision >(sqrt(static_cast<const mpf_class&>(a)));
116  }
117 
118  template< unsigned int precision >
119  inline Dune::GMPField< precision >
120  abs ( const Dune::GMPField< precision > &a )
121  {
122  return Dune::GMPField< precision >( abs( static_cast< const mpf_class & >( a ) ) );
123  }
124 
125 }
126 
127 #endif // HAVE_GMP
128 
129 #endif // #ifndef DUNE_GMPFIELD_HH
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::size_t y)
Definition: bigunsignedint.hh:485
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::size_t y)
Definition: bigunsignedint.hh:492
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::size_t y)
Definition: bigunsignedint.hh:499
bigunsignedint< k > operator/(const bigunsignedint< k > &x, std::size_t y)
Definition: bigunsignedint.hh:506