Interpreting decimal strings is a common task in programming, wherever a text-based format is used for data : source code, data exchange with JSON, configuration with TOML...
Most implementations I have found are complex (multiple source files, implementing custom types, big lookup tables, thousand line of codes...). There may be the need for a smaller implementation, in the same spirit as the STB libraries. I also wanted to give a go to a low-level problem. Given that this journey was longer than what I expected, I wanted to write about how I tackled the problem, how I reached this implementation, such that to keep and share familiarity with the implementation.
For legibility, I have split the writing into three articles. The third article contains discussion about correctness and performances. I have not copied the entire implementation verbatim in these articles: I recommend to read the C code along the explanations given in these articles, my implementation is available online, in the public domain. Finally, a couple math proofs were put off to the end of the article.
Float encodes numbers also as three parts: a sign \(s \pm 1\) , an integer part \(m\) and an integer exponent part \(p\) , except that a power of two is used: