Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6501
| Subject | Re: float("nan") in set or as key |
|---|---|
| From | Albert Hopkins <marduk@letterboxes.org> |
| Date | 2011-05-28 20:28 -0400 |
| References | <4DE1881C.8000701@mrabarnett.plus.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2207.1306628936.9059.python-list@python.org> (permalink) |
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.
Two "nan"s are not equal in the manner that 1.0 and 1.0 are equal:
>>> 1.0 == 1.0
True
>>> float("nan") == float("nan")
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.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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