Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'algorithm': 0.04; 'binary': 0.07; 'problem:': 0.07; 'anders': 0.09; 'fixed,': 0.09; 'function,': 0.09; 'python': 0.11; 'bug': 0.12; '2.7': 0.14; 'equivalence': 0.16; 'nan': 0.16; 'unequal': 0.16; 'wrote:': 0.18; '(but': 0.19; '>>>': 0.22; 'platforms': 0.22; 'import': 0.22; '(in': 0.22; 'issue.': 0.22; 'convenient': 0.24; 'fraction': 0.24; 'tells': 0.24; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; 'decimal': 0.31; 'class': 0.32; 'cases': 0.33; 'implemented': 0.33; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'doubt': 0.36; 'false': 0.36; 'expected': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'bad': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'ian': 0.60; 'you.': 0.62; 'provide': 0.64; 'news': 0.67; 'between': 0.67; 'integrity': 0.74; 'jul': 0.74; 'subject:For': 0.78; 'everything,': 0.84; 'itself?': 0.84; 'regard.': 0.84; 'relation.': 0.84 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=5El9I+LzhrzYJhR/kgGCAceiRZMWjnp+RM6N7nFokKg=; b=STogadmwGaDDxHs1l/BvaIxv2xYza+IHV8AwvvLC2QNUxKYjUCD77Jw4Ipoyh2l0QC GVqeZi70uGvbAfHsYPSWobRZmEW13O+lnPnfZv7pZ6BbH/LpFfeXRjdFryvKHBrWpKCC p5SK0eqzdb3RquwjMb+4RsBQRscS/gMsR7vUDpr5HwUj3kF29YPI/101KyebyCJLaiH9 xyU/T9rPkr4kC8Ys7jlyN/rEp3VbDJsVuIvfD/DYZu05OXBwvWwhPIeZWmgKjiuqAJMi jQrj8HCoQjQyvXacs9iLm++lj4xPR48uZ+KenDHLqeBYG+Dob3gP4sl5O3HTYc018Hjm sYNg== X-Received: by 10.70.126.130 with SMTP id my2mr7099426pdb.124.1404849492282; Tue, 08 Jul 2014 12:58:12 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53BC3E4E.3020707@jmunch.dk> References: <53BC05FB.4050707@jmunch.dk> <53BC3E4E.3020707@jmunch.dk> From: Ian Kelly Date: Tue, 8 Jul 2014 13:57:30 -0600 Subject: Re: NaN comparisons - Call For Anecdotes To: Python Content-Type: text/plain; charset=UTF-8 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404849501 news.xs4all.nl 2904 [2001:888:2000:d::a6]:53343 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74209 On Tue, Jul 8, 2014 at 12:54 PM, Anders J. Munch <2014@jmunch.dk> wrote: > > Ian Kelly wrote: >> >> As far as I know nothing changed between 2.4 and 2.7 in this regard. >> Python has always had NaN compare unequal to everything, per the >> standard. > > It might have been platform-specific in 2.4. I doubt it, but okay, which platform? >> Okay, here's your problem: there isn't just one binary representation >> for NaN. > > I'm fully aware of that. Whether NaN's are one equivalence class or several > is not the issue. What matters is the integrity of the equivalence relation. I have some bad news for you. This is on Python 2.7.6: >>> from decimal import Decimal >>> from fractions import Fraction >>> Decimal(2) == 2 True >>> 2 == Fraction(2) True >>> Decimal(2) == Fraction(2) False I'm not sure exactly when this bug was fixed, but it works as expected in 3.4.0. >> Following the standard isn't a good reason itself? > > If a standard tells you to jump of a cliff... So I don't know of a good use case for nan != nan in Python (but really I'm not the one to ask), but I do know of use cases in other scenarios. On platforms that don't provide an isnan() function, the only convenient and efficient way to test for nan is by testing reflexivity: x != x. Following the standard means that any algorithm that uses this trick can (in theory) be implemented in Python without changes.