AnimatLab  2
Test
StdFixed.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 namespace StdUtils
10 {
22 CStdFixed::CStdFixed(int iM, int iN, int iMultM, int iMultN)
23 {
24  Configure(iM, iN, iMultM, iMultN);
25 }
26 
39 CStdFixed::CStdFixed(int iM, int iN, double dblVal, int iMultM, int iMultN)
40 {
41  Configure(iM, iN, iMultM, iMultN);
42  Fixed( (long) Convert(dblVal));
43 }
44 
57 CStdFixed::CStdFixed(int iM, int iN, long lVal, int iMultM, int iMultN)
58 {
59  Configure(iM, iN, iMultM, iMultN);
60  Fixed( (long) lVal);
61 }
62 
70 {
71 }
72 
84 void CStdFixed::Configure(int iM, int iN, int iMultM, int iMultN)
85 {
86  //if(iM < 1)
87  // THROW_PARAM_ERROR(Std_Err_lBitSizeInvalid, Std_Err_strBitSizeInvalid, " M must be positive and greater than 0", iM);
88 
89  if(iN < 0)
90  THROW_PARAM_ERROR(Std_Err_lBitSizeInvalid, Std_Err_strBitSizeInvalid, " N must be positive or zero N", iN);
91 
92  if(iM+iN >= 32)
93  THROW_PARAM_ERROR(Std_Err_lBitSizeToLarge, Std_Err_strBitSizeToLarge, "BitSize=M+N ", (iM+iN));
94 
95  m_iM = iM;
96  m_iN = iN;
97 
98  if(iMultM <=0)
100  else
101  m_iMultiplyM = iMultM;
102 
103  if(iMultN <=0)
104  m_iMultiplyN = m_iN;
105  else
106  m_iMultiplyN = iMultN;
107 
108  m_lMaxReal = (long) pow(2.0, m_iM);
109  m_lMaxInt = (long) pow(2.0, (iM+iN));
110 
111  m_dblConvertReal = ((double) m_lMaxReal/ (double) m_lMaxInt);
112  m_dblConvertInt = ((double) m_lMaxInt/(double) m_lMaxReal);
113 
114  m_lAddPosMask = 0xFFFFFFFF >> (32 -m_iM - m_iN);
115  m_lAddNegMask = 0xFFFFFFFF << (m_iM + m_iN);
116  m_lAddTestMask = 1 << (m_iM + m_iN);
117 
118  m_lFixed = 0;
119  m_dblVal = 0;
120  m_fltVal = 0;
121 }
122 
123 
124 //CStdFixed operator+(float &fltA, CStdFixed fxB)
125 //{
126 // CStdFixed fxC(fxB.M(), fxB.N(), fltA);
127 //
128 // fxC = (fxC.FixedVal() + fxB.FixedVal());
129 // return fxC;
130 //}
131 //
132 
133 } //StdUtils
unsigned long m_lMaxReal
This is the maximum real value attainable by the fixed number.
Definition: StdFixed.h:55
double m_dblVal
Actual value in double variable.
Definition: StdFixed.h:46
long m_lAddTestMask
Mask that is used to make certain that the number cannot go above the maximum number of bits...
Definition: StdFixed.h:70
double m_dblConvertReal
The value to convert a fixed-point number to a floating-point number.
Definition: StdFixed.h:58
double m_dblConvertInt
The value to convert a floating-point number to a fixed-point number.
Definition: StdFixed.h:61
long m_lAddNegMask
Mask that is used to make certain that the number cannot go above the maximum number of bits...
Definition: StdFixed.h:67
long Convert(double dblVal)
Converts floating-point number to a fixed-point number.
Definition: StdFixed.h:82
long m_lAddPosMask
Mask that is used to make certain that the number cannot go above the maximum number of bits...
Definition: StdFixed.h:64
float m_fltVal
Actual value in float variable.
Definition: StdFixed.h:49
CStdFixed()
Default constructor.
Definition: StdFixed.h:110
virtual void Configure(int iM, int iN, int iMultM=-1, int iMultN=-1)
Configures the fixed-point representation values.
Definition: StdFixed.cpp:84
void Fixed(long lVal)
Sets the fixed-point representation of the number.
Definition: StdFixed.h:191
long m_lFixed
The fixed-point representation of the number.
Definition: StdFixed.h:43
Namespace for the standard utility objects.
Definition: MarkupSTL.cpp:19
~CStdFixed(void)
Destructor.
Definition: StdFixed.cpp:69
unsigned long m_lMaxInt
This is the maximum integer value attainable by the fixed number.
Definition: StdFixed.h:52