IT++ Logo
fix.h
Go to the documentation of this file.
1 
29 #ifndef FIX_H
30 #define FIX_H
31 
32 #include <itpp/fixed/fix_base.h>
33 #include <itpp/fixed/fix_factory.h>
34 #include <itpp/itexports.h>
35 
36 namespace itpp
37 {
38 
39 // Forward declarations
40 template<class Num_T> class Vec;
41 template<class Num_T> class Mat;
42 
45 
51 class ITPP_EXPORT Fix : public Fix_Base
52 {
53  friend class CFix;
54  template<int, e_mode, o_mode, q_mode> friend class Fixed;
55  template<int, e_mode, o_mode, q_mode> friend class CFixed;
56 public:
58  Fix(double x = 0.0, int s = 0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
59  : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(x)) {}
61  explicit Fix(const Fix_Factory &f)
62  : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {}
64  Fix(fixrep r, int s, int, int)
65  : Fix_Base(s), re(r) {}
67  Fix(const Fix &x, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
68  : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re) {}
70  virtual ~Fix() {}
71 
73  Fix& operator=(const Fix &x);
75  Fix& operator=(const int x);
77  Fix& operator+=(const Fix &x);
79  Fix& operator+=(const int x);
81  Fix& operator-=(const Fix &x);
83  Fix& operator-=(const int x);
85  Fix& operator*=(const Fix &x);
87  Fix& operator*=(const int x);
89  Fix& operator/=(const Fix &x);
91  Fix& operator/=(const int x);
93  Fix operator-() const;
95  Fix& operator<<=(const int n);
97  Fix& operator>>=(const int n);
98 
100  void set(double x, int n);
102  void set(double x, int n, q_mode q);
104  void set_re(fixrep x) {re = apply_o_mode(x);}
105 
107  void lshift(int n);
109  void rshift(int n);
111  void rshift(int n, q_mode q);
112 
114  virtual void print() const;
116  fixrep get_re() const {return re;}
118  double unfix() const;
119 
120 #ifndef NO_IMPLICIT_FIX_CONVERSION
121 
122  operator double() const {
123  it_assert_debug(shift>=-63 && shift <= 64, "Fix::operator double: Illegal shift!");
124  return double(re)*DOUBLE_POW2[64 - shift];
125  }
126 #endif
127 
129  friend ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
131  friend ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
133  friend ITPP_EXPORT int assert_shifts(const Fix &x, int y);
134 
135 protected:
138 };
139 
141 ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
143 ITPP_EXPORT int assert_shifts(const Fix &x, int y);
144 
146 ITPP_EXPORT std::istream &operator>>(std::istream &is, Fix &x);
148 ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const Fix &x);
149 
151 typedef Vec<Fix> fixvec;
153 typedef Mat<Fix> fixmat;
154 
155 // Specialization of template definition in vec.cpp
156 template<> void fixvec::set(const char *values);
157 // Specialization of template definition in mat.cpp
158 template<> void fixmat::set(const char *values);
159 
161 
162 } // namespace itpp
163 
164 #endif // #ifndef FIX_H
SourceForge Logo

Generated on Sat May 25 2013 16:32:22 for IT++ by Doxygen 1.8.2