realroot_doc 0.1.1
|
00001 /******************************************************************** 00002 * This file is part of the source code of the realroot library. 00003 * Description: rounding mode for Numerix floating type 00004 * Author(s): G.M. Tzoumas, NKU Athens 00005 ********************************************************************/ 00006 #ifndef realroot_MPFR_ROUNDING_MODE_HPP 00007 #define realroot_MPFR_ROUNDING_MODE_HPP 00008 //-------------------------------------------------------------------- 00009 00010 #include <numerix/floating.hpp> 00011 #include <mpfr.h> 00012 #include <realroot/rounding_mode.hpp> 00013 //-------------------------------------------------------------------- 00014 namespace mmx { 00015 //-------------------------------------------------------------------- 00016 namespace numerics 00017 { 00018 template<> struct LongVersion<floating<> > { typedef floating<> result_t; }; 00019 template<> struct fpu_rounding<floating<> > 00020 { 00021 typedef mpfr_rnd_t rnd_t; 00022 inline static rnd_t getrnd() { return mmx_rounding_mode; }; 00023 inline static void setrnd( rnd_t r ) { mmx_rounding_mode = r; }; 00024 inline static rnd_t rnd_up() { return GMP_RNDU;}; 00025 inline static rnd_t rnd_dw() { return GMP_RNDD;}; 00026 inline static rnd_t rnd_nr() { return GMP_RNDN;}; 00027 inline static rnd_t rnd_z() { return GMP_RNDZ;}; 00028 static const int id = 123; // george: what's this? 00029 00030 private: 00031 rnd_t m_prev; 00032 bool m_chg; 00033 public: 00034 00035 fpu_rounding( rnd_t rnd ) 00036 { 00037 m_chg = false; 00038 m_prev = getrnd(); 00039 00040 if ( m_prev != rnd ) 00041 { 00042 m_chg = true; 00043 setrnd(rnd); 00044 }; 00045 }; 00046 ~fpu_rounding() { 00047 if ( m_chg ) setrnd(m_prev); 00048 }; 00049 00050 00051 }; 00052 00053 }; //namespace numerics 00054 //====================================================================== 00055 } //namespace mmx 00056 //====================================================================== 00057 #endif