5 ms·
This is in the running for the best HN post I've seen this year. I've read all about floating point precision, never about rendering. The existence of this pro
by jrumbut 6y ago
This is in the running for the best HN post I've seen this year. I've read all about floating point precision, never about rendering.
The existence of this problem is so obvious in hindsight and I was so completely unaware of it previously.
- SloopJon 6y agoI think Python was the first to bring this into my consciousness. See this enhancement request, which changed the float-to-string conversion from seventeen significant figures to shortest: https://bugs.python.org/issue1580 https://bugs.python.org/issue1580 After they did that, I learned that Scheme specifies similar behavior. In fact, I think it was added to R4RS after the Steele and White paper. As the article says, this behavior spread across languages, so that it's weird to see something different now. If you want to nerd out on this, here are a few other posts that explore the topic: https://www.exploringbinary.com/the-shortest-decimal-string-that-round-trips-examples/ https://www.exploringbinary.com/the-shortest-decimal-string-... https://www.exploringbinary.com/the-shortest-decimal-string-that-round-trips-may-not-be-the-nearest/ https://www.exploringbinary.com/the-shortest-decimal-string-... https://www.exploringbinary.com/java-doesnt-print-the-shortest-strings-that-round-trip/ https://www.exploringbinary.com/java-doesnt-print-the-shorte...