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>
34#include <itpp/itexports.h>
35
36namespace itpp
37{
38
39// Forward declarations
40template<class Num_T> class Vec;
41template<class Num_T> class Mat;
42
45
51class 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;
56public:
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
122 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
135protected:
138};
139
141ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
143ITPP_EXPORT int assert_shifts(const Fix &x, int y);
144
146ITPP_EXPORT std::istream &operator>>(std::istream &is, Fix &x);
148ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const Fix &x);
149
154
155// Specialization of template definition in vec.cpp
156template<> void fixvec::set(const char *values);
157// Specialization of template definition in mat.cpp
158template<> void fixmat::set(const char *values);
159
161
162} // namespace itpp
163
164#endif // #ifndef FIX_H
General array class.
Definition array.h:105
Array< T > & operator=(const T &e)
Assignment operator.
Definition array.h:338
Complex fixed-point data type.
Definition cfix.h:52
Templated complex fixed-point data type.
Definition cfixed.h:51
Base class for fixed-point data types.
Definition fix_base.h:982
Class factory for fixed-point data types Fix and CFix.
Fixed-point data type.
Definition fix.h:52
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
fixrep re
Data representation.
Definition fix.h:137
Fix(const Fix_Factory &f)
Constructor.
Definition fix.h:61
fixrep get_re() const
Get data representation (mainly for internal use since it reveals the representation type)
Definition fix.h:116
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
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
void set_re(fixrep x)
Set data representation (mainly for internal use since it reveals the representation type)
Definition fix.h:104
virtual ~Fix()
Destructor.
Definition fix.h:70
Templated fixed-point data type.
Definition fixed.h:49
void set(const std::string &str)
Set matrix equal to values in the string str.
Definition mat.h:762
A class for sampling a signal and calculating statistics.
Definition misc_stat.h:49
Definitions of a base class for fixed-point data types.
Definitions of a class factory for fixed-point data types Fix and CFix.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition itassert.h:107
const int MAX_WORDLEN
Max word length.
Definition fix_base.h:886
o_mode
Overflow modes (aligned with SystemC)
Definition fix_base.h:948
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Definition fix_base.h:906
e_mode
Sign encoding modes (aligned with SystemC)
Definition fix_base.h:942
double unfix(const Fix &x)
Convert Fix to double by multiplying the bit representation with pow2(-shift)
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
void set(const char *str)
Set the vector equal to the values in the str string.
Definition vec.h:814
q_mode
Quantization modes (aligned with SystemC)
Definition fix_base.h:957
Mat< Fix > fixmat
Typedef for fixed-point matrix type.
Definition fix.h:153
Vec< Fix > fixvec
Typedef for fixed-point vector type.
Definition fix.h:151
@ WRAP
Wrap-around.
Definition fix_base.h:952
@ TC
Two's complement.
Definition fix_base.h:943
@ TRN
Truncation.
Definition fix_base.h:964
itpp namespace
Definition itmex.h:37
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition binary.cpp:36
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
Definition mat.h:1382
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Definition binary.cpp:42
SourceForge Logo

Generated on Mon Jun 10 2024 11:49:23 for IT++ by Doxygen 1.9.8