IQmath
8 - 20 C2000 Microcontroller Workshop - Numerical Concepts
Using the operator overloading features of C++, we can overload the multiplication operand "*"
such that when a particular data type is encountered, it will automatically implement the scaled
multiply operation. Let’s define a data type called "iq" and assign the linear variables to this data
type:
iq Y, M, X, B // numbers are all Q24
The overloading of the multiply operand in C++ can be defined as follows:
iq operator*(const iq &M, const iq &X){return((int64)M*(int64) X) >> 24;}
Then the linear equation, in C++, becomes:
Y = M * X + B;
This final equation looks identical to the floating-point representation. It looks "natural". The
four approaches are summarized in the table below:
32-bit floating-point math in C
32-bit fixed-point "Q" math in C
Y = ((int64) M * (int64) X) + (int64) B << 24) >> 24;
Essentially, the mathematical approach of scaling the multiplier operand enables a cleaner and a
more "natural" approach to coding fixed-point problems. For want of a better term, we call this
approach "IQmath" or can also be described as "virtual floating-point".