Developer documentation

rounding_mode_mpfr.hpp
Go to the documentation of this file.
1 /********************************************************************
2  * This file is part of the source code of the realroot library.
3  * Description: rounding mode for Numerix floating type
4  * Author(s): G.M. Tzoumas, NKU Athens
5  ********************************************************************/
6 #ifndef realroot_MPFR_ROUNDING_MODE_HPP
7 #define realroot_MPFR_ROUNDING_MODE_HPP
8 //--------------------------------------------------------------------
9 
10 #include <numerix/floating.hpp>
11 #include <mpfr.h>
13 //--------------------------------------------------------------------
14 namespace mmx {
15 //--------------------------------------------------------------------
16 namespace numerics
17 {
18  template<> struct LongVersion<floating<> > { typedef floating<> result_t; };
19  template<> struct fpu_rounding<floating<> >
20  {
21  typedef mpfr_rnd_t rnd_t;
22  inline static rnd_t getrnd() { return mmx_rounding_mode; };
23  inline static void setrnd( rnd_t r ) { mmx_rounding_mode = r; };
24  inline static rnd_t rnd_up() { return GMP_RNDU;};
25  inline static rnd_t rnd_dw() { return GMP_RNDD;};
26  inline static rnd_t rnd_nr() { return GMP_RNDN;};
27  inline static rnd_t rnd_z() { return GMP_RNDZ;};
28  static const int id = 123; // george: what's this?
29 
30  private:
31  rnd_t m_prev;
32  bool m_chg;
33  public:
34 
35  fpu_rounding( rnd_t rnd )
36  {
37  m_chg = false;
38  m_prev = getrnd();
39 
40  if ( m_prev != rnd )
41  {
42  m_chg = true;
43  setrnd(rnd);
44  };
45  };
47  if ( m_chg ) setrnd(m_prev);
48  };
49 
50 
51  };
52 
53 }; //namespace numerics
54 //======================================================================
55 } //namespace mmx
56 //======================================================================
57 #endif
static rnd_t rnd_nr()
Definition: rounding_mode_mpfr.hpp:26
static void setrnd(rnd_t r)
Definition: rounding_mode.hpp:35
static rnd_t rnd_dw()
Definition: rounding_mode_mpfr.hpp:25
static rnd_t getrnd()
Definition: rounding_mode_mpfr.hpp:22
Definition: rounding_mode.hpp:28
static rnd_t rnd_up()
Definition: rounding_mode_mpfr.hpp:24
~fpu_rounding()
Definition: rounding_mode_mpfr.hpp:46
static void setrnd(rnd_t r)
Definition: rounding_mode_mpfr.hpp:23
static rnd_t getrnd()
Definition: rounding_mode.hpp:34
floating result_t
Definition: rounding_mode_mpfr.hpp:18
Definition: rounding_mode.hpp:31
static rnd_t rnd_z()
Definition: rounding_mode_mpfr.hpp:27
mpfr_rnd_t rnd_t
Definition: rounding_mode_mpfr.hpp:21
Definition: array.hpp:12
fpu_rounding(rnd_t rnd)
Definition: rounding_mode_mpfr.hpp:35
Home