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.
For the following code
float x = -32768.0f;
int x_i = (int) x;
long x_l_1 = (int) x;
long x_l_2 = (long) x;
long x_l_3 = (int) -32768.0f;
compiled with TMS320C24xx ANSI C Compiler, Version 7.04 I get on a TMS320LF2407A the following results (in the watch window from CCS3.3):
x: -32768.0
x_l_3: -32768
x_i: -29186
x_l_1: 167422
x_l_2: -32768
The values of x_i and x_l_1 are unexpected. Can someone please comment on this?
Regards
Johannes
That is without a doubt a bug. Please run this program to check whether it is the compiler or the watch window that is at fault (my bet is the compiler):
#include <stdio.h> int main() { float x = -32768.0f; int x_i = (int) x; long x_l_1 = (int) x; long x_l_2 = (long) x; long x_l_3 = (int) -32768.0f; printf("%f\n", x); printf("%d\n", x_i); printf("%ld\n", x_l_1); printf("%ld\n", x_l_2); printf("%ld\n", x_l_3); return 0; }
The output of this program in Stdout tab is consistent with the contents of the watch window.
Regards, Johannes
It seems pretty likely that there is a bug in the library helper function which converts from float to int (F$$FTOI). However, I am not at all familiar with C24x assembly code, so I can't analyze this any further; I can't even verify that the problem is actually in F$$FTOI rather than the compiler. There is no more recent version of the C24x compiler available, and no updates will be made. It should be possible to extract F$$FTOI from the library and make whatever fixes are necessary, and add that directly to your project, but it would probably be easier just to make sure you never attempt to cast from float to int; cast to long instead. I'm sorry I cannot be of further help.
Hi,
My code is:
void AdcShow(char c, int value)
{
float temp1, temp2;
uint32_t i, count;
temp1 = (float)(value-2048);
temp1 /= 410;
intToString(temp1,sendbuf);
mibspiSendData(c);
wait(0x400);
mibspiSendData(' ');
wait(0x400);
if(value < 0)
count = 5;
else
count = 4;
for(i = count; i > 0; i--)
{
mibspiSendData(sendbuf[i-1]);
wait(0x400);
}
mibspiSendData('g');
wait(0x400);
}
In debug mode,when excuting temp1 = (float)(value-2048); it goes wrong. It come into sys_intvecs.asm. Can you give me a hand? Thank you!