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.
您好,
最近我在使用CCS7调试28335的时候,给一个全局变量赋值,比如在watch window里给float型变量test1赋值0.001,但是显示的时候为0.00100000005,如下图所示:
程序如下所示:
/**
* main.c
*/
float test1 = 0.001, test2 = 20, test3 = 0;
int main(void)
{
for(;;)
{
test3 = test1/test2;
}
return 0;
}
这是显示的问题还是存储的问题呢?
谢谢!
CCS7.2.0和7.4.0都是这样的问题,CCS5.3没有这个问题;仿真器是XDS100V2。
对于 单精度32-bit的浮点数
1、其第31 bit为符号位,为0则表示正数,反之为复数,其读数值用s表示;
2、第30~23 bit为幂数,其读数值用e表示;
3、第22~0 bit共23 bit作为系数,视为二进制纯小数,假定该小数的十进制值为x;
浮点数的值用十进制表示为:
= (-1)^s * (1 + x) * 2^(e - 127)