Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.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; 'definitions': 0.07; 'float': 0.07; 'integral': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; 'assume': 0.14; '(metaclass)': 0.16; 'caused.': 0.16; 'defined.': 0.16; 'enum': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'unequal': 0.16; ':-)': 0.16; 'wrote:': 0.18; "python's": 0.19; 'otherwise,': 0.22; 'header:User-Agent:1': 0.23; 'fraction': 0.24; 'instance,': 0.24; 'mon,': 0.24; 'developers': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'sets': 0.30; "d'aprano": 0.31; 'equality': 0.31; 'steven': 0.31; 'values.': 0.31; 'class': 0.32; 'becomes': 0.33; 'sense': 0.34; 'but': 0.35; 'there': 0.35; 'words,': 0.36; 'requirements': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'received:173': 0.61; 'skip:n 10': 0.64; 'jul': 0.74; 'introduce': 0.78; 'received:fios.verizon.net': 0.84; 'cast': 0.91; 'subject:results': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Unexpected results comparing float to Fraction Date: Mon, 29 Jul 2013 16:48:40 -0400 References: <51f68d9c$0$30000$c3e8da3$5496439d@news.astraweb.com> <51f6a68c$0$30000$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: <51f6a68c$0$30000$c3e8da3$5496439d@news.astraweb.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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375130932 news.xs4all.nl 15997 [2001:888:2000:d::a6]:49356 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51494 On 7/29/2013 1:29 PM, Steven D'Aprano wrote: > On Mon, 29 Jul 2013 13:08:20 -0400, Terry Reedy wrote: > >> In other words, there can be multiple unequal Franctions that have the >> same float value: for instance, Fraction(1,3) and >> Fraction(6004799503160661, 18014398509481984) >> >> > So from that standpoint it makes sense to me to cast to Fraction when >> > comparing. >> >> Otherwise, == becomes non-transitive > > This is Python, and we can make __eq__ methods that do anything, > including be non-transitive, non-reflexive, and nonsensical if we like :-) Yes, Python's developers can intentionally introduce bugs, but we try not to. The definitions of sets and dicts and containment assume that == means equality as mathematically defined. As one time, we had 0 == 0.0 and 0 == Decimal(0) but 0.0 != Decimal(0) (and so on for all integral float values. That 'misfeature' was corrected because of the 'problems' it caused. That lesson learned, one of the design requirements for the new enum class (metaclass) was that it not re-introduce non-transitivity. -- Terry Jan Reedy