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.
Tool/software: TI C/C++ Compiler
Hi,
I am trying to use function macro to convert Q15.16 number to floating-point number by converting integer value to float and multiplying the result by inverse of 65536.0.
#define Fix16ToFloat(x) ( (float)(x) * 0x1p-16 )
However, the compiler (15.2.12) list file shows that the exact hexadecimal value has been changed to 0.000015F.
Hexadecimal value of 0x1p-16 is exactly 0x37800000 but value of 0.000015F is 0x377ba882.
For example, the following program compiled with GCC shows the problem:
float u = 1.0f/65536.0f;
float v = 0x1p-16;
float t = 0.000015f;
printf("\n%08x %f %g\n%08x %f %g\n%08x %f %g\n", *(uint32_t *)&u, u, u, *(uint32_t *)&v, v, v, *(uint32_t *)&t, t, t );
which prints out:
37800000 0.000015 1.52588e-005
37800000 0.000015 1.52588e-005
377ba882 0.000015 1.5e-005
Compiler uses 0.000015F Even if I explicitly use 0x1p-16 in calculation.
Now, if I compile the following program with C2000
float u = 1.0f/65536.0f;
float v = 0x1p-16;
float t = 0.000015f;
the lst file shows
4607 ;*** 639 ----------------------- u = 0.000015F;
4608 ;*** 640 ----------------------- v = u;
4609 ;*** 641 ----------------------- t = 0.000015F;
EDIT: It seems that the memory contents are still ok...
u == 37800000
v == 37800000
t == 377BA882
So I guess nothing after all except that lst/asm file could show the exact floating-point value.
Juhamatti
Juhamatti Nikander said:So I guess nothing after all except that lst/asm file could show the exact floating-point value.
Thank you for letting us know about this problem. I can reproduce it. I filed CODEGEN-5426 in the SDOWP system to have this investigated. You are welcome to follow it with the SDOWP link below in my signature.
Thanks and regards,
-George