Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!news.kjsl.com!news.alt.net!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: float("nan") in set or as key References: X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney Date: Wed, 01 Jun 2011 15:18:40 +1000 Message-ID: <87ei3e6sen.fsf@benfinney.id.au> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:FKvz3ewMEYMr6TPFOr+ySjm+MW0= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 42 Organization: Unlimited download news at news.astraweb.com NNTP-Posting-Host: fd759b62.news.astraweb.com X-Trace: DXC=3;=GGcX\?LRJ[9olalG_WRL?0kYOcDh@ZW\:Hm@YlDbZAeC]Q<\cKkZUGD@iN[Hd?_YE8aKg9ed^Q Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6786 Chris Angelico writes: > Right. Obviously a true 'real number' representation can't be done. > But there are multiple plausible approximations thereof (the best > being rationals). Sure. But most of those are not what is most commonly meant by ‘float’ type. > Not asking for Python to be changed, just wondering why it's defined > by what looks like an implementation detail. Because, in the case of the ‘float’ type, the agreed-upon meaning of that type – in Python as in just about every other language that is well-specified – is “an IEEE float as per the IEEE 754 spec”. A foolish consistency to the spec would be a hobgoblin for little minds. But, given that a ‘float’ type which deviated from that spec would just be inviting all sorts of other confusion, it's not a foolish consistency. > It's like defining that a 'character' is an 8-bit number using the > ASCII system, which then becomes problematic with Unicode. Right. That's why in Python 3 the Unicode text type is called ‘unicode’, the IEEE float type is called ‘float’, and the byte string type is called ‘bytes’. It's also why the ‘str’ type in Python 2 was painful enough to need changing: it didn't clearly stick to a specification, but tried to straddle the worlds between one specification (a text type) and an incompatible other specification (a bytes sequence type). Where there is a clearly-defined widely-agreed specification for a type, it's a good idea to stick to that specification when claiming to implement that functionality in a type. -- \ “The man who is denied the opportunity of taking decisions of | `\ importance begins to regard as important the decisions he is | _o__) allowed to take.” —C. Northcote Parkinson | Ben Finney