Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.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.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'mrab': 0.05; 'float': 0.07; 'constructor.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'rounding': 0.16; 'wrote:': 0.18; 'library': 0.18; 'all,': 0.19; 'header:User-Agent:1': 0.23; 'error': 0.23; 'fraction': 0.24; 'mon,': 0.24; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'cool': 0.30; "i'm": 0.30; '>>>>': 0.31; 'received:84': 0.35; 'but': 0.35; 'should': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'ago,': 0.61; 'mentioned': 0.61; 'become': 0.64; 'more': 0.64; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'jul': 0.74; 'reply- to:addr:python.org': 0.84; 'drops': 0.91; 'subject:results': 0.91; '2013': 0.98 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=RZapVTdv c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=POziZqpqTb0A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=qLDMBdlwUyoA:10 a=exGjJRzzmXzMdR8uyyAA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Mon, 29 Jul 2013 17:48:21 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Unexpected results comparing float to Fraction References: <51f68d9c$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F693B4.9000201@mrabarnett.plus.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375116500 news.xs4all.nl 15933 [2001:888:2000:d::a6]:48955 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51460 On 29/07/2013 17:20, Chris Angelico wrote: > On Mon, Jul 29, 2013 at 5:09 PM, MRAB wrote: >> I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats >> are approximate anyway, and the float value 1/3 is more likely to be >> Fraction(1, 3) than Fraction(6004799503160661, 18014398509481984). > > At what point should it become Fraction(1, 3)? > When the error drops below a certain threshold. >>>> Fraction(0.3) > Fraction(5404319552844595, 18014398509481984) >>>> Fraction(0.33) > Fraction(5944751508129055, 18014398509481984) >>>> Fraction(0.333) > Fraction(5998794703657501, 18014398509481984) >>>> Fraction(0.3333333) > Fraction(6004798902680711, 18014398509481984) >>>> Fraction(0.3333333333) > Fraction(6004799502560181, 18014398509481984) >>>> Fraction(0.3333333333333) > Fraction(6004799503160061, 18014398509481984) >>>> Fraction(0.33333333333333333) > Fraction(6004799503160661, 18014398509481984) > > Rounding off like that is a job for a cool library function (one of > which was mentioned on this list a little while ago, I believe), but > not IMO for the Fraction constructor. >