Why 0.1 + 0.2 == 0.3 in D?

后端 未结 3 2092
粉色の甜心
粉色の甜心 2020-12-04 11:27
assert(0.1 + 0.2 != 0.3); // shall be true

is my favorite check that a language uses native floating point arithmetic.

C++



        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 11:38

    It's probably being optimized to (0.3 != 0.3). Which is obviously false. Check optimization settings, make sure they're switched off, and try again.

提交回复
热议问题