33 #include <itpp/itexports.h> 40 template<
class Num_T>
class Vec;
41 template<
class Num_T>
class Mat;
53 template<
int, e_mode, o_mode, q_mode>
friend class CFixed;
57 :
Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(r)), im(scale_and_apply_modes(i)) {}
60 :
Fix_Base(s, w, e, o, q, ptr), re(scale_and_apply_modes(
std::
real(x))), im(scale_and_apply_modes(
std::
imag(x))) {}
63 :
Fix_Base(0, f.wordlen, f.emode, f.omode, f.qmode, f.stat_ptr), re(0), im(0) {}
72 :
Fix_Base(x.shift, w, e, o, q, ptr), re(x.re), im(x.im) {}
81 CFix& operator=(
const std::complex<double> &x);
83 CFix& operator=(
const int x);
89 CFix& operator+=(
const int x);
95 CFix& operator-=(
const int x);
101 CFix& operator*=(
const int x);
105 CFix& operator/=(
const Fix &x);
107 CFix& operator/=(
const int x);
111 CFix& operator<<=(
const int n);
113 CFix& operator>>=(
const int n);
116 void set(
double real,
double imag,
int n);
120 void set(
const std::complex<double> &x,
int n);
122 void set(
const std::complex<double> &x,
int n,
q_mode q);
133 void rshift(
int n,
q_mode q);
136 virtual void print()
const;
142 std::complex<double>
unfix()
const;
144 #ifndef NO_IMPLICIT_FIX_CONVERSION 145 operator std::complex<double>()
const {
147 it_assert_debug(shift >= -63 && shift <= 64,
"CFix::operator complex<double>: Illegal shift!");
148 return std::complex<double>(double(re)*
DOUBLE_POW2[64 - shift],
154 friend ITPP_EXPORT
int assert_shifts(
const CFix &x,
const CFix &y);
156 friend ITPP_EXPORT
int assert_shifts(
const CFix &x,
const Fix &y);
175 ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const CFix &x);
191 #endif // #ifndef CFIX_H Templated complex fixed-point data type.
CFix(const Fix_Factory &f)
Constructor.
CFix(fixrep r, fixrep i, int s, int, int)
Constructor for internal use. No restrictions are applied. The dummies help to avoid ambiguities...
vec imag(const cvec &data)
Imaginary part of complex values.
Mat< CFix > cfixmat
Typedef for complex fixed-point matrix type.
void set(const char *str)
Set the vector equal to the values in the str string.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
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.
void set(const std::string &str)
Set matrix equal to values in the string str.
Class factory for fixed-point data types Fix and CFix.
double unfix(const Fix &x)
Convert Fix to double by multiplying the bit representation with pow2(-shift)
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Complex fixed-point data type.
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
e_mode
Sign encoding modes (aligned with SystemC)
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.
o_mode
Overflow modes (aligned with SystemC)
void set_im(fixrep x)
Set data representation for imaginary part (mainly for internal use since it reveals the representati...
const int MAX_WORDLEN
Max word length.
virtual ~CFix()
Destructor.
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.
void set_re(fixrep x)
Set data representation for real part (mainly for internal use since it reveals the representation ty...
fixrep im
Imaginary data part.
fixrep get_im() const
Get data representation for imaginary part (mainly for internal use since it reveals the representati...
Base class for fixed-point data types.
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) ...
Vec< CFix > cfixvec
Typedef for complex fixed-point vector type.
Definitions of a fixed-point data type Fix.
fixrep get_re() const
Get data representation for real part (mainly for internal use since it reveals the representation ty...
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.
int64_t fixrep
Representation for fixed-point data types.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
A class for sampling a signal and calculating statistics.
vec real(const cvec &data)
Real part of complex values.
q_mode
Quantization modes (aligned with SystemC)