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