00001 00030 #ifndef CFIX_H 00031 #define CFIX_H 00032 00033 #include <itpp/fixed/fix.h> 00034 00035 00036 namespace itpp { 00037 00038 // Forward declarations 00039 template<class Num_T> class Vec; 00040 template<class Num_T> class Mat; 00041 00044 00050 class CFix : public Fix_Base { 00051 template<int, e_mode, o_mode, q_mode> friend class CFixed; 00052 public: 00054 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) 00055 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(r)), im(scale_and_apply_modes(i)) {} 00057 CFix(std::complex<double> x, double dummy=0.0, int s=0, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0) 00058 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(std::real(x))), im(scale_and_apply_modes(std::imag(x))) {} 00060 explicit CFix(const Fix_Factory &f) 00061 : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {} 00063 CFix(fixrep r, fixrep i, int s, int dummy1, int dummy2) 00064 : Fix_Base(s), re(r), im(i) {} 00066 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) 00067 : Fix_Base(assert_shifts(r, i), w, e, o, q, ptr), re(r.re), im(i.re) {} 00069 CFix(const CFix &x, double dummy=0.0, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0) 00070 : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re), im(x.im) {} 00072 virtual ~CFix() {} 00073 00075 CFix& operator=(const CFix &x); 00077 CFix& operator=(const Fix &x); 00079 CFix& operator=(const std::complex<double> &x); 00081 CFix& operator=(const int x); 00083 CFix& operator+=(const CFix &x); 00085 CFix& operator+=(const Fix &x); 00087 CFix& operator+=(const int x); 00089 CFix& operator-=(const CFix &x); 00091 CFix& operator-=(const Fix &x); 00093 CFix& operator-=(const int x); 00095 CFix& operator*=(const CFix &x); 00097 CFix& operator*=(const Fix &x); 00099 CFix& operator*=(const int x); 00101 CFix& operator/=(const CFix &x); 00103 CFix& operator/=(const Fix &x); 00105 CFix& operator/=(const int x); 00107 CFix operator-() const; 00109 CFix& operator<<=(const int n); 00111 CFix& operator>>=(const int n); 00112 00114 void set(double real, double imag, int n); 00116 void set(double real, double imag, int n, q_mode q); 00118 void set(const std::complex<double> &x, int n); 00120 void set(const std::complex<double> &x, int n, q_mode q); 00122 void set_re(fixrep x) {re = apply_o_mode(x);} 00124 void set_im(fixrep x) {im = apply_o_mode(x);} 00125 00127 void lshift(int n); 00129 void rshift(int n); 00131 void rshift(int n, q_mode q); 00132 00134 virtual void print() const; 00136 fixrep get_re() const {return re;} 00138 fixrep get_im() const {return im;} 00140 std::complex<double> unfix() const; 00141 00142 #ifndef NO_IMPLICIT_FIX_CONVERSION 00144 operator std::complex<double>() const 00145 { 00146 it_assert_debug(shift>=-63 && shift<=64, "CFix::operator complex<double>: Illegal shift!"); 00147 return std::complex<double>(double(re)*DOUBLE_POW2[64 - shift], 00148 double(im)*DOUBLE_POW2[64 - shift]); 00149 } 00150 #endif 00151 00153 friend int assert_shifts(const CFix &x, const CFix &y); 00155 friend int assert_shifts(const CFix &x, const Fix &y); 00157 friend int assert_shifts(const CFix &x, int y); 00158 00159 protected: 00160 fixrep re; 00161 fixrep im; 00162 }; 00163 00165 int assert_shifts(const CFix &x, const CFix &y); 00167 int assert_shifts(const CFix &x, const Fix &y); 00169 int assert_shifts(const CFix &x, int y); 00170 00172 std::istream &operator>>(std::istream &is, CFix &x); 00174 std::ostream &operator<<(std::ostream &os, const CFix &x); 00175 00177 typedef Vec<CFix> cfixvec; 00179 typedef Mat<CFix> cfixmat; 00180 00181 // Specialization of template definition in vec.cpp 00182 template<> void cfixvec::set(const char *values); 00183 // Specialization of template definition in mat.cpp 00184 template<> void cfixmat::set(const char *values); 00185 00187 00188 } // namespace itpp 00189 00190 #endif // #ifndef CFIX_H
Generated on Sat Apr 19 10:41:56 2008 for IT++ by Doxygen 1.5.5