IT++ Logo Newcom Logo

fix.h

Go to the documentation of this file.
00001 
00033 #ifndef FIX_H
00034 #define FIX_H
00035 
00036 #include <itpp/fixedpoint/fix_base.h>
00037 #include <itpp/fixedpoint/fix_factory.h>
00038 
00039 
00040 namespace itpp {
00041 
00042   // Forward declarations
00043   template<class Num_T> class Vec;
00044   template<class Num_T> class Mat;
00045 
00048 
00054   class Fix : public Fix_Base {
00055     friend class CFix;
00056     template<int, e_mode, o_mode, q_mode> friend class Fixed;
00057     template<int, e_mode, o_mode, q_mode> friend class CFixed;
00058   public:
00060     Fix(double x=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(x)) {}
00063     explicit Fix(const Fix_Factory &f)
00064       : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {}
00066     Fix(fixrep r, int s, int dummy1, int dummy2)
00067       : Fix_Base(s), re(r) {}
00069     Fix(const Fix &x, 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) {}
00072     virtual ~Fix() {}
00073 
00075     Fix& operator=(const Fix &x);
00077     Fix& operator=(const int x);
00079     Fix& operator+=(const Fix &x);
00081     Fix& operator+=(const int x);
00083     Fix& operator-=(const Fix &x);
00085     Fix& operator-=(const int x);
00087     Fix& operator*=(const Fix &x);
00089     Fix& operator*=(const int x);
00091     Fix& operator/=(const Fix &x);
00093     Fix& operator/=(const int x);
00095     Fix operator-() const;
00097     Fix& operator<<=(const int n);
00099     Fix& operator>>=(const int n);
00100 
00102     void set(double x, int n);
00104     void set(double x, int n, q_mode q);
00106     void set_re(fixrep x) {re = apply_o_mode(x);}
00107 
00109     void lshift(int n);
00111     void rshift(int n);
00113     void rshift(int n, q_mode q);
00114 
00116     virtual void print() const;
00118     fixrep get_re() const {return re;}
00120     double unfix() const;
00121 
00122 #ifndef NO_IMPLICIT_FIX_CONVERSION
00124     operator double() const
00125     {
00126       it_assert1(shift>=-63 && shift<=64, "Fix::operator double: Illegal shift!");
00127       return double(re)*DOUBLE_POW2[64 - shift];
00128     }
00129 #endif
00130 
00132     friend int assert_shifts(const CFix &x, const Fix &y);
00134     friend int assert_shifts(const Fix &x, const Fix &y);
00136     friend int assert_shifts(const Fix &x, int y);
00137 
00138   protected:
00140     fixrep re;
00141   };
00142 
00144   std::istream &operator>>(std::istream &is, Fix &x);
00146   std::ostream &operator<<(std::ostream &os, const Fix &x);
00147 
00149   typedef Vec<Fix> fixvec;
00151   typedef Mat<Fix> fixmat;
00152 
00153   // Specialization of template definition in vec.cpp
00154   template<> bool fixvec::set(const char *values);
00155   // Specialization of template definition in mat.cpp
00156   template<> bool fixmat::set(const char *values);
00157 
00159 
00160 } // namespace itpp
00161 
00162 #endif // #ifndef FIX_H
SourceForge Logo

Generated on Wed Apr 18 11:19:59 2007 for IT++ by Doxygen 1.5.2