

Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- IEEE-754 is a harsh mistress.by chasil
- For a long time Microsoft's strtod implementation was broken, I'd think most people would be using netlib or one of the newer algorithms.
https://www.exploringbinary.com/visual-c-plus-plus-strtod-st...
https://lemire.me/blog/2026/02/01/converting-floats-to-strin...
by RossBencina - When I was writing some ASM for a microcontroller to do string <--> float conversion, I could find almost nothing on how to best perform the operations.
There were essentially three ways to do it. Muddle through with a naive implementation. Look at the ASM of an old 8-bit machine. The final category was the by far the most dominant suggestion, to the point that anything else is almost like lost knowledge now. That solution was to use the C standard functions.
It seems like this is a sufficiently unpleasant task that as soon as anyone didn't absolutely have to do it all themselves, the punted to a black box solution.
There's probably something to be said there about the plethora of hobbiest 3d engines in comparison.
by Lerc - Floats? You can't even parse ints! https://blog.habets.se/2022/10/No-way-to-parse-integers-in-C...
- A subtlety around denormals too. In the article, it quotes a definition of ERANGE underflow as closer to zero than the smallest _normalised_ positive value.
Denormals therefore count as underflow and strtod() sets ERANGE for them, even though they they are legitimate values to store as strings and parse back.
Some implementations of strtod() return the correct floating-point value for these, while setting ERANGE. Others discard the value and return 0.0, preventing them from being round-tripped to strings.
by jlokier - > the linux man pages for these functions literally don't mention this at all
> the fact that the man page never makes any note of this being an extension ([…]) is really notable to me.
> this is completely undocumented on the linux man page.
The Linux man page maintainers are really friendly in my experience, so it's probably worth reporting this to them [0] [1].
[0]: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/...
- C number parsing functions are fundamentally broken, since they are locale-dependend. There are many bugs when one parses a number assuming it has decimal point, but later on systems with locale different from one used on developer's machine it may be suddenly comma instead of point. So, one should avoid using them almost always and use std::from_chars (available in new C++ versions) or some other thirdparty library.by Panzerschrek
- It's quite astonishing how the historical inability of commonly used programming languages (from FORTRAN all the way to, say, Java/C#) to ergonomically return two values from a function call has caused people to invent all kinds of insane APIs/contracts.
Instead, we're stuck with "check if the return value is -1 and if it is, check the global variable errno" at best, and with "the function doesn't really reliably reports its errors so don't feed it malformed data, idc" at worst.[double x, errno_t errno] = strtod(s, nullptr); if (errno != 0) { // ... } [x, _] = strtod(s, nullptr); // When you're certain the error is impossible or just don't careby Joker_vD