IT++ Logo

cfix.h

Go to the documentation of this file.
00001 
00030 #ifndef CFIX_H
00031 #define CFIX_H
00032 
00033 #include <itpp/fixed/fix.h>
00034 
00035 
00036 namespace itpp
00037 {
00038 
00039 // Forward declarations
00040 template<class Num_T> class Vec;
00041 template<class Num_T> class Mat;
00042 
00045 
00051 class CFix : public Fix_Base
00052 {
00053   template<int, e_mode, o_mode, q_mode> friend class CFixed;
00054 public:
00056   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)
00057       : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(r)), im(scale_and_apply_modes(i)) {}
00059   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)
00060       : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(std::real(x))), im(scale_and_apply_modes(std::imag(x))) {}
00062   explicit CFix(const Fix_Factory &f)
00063       : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {}
00065   CFix(fixrep r, fixrep i, int s, int, int)
00066       : Fix_Base(s), re(r), im(i) {}
00068   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)
00069       : Fix_Base(assert_shifts(r, i), w, e, o, q, ptr), re(r.re), im(i.re) {}
00071   CFix(const CFix &x, double, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
00072       : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re), im(x.im) {}
00074   virtual ~CFix() {}
00075 
00077   CFix& operator=(const CFix &x);
00079   CFix& operator=(const Fix &x);
00081   CFix& operator=(const std::complex<double> &x);
00083   CFix& operator=(const int x);
00085   CFix& operator+=(const CFix &x);
00087   CFix& operator+=(const Fix &x);
00089   CFix& operator+=(const int x);
00091   CFix& operator-=(const CFix &x);
00093   CFix& operator-=(const Fix &x);
00095   CFix& operator-=(const int x);
00097   CFix& operator*=(const CFix &x);
00099   CFix& operator*=(const Fix &x);
00101   CFix& operator*=(const int x);
00103   CFix& operator/=(const CFix &x);
00105   CFix& operator/=(const Fix &x);
00107   CFix& operator/=(const int x);
00109   CFix operator-() const;
00111   CFix& operator<<=(const int n);
00113   CFix& operator>>=(const int n);
00114 
00116   void set(double real, double imag, int n);
00118   void set(double real, double imag, int n, q_mode q);
00120   void set(const std::complex<double> &x, int n);
00122   void set(const std::complex<double> &x, int n, q_mode q);
00124   void set_re(fixrep x) {re = apply_o_mode(x);}
00126   void set_im(fixrep x) {im = apply_o_mode(x);}
00127 
00129   void lshift(int n);
00131   void rshift(int n);
00133   void rshift(int n, q_mode q);
00134 
00136   virtual void print() const;
00138   fixrep get_re() const {return re;}
00140   fixrep get_im() const {return im;}
00142   std::complex<double> unfix() const;
00143 
00144 #ifndef NO_IMPLICIT_FIX_CONVERSION
00146   operator std::complex<double>() const {
00147     it_assert_debug(shift >= -63 && shift <= 64, "CFix::operator complex<double>: Illegal shift!");
00148     return std::complex<double>(double(re)*DOUBLE_POW2[64 - shift],
00149                                 double(im)*DOUBLE_POW2[64 - shift]);
00150   }
00151 #endif
00152 
00154   friend int assert_shifts(const CFix &x, const CFix &y);
00156   friend int assert_shifts(const CFix &x, const Fix &y);
00158   friend int assert_shifts(const CFix &x, int y);
00159 
00160 protected:
00161   fixrep re;   
00162   fixrep im;   
00163 };
00164 
00166 int assert_shifts(const CFix &x, const CFix &y);
00168 int assert_shifts(const CFix &x, const Fix &y);
00170 int assert_shifts(const CFix &x, int y);
00171 
00173 std::istream &operator>>(std::istream &is, CFix &x);
00175 std::ostream &operator<<(std::ostream &os, const CFix &x);
00176 
00178 typedef Vec<CFix> cfixvec;
00180 typedef Mat<CFix> cfixmat;
00181 
00182 // Specialization of template definition in vec.cpp
00183 template<> void cfixvec::set(const char *values);
00184 // Specialization of template definition in mat.cpp
00185 template<> void cfixmat::set(const char *values);
00186 
00188 
00189 } // namespace itpp
00190 
00191 #endif // #ifndef CFIX_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Wed Jan 20 23:03:05 2010 for IT++ by Doxygen 1.6.2