Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!novia!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: Wed, 1 Jun 2011 21:01:23 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 38 Message-ID: References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: dsl.comtrol.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1306962083 26348 64.122.56.22 (1 Jun 2011 21:01:23 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 1 Jun 2011 21:01:23 +0000 (UTC) User-Agent: slrn/pre0.9.9-102 (Linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6827 On 2011-05-29, Nobody wrote: > On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: > >>> The correct answer to "nan == nan" is to raise an exception, because >>> you have asked a question for which the answer is nether True nor >>> False. >> >> Wrong. > > That's overstating it. There's a good argument to be made for raising > an exception. Bear in mind that an exception is not necessarily an > error, just an "exceptional" condition. > >> The correct answer to "nan == nan" is False, they are not equal. > > There is no correct answer to "nan == nan". For those of us who have to deal with the real world (that means complying with IEEE-754), there _is_ a correct answer. IIRC, the IEEE standard requires nan == nan is false, and nan != nan is true. That said, I don't remember what the other comparisons are supposed to do... > Defining it to be false is just the "least wrong" answer. > > Arguably, "nan != nan" should also be false, but that would violate > the invariant "(x != y) == !(x == y)". And it would violate the IEEE standard. IEEE-754 has it's warts, but we're far better off than we were with dozens of incompatible, undocumented, vendor-specific schemes (most of which had more warts than IEEE-754). -- Grant Edwards grant.b.edwards Yow! I'm dressing up in at an ill-fitting IVY-LEAGUE gmail.com SUIT!! Too late...