4 ms·
This is similar to "fatvals" in SpiderMonkey (Firefox's JS engine). IIRC SpiderMonkey stores doubles -- the fundamental numeric data type in JS -- as "unboxed"
by jlebar 12y ago
This is similar to "fatvals" in SpiderMonkey (Firefox's JS engine).
IIRC SpiderMonkey stores doubles -- the fundamental numeric data type in JS -- as "unboxed" values, using this article's terminology. I'm not sure if there's good documentation about this out there, but it's an interesting hack, and much more complicated than just setting the bottom bit of the value.
- ufo 12y agoI think you are thinking about a different trick called NaN tagging. http://wingolog.org/archives/2011/05/18/value-representation-in-javascript-implementations http://wingolog.org/archives/2011/05/18/value-representation... The basic idea is that there are 2^53 different bit patterns that are counted as NaN by the computer but only one is actually used in practice. This means that you can "steal" the rest of the NaNs and use them to encode numbers or pointers.
- munificent 12y agoI'm hacking on a fast little dynamically-typed language that uses that technique. It works fantastically well. I describe it in detail here: https://github.com/munificent/wren/blob/master/src/wren_value.h#L400 https://github.com/munificent/wren/blob/master/src/wren_valu...
- ufo 12y agoThanks for the link! I was actually surprised how hard it was to find a good description of NaN tagging yesterday.