00001 00030 #ifndef FIX_H 00031 #define FIX_H 00032 00033 #include <itpp/fixed/fix_base.h> 00034 #include <itpp/fixed/fix_factory.h> 00035 00036 00037 namespace itpp 00038 { 00039 00040 // Forward declarations 00041 template<class Num_T> class Vec; 00042 template<class Num_T> class Mat; 00043 00046 00052 class Fix : public Fix_Base 00053 { 00054 friend class CFix; 00055 template<int, e_mode, o_mode, q_mode> friend class Fixed; 00056 template<int, e_mode, o_mode, q_mode> friend class CFixed; 00057 public: 00059 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) 00060 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(x)) {} 00062 explicit Fix(const Fix_Factory &f) 00063 : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {} 00065 Fix(fixrep r, int s, int, int) 00066 : Fix_Base(s), re(r) {} 00068 Fix(const Fix &x, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0) 00069 : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re) {} 00071 virtual ~Fix() {} 00072 00074 Fix& operator=(const Fix &x); 00076 Fix& operator=(const int x); 00078 Fix& operator+=(const Fix &x); 00080 Fix& operator+=(const int x); 00082 Fix& operator-=(const Fix &x); 00084 Fix& operator-=(const int x); 00086 Fix& operator*=(const Fix &x); 00088 Fix& operator*=(const int x); 00090 Fix& operator/=(const Fix &x); 00092 Fix& operator/=(const int x); 00094 Fix operator-() const; 00096 Fix& operator<<=(const int n); 00098 Fix& operator>>=(const int n); 00099 00101 void set(double x, int n); 00103 void set(double x, int n, q_mode q); 00105 void set_re(fixrep x) {re = apply_o_mode(x);} 00106 00108 void lshift(int n); 00110 void rshift(int n); 00112 void rshift(int n, q_mode q); 00113 00115 virtual void print() const; 00117 fixrep get_re() const {return re;} 00119 double unfix() const; 00120 00121 #ifndef NO_IMPLICIT_FIX_CONVERSION 00123 operator double() const { 00124 it_assert_debug(shift>=-63 && shift <= 64, "Fix::operator double: Illegal shift!"); 00125 return double(re)*DOUBLE_POW2[64 - shift]; 00126 } 00127 #endif 00128 00130 friend int assert_shifts(const CFix &x, const Fix &y); 00132 friend int assert_shifts(const Fix &x, const Fix &y); 00134 friend int assert_shifts(const Fix &x, int y); 00135 00136 protected: 00138 fixrep re; 00139 }; 00140 00142 int assert_shifts(const Fix &x, const Fix &y); 00144 int assert_shifts(const Fix &x, int y); 00145 00147 std::istream &operator>>(std::istream &is, Fix &x); 00149 std::ostream &operator<<(std::ostream &os, const Fix &x); 00150 00152 typedef Vec<Fix> fixvec; 00154 typedef Mat<Fix> fixmat; 00155 00156 // Specialization of template definition in vec.cpp 00157 template<> void fixvec::set(const char *values); 00158 // Specialization of template definition in mat.cpp 00159 template<> void fixmat::set(const char *values); 00160 00162 00163 } // namespace itpp 00164 00165 #endif // #ifndef FIX_H
Generated on Tue Nov 23 08:45:11 2010 for IT++ by Doxygen 1.6.1