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(); }
#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.
virtual void print() const
Print restrictions.
Num_T * data
Protected data pointer.
Fix & operator>>=(const int n)
Right shift n bits using quantization mode qmode (constructor argument)
fixrep scale_and_apply_modes(double x) const
Convert from double to fixrep using shift and quantization mode qmode, then call limit() ...
const Num_T & operator()(int r, int c) const
Get element (r,c) from matrix.
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.
void set(const char *str)
Set the vector equal to the values in the str string.
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.
void set(double x, int n)
Set to x * pow2(n) 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) ...
Fix & operator=(const Fix &x)
Assignment from Fix.
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.
double unfix() const
Conversion to double.
Fix & operator<<=(const int n)
Left shift n bits.
int datasize
The current number of elements in the vector.
Fix & operator*=(const Fix &x)
Multiplication with Fix.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
fixrep get_re() const
Get data representation (mainly for internal use since it reveals the representation type) ...
void lshift(int n)
Left shift n bits.
int cols() const
The number of columns.
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Output fixed-point representation only.
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
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) ...
Fix operator-() const
Unary negative of Fix.
int shift
Accumulated bitshift (positive means left-shifted, negative means right-shifted)
Error handling functions - header file.
Output floating-point value followed by <<shift.
Fix & operator-=(const Fix &x)
Subtraction of Fix.
Fix & operator/=(const Fix &x)
Division with Fix using quantization mode TRN.
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) ...
Definitions of a fixed-point data type Fix.
#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.
int64_t fixrep
Representation for fixed-point data types.
Fix & operator+=(const Fix &x)
Addition of Fix.
Output fixed-point representation followed by <shift> (default)
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
q_mode
Quantization modes (aligned with SystemC)
void set_re(fixrep x)
Set data representation (mainly for internal use since it reveals the representation type) ...
int get_shift() const
Get shift.
virtual void print() const
Print restrictions.