int a; …; (a == a) fails?

后端 未结 9 964
执笔经年
执笔经年 2020-12-31 19:05

if we set float and double type to NaN then they are not equal to anything including themselves.
can such a thing happens for

9条回答
  •  攒了一身酷
    2020-12-31 19:23

    No. The comparation for floats is defines in such way, that NaN compared to any number will return false. Anyway, for ints there is another formula:

    ZF = !(a ^ b);
    

    That will give true for any possible value of a.

    EDIT: on GCC, with any -O flag, the comparation just dissapears to true.

提交回复
热议问题