Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!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.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.05; 'python': 0.08; '>>>>': 0.09; 'bug?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:95': 0.09; 'float': 0.13; 'precision,': 0.16; 'header:In-Reply-To:1': 0.22; 'math': 0.24; 'skip:1 30': 0.29; 'subject: .': 0.29; 'correct': 0.29; 'url:wiki': 0.29; 'precision': 0.30; 'there': 0.33; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.34; 'to:addr:python- list': 0.35; 'received:org': 0.36; 'uses': 0.38; 'mathematical': 0.38; 'url:org': 0.39; 'url:en': 0.39; 'received:de': 0.39; 'received:78': 0.40; 'to:addr:python.org': 0.40; 'platforms': 0.40; 'url:%0': 0.60; 'simple': 0.61; 'double': 0.61; 'unlimited': 0.64; 'url:%2b': 0.67; 'url:i': 0.74; 'url:530': 0.84; 'url:74': 0.84; 'aka': 0.91; 'only:': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Christian Heimes Subject: Re: Python math is off by .000000000000045 Date: Wed, 22 Feb 2012 19:26:26 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: f049015226.adsl.alicedsl.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329935200 news.xs4all.nl 6963 [2001:888:2000:d::a6]:42069 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20691 Am 22.02.2012 19:13, schrieb Alec Taylor: > Simple mathematical problem, + and - only: > >>>> 1800.00-1041.00-555.74+530.74-794.95 > -60.950000000000045 > > That's wrong. That's only the correct answer for unlimited precision, not for IEEE-754 semantics. http://en.wikipedia.org/wiki/IEEE_754 > Proof > http://www.wolframalpha.com/input/?i=1800.00-1041.00-555.74%2B530.74-794.95 > -60.95 aka (-(1219/20)) > > Is there a reason Python math is only approximated? - Or is this a bug? Python uses the platforms double precision float datatype. Floats are almost never exact. Christian