Negative NaN is not a NaN?

后端 未结 6 1417
感情败类
感情败类 2020-12-09 15:43

While writing some test cases, and some of the tests check for the result of a NaN.

I tried using std::isnan but the assert failes:

Asse         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 16:10

    You can check the bits of number. IEEE 754 has defined mask for NaN:

    • A signaling NaN is represented by any bit pattern between X'7F80 0001' and X'7FBF FFFF' or between X'FF80 0001' and X'FFBF FFFF'.
    • A quiet NaN is represented by any bit pattern between X'7FC0 0000' and X'7FFF FFFF' or between X'FFC0 0000' and X'FFFF FFFF'.

    This might be not portable, but if you are sure about your platfofm it can be acceptable. More: http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlf101l.doc/xlfopg/fpieee.htm

提交回复
热议问题