exact representation of floating points in c

前端 未结 9 916
离开以前
离开以前 2020-12-01 17:40
void main()
{
    float a = 0.7;

    if (a < 0.7)
        printf(\"c\");
    else
        printf(\"c++\");
} 

In the above question for 0.7, \"

9条回答
  •  抹茶落季
    2020-12-01 18:20

    Floating point comparisons are not reliable, whatever you do. You should use threshold tolerant comparison/ epsilon comparison of floating points.

    Try IEEE-754 Floating-Point Conversion and see what you get. :)

提交回复
热议问题