chinuhark
Member level 5
After spending the past few days getting the fixed point library to actually build, I was shocked to see that there are only Add and Subtract functions in the libq.h
First question is why no Multiply and Divide?
After playing around, I did get the the following code to multiply and give the correct result:
The calculated value is correct (at least for these values) and measuring the speed shows the above multiplication takes about 0.5usec as opposed to 2.25usec for floating point. So atleast the purpose is not defeated.
But seriously, am I missing something? Is there no official super optimized function for Q15 multiplication and division from Microchip?
Also what trouble can I expect to run into if I use the above code...(calculation errors, overflows etc)?
First question is why no Multiply and Divide?
After playing around, I did get the the following code to multiply and give the correct result:
Code:
_Q15 a1 = _Q15ftoi(0.25);
_Q15 a2 = _Q15ftoi(0.45);
_Q15 a3;
long test1, test2, temp;
test1 = a1;
test2 = a2;
temp = test1*test2;
temp = temp>>15;
a3 = temp;
product = _itofQ15(a3);
The calculated value is correct (at least for these values) and measuring the speed shows the above multiplication takes about 0.5usec as opposed to 2.25usec for floating point. So atleast the purpose is not defeated.
But seriously, am I missing something? Is there no official super optimized function for Q15 multiplication and division from Microchip?
Also what trouble can I expect to run into if I use the above code...(calculation errors, overflows etc)?