I know that IEEE 754 defines NaNs to have the following bitwise representation:
0
or 1
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.
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
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.