Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6510

Re: float("nan") in set or as key

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 <invalid@invalid.invalid>
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 <irsarj$2b9$1@reader1.panix.com> (permalink)
References <4DE1881C.8000701@mrabarnett.plus.com> <mailman.2207.1306628936.9059.python-list@python.org>
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

Show key headers only | View raw


On 2011-05-29, Albert Hopkins <marduk@letterboxes.org> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: float("nan") in set or as key Albert Hopkins <marduk@letterboxes.org> - 2011-05-28 20:28 -0400
  Re: float("nan") in set or as key Erik Max Francis <max@alcyone.com> - 2011-05-28 17:44 -0700
  Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-05-29 02:25 +0000
    Re: float("nan") in set or as key Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-05-29 10:27 +0200
      Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-05-29 14:41 +0000
        Re: float("nan") in set or as key MRAB <python@mrabarnett.plus.com> - 2011-05-29 18:44 +0100
          Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:27 +0000
        Re: float("nan") in set or as key Chris Angelico <rosuav@gmail.com> - 2011-05-30 03:50 +1000
        Re: float("nan") in set or as key Christian Heimes <lists@cheimes.de> - 2011-05-29 20:05 +0200
          Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:46 +0000
        Re: float("nan") in set or as key Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-05-29 20:36 -0700

csiph-web