5 ms·
My favorite FP trick: embedding meaningful data in the "ignored" bits of a floating point NaN. That gives you 22 bits (must have 1 nonzero) to play with in a 3
by fiatmoney 12y ago
My favorite FP trick: embedding meaningful data in the "ignored" bits of a floating point NaN. That gives you 22 bits (must have 1 nonzero) to play with in a 32-bit float representation, or 51 in a 64-bit float.
As I recall, at one point someone used this at battlecode [1] to lightly obscure their communication protocol. It's also a nasty but effective way to pack more nuanced metadata than you "should" be able to in a packed Java float[] or double[].
[1] http://www.battlecode.org/ http://www.battlecode.org/
- yoklov 12y agoThis is used in some dynamic language runtimes as a way to represent a compact (64bit) tagged union. It's known as nan-boxing, and a couple years ago most of the JS vms did it (in fairly different ways) but I'm not sure they still do, as my understanding is that it was only useful for the pre-optimized codepath.
- beagle3 12y agoLuaJIT2 uses this to great effect. I think IonMonkey does too, but I'm not sure.