166 std::cout <<
"re = " <<
re << std::endl;
180 it_error(
"assert_shifts: Different shifts not allowed!");
188 "assert_shifts: Different shifts not allowed!");
196 if (!is.eof() && (is.peek() ==
'<')) {
199 if (is.peek() ==
'<') {
231 os << double(x) <<
"<<" << x.
get_shift();
234 it_error(
"operator<<: Illegal output mode!");
243 std::istringstream buffer(values);
245 int default_shift = 0, pos = 0, maxpos = 10;
248 default_shift =
data[0].get_shift();
251 while (buffer.peek() != EOF) {
252 switch (buffer.peek()) {
258 if (!buffer.eof() && buffer.peek() ==
':') {
262 while (
int(
double(
data[pos-1])) + b - c <= 0) {
274 while (
int(
double(
data[pos-1])) < b) {
294 data[pos-1].set_shift(default_shift);
295 buffer >>
data[pos-1];
296 while (buffer.peek() ==
' ') { buffer.get(); }
307 std::istringstream buffer(values);
308 int default_shift = 0,
rows = 0, maxrows = 10,
cols = 0, nocols = 0, maxcols = 10;
311 default_shift =
data[0].get_shift();
313 alloc(maxrows, maxcols);
314 while (buffer.peek() != EOF) {
316 if (
rows > maxrows) {
317 maxrows = maxrows * 2;
321 while ((buffer.peek() !=
';') && (buffer.peek() != EOF)) {
322 if (buffer.peek() ==
',') {
329 if (
cols > maxcols) {
330 maxcols = maxcols * 2;
336 while (buffer.peek() ==
' ') { buffer.get(); }
virtual void print() const
Print restrictions.
fixrep apply_o_mode(fixrep x) const
Handle overflows using overflow mode omode and make call to statistics object (if any)
fixrep scale_and_apply_modes(double x) const
Convert from double to fixrep using shift and quantization mode qmode, then call limit()
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)
output_mode get_output_mode() const
Get output mode.
void set_shift(int s)
Set shift (without shifting)
int get_shift() const
Get shift.
int shift
Accumulated bitshift (positive means left-shifted, negative means right-shifted)
void lshift(int n)
Left shift n bits.
Fix & operator/=(const Fix &x)
Division with Fix using quantization mode TRN.
fixrep re
Data representation.
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
void set(double x, int n)
Set to x * pow2(n) using quantization mode qmode (constructor argument)
Fix & operator=(const Fix &x)
Assignment from Fix.
Fix & operator+=(const Fix &x)
Addition of Fix.
Fix & operator>>=(const int n)
Right shift n bits using quantization mode qmode (constructor argument)
fixrep get_re() const
Get data representation (mainly for internal use since it reveals the representation type)
Fix operator-() const
Unary negative of Fix.
double unfix() const
Conversion to double.
Fix & operator-=(const Fix &x)
Subtraction of Fix.
Fix & operator<<=(const int n)
Left shift n bits.
Fix & operator*=(const Fix &x)
Multiplication with Fix.
void set_re(fixrep x)
Set data representation (mainly for internal use since it reveals the representation type)
friend ITPP_EXPORT int assert_shifts(const CFix &x, const Fix &y)
Check that x.shift==y.shift OR x==0 OR y==0 and return the shift (for the non-zero argument)
virtual void print() const
Print restrictions.
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
void set(const std::string &str)
Set matrix equal to values in the string str.
int rows() const
The number of rows.
Num_T * data
Protected data pointer.
int cols() const
The number of columns.
const Num_T & operator()(int r, int c) const
Get element (r,c) from matrix.
void alloc(int rows, int cols)
Allocate memory for the matrix.
int datasize
The current number of elements in the vector.
Num_T * data
A pointer to the data area.
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
void alloc(int size)
Allocate storage for a vector of length size.
Definitions of a fixed-point data type Fix.
#define it_error_if(t, s)
Abort if t is true.
#define it_error(s)
Abort unconditionally.
#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)
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)
void set(const char *str)
Set the vector equal to the values in the str string.
q_mode
Quantization modes (aligned with SystemC)
int64_t fixrep
Representation for fixed-point data types.
@ OUTPUT_FIX
Output fixed-point representation only.
@ OUTPUT_FLOAT
Output floating-point value.
@ OUTPUT_FIX_SHIFT
Output fixed-point representation followed by <shift> (default)
@ OUTPUT_FLOAT_SHIFT
Output floating-point value followed by <<shift.
Error handling functions - header file.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.