1/2 Hey folks, to welcome September, a pair of ultrageek blog posts on representing 64-bit IEEE 754 floats in the minimum possible number of UTF-8 bytes.
-
1/2 Hey folks, to welcome September, a pair of ultrageek blog posts on representing 64-bit IEEE 754 floats in the minimum possible number of UTF-8 bytes. The 95% of you who just thought “Huh? What?” or “Who even cares” are being entirely sensible. For the rest of you, here’s “Q Numbers Redux”: https://www.tbray.org/ongoing/When/202x/2024/08/28/Q-Numbers-2 which contains this terrifying Go code:
mask := (u>>63)*^uint64(0) | (1 << 63)
return numbits(u ^ mask) -
2/2 And here’s “Q Numbers Redux Explained”, a guest-authored entry from Arne Hormann, which explains the baffling bit-banging: https://www.tbray.org/ongoing/When/202x/2024/08/31/QNum-Redux-Explained
-
@timbray This is lovely.
-
@timbray
Brought to mind posits.
https://en.m.wikipedia.org/wiki/Unum_(number_format) -
@robpike My Quamina project is providing me endless coding fun and blogging fuel too.
-
@timbray I think you can save one instruction by doing:
mask := uint64((int64(u) >> 63)) | (1 << 63)
In my godbolt, this compiles as an arithmetic right shift as opposed to a logical right shift followed by negation.
-
@raph You are, of course, volunteering to write the multi-paragraph comment explaining WTAF is going on? But seriously, just kidding, that's really cool.
-
@timbray I am happy to write it up if you like, but Ivan has it, except that int64(u) not a float-to-int case, it's an unsigned-to-signed cast.
I've been doing quite a bit of low level bit magic in my sparse strip GPU path rendering implementation. That really needs a writeup!
-
@raph I promise to link to that write-up when it appears.