float f = 0.7;
if( f == 0.7 )
printf("equal");
else
printf("not equal");
Run Code Online (Sandbox Code Playgroud)
为什么输出not equal?
为什么会这样?
void main()
{
float a = 0.7;
if (a < 0.7)
printf("c");
else
printf("c++");
}
Run Code Online (Sandbox Code Playgroud)
在上面的0.7问题中,将打印"c",但是对于0.8,将打印"c ++".为什么?
那么浮点数是如何用二进制形式表示的?
在某些地方,提到内部0.7将存储为0.699997,但0.8存储为0.8000011.为什么这样?