Why 0.1 + 0.2 == 0.3 in D?

后端 未结 3 2081
粉色の甜心
粉色の甜心 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:42

    According to my interpretation of the D language specification, floating point arithmetic on x86 would use 80 bits of precision internally, instead of only 64 bits.

    One would have to check however that that is enough to explain the result you observe.

提交回复
热议问题