245 std::cout <<
"re = " <<
re << std::endl;
246 std::cout <<
"im = " <<
im << std::endl;
255 else if (x.
re == 0 && x.
im == 0)
257 else if (y.
re == 0 && y.
im == 0)
260 it_error(
"assert_shifts: Different shifts not allowed!");
271 else if (x.
re == 0 && x.
im == 0)
276 it_error(
"assert_shifts: Different shifts not allowed!");
284 && (y != 0),
"assert_shifts: Different shifts not allowed!");
290 std::complex<double> value;
292 if (!is.eof() && (is.peek() ==
'<')) {
295 if (is.peek() ==
'<') {
333 os << std::complex<double>(x);
336 os << std::complex<double>(x) <<
"<<" << x.
get_shift();
339 it_error(
"operator<<: Illegal output mode!");
348 std::istringstream buffer(values);
349 int default_shift = 0, pos = 0, maxpos = 10;
352 default_shift =
data[0].get_shift();
355 while (buffer.peek() != EOF) {
356 switch (buffer.peek()) {
358 it_error(
"set: expressions with ':' are not valid for cfixvec");
369 data[pos-1].set_shift(default_shift);
370 buffer >>
data[pos-1];
371 while (buffer.peek() ==
' ') { buffer.get(); }
382 std::istringstream buffer(values);
383 int default_shift = 0,
rows = 0, maxrows = 10,
cols = 0, nocols = 0, maxcols = 10;
386 default_shift =
data[0].get_shift();
388 alloc(maxrows, maxcols);
389 while (buffer.peek() != EOF) {
391 if (
rows > maxrows) {
392 maxrows = maxrows * 2;
396 while ((buffer.peek() !=
';') && (buffer.peek() != EOF)) {
397 if (buffer.peek() ==
',') {
404 if (
cols > maxcols) {
405 maxcols = maxcols * 2;
411 while (buffer.peek() ==
' ') { buffer.get(); }
#define it_error_if(t, s)
Abort if t is true.
output_mode get_output_mode() const
Get output mode.
void alloc(int rows, int cols)
Allocate memory for the matrix.
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
Num_T * data
Protected data pointer.
CFix operator-() const
Unary negative of CFix.
CFix & operator*=(const CFix &x)
Multiplication with CFix. Temporary variables use the maximum word length (64 bits) ...
fixrep scale_and_apply_modes(double x) const
Convert from double to fixrep using shift and quantization mode qmode, then call limit() ...
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
const Num_T & operator()(int r, int c) const
Get element (r,c) from matrix.
vec imag(const cvec &data)
Imaginary part of complex values.
CFix & operator-=(const CFix &x)
Subtraction of CFix.
CFix & operator/=(const CFix &x)
Division with CFix using quantization mode TRN. Temporary variables use the maximum word length (64 b...
void set(const char *str)
Set the vector equal to the values in the str string.
friend ITPP_EXPORT 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) ...
CFix & operator+=(const CFix &x)
Addition of CFix.
Output floating-point value.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Num_T * data
A pointer to the data area.
CFix & operator>>=(const int n)
Right shift n bits using quantization mode qmode (constructor argument)
void set_shift(int s)
Set shift (without shifting)
fixrep apply_o_mode(fixrep x) const
Handle overflows using overflow mode omode and make call to statistics object (if any) ...
void set(const std::string &str)
Set matrix equal to values in the string str.
fixrep rshift_and_apply_q_mode(fixrep x, int n) const
Right shift n bits using quantization mode qmode and make call to statistics object (if any) ...
fixrep re
Data representation.
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
int datasize
The current number of elements in the vector.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
std::complex< double > unfix() const
Conversion to std::complex<double>
int cols() const
The number of columns.
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
CFix & operator<<=(const int n)
Left shift n bits.
Complex fixed-point data type.
virtual void print() const
Print restrictions.
Output fixed-point representation only.
void set_im(fixrep x)
Set data representation for imaginary part (mainly for internal use since it reveals the representati...
void lshift(int n)
Left shift n bits.
int shift
Accumulated bitshift (positive means left-shifted, negative means right-shifted)
Error handling functions - header file.
void set(double real, double imag, int n)
Set to (real + i*imag) * pow2(n) using quantization mode qmode (constructor argument) ...
CFix & operator=(const CFix &x)
Assignment from CFix.
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.
Output floating-point value followed by <<shift.
fixrep get_im() const
Get data representation for imaginary part (mainly for internal use since it reveals the representati...
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) ...
#define it_error(s)
Abort unconditionally.
int rows() const
The number of rows.
void alloc(int size)
Allocate storage for a vector of length size.
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.
Output fixed-point representation followed by <shift> (default)
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
vec real(const cvec &data)
Real part of complex values.
q_mode
Quantization modes (aligned with SystemC)
int get_shift() const
Get shift.
virtual void print() const
Print restrictions.
Definitions of a complex fixed-point data type CFix.