IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
34 
35 namespace itpp
36 {
37 
38 // Forward declarations
39 template<class Num_T> class Vec;
40 template<class Num_T> class Mat;
41 
44 
50 class CFix : public Fix_Base
51 {
52  template<int, e_mode, o_mode, q_mode> friend class CFixed;
53 public:
55  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)
56  : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(r)), im(scale_and_apply_modes(i)) {}
58  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)
59  : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(std::real(x))), im(scale_and_apply_modes(std::imag(x))) {}
61  explicit CFix(const Fix_Factory &f)
62  : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {}
64  CFix(fixrep r, fixrep i, int s, int, int)
65  : Fix_Base(s), re(r), im(i) {}
67  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)
68  : Fix_Base(assert_shifts(r, i), w, e, o, q, ptr), re(r.re), im(i.re) {}
70  CFix(const CFix &x, double, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
71  : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re), im(x.im) {}
73  virtual ~CFix() {}
74 
76  CFix& operator=(const CFix &x);
78  CFix& operator=(const Fix &x);
80  CFix& operator=(const std::complex<double> &x);
82  CFix& operator=(const int x);
84  CFix& operator+=(const CFix &x);
86  CFix& operator+=(const Fix &x);
88  CFix& operator+=(const int x);
90  CFix& operator-=(const CFix &x);
92  CFix& operator-=(const Fix &x);
94  CFix& operator-=(const int x);
96  CFix& operator*=(const CFix &x);
98  CFix& operator*=(const Fix &x);
100  CFix& operator*=(const int x);
102  CFix& operator/=(const CFix &x);
104  CFix& operator/=(const Fix &x);
106  CFix& operator/=(const int x);
108  CFix operator-() const;
110  CFix& operator<<=(const int n);
112  CFix& operator>>=(const int n);
113 
115  void set(double real, double imag, int n);
117  void set(double real, double imag, int n, q_mode q);
119  void set(const std::complex<double> &x, int n);
121  void set(const std::complex<double> &x, int n, q_mode q);
123  void set_re(fixrep x) {re = apply_o_mode(x);}
125  void set_im(fixrep x) {im = apply_o_mode(x);}
126 
128  void lshift(int n);
130  void rshift(int n);
132  void rshift(int n, q_mode q);
133 
135  virtual void print() const;
137  fixrep get_re() const {return re;}
139  fixrep get_im() const {return im;}
141  std::complex<double> unfix() const;
142 
143 #ifndef NO_IMPLICIT_FIX_CONVERSION
144 
145  operator std::complex<double>() const {
146  it_assert_debug(shift >= -63 && shift <= 64, "CFix::operator complex<double>: Illegal shift!");
147  return std::complex<double>(double(re)*DOUBLE_POW2[64 - shift],
148  double(im)*DOUBLE_POW2[64 - shift]);
149  }
150 #endif
151 
153  friend int assert_shifts(const CFix &x, const CFix &y);
155  friend int assert_shifts(const CFix &x, const Fix &y);
157  friend int assert_shifts(const CFix &x, int y);
158 
159 protected:
162 };
163 
165 int assert_shifts(const CFix &x, const CFix &y);
167 int assert_shifts(const CFix &x, const Fix &y);
169 int assert_shifts(const CFix &x, int y);
170 
172 std::istream &operator>>(std::istream &is, CFix &x);
174 std::ostream &operator<<(std::ostream &os, const CFix &x);
175 
180 
181 // Specialization of template definition in vec.cpp
182 template<> void cfixvec::set(const char *values);
183 // Specialization of template definition in mat.cpp
184 template<> void cfixmat::set(const char *values);
185 
187 
188 } // namespace itpp
189 
190 #endif // #ifndef CFIX_H
SourceForge Logo

Generated on Fri Mar 21 2014 17:14:13 for IT++ by Doxygen 1.8.1.2