News for hackers. Stuff that matters.
Re:Python rounds float values by converting them to string a... by mumblemumble on Wednesday August 28, 2019 @09:41AM (#20819648)
The "why does this happen" on that page hits on it, at least tangentially. A lot of what's confusing about IEEE floats isn't the inability to represent all rationals in and of itself, it's more that the particular patterns of inaccuracy end up being different between the computer approximation and the approximations we'd make on paper, because of the different numeric bases.
Re:Python rounds float values by converting them to string a... by ben509 on Wednesday August 28, 2019 @11:05AM (#20820499)
Related to that problem, a major source of confusion with IEEE floats is that languages go to great lengths[1] to present them as decimals and hide the underlying binary denominator. Even when you know they're binary internally, it throws you off.

High level languages are also annoying in that they don't provide great support for working with them as binary denominated rationals, e.g. there's no round_base2 in python, and there's no hex float representation in printf.

[1]: https://news.ycombinator.com/item?id=10915182

Re:Python rounds float values by converting them to string a... by mark-r on Wednesday August 28, 2019 @11:23AM (#20820675)
Python doesn't support hex float in printf, but it does give you an easy way to do the conversion: x.hex()