C compiler bug (floating point arithmetic)?

后端 未结 3 1477
北海茫月
北海茫月 2020-12-04 04:26
#include

int main()
{
    double fract=0;
    int tmp;

    //scanf(\"%lf\",&fract);
    fract=0.312;
    printf(\"%lf\",fract);
    printf(\"\\n         


        
3条回答
  •  醉酒成梦
    2020-12-04 04:53

    Floating-point arithmetic is confusing, and not guaranteed to behave intuitively.

    Here's a good reference document: What Every Computer Scientist Should Know About Floating-Point Arithmetic. It's a long document, because it's a complicated problem.

    In summary: Don't use floating-point values if you are relying on exact values.

提交回复
热议问题