gmpfield.hh
Go to the documentation of this file.00001 #ifndef DUNE_GMPFIELD_HH
00002 #define DUNE_GMPFIELD_HH
00003
00004 #include <iostream>
00005
00006 #if HAVE_GMP
00007
00008 #include <gmpxx.h>
00009
00010 namespace Dune
00011 {
00012
00013 template< unsigned int precision >
00014 class GMPField
00015 : public mpf_class
00016 {
00017 typedef mpf_class Base;
00018
00019 public:
00020 GMPField ()
00021 : Base(0,precision)
00022 {}
00023
00024 template< class T >
00025 GMPField ( const T &v )
00026 : Base( v,precision )
00027 {}
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 operator double () const
00039 {
00040 return this->get_d();
00041 }
00042
00043 operator float () const
00044 {
00045 return this->get_d();
00046 }
00047
00048 operator mpf_class () const
00049 {
00050 return static_cast<const mpf_class&>(*this);
00051 }
00052 };
00053
00054
00055
00056 template< unsigned int precision >
00057 inline GMPField< precision >
00058 operator+ ( const GMPField< precision > &a, const GMPField< precision > &b )
00059 {
00060 typedef mpf_class F;
00061 return ((const F &)a + (const F &)b);
00062 }
00063
00064 template< unsigned int precision >
00065 inline GMPField< precision >
00066 operator- ( const GMPField< precision > &a, const GMPField< precision > &b )
00067 {
00068 typedef mpf_class F;
00069 return ((const F &)a - (const F &)b);
00070 }
00071
00072 template< unsigned int precision >
00073 inline GMPField< precision >
00074 operator- ( const GMPField< precision > &a )
00075 {
00076 typedef mpf_class F;
00077 return -((const F &)a);
00078 }
00079
00080 template< unsigned int precision >
00081 inline GMPField< precision >
00082 operator* ( const GMPField< precision > &a, const GMPField< precision > &b )
00083 {
00084 typedef mpf_class F;
00085 return ((const F &)a * (const F &)b);
00086 }
00087
00088 template< unsigned int precision >
00089 inline GMPField< precision >
00090 operator/ ( const GMPField< precision > &a, const GMPField< precision > &b )
00091 {
00092 typedef mpf_class F;
00093 return ((const F &)a / (const F &)b);
00094 }
00095
00096
00097
00098 template< unsigned int precision >
00099 inline std::ostream &
00100 operator<< ( std::ostream &out, const GMPField< precision > &value )
00101 {
00102 return out << static_cast<const mpf_class&>(value);
00103 }
00104
00105 }
00106
00107 namespace std
00108 {
00109
00110 template< unsigned int precision >
00111 inline Dune::GMPField< precision >
00112 sqrt ( const Dune::GMPField< precision > &a )
00113 {
00114 return Dune::GMPField< precision >(sqrt(static_cast<const mpf_class&>(a)));
00115 }
00116
00117 template< unsigned int precision >
00118 inline Dune::GMPField< precision >
00119 abs ( const Dune::GMPField< precision > &a )
00120 {
00121 return Dune::GMPField< precision >( abs( static_cast< const mpf_class & >( a ) ) );
00122 }
00123
00124 }
00125
00126 #endif // HAVE_GMP
00127
00128 #endif // #ifndef DUNE_GMPFIELD_HH