What uses do floating point NaN payloads have?

后端 未结 3 1648
一向
一向 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.

    0 讨论(0)
  • 2020-12-06 11:00

    https://softwareengineering.stackexchange.com/questions/185406/what-is-the-purpose-of-nan-boxing

    Take a look at that link for an explanation of how js engines use nan boxing

    0 讨论(0)
  • 2020-12-06 11:13

    The statistical environment R uses NaN payloads to distinguish one specific NaN as representing a statistical "missing value", which prints as NA. This allows 'missing' to propagate through numeric calculations -- although when combining a missing value with another NaN it is not predictable which one is propagated.

    0 讨论(0)
提交回复
热议问题