What uses do floating point NaN payloads have?

后端 未结 3 1657
一向
一向 2020-12-06 10:36

I know that IEEE 754 defines NaNs to have the following bitwise representation:

  • The sign bit can be either 0 or 1
  • The expone
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 10:58

    It was thought to be a good idea when IEEE754 and NaN's were developed. I have actually seen it used to store the reason why a NaN was created.

    Today, I wouldn't use it in portable code for several reasons. How sure are you that this payload will survive for example an assignment? If you assign x = y, how sure are you that x has the same NaN payload as y? And how sure are you that it will survive arithmetic? If a or b is an NaN, then a op b is supposed to be the one NaN, or one of the two NaNs if they are both NaN. Sure that this is the case? I wouldn't be willing to bet on it.

提交回复
热议问题