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 // 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 friend class CFix; 00053 template<int, e_mode, o_mode, q_mode> friend class Fixed; 00054 template<int, e_mode, o_mode, q_mode> friend class CFixed; 00055 public: 00057 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) 00058 : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(x)) {} 00060 explicit Fix(const Fix_Factory &f) 00061 : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {} 00063 Fix(fixrep r, int s, int dummy1, int dummy2) 00064 : Fix_Base(s), re(r) {} 00066 Fix(const Fix &x, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0) 00067 : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re) {} 00069 virtual ~Fix() {} 00070 00072 Fix& operator=(const Fix &x); 00074 Fix& operator=(const int x); 00076 Fix& operator+=(const Fix &x); 00078 Fix& operator+=(const int x); 00080 Fix& operator-=(const Fix &x); 00082 Fix& operator-=(const int x); 00084 Fix& operator*=(const Fix &x); 00086 Fix& operator*=(const int x); 00088 Fix& operator/=(const Fix &x); 00090 Fix& operator/=(const int x); 00092 Fix operator-() const; 00094 Fix& operator<<=(const int n); 00096 Fix& operator>>=(const int n); 00097 00099 void set(double x, int n); 00101 void set(double x, int n, q_mode q); 00103 void set_re(fixrep x) {re = apply_o_mode(x);} 00104 00106 void lshift(int n); 00108 void rshift(int n); 00110 void rshift(int n, q_mode q); 00111 00113 virtual void print() const; 00115 fixrep get_re() const {return re;} 00117 double unfix() const; 00118 00119 #ifndef NO_IMPLICIT_FIX_CONVERSION 00121 operator double() const 00122 { 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 Sun Dec 9 17:26:19 2007 for IT++ by Doxygen 1.5.4