Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.052 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '0.1': 0.09; 'omit': 0.09; 'subject:question': 0.10; '-tkc': 0.16; '0.3': 0.16; '[1].': 0.16; 'formatted': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'zero.': 0.16; 'wrote:': 0.18; 'pfxlen:0': 0.19; '>>>': 0.22; 'cc:addr:gmail.com': 0.22; 'module,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; '[1]': 0.29; "i'm": 0.30; 'url:wiki': 0.31; 'decimal': 0.31; 'url:wikipedia': 0.31; 'anybody': 0.35; 'really': 0.36; 'subject:Simple': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'should': 0.36; 'detail': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'remove': 0.60; 'read': 0.60; 'most': 0.60; 'numbers': 0.61; 'first': 0.61; 'times': 0.62; 'show': 0.63; 'more': 0.64; 'effectively': 0.66; 'internally.': 0.84; 'phil': 0.84; 'received:50.22': 0.84 Date: Tue, 15 Apr 2014 13:33:40 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Simple question In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397586829 news.xs4all.nl 2897 [2001:888:2000:d::a6]:45456 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70284 On 2014-04-15 19:18, Phil Dobbin wrote: > I'm confused as to this part: > > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? You omit one key detail in your "....", the "e-17" which means that is 5.55111... times 10^-17 which is a REALLY small number. To better show that, have it formatted to place: >>> "%55.55f" % (0.1 + 0.1 + 0.1 - 0.3) '0.0000000000000000555111512312578270211815834045410156250' For most engineering purposes, that's effectively zero. It comes about because of how floating-point numbers are represented internally. You can read a lot more than anybody should want to know at [1]. By using the Decimal module, you remove some of that imprecision. -tkc [1] http://en.wikipedia.org/wiki/Ieee_float