I was reading Robert Nystrom's Crafting Interpreters section on NaN boxing/tagging, and was curious about his oblique mention of not wanting to collide with a special NaN value which he calls "Intel’s 'QNaN Floating-Point Indefinite'" (a hazard when storing data in specially crafted NaN payloads).
From this reference sheet provided by intel, they do define a "Real Indefinite" as the NaN representation returned by various invalid arithmetic operations (0.0/0.0, -infinity + infinity, etc). This sheet defines the Real Indefinite as a QNaN with sign bit '1' and the payload zeroed (the payload being all fraction bits lower than the one used to distinguish quiet NaNs from signaling NaNs).
To avoid arithmetic producing a NaN that the program disastrously misinterprets as one of the special tagged NaNs, Nystrom sets the highest payload bit to 1 when storing non-double types, which seems fine, but...
Wouldn't one achieve the same result by marking tagged NaNs with a zero sign bit (rather than using the most significant payload bit for this purpose as Nystrom does), with the added simplicity of keeping the usable bits contiguous?
Indefinite real:
_______________________
|1|1.....1|1|0.......0|
^ ^ ^ ^
| exp | payload
sign quiet NaN
Tagged (sign flag):
_______________________
|0|1.....1|1|x.......x|
Tagged (payload flag):
_______________________
|x|1.....1|11|x......x|