Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What uses do floating point NaN payloads have?

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?

like image 800
Jordan Melo Avatar asked Nov 28 '15 04:11

Jordan Melo


2 Answers

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.

like image 59
gnasher729 Avatar answered Oct 24 '22 02:10

gnasher729


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

like image 41
Dan Heidinga Avatar answered Oct 24 '22 03:10

Dan Heidinga