Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.063 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'mrab': 0.05; 'float': 0.07; '0.1': 0.09; 'pretend': 0.09; 'did.': 0.16; 'evaluates': 0.16; 'formatted': 0.16; 'rounding': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'meant': 0.20; 'mon,': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'decimal': 0.31; 'division': 0.31; 'equality': 0.31; 'checking': 0.33; 'case,': 0.35; 'equal': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'opposed': 0.36; "didn't": 0.36; 'useful': 0.36; 'error.': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'ian': 0.60; 'range': 0.61; "you're": 0.61; 'such': 0.63; 'within': 0.65; 'worth': 0.66; 'to,': 0.72; 'jul': 0.74; 'subject:results': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=2JgK96EqEY8bvBROQlGXJDDl6wkLYAQ7q4e/1Lqh+r4=; b=oSFhfMBUNgN8X++NsbnrmSmb9ZA+5dBCdYuiVxOChKvKfBTucLHNiMYRx+qNepYbmd LpnvTyfrE9FKHS2CHAqL5YlXabbg/93nL+cw+xoooJphz+ezWA6zAoNhsbzd9urrtGbK Hmz0Qh/DntVlJHYVTr8kvpiI5dF8KuGpNgLdadmvuAZ70e275xeBG+QRhYx5wFNbm1m0 dRBD6EBfr6rB1b2yDOa2+SK8ff4KjO8x/ISdmTwetOfQOKsx4xl6v+3M7arO89/0QNpO jdWKUl4vXbami8JMCN/6Me4QFAcc0BMZjfD4JyNuxuNRDOKoszNlr07Za9wfnH06IVft 1xDg== X-Received: by 10.68.129.138 with SMTP id nw10mr37132002pbb.158.1375119358783; Mon, 29 Jul 2013 10:35:58 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51F6A093.5000803@mrabarnett.plus.com> References: <51f68d9c$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F693B4.9000201@mrabarnett.plus.com> <51F6A093.5000803@mrabarnett.plus.com> From: Ian Kelly Date: Mon, 29 Jul 2013 11:35:18 -0600 Subject: Re: Unexpected results comparing float to Fraction 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375119362 news.xs4all.nl 15982 [2001:888:2000:d::a6]:57795 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51469 On Mon, Jul 29, 2013 at 11:04 AM, MRAB wrote: > On 29/07/2013 17:40, Ian Kelly wrote: >> At the point where the float is exactly equal to the value you get >> from the floating-point division 1/3. If it's some other float then >> the user didn't get there by entering 1/3, so it's not worth trying to >> pretend that they did. >> > I thought that you're not meant to check for equality when using floats. Equality checking is useful for floats when there is exactly one value that you want to test for as in this case, as opposed to a range of approximate values that are considered to be equal within rounding error. There is exactly one float that the expression 0.1 evaluates to, and although it's not equal to the decimal 0.1, it is the only float that we want to format as "0.1". The immediately preceding and following floats are 0.09999999999999999 and 0.10000000000000002, and they are formatted as such because they're not equal to the float that you get from 0.1.