What uses do floating point NaN payloads have?

馋奶兔 提交于 2019-11-27 05:59:13

问题


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

  • The sign bit can be either 0 or 1
  • The exponent field contains all 1 bits
  • Some bits of the mantissa are used to specify whether it's a quiet NaN or signalling NaN
  • The mantissa cannot be all 0 bits because that bit pattern is reserved for representing infinity
  • The remaining bits of the mantissa form a payload

The payload is propagated (as is the NaN as a whole) to the result of a floating point calculation when the input of the calculation is NaN, though I have no knowledge of the details of this propagation or whether the standard specifies how this is done. Who sets the original payload? What happens if I add two NaNs with different payloads?

But most importantly: I've never seen NaN payloads used before. What uses does this payload field have?


回答1:


It was thought to be a good idea whenIEEE754 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.




回答2:


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



来源:https://stackoverflow.com/questions/33967804/what-uses-do-floating-point-nan-payloads-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!