Hi Ahn,
As correctly mentioned by Edward:
We should divide 32-bit fixed point number in format Q1.31 by 0x80000000 for getting signed fractional [-1,1) number.
FRAC32() is defined in SWLIBS_Defines.h file as:
/*! Macro converting a signed fractional [-1,1) number into a 32-bit fixed point number in format Q1.31.*/
#define FRAC32(x) ((tFrac32) ((x < FRACT_MAX) ? ((x >= FRACT_MIN) ? (x*2147483648.0) : INT32_MIN) : INT32_MAX))
Note: 2147483648=0x80000000
Since tFrac32 type = tS32 type = signed long type (according SWLIBS_Typedefs.h), we do not need to test sign in this case and command
float f = (float)x / 0x80000000;
should work correctly also for negative numbers.
Code
if( x & 0x8000000) // is it negative
f = - ( (float)(0-x) / 0x80000000 );
else
f = (float)x / 0x80000000 ;
is necessary when input data x are unsigned type.
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------