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.

Some confusion regarding _iq number

Hello,

I am reading the document of C28x IQmath Library ( sprc990c). However, on the page 65, there is one piece of sample code:

#include “IQmathLib.h”
#define PI 3.14156L
_iq xin1, yin1, out1;
_iq29 xin2, yin2, out2;
void main(void )

{
// xin1 = xin2 = cos(PI/5) x 2^29 = 0x19E37FA8
// yin1 = yin2 = sin(PI/5) x 2^29 = 0x12CF17EF
// out1 = out2 = PI/5 x 2^29 = 0x141B21C3
xin1 = _IQcos(_IQ(PI/5.0L));
yin1 = _IQsin(_IQ(PI/5.0L));
out1 = _IQatan2(yin1,xin1);
xin2 = _IQ29cos(_IQ29(PI/5.0L));
yin2 = _IQ29sin(_IQ29(PI/5.0L));
out2 = _IQ29atan2(yin1,xin1);

}

I noticed that xin1, yin1, out1 are defined as "_iq". but in the comments of the code, there is "// xin1 = xin2 = cos(PI/5) x 2^29 = 0x19E37FA8"

Where does this "2^29" come from? Why is this 2^29 here? What if I define "_iq xin2, yin2, out2"? Would there be 2^29 again in the example?

Thanks a lot!

  • Hello Yue,

    Yes, it would.

    Declaring a variable as "_iq" means the Q-format is fixed by the GLOBAL_Q definition in the header file "IQmathLib.h".  If you open that file, you'll find the definition near the top and the user can set it to whatever he or she wishes.  In the example code it was assumed GLOBAL_Q was set to 29 (stated just above the code).  All variables in the declared in the code then take on this default Q-value.

    Section 3.9 on page 22 of the document you refer to has some information on selecting a global IQ format.

    I hope this helps.

    Regards,

    Richard

  • Thank you for answer! That is really helpful.