<分区>
Possible Duplicates:
Difference between float and double
strange output in comparision of float with float literal
我正在使用 visual C++ 6.0,在一个程序中我正在比较 float 和 double 变量 例如对于这个程序
#include<stdio.h>
int main()
{
float a = 0.7f;
double b = 0.7;
printf("%d %d %d",a<b,a>b,a==b);
return 0;
}
我得到 1 0 0 作为输出
为了
#include<stdio.h>
int main()
{
float a = 1.7f;
double b = 1.7;
printf("%d %d %d",a<b,a>b,a==b);
return 0;
}
我得到 0 1 0 作为输出。
请告诉我为什么会得到这些奇怪的输出,以及有什么方法可以在同一处理器上预测这些输出。还有 C 中如何比较两个变量?