python math problem

Chris Angelico rosuav at gmail.com
Sat Feb 16 15:30:39 CET 2013


On Sun, Feb 17, 2013 at 12:55 AM, Nobody <nobody at nowhere.com> wrote:
> Furthermore, any such calculation for which the correct answer isn't
> exactly representable should produce the same result as if the correct
> answer had been calculated to an infinite number of digits then rounded to
> the nearest representable value according to the current rounding mode.

That doesn't change the fact that, according to Murphy's Law of
Floating Point Operations, the error will accumulate in one direction
instead of balancing itself out. So while one operation might well
produce the nearest representable value to what you'd expect from real
arithmetic (and I'm not differentiating "real" from "fake" here, but
rather referring to the notion of "real numbers"), multiple sequential
operations will quite probably draw you further and further away. It's
not something to *fear*, just something to understand and manage. It's
no different from estimating by rounding things off, except that a
computer estimates with a tad more precision than a human (since a
computer does *everything* with a tad more precision).

Gratuitous example of ridiculous rounding that still results in a
plausible ball-park figure: "One pound is one kilogram."
http://what-if.xkcd.com/4/

ChrisA



More information about the Python-list mailing list