Path: csiph.com!usenet.pasdenom.info!goblin1!goblin.stu.neva.ru!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.058 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'referring': 0.07; 'rounding': 0.09; 'subject:python': 0.11; '"real"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'nearest': 0.16; 'sequential': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'balancing': 0.22; 'subject:problem': 0.22; 'example': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'operations,': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'correct': 0.28; 'received:209.85.212': 0.28; '(since': 0.29; 'arithmetic': 0.29; 'mode.': 0.29; 'probably': 0.29; "i'm": 0.29; 'error': 0.30; 'expect': 0.31; 'point': 0.31; '(and': 0.32; 'to:addr:python- list': 0.33; 'operations': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'direction': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'except': 0.36; 'but': 0.36; 'should': 0.36; 'itself': 0.37; 'does': 0.37; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'things': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'further': 0.61; 'real': 0.61; 'different': 0.63; 'more': 0.63; 'results': 0.65; 'url:4': 0.72; '2013': 0.84; 'notion': 0.84; 'off,': 0.84; '"one': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=QOd97kDyNujbFagl54QPzxKbpIpfjcvEnB+bKQiuzyQ=; b=Px2o3bU8yxy984+XQzu5Xvdkc1ZVgawpEB8K4Nl25CcbPl8agZ9QUVYsS1s4b9MwrE jYdNHcy3me6jaXuiXH6HboXWYJaYBUU8vjD1PIFpV7l8KBViSnBgZNHSwEj7/Iz9sf+z JOAtW8tpMX+FVkMQHAINN4Bj4pfgMweYmbqKabKBFRRGeH83lD48UHHOWhP1M23ud5i8 HhGuSXu8aKymJePGHDuW51Y+yHCjhfUxo4vZt5UmkOb1nePpGMTwq6wAvtlgsHBYAVhH GyVpGu5FIY+Z1ItTC8U3B54BB8bFFrnN7uF3ROnG1BhCAAO8jACLSOyI/8lTvynzQ9dF kB5Q== MIME-Version: 1.0 X-Received: by 10.58.50.7 with SMTP id y7mr8186451ven.24.1361025039855; Sat, 16 Feb 2013 06:30:39 -0800 (PST) In-Reply-To: References: Date: Sun, 17 Feb 2013 01:30:39 +1100 Subject: Re: python math problem From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361025049 news.xs4all.nl 6875 [2001:888:2000:d::a6]:36858 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39001 On Sun, Feb 17, 2013 at 12:55 AM, Nobody 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