When using IQ numbers, is _IQmpy superior to just the "*" symbol?
Which would be the preferred way to calculate a = a*b?
1) a *= b;
2) a = _IQmpy(a, b);
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
When using IQ numbers, is _IQmpy superior to just the "*" symbol?
Which would be the preferred way to calculate a = a*b?
1) a *= b;
2) a = _IQmpy(a, b);
Hello Mark,
If you are using IQMath datatypes, then you need to perform multiply operations using the appropriate functions, since these datatypes are not necessarily interchangeable with integers (they are fixed-point, and have a specific precision). I tried to run an example based off your code (a snippet is shown below), and the resulting output for testResult is 0, but resultMult contains the correct output.
_iq param0 = _IQ(9.0);
_iq param1 = _IQ(3.0);
_iq resultMult = _IQmpy(param0, param1);
_iq testResult = param0;
testResult *= param1; //Alternatively: _iq testResult = param0 * param1 does not work either
Best regards,
Omer Amir
Hello Mark,
I'm assuming this fmod is the one located in math.h. Looking at the function prototype "fmod(double x, double y);", it seems that it only accepts doubles (64-bit floating point). IQMath is essentially just fixed-point data types and fixed-point operations. I tested this function with an _iq data type, and I did not get 0.4, so this may be why.
Best regards,
Omer Amir