c中的浮点数比较

const float CHAZHI = 0.0000001;
float a = ...;
float b = ...;
float d = a - b;

if( d > CHAZHI)
{
    printf("a > b");
} 
else if( d < -CHAZHI)
{
    printf("a < b");
}
else if(d <= fabs(CHAZHI))
{
    printf("a = b");
}

参考资料 

http://blog.csdn.net/tjlakewalker/article/details/6836735

你可能感兴趣的:(c中的浮点数比较)