Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!209.197.12.246.MISMATCH!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: float("nan") in set or as key Date: Sun, 29 May 2011 02:25:55 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 36 Message-ID: References: <4DE1881C.8000701@mrabarnett.plus.com> NNTP-Posting-Host: 67-220-17-92.usiwireless.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1306635955 2409 67.220.17.92 (29 May 2011 02:25:55 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 29 May 2011 02:25:55 +0000 (UTC) User-Agent: slrn/0.9.9p1 (Linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6510 On 2011-05-29, Albert Hopkins wrote: > On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: >> Here's a curiosity. float("nan") can occur multiple times in a set or as >> a key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> > These two nans are not equal (they are two different nans) > >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} > > This is the same nan, so it is equal to itself. No, it's not. >>> x = float("nan") >>> y = x >>> x is y True >>> x == y False > I can't cite this in a spec, but it makes sense (to me) that two things > which are nan are not necessarily the same nan. Even if they _are_ the same nan, it's still not equal to itself. -- Grant