fix.h
Go to the documentation of this file.
#ifndef FIX_H
#define FIX_H
#include <itpp/fixed/fix_base.h>
#include <itpp/fixed/fix_factory.h>
#include <itpp/itexports.h>
namespace itpp
{
// Forward declarations
template<class Num_T> class Vec;
template<class Num_T> class Mat;
class ITPP_EXPORT Fix : public Fix_Base
{
friend class CFix;
template<int, e_mode, o_mode, q_mode> friend class Fixed;
template<int, e_mode, o_mode, q_mode> friend class CFixed;
public:
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)
: Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(x)) {}
explicit Fix(const Fix_Factory &f)
: Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0) {}
Fix(fixrep r, int s, int, int)
: Fix_Base(s), re(r) {}
Fix(const Fix &x, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
: Fix_Base(x.shift, w, e, o, q, ptr), re(x.re) {}
virtual ~Fix() {}
Fix& operator=(const Fix &x);
Fix& operator=(const int x);
Fix& operator+=(const Fix &x);
Fix& operator+=(const int x);
Fix& operator-=(const Fix &x);
Fix& operator-=(const int x);
Fix& operator*=(const Fix &x);
Fix& operator*=(const int x);
Fix& operator/=(const Fix &x);
Fix& operator/=(const int x);
Fix operator-() const;
Fix& operator<<=(const int n);
Fix& operator>>=(const int n);
void set(double x, int n);
void set(double x, int n, q_mode q);
void set_re(fixrep x) {re = apply_o_mode(x);}
void lshift(int n);
void rshift(int n);
void rshift(int n, q_mode q);
virtual void print() const;
fixrep get_re() const {return re;}
double unfix() const;
#ifndef NO_IMPLICIT_FIX_CONVERSION
operator double() const {
it_assert_debug(shift>=-63 && shift <= 64, "Fix::operator double: Illegal shift!");
return double(re)*DOUBLE_POW2[64 - shift];
}
#endif
friend ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
friend ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
friend ITPP_EXPORT int assert_shifts(const Fix &x, int y);
protected:
fixrep re;
};
ITPP_EXPORT int assert_shifts(const Fix &x, const Fix &y);
ITPP_EXPORT int assert_shifts(const Fix &x, int y);
ITPP_EXPORT std::istream &operator>>(std::istream &is, Fix &x);
ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const Fix &x);
typedef Vec<Fix> fixvec;
typedef Mat<Fix> fixmat;
// Specialization of template definition in vec.cpp
template<> void fixvec::set(const char *values);
// Specialization of template definition in mat.cpp
template<> void fixmat::set(const char *values);
} // namespace itpp
#endif // #ifndef FIX_H
itpp::Fixed
Templated fixed-point data type.
Definition: fixed.h:48
itpp::CFixed
Templated complex fixed-point data type.
Definition: cfixed.h:50
fix_base.h
Definitions of a base class for fixed-point data types.
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::Vec::set
void set(const char *str)
Set the vector equal to the values in the str string.
Definition: vec.h:814
itpp::Mat
Matrix Class (Templated)
Definition: factory.h:41
fix_factory.h
Definitions of a class factory for fixed-point data types Fix and CFix.
itpp::operator<<
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition: binary.cpp:36
itpp::Mat::set
void set(const std::string &str)
Set matrix equal to values in the string str.
Definition: mat.h:762
itpp::Fix_Factory
Class factory for fixed-point data types Fix and CFix.
Definition: fix_factory.h:120
itpp::Fix::re
fixrep re
Data representation.
Definition: fix.h:137
itpp::unfix
double unfix(const Fix &x)
Convert Fix to double by multiplying the bit representation with pow2(-shift)
Definition: fix_functions.h:463
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::Fix::~Fix
virtual ~Fix()
Destructor.
Definition: fix.h:70
itpp::DOUBLE_POW2
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Definition: fix_base.h:906
itpp::CFix
Complex fixed-point data type.
Definition: cfix.h:51
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::e_mode
e_mode
Sign encoding modes (aligned with SystemC)
Definition: fix_base.h:942
itpp::TRN
Truncation.
Definition: fix_base.h:964
itpp::o_mode
o_mode
Overflow modes (aligned with SystemC)
Definition: fix_base.h:948
itpp
itpp namespace
Definition: itmex.h:36
itpp::MAX_WORDLEN
const int MAX_WORDLEN
Max word length.
Definition: fix_base.h:886
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::Fix
Fixed-point data type.
Definition: fix.h:51
itpp::Fix_Base
Base class for fixed-point data types.
Definition: fix_base.h:981
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
itpp::Vec
Vector Class (Templated)
Definition: factory.h:42
itpp::Fix::Fix
Fix(const Fix_Factory &f)
Constructor.
Definition: fix.h:61
itpp::fixrep
int64_t fixrep
Representation for fixed-point data types.
Definition: fix_base.h:884
itpp::fixmat
Mat< Fix > fixmat
Typedef for fixed-point matrix type.
Definition: fix.h:153
itpp::WRAP
Wrap-around.
Definition: fix_base.h:952
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::operator>>
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Definition: binary.cpp:42
itpp::TC
Two's complement.
Definition: fix_base.h:943
itpp::Stat
A class for sampling a signal and calculating statistics.
Definition: misc_stat.h:48
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::q_mode
q_mode
Quantization modes (aligned with SystemC)
Definition: fix_base.h:957
itpp::fixvec
Vec< Fix > fixvec
Typedef for fixed-point vector type.
Definition: fix.h:151
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

Generated on Thu Aug 20 2015 21:02:51 for IT++ by Doxygen 1.8.9.1