Hacker News new | past | comments | ask | show | jobs | submit login

NaN tagging is really neat --- in LuaJIT, all values are stored as doubles; pointers are encoded as a NaN with the pointer part embedded in the NaN data field (you get about 50 bits to play with).

The beauty is that NaNs propagate; you can perform a complex numeric operation on them, and then test the result once while you're finished. If it's a NaN, then you know that one of the operands must have been a NaN and you escape back to the JIT for more analysis. If it's not... then it worked, and you just continue. And testing for a NaN is cheap.




NaN tagging exists since the dawn of time. CDC 6600 had reserved NaN mantissa bits... in 1963! The IEEE floating point standard just carried on these features. Many lisp implementation used NaN for packing data in the 80's/90's. Google for: lisp nan tagged data.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: