
Shortest Round-Trip: Implementing IEEE 754 to Decimal Conversion in Go
Every programmer has seen this: 0.1 + 0.2 = 0.30000000000000004 The joke is that floating-point arithmetic is broken. It isn't. IEEE 754 is doing exactly what it specifies. The problem surfaces when you need to serialize these values to text — and when two different systems need to produce exactly the same text for the same value. This is what RFC 8785 (JSON Canonicalization Scheme) requires: byte-deterministic JSON output. And the hardest part of that requirement is number formatting. You need the shortest decimal string that, when parsed back, recovers the original IEEE 754 bits. You need to agree on tie-breaking when two representations are equally short. And you need to match the exact output format specified by ECMA-262 Number serialization , because that's what RFC 8785 mandates. Go's strconv.FormatFloat is a high-quality shortest-round-trip formatter, but it is not an ECMA-262 conformance contract. So I implemented the Burger-Dybvig algorithm from scratch in 490 lines of Go, val
Continue reading on Dev.to
Opens in a new tab


