Live data from Hacker News

Python rounds float values by converting them to string and then back

github.com

151–152 of 152 posts

Re: Python rounds float values by converting them to string and then back

#151
post #145

Earlier quoted context omitted.

> floating-point calculations are absolutely exact Are you sure about that? What about 1.00000000000001^2 (using eg 64 bit double)?

Maybe the parent wanted to say that the result is detetministic and not far too off from the true value (in fact, as accurate as possible given the format). In the other words FP is exact but abides by a slight different calculation rule involving rounding.

Floating point is usually deterministic, but from a math point of view it is inexact (in most cases it only approximates the exact answer). In many cases that is fine, which is why it is used, but it is important to remember that.
Post reply on HN