IT++ Logo
Public Member Functions | Protected Attributes | Friends | List of all members
itpp::Fix_Factory Class Reference

Class factory for fixed-point data types Fix and CFix. More...

#include <itpp/fixed/fix_factory.h>

Inheritance diagram for itpp::Fix_Factory:
itpp::Factory

Public Member Functions

 Fix_Factory (int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0)
 Constructor.
 
virtual ~Fix_Factory ()
 Destructor.
 
 operator double () const
 Conversion operator. Useful in templated code.
 
virtual void create (Fix *&ptr, const int n) const
 Create an n-length array of Fix.
 
virtual void create (CFix *&ptr, const int n) const
 Create an n-length array of CFix.
 

Protected Attributes

int wordlen
 Word length.
 
e_mode emode
 Sign encoding mode.
 
o_mode omode
 Overflow mode.
 
q_mode qmode
 Quantization mode.
 
Statstat_ptr
 Pointer to statistics object.
 

Friends

class Fix
 
class CFix
 

Detailed Description

Class factory for fixed-point data types Fix and CFix.

For an introduction to factories, see the Detailed Description for Factory. For more information on the fixed-point data types, see the Detailed Description in the Fixed-point Module module.

This example shows how to declare a Fix_Factory:

// Declare UFIX32, a factory for 32-bit unsigned Fix/CFix with wrap-around
// i.e. a factory for Fix(0.0, 0, 32, US, WRAP) and CFix(0.0, 0, 32, US, WRAP)
Fix_Factory UFIX32(32, US, WRAP);

However, the user does not need to declare UFIX32 since it is one of the already declared factories in fix_factory.h (which is included by itbase.h):

Fix_Factory FIX1(1, TC, WRAP); // for Fix/CFix with 1 bit
...
Fix_Factory FIX64(64, TC, WRAP); // for Fix/CFix with 64 bits
Fix_Factory UFIX1(1, US, WRAP); // for Unsigned Fix/CFix with 1 bit
...
Fix_Factory UFIX64(64, US, WRAP); // for Unsigned Fix/CFix with 64 bits
Fix_Factory SFIX1(1, TC, SAT); // for Saturated Fix/CFix with 1 bit
...
Fix_Factory SFIX64(64, TC, SAT); // for Saturated Fix/CFix with 64 bits
Fix_Factory SUFIX1(1, US, SAT); // for Saturated Unsigned Fix/CFix with 1 bit
...
Fix_Factory SUFIX64(64, US, SAT); // for Saturated Unsigned Fix/CFix with 64 bits

This means that it is only necessary for the user to declare a Fix_Factory if it is desired to have some other overflow mode than WRAP or SAT, or some other quantization mode than TRN, or a non-zero statistics object pointer.

Note
U stands for Unsigned but S stands for Saturated, NOT for Signed.

The Array/Vec/Mat constructors can take a Fix_Factory as an argument:

// Declare a Vec<Fix> with size 10 that will use
// Fix(0.0, 0, 32, US, WRAP) for element creation
Vec<Fix> vf(10, UFIX32);
// Declare an Array<Array<Mat<CFix> > > with size 10 that will use
// CFix(0.0, 0, 32, US, WRAP) for element creation
Array<Array<Mat<CFix> > > aamcf(10, UFIX32);

Even a Fix/CFix declaration can take a Fix_Factory as a constructor argument:

// Equivalent to
// Fix f(0.0, 0, 32, US, WRAP);
Fix f(UFIX32);

This syntax is also legal if Fix is replaced with double and CFix is replaced with complex<double>, i.e.

// The factory will be ignored
Vec<double> vd(10, UFIX32);
// The factory will be ignored
Array<Array<Mat<complex<double> > > > aamcd(10, UFIX32);
// The factory will be converted to double(0.0) i.e. innocent initialization
double d(UFIX32);

which can be useful in templated code, e.g. when the same code should support both floating- and fixed-point data types.

Definition at line 120 of file fix_factory.h.


The documentation for this class was generated from the following files:
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:34 for IT++ by Doxygen 1.8.2