Strange behavior when casting an int to float in C

前端 未结 5 1738
予麋鹿
予麋鹿 2021-02-18 14:27

I have a doubt concerning the output of the following C program. I tried to compile it using both Visual C++ 6.0 and MinGW32 (gcc 3.4.2).

#include 

        
5条回答
  •  迷失自我
    2021-02-18 14:46

    Visual C++ 6.0 was released last century, and I believe it predates standard C++. It is wholly unsurprising that VC++ 6.0 exhibits broken behaviour.

    You'll also note that gcc-3.4.2 is from 2004. Indeed, you're using a 32-bit compiler. gcc on x86 plays rather fast and loose with floating-point math. This may technically be justified by the C standard if gcc sets FLT_EVAL_METHOD to something nonzero.

提交回复
热议问题