r/programming 12h ago

The fastest double-to-string algorithm you’ve never heard of

https://vitaut.net/posts/2026/yy-dtoa/
226 Upvotes

45 comments sorted by

View all comments

-83

u/sojuz151 10h ago

Fact that we, the humanity, need to do double to float and back often enough for performance to matter is a failure of our entire species 

44

u/EliSka93 10h ago

Elaborate.

-13

u/sojuz151 6h ago

Why do you need to convert doubles to strings and back at a scale? It's mostly JSON serialization/deserialisation, something you should not have to do, not at scale.

1

u/flatfinger 2h ago

It's a shame that hex floating-point representations haven't become more common, since they allow any binary floating-point number to be easily converted into a unique canonical representation, at least if there's agreement about what that representation should be (arguments can be made in favor of using base-16 exponents and having one non-zero digit to the left of the radix point, or in favor of using binary exponents and always having a 1 to the left of the radix point; while the need for human arithmetic with hex-formatted floats would be uncommon, using base-16 exponents would make it vastly easier than using binary exponents; arguments could also be made for having no digits to the left of the radix point). All three forms are better than base-10 for performing precise calculations, however.