Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74192
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| 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; 'false.': 0.09; 'keys,': 0.09; 'lookup': 0.09; 'raises': 0.09; 'thus,': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; 'thread': 0.14; "wouldn't": 0.14; 'posted': 0.15; '"=="': 0.16; '"is"': 0.16; 'dict': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'nan': 0.16; 'nans,': 0.16; 'other:': 0.16; 'shortcut': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'comparing': 0.24; 'test.': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'equality': 0.31; 'keyerror:': 0.31; 'file': 0.32; 'class': 0.32; 'this.': 0.32; 'another': 0.32; '(most': 0.33; 'skip:_ 10': 0.34; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'operations': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'otherwise.': 0.36; 'rather': 0.38; 'anything': 0.39; 'recent': 0.39; "couldn't": 0.39; 'itself': 0.39; 'even': 0.60; 'fact,': 0.69; 'jul': 0.74; 'surprise': 0.74; 'subject:For': 0.78; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=HsTApH63BZvKEyZb1dqRu1fsS9Y0foHRRe7c9vWd1T0=; b=DL5oYqCIvgmptgh1Ca0IemWl11st4FhOPwhf/smLgBKbC1SVCCEacY1KgP/ln1zCHt bIHAK8y/VEhkjlrZ7twfoYqooIi0atlQ5CypEBbgu8Law7BMeD8pu9+cesw9Cv+RLgra NTcrq7y4T47lFBxpsgqV3UyA4TNeMYUihJDFuXi3F9mv5lmkiMwURy/yAbATfv3nzd1Q SKxvEpLSvd4yXVSJyGMHp40Pj6plIj9LHRGJI1KHXTcpDMZlOrAyLUzCUp3NxigeY62X YOhx9IqQdT+nTEF7uo9wAwDq3Iy9Y0DUIcm1YPgode1dZeBr1lSWSfykwCwhWELdkQW2 Aacg== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.232.200 with SMTP id tq8mr8177368vdc.32.1404842093270; Tue, 08 Jul 2014 10:54:53 -0700 (PDT) |
| In-Reply-To | <871ttvahaq.fsf@elektro.pacujo.net> |
| References | <53BC05FB.4050707@jmunch.dk> <mailman.11630.1404832805.18130.python-list@python.org> <878uo3akqy.fsf@elektro.pacujo.net> <mailman.11640.1404836832.18130.python-list@python.org> <871ttvahaq.fsf@elektro.pacujo.net> |
| Date | Wed, 9 Jul 2014 03:54:52 +1000 |
| Subject | Re: NaN comparisons - Call For Anecdotes |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11646.1404842102.18130.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1404842102 news.xs4all.nl 2859 [2001:888:2000:d::a6]:36461 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74192 |
Show key headers only | View raw
On Wed, Jul 9, 2014 at 3:31 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> I'd say it would surprise people rather a lot if operations like dict
>> insertion/lookup could trigger arithmetic exceptions. :)
>
> That wouldn't trigger exceptions.
>
> Dict operations do an "is" test before an "==" test. In fact, you
> couldn't even use NaN as a dict key otherwise. Thus, dict operations
> never test NaN == NaN.
Check out the example I posted early in this thread of a dict with
three keys, all of them NaN. And note that hash(float("nan"))==0. Now
try looking up d[0]. Before it raises KeyError, it has to compare that
0 for equality with each of the nans, because it can't shortcut it
based on the hash. In fact, I can prove it thus:
>>> class X:
def __eq__(self, other):
if self is other:
print("Comparing against self - I am me!")
return True
print("Comparing against",other,"-",id(other))
return False
def __hash__(self):
return 0
>>> d[X()]
Comparing against nan - 18777952
Comparing against nan - 19624864
Comparing against nan - 18776272
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
d[X()]
KeyError: <__main__.X object at 0x016B40D0>
Any lookup of anything with a hash of 0 will do this. 0 itself (as any
type of number), another NaN, or anything at all. For the dict to work
sanely, these comparisons have to work and be False.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-09 01:19 +1000
Re: NaN comparisons - Call For Anecdotes Marko Rauhamaa <marko@pacujo.net> - 2014-07-08 19:16 +0300
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-09 02:27 +1000
Re: NaN comparisons - Call For Anecdotes Marko Rauhamaa <marko@pacujo.net> - 2014-07-08 20:31 +0300
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-09 03:54 +1000
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-09 03:57 +1000
Re: NaN comparisons - Call For Anecdotes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-08 18:12 +0000
Re: NaN comparisons - Call For Anecdotes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-08 18:10 +0000
csiph-web