【发布时间】:2014-06-02 19:43:42
【问题描述】:
案例一
float a = 0.6;
if (a < 0.6)
{
printf("c");
}
else
{
printf("c#");
}
输出c#
案例2
float a = 0.9;
if (a < 0.9)
{
printf("c");
}
else
{
printf("c#");
}
输出c
现在的问题是为什么?
【问题讨论】:
-
该代码甚至无法编译。它是
if不是If而且它的格式也不好让我们看看发生了什么。 -
请搜索论文What Every Computer Scientist Should Know About Floating-Point Arithmetic 并阅读。
标签: c floating-point comparison