Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; '(at': 0.04; 'resulting': 0.04; 'float': 0.07; 'converts': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'nearest': 0.16; 'precision,': 0.16; 'surprises': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'aug': 0.22; 'fraction': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'operations,': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'quite': 0.32; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'range': 0.61; 'float,': 0.84; '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:date:message-id:subject:from:to :content-type; bh=L7J9ESQ7FVU/Iy4trGZycP01OFnFt8eKMu+GMK3tM2M=; b=P4OyRpwiJo+8wsxrEEo99sB9xzB0q7FLOjbI2HClPn1ZkeFQmtD/q9Ru7Q2oPx/Vj2 9U0CbjDJlHnZXWRC2ic05w9UKZE+YgqXYxA9uBdy+cw4VwL2/BouCpBg8qoVAJV7moUJ CQPzOb/AgzNSuyIVf1hYDNZxH9leQ6QFB8KrHl0QB2+qd+Kmuhus7uaIcyNfiYgd8pub lXKlpdPclw+Gy0fRtlqR7AToDTNTMboZmtQrWpnlDgveqk6j6oyWbGfqdvqwPtmaqXXj kVBboVdj/8oDID2IffUxhN9WDfi0KUVNA3gM3F4trsy9ELC4EOwLadRZEajvduNHW6pb pe/w== MIME-Version: 1.0 X-Received: by 10.220.43.19 with SMTP id u19mr25139vce.3.1375338776921; Wed, 31 Jul 2013 23:32:56 -0700 (PDT) In-Reply-To: <51f9fe27$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <51f68d9c$0$30000$c3e8da3$5496439d@news.astraweb.com> <-tidnZTes6qk72TMnZ2dnUVZ8kadnZ2d@giganews.com> <51f9fe27$0$30000$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 1 Aug 2013 07:32:56 +0100 Subject: Re: Unexpected results comparing float to Fraction 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375338779 news.xs4all.nl 15895 [2001:888:2000:d::a6]:39671 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51719 On Thu, Aug 1, 2013 at 7:20 AM, Steven D'Aprano wrote: > I know this, and that's not what surprised me. What surprised me was that > Fraction converts the float to a fraction, then compares. It surprises me > because in other operations, Fractions down-cast to float. > > Adding a float to a Fraction converts the Fraction to the nearest float, > then adds: > > py> 1/3 + Fraction(1, 3) > 0.6666666666666666 Hmm. This is the one that surprises me. That would be like the addition of a float and an int resulting in an int (at least in C; in Python, where floats have limited range and ints have arbitrary precision, the matter's not quite so clear-cut). Perhaps this needs to be changed? ChrisA