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.

[参考译文] CCS/MSP430G2553:未为变量分配精确值

Guru**** 2553450 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/815648/ccs-msp430g2553-variable-is-not-being-assigned-the-exact-value

器件型号:MSP430G2553

工具/软件:Code Composer Studio

您好!

在我的代码中、我通过以下方式分配了一个变量、

浮点 I;

I = 0.29;

但是、当我使用阶跃返回并在观察下添加变量时、它会显示出这一点

I = 0.289999992

这种异常的原因。 如何纠正它?

谢谢你

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Aditya、

    看起来不错。
    根据 IEEE754:
    单精度(浮点数)提供23位的有效值、8位的指数以及1个符号位、
    双精度(双精度)提供52位的有效值、11位的指数和1个符号位。

    如果是浮点,则可以得到的最佳精度为23*log10(2)=6.92的十进制数字。