cfix.h
Go to the documentation of this file.
#ifndef CFIX_H
#define CFIX_H
#include <itpp/fixed/fix.h>
#include <itpp/itexports.h>
namespace itpp
{
// Forward declarations
template<class Num_T> class Vec;
template<class Num_T> class Mat;
class ITPP_EXPORT CFix : public Fix_Base
{
template<int, e_mode, o_mode, q_mode> friend class CFixed;
public:
CFix(double r = 0.0, double i = 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(r)), im(scale_and_apply_modes(i)) {}
CFix(std::complex<double> x, double, 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(std::real(x))), im(scale_and_apply_modes(std::imag(x))) {}
explicit CFix(const Fix_Factory &f)
: Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {}
CFix(fixrep r, fixrep i, int s, int, int)
: Fix_Base(s), re(r), im(i) {}
CFix(const Fix &r, const Fix &i = 0.0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
: Fix_Base(assert_shifts(r, i), w, e, o, q, ptr), re(r.re), im(i.re) {}
CFix(const CFix &x, double, 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), im(x.im) {}
virtual ~CFix() {}
CFix& operator=(const CFix &x);
CFix& operator=(const Fix &x);
CFix& operator=(const std::complex<double> &x);
CFix& operator=(const int x);
CFix& operator+=(const CFix &x);
CFix& operator+=(const Fix &x);
CFix& operator+=(const int x);
CFix& operator-=(const CFix &x);
CFix& operator-=(const Fix &x);
CFix& operator-=(const int x);
CFix& operator*=(const CFix &x);
CFix& operator*=(const Fix &x);
CFix& operator*=(const int x);
CFix& operator/=(const CFix &x);
CFix& operator/=(const Fix &x);
CFix& operator/=(const int x);
CFix operator-() const;
CFix& operator<<=(const int n);
CFix& operator>>=(const int n);
void set(double real, double imag, int n);
void set(double real, double imag, int n, q_mode q);
void set(const std::complex<double> &x, int n);
void set(const std::complex<double> &x, int n, q_mode q);
void set_re(fixrep x) {re = apply_o_mode(x);}
void set_im(fixrep x) {im = 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;}
fixrep get_im() const {return im;}
std::complex<double> unfix() const;
#ifndef NO_IMPLICIT_FIX_CONVERSION
operator std::complex<double>() const {
it_assert_debug(shift >= -63 && shift <= 64, "CFix::operator complex<double>: Illegal shift!");
return std::complex<double>(double(re)*DOUBLE_POW2[64 - shift],
double(im)*DOUBLE_POW2[64 - shift]);
}
#endif
friend ITPP_EXPORT int assert_shifts(const CFix &x, const CFix &y);
friend ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
friend ITPP_EXPORT int assert_shifts(const CFix &x, int y);
protected:
fixrep re;
fixrep im;
};
ITPP_EXPORT int assert_shifts(const CFix &x, const CFix &y);
ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y);
ITPP_EXPORT int assert_shifts(const CFix &x, int y);
ITPP_EXPORT std::istream &operator>>(std::istream &is, CFix &x);
ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const CFix &x);
typedef Vec<CFix> cfixvec;
typedef Mat<CFix> cfixmat;
// Specialization of template definition in vec.cpp
template<> void cfixvec::set(const char *values);
// Specialization of template definition in mat.cpp
template<> void cfixmat::set(const char *values);
} // namespace itpp
#endif // #ifndef CFIX_H
itpp::CFixed
Templated complex fixed-point data type.
Definition: cfixed.h:50
itpp::CFix::CFix
CFix(const Fix_Factory &f)
Constructor.
Definition: cfix.h:62
itpp::CFix::CFix
CFix(fixrep r, fixrep i, int s, int, int)
Constructor for internal use. No restrictions are applied. The dummies help to avoid ambiguities...
Definition: cfix.h:65
itpp::imag
vec imag(const cvec &data)
Imaginary part of complex values.
Definition: elem_math.cpp:180
itpp::cfixmat
Mat< CFix > cfixmat
Typedef for complex fixed-point matrix type.
Definition: cfix.h:180
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
itpp::operator<<
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition: binary.cpp:36
itpp::CFix::CFix
CFix(const Fix &r, const Fix &i=0.0, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0)
Constructor.
Definition: cfix.h:68
std
STL namespace.
itpp::CFix::re
fixrep re
Real data part.
Definition: cfix.h:161
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::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::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::CFix::CFix
CFix(const CFix &x, double, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0)
Copy constructor.
Definition: cfix.h:71
itpp::o_mode
o_mode
Overflow modes (aligned with SystemC)
Definition: fix_base.h:948
itpp::CFix::set_im
void set_im(fixrep x)
Set data representation for imaginary part (mainly for internal use since it reveals the representati...
Definition: cfix.h:126
itpp
itpp namespace
Definition: itmex.h:36
itpp::MAX_WORDLEN
const int MAX_WORDLEN
Max word length.
Definition: fix_base.h:886
itpp::CFix::~CFix
virtual ~CFix()
Destructor.
Definition: cfix.h:74
itpp::CFix::CFix
CFix(std::complex< double > x, double, int s=0, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0)
Constructor.
Definition: cfix.h:59
itpp::CFix::set_re
void set_re(fixrep x)
Set data representation for real part (mainly for internal use since it reveals the representation ty...
Definition: cfix.h:124
itpp::CFix::im
fixrep im
Imaginary data part.
Definition: cfix.h:162
itpp::Fix
Fixed-point data type.
Definition: fix.h:51
itpp::CFix::get_im
fixrep get_im() const
Get data representation for imaginary part (mainly for internal use since it reveals the representati...
Definition: cfix.h:140
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::cfixvec
Vec< CFix > cfixvec
Typedef for complex fixed-point vector type.
Definition: cfix.h:178
fix.h
Definitions of a fixed-point data type Fix.
itpp::Vec
Vector Class (Templated)
Definition: factory.h:42
itpp::CFix::get_re
fixrep get_re() const
Get data representation for real part (mainly for internal use since it reveals the representation ty...
Definition: cfix.h:138
itpp::CFix::CFix
CFix(double r=0.0, double i=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: cfix.h:56
itpp::fixrep
int64_t fixrep
Representation for fixed-point data types.
Definition: fix_base.h:884
itpp::WRAP
Wrap-around.
Definition: fix_base.h:952
itpp::operator>>
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Definition: binary.cpp:42
itpp::TC
Two&#39;s complement.
Definition: fix_base.h:943
itpp::Stat
A class for sampling a signal and calculating statistics.
Definition: misc_stat.h:48
itpp::real
vec real(const cvec &data)
Real part of complex values.
Definition: elem_math.cpp:157
itpp::q_mode
q_mode
Quantization modes (aligned with SystemC)
Definition: fix_base.h:957

Generated on Sat Sep 30 2017 07:04:09 for IT++ by Doxygen 1.8.13