IT++ Logo
fix.h
Go to the documentation of this file.
1 
29 #ifndef FIX_H
30 #define FIX_H
31 
32 #include <itpp/fixed/fix_base.h>
33 #include <itpp/fixed/fix_factory.h>
34 #include <itpp/itexports.h>
35 
36 namespace itpp
37 {
38 
39 // Forward declarations
40 template<class Num_T> class Vec;
41 template<class Num_T> class Mat;
42 
45 
51 class ITPP_EXPORT Fix : public Fix_Base
52 {
53  friend class CFix;
54  template<int, e_mode, o_mode, q_mode> friend class Fixed;
55  template<int, e_mode, o_mode, q_mode> friend class CFixed;
56 public:
58  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)
59  : Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(x)) {}
61  explicit Fix(const Fix_Factory &f)
62  : Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {}
64  Fix(fixrep r, int s, int, int)
65  : Fix_Base(s), re(r) {}
67  Fix(const Fix &x, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
68  : Fix_Base(x.shift, w, e, o, q, ptr), re(x.re) {}
70  virtual ~Fix() {}
71 
73  Fix& operator=(const Fix &x);
75  Fix& operator=(const int x);
77  Fix& operator+=(const Fix &x);
79  Fix& operator+=(const int x);
81  Fix& operator-=(const Fix &x);
83  Fix& operator-=(const int x);
85  Fix& operator*=(const Fix &x);
87  Fix& operator*=(const int x);
89  Fix& operator/=(const Fix &x);
91  Fix& operator/=(const int x);
93  Fix operator-() const;
95  Fix& operator<<=(const int n);
97  Fix& operator>>=(const int n);
98 
100  void set(double x, int n);
102  void set(double x, int n, q_mode q);
104  void set_re(fixrep x) {re = apply_o_mode(x);}
105 
107  void lshift(int n);
109  void rshift(int n);
111  void rshift(int n, q_mode q);
112 
114  virtual void print() const;
116  fixrep get_re() const {return re;}
118  double unfix() const;
119 
120 #ifndef NO_IMPLICIT_FIX_CONVERSION
121  operator double() const {
123  it_assert_debug(shift>=-63 && shift <= 64, "Fix::operator double: Illegal shift!");
124  return double(re)*DOUBLE_POW2[64 - shift];
125  }
126 #endif
127 
129  friend ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
131  friend ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
133  friend ITPP_EXPORT int assert_shifts(const Fix &x, int y);
134 
135 protected:
138 };
139 
141 ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
143 ITPP_EXPORT int assert_shifts(const Fix &x, int y);
144 
146 ITPP_EXPORT std::istream &operator>>(std::istream &is, Fix &x);
148 ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const Fix &x);
149 
151 typedef Vec<Fix> fixvec;
153 typedef Mat<Fix> fixmat;
154 
155 // Specialization of template definition in vec.cpp
156 template<> void fixvec::set(const char *values);
157 // Specialization of template definition in mat.cpp
158 template<> void fixmat::set(const char *values);
159 
161 
162 } // namespace itpp
163 
164 #endif // #ifndef FIX_H
itpp::operator>>
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Definition: binary.cpp:42
itpp::Fix::Fix
Fix(const Fix &x, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0)
Copy constructor.
Definition: fix.h:67
itpp::fixmat
Mat< Fix > fixmat
Typedef for fixed-point matrix type.
Definition: fix.h:153
itpp::unfix
double unfix(const Fix &x)
Convert Fix to double by multiplying the bit representation with pow2(-shift)
Definition: fix_functions.h:463
itpp::DOUBLE_POW2
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Definition: fix_base.h:906
itpp::Mat::set
void set(const std::string &str)
Set matrix equal to values in the string str.
Definition: mat.h:762
itpp::WRAP
@ WRAP
Wrap-around.
Definition: fix_base.h:952
itpp::Fix
Fixed-point data type.
Definition: fix.h:52
itpp::operator-
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
Definition: mat.h:1382
itpp::operator<<
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition: binary.cpp:36
itpp::Vec::set
void set(const char *str)
Set the vector equal to the values in the str string.
Definition: vec.h:814
itpp::fixvec
Vec< Fix > fixvec
Typedef for fixed-point vector type.
Definition: fix.h:151
itpp
itpp namespace
Definition: itmex.h:37
itpp::CFix
Complex fixed-point data type.
Definition: cfix.h:52
itpp::Fix::Fix
Fix(fixrep r, int s, int, int)
Constructor for internal use. No restrictions are applied. The dummies help to avoid ambiguities.
Definition: fix.h:64
itpp::Fix::get_re
fixrep get_re() const
Get data representation (mainly for internal use since it reveals the representation type)
Definition: fix.h:116
itpp::o_mode
o_mode
Overflow modes (aligned with SystemC)
Definition: fix_base.h:948
fix_base.h
Definitions of a base class for fixed-point data types.
it_assert_debug
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition: itassert.h:107
itpp::e_mode
e_mode
Sign encoding modes (aligned with SystemC)
Definition: fix_base.h:942
itpp::TRN
@ TRN
Truncation.
Definition: fix_base.h:964
itpp::Fix_Factory
Class factory for fixed-point data types Fix and CFix.
Definition: fix_factory.h:121
itpp::Fixed
Templated fixed-point data type.
Definition: fixed.h:49
itpp::CFixed
Templated complex fixed-point data type.
Definition: cfixed.h:51
itpp::fixrep
int64_t fixrep
Representation for fixed-point data types.
Definition: fix_base.h:884
itpp::Fix::Fix
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)
Default constructor.
Definition: fix.h:58
itpp::Fix::set_re
void set_re(fixrep x)
Set data representation (mainly for internal use since it reveals the representation type)
Definition: fix.h:104
itpp::Fix::Fix
Fix(const Fix_Factory &f)
Constructor.
Definition: fix.h:61
itpp::TC
@ TC
Two's complement.
Definition: fix_base.h:943
itpp::Mat
Matrix Class (Templated)
Definition: mat.h:202
itpp::Stat
A class for sampling a signal and calculating statistics.
Definition: misc_stat.h:49
itpp::q_mode
q_mode
Quantization modes (aligned with SystemC)
Definition: fix_base.h:957
itpp::Fix::~Fix
virtual ~Fix()
Destructor.
Definition: fix.h:70
itpp::Fix_Base
Base class for fixed-point data types.
Definition: fix_base.h:982
itpp::MAX_WORDLEN
const int MAX_WORDLEN
Max word length.
Definition: fix_base.h:886
itpp::Fix::re
fixrep re
Data representation.
Definition: fix.h:137
itpp::Vec
Vector Class (Templated)
Definition: vec.h:245
itpp::assert_shifts
int assert_shifts(const CFix &x, const CFix &y)
Check that x.shift==y.shift OR x==0 OR y==0 and return the shift (for the non-zero argument)
Definition: cfix.cpp:249
fix_factory.h
Definitions of a class factory for fixed-point data types Fix and CFix.

Generated on Sun Jan 3 2021 11:31:33 for IT++ by Doxygen 1.8.20