ysaie

31 / ⚧ / code, music, art, games

──────────────────────────────
🌸 many-shaped creature
✨ too many projects
🚀 cannot be stopped
🌙 stayed up too late
:eggbug: eggbug enjoyer
──────────────────────────────
header image: chapter 8 complete from celeste
avatar: made using this character builder


📩 email
contact@echowritescode.dev

so i was implementing format() for Crucible and i decided i wanted to tackle formatting integers and floats by hand so they could be constexpr. integers i came up with a probably-not-super-great-but-good-enough implementation in a couple hours. then i decided to look up algorithms for printing floats.

as it turns out, there have been entire academic papers written on the subject of "printing floating point numbers quickly and accurately" (literal title of one paper)

i found a pretty good summary of the general idea in this article, and while it's definitely not the most complicated code i've ever dealt with, it's amazing how a different format can spiral out into so much complexity, even with the same number of bits!


You must log in to comment.

in reply to @ysaie's post:

indeed! when i took a crack at this i did not read any papers and ended up doing things with a hand-rolled bigint library and a massive lookup table for every possible exponent. i do not recommend this and am eager to read about actual algorithms for this!