00001 00029 #ifndef FIX_H 00030 #define FIX_H 00031 00032 #include <itpp/fixed/fix_base.h> 00033 #include <itpp/fixed/fix_factory.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 Fix : public Fix_Base 00052 { 00053 friend class CFix; 00054 template<int, e_mode, o_mode, q_mode> friend class Fixed; 00055 template<int, e_mode, o_mode, q_mode> friend class CFixed; 00056 public: 00058 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) 00059 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(x)) {} 00061 explicit Fix(const Fix_Factory &f) 00062 : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {} 00064 Fix(fixrep r, int s, int, int) 00065 : Fix_Base(s), re(r) {} 00067 Fix(const Fix &x, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0) 00068 : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re) {} 00070 virtual ~Fix() {} 00071 00073 Fix& operator=(const Fix &x); 00075 Fix& operator=(const int x); 00077 Fix& operator+=(const Fix &x); 00079 Fix& operator+=(const int x); 00081 Fix& operator-=(const Fix &x); 00083 Fix& operator-=(const int x); 00085 Fix& operator*=(const Fix &x); 00087 Fix& operator*=(const int x); 00089 Fix& operator/=(const Fix &x); 00091 Fix& operator/=(const int x); 00093 Fix operator-() const; 00095 Fix& operator<<=(const int n); 00097 Fix& operator>>=(const int n); 00098 00100 void set(double x, int n); 00102 void set(double x, int n, q_mode q); 00104 void set_re(fixrep x) {re = apply_o_mode(x);} 00105 00107 void lshift(int n); 00109 void rshift(int n); 00111 void rshift(int n, q_mode q); 00112 00114 virtual void print() const; 00116 fixrep get_re() const {return re;} 00118 double unfix() const; 00119 00120 #ifndef NO_IMPLICIT_FIX_CONVERSION 00121 00122 operator double() const { 00123 it_assert_debug(shift>=-63 && shift <= 64, "Fix::operator double: Illegal shift!"); 00124 return double(re)*DOUBLE_POW2[64 - shift]; 00125 } 00126 #endif 00127 00129 friend int assert_shifts(const CFix &x, const Fix &y); 00131 friend int assert_shifts(const Fix &x, const Fix &y); 00133 friend int assert_shifts(const Fix &x, int y); 00134 00135 protected: 00137 fixrep re; 00138 }; 00139 00141 int assert_shifts(const Fix &x, const Fix &y); 00143 int assert_shifts(const Fix &x, int y); 00144 00146 std::istream &operator>>(std::istream &is, Fix &x); 00148 std::ostream &operator<<(std::ostream &os, const Fix &x); 00149 00151 typedef Vec<Fix> fixvec; 00153 typedef Mat<Fix> fixmat; 00154 00155 // Specialization of template definition in vec.cpp 00156 template<> void fixvec::set(const char *values); 00157 // Specialization of template definition in mat.cpp 00158 template<> void fixmat::set(const char *values); 00159 00161 00162 } // namespace itpp 00163 00164 #endif // #ifndef FIX_H
Generated on Wed Jul 27 2011 16:27:05 for IT++ by Doxygen 1.7.4