IT++ Logo
cfix.h
Go to the documentation of this file.
1 
29 #ifndef CFIX_H
30 #define CFIX_H
31 
32 #include <itpp/fixed/fix.h>
33 #include <itpp/itexports.h>
34 
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 CFix : public Fix_Base
52 {
53  template<int, e_mode, o_mode, q_mode> friend class CFixed;
54 public:
56  CFix(double r = 0.0, double i = 0.0, int s = 0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
57  : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(r)), im(scale_and_apply_modes(i)) {}
59  CFix(std::complex<double> x, double, int s = 0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
60  : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(std::real(x))), im(scale_and_apply_modes(std::imag(x))) {}
62  explicit CFix(const Fix_Factory &f)
63  : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {}
65  CFix(fixrep r, fixrep i, int s, int, int)
66  : Fix_Base(s), re(r), im(i) {}
68  CFix(const Fix &r, const Fix &i = 0.0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
69  : Fix_Base(assert_shifts(r, i), w, e, o, q, ptr), re(r.re), im(i.re) {}
71  CFix(const CFix &x, double, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
72  : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re), im(x.im) {}
74  virtual ~CFix() {}
75 
77  CFix& operator=(const CFix &x);
79  CFix& operator=(const Fix &x);
81  CFix& operator=(const std::complex<double> &x);
83  CFix& operator=(const int x);
85  CFix& operator+=(const CFix &x);
87  CFix& operator+=(const Fix &x);
89  CFix& operator+=(const int x);
91  CFix& operator-=(const CFix &x);
93  CFix& operator-=(const Fix &x);
95  CFix& operator-=(const int x);
97  CFix& operator*=(const CFix &x);
99  CFix& operator*=(const Fix &x);
101  CFix& operator*=(const int x);
103  CFix& operator/=(const CFix &x);
105  CFix& operator/=(const Fix &x);
107  CFix& operator/=(const int x);
109  CFix operator-() const;
111  CFix& operator<<=(const int n);
113  CFix& operator>>=(const int n);
114 
116  void set(double real, double imag, int n);
118  void set(double real, double imag, int n, q_mode q);
120  void set(const std::complex<double> &x, int n);
122  void set(const std::complex<double> &x, int n, q_mode q);
124  void set_re(fixrep x) {re = apply_o_mode(x);}
126  void set_im(fixrep x) {im = apply_o_mode(x);}
127 
129  void lshift(int n);
131  void rshift(int n);
133  void rshift(int n, q_mode q);
134 
136  virtual void print() const;
138  fixrep get_re() const {return re;}
140  fixrep get_im() const {return im;}
142  std::complex<double> unfix() const;
143 
144 #ifndef NO_IMPLICIT_FIX_CONVERSION
145 
146  operator std::complex<double>() const {
147  it_assert_debug(shift >= -63 && shift <= 64, "CFix::operator complex<double>: Illegal shift!");
148  return std::complex<double>(double(re)*DOUBLE_POW2[64 - shift],
149  double(im)*DOUBLE_POW2[64 - shift]);
150  }
151 #endif
152 
154  friend ITPP_EXPORT int assert_shifts(const CFix &x, const CFix &y);
156  friend ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
158  friend ITPP_EXPORT int assert_shifts(const CFix &x, int y);
159 
160 protected:
163 };
164 
166 ITPP_EXPORT int assert_shifts(const CFix &x, const CFix &y);
168 ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
170 ITPP_EXPORT int assert_shifts(const CFix &x, int y);
171 
173 ITPP_EXPORT std::istream &operator>>(std::istream &is, CFix &x);
175 ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const CFix &x);
176 
181 
182 // Specialization of template definition in vec.cpp
183 template<> void cfixvec::set(const char *values);
184 // Specialization of template definition in mat.cpp
185 template<> void cfixmat::set(const char *values);
186 
188 
189 } // namespace itpp
190 
191 #endif // #ifndef CFIX_H
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:24 for IT++ by Doxygen 1.8.2