Usefulness of signaling NaN?

后端 未结 3 748
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 21:09

I\'ve recently read up quite a bit on IEEE 754 and the x87 architecture. I was thinking of using NaN as a \"missing value\" in some numeric calculation code I\'m working on

3条回答
  •  一向
    一向 (楼主)
    2020-12-04 21:57

    Couldn't you just have a const uint64_t where the bits have been set to those of a signaling nan? as long as you treat it as an integer type, the signaling nan is not different from other integers. You could write it where you want through pointer-casting:

    Const uint64_t sNan = 0xfff0000000000000;
    Double[] myData;
    ...
    Uint64* copier = (uint64_t*) &myData[index];
    *copier=sNan | myErrorFlags;
    

    For info on the bits to set: https://www.doc.ic.ac.uk/~eedwards/compsys/float/nan.html

提交回复
热议问题