00001 00033 #ifndef CFIX_H 00034 #define CFIX_H 00035 00036 #include <itpp/fixedpoint/fix.h> 00037 00038 00039 namespace itpp { 00040 00041 // Forward declarations 00042 template<class Num_T> class Vec; 00043 template<class Num_T> class Mat; 00044 00047 00053 class CFix : public Fix_Base { 00054 template<int, e_mode, o_mode, q_mode> friend class CFixed; 00055 public: 00057 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) 00058 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(r)), im(scale_and_apply_modes(i)) {} 00060 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) 00061 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(std::real(x))), im(scale_and_apply_modes(std::imag(x))) {} 00063 explicit CFix(const Fix_Factory &f) 00064 : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {} 00066 CFix(fixrep r, fixrep i, int s, int dummy1, int dummy2) 00067 : Fix_Base(s), re(r), im(i) {} 00069 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) 00070 : Fix_Base(assert_shifts(r, i), w, e, o, q, ptr), re(r.re), im(i.re) {} 00072 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) 00073 : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re), im(x.im) {} 00075 virtual ~CFix() {} 00076 00078 CFix& operator=(const CFix &x); 00080 CFix& operator=(const Fix &x); 00082 CFix& operator=(const std::complex<double> &x); 00084 CFix& operator=(const int x); 00086 CFix& operator+=(const CFix &x); 00088 CFix& operator+=(const Fix &x); 00090 CFix& operator+=(const int x); 00092 CFix& operator-=(const CFix &x); 00094 CFix& operator-=(const Fix &x); 00096 CFix& operator-=(const int x); 00098 CFix& operator*=(const CFix &x); 00100 CFix& operator*=(const Fix &x); 00102 CFix& operator*=(const int x); 00104 CFix& operator/=(const CFix &x); 00106 CFix& operator/=(const Fix &x); 00108 CFix& operator/=(const int x); 00110 CFix operator-() const; 00112 CFix& operator<<=(const int n); 00114 CFix& operator>>=(const int n); 00115 00117 void set(double real, double imag, int n); 00119 void set(double real, double imag, int n, q_mode q); 00121 void set(const std::complex<double> &x, int n); 00123 void set(const std::complex<double> &x, int n, q_mode q); 00125 void set_re(fixrep x) {re = apply_o_mode(x);} 00127 void set_im(fixrep x) {im = apply_o_mode(x);} 00128 00130 void lshift(int n); 00132 void rshift(int n); 00134 void rshift(int n, q_mode q); 00135 00137 virtual void print() const; 00139 fixrep get_re() const {return re;} 00141 fixrep get_im() const {return im;} 00143 std::complex<double> unfix() const; 00144 00145 #ifndef NO_IMPLICIT_FIX_CONVERSION 00147 operator std::complex<double>() const 00148 { 00149 it_assert1(shift>=-63 && shift<=64, "CFix::operator complex<double>: Illegal shift!"); 00150 return std::complex<double>(double(re)*DOUBLE_POW2[64 - shift], 00151 double(im)*DOUBLE_POW2[64 - shift]); 00152 } 00153 #endif 00154 00156 friend int assert_shifts(const CFix &x, const CFix &y); 00158 friend int assert_shifts(const CFix &x, const Fix &y); 00160 friend int assert_shifts(const CFix &x, int y); 00161 00162 protected: 00164 fixrep re, im; 00165 }; 00166 00168 std::istream &operator>>(std::istream &is, CFix &x); 00170 std::ostream &operator<<(std::ostream &os, const CFix &x); 00171 00173 typedef Vec<CFix> cfixvec; 00175 typedef Mat<CFix> cfixmat; 00176 00177 // Specialization of template definition in vec.cpp 00178 template<> bool cfixvec::set(const char *values); 00179 // Specialization of template definition in mat.cpp 00180 template<> bool cfixmat::set(const char *values); 00181 00183 00184 } // namespace itpp 00185 00186 #endif // #ifndef CFIX_H
Generated on Fri Jun 8 00:27:16 2007 for IT++ by Doxygen 1.5.2