3 ms·
https://github.com/philihp/nanbox https://github.com/philihp/nanbox You don't even need a Double, you can use a Float NaN to encode strings: > IEEE 754 encode
by ElectricalUnion 4y ago
https://github.com/philihp/nanbox https://github.com/philihp/nanbox
You don't even need a Double, you can use a Float NaN to encode strings:
> IEEE 754 encodes 32-bit floating points with 1 bit for the sign, 8 bits for the exponent, and 23 bits for the number part (mantissa). (...)
> 23 bits isn't much space, but conveniently the max size of a Unicode codepoint is 0x10FFFF, making it a 22-bit charset. When you encode your strings in UTF-32, you're only going to be using 22 of those bits, so masking the top portion with the NaN signature makes all of your characters NaNs.