Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.04; 'distinction': 0.07; 'happily': 0.07; 'patterns': 0.07; 'removes': 0.07; 'python': 0.08; 'precision': 0.09; 'struct': 0.09; 'pm,': 0.10; 'binary': 0.14; 'wrote:': 0.14; 'defined': 0.14; "'int'": 0.16; "'long'": 0.16; 'angelico': 0.16; 'conforms': 0.16; 'exposes': 0.16; 'floats': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer.': 0.16; 'nan': 0.16; 'okay,': 0.16; 'pointers,': 0.16; 'py3': 0.16; 'subject:key': 0.16; 'subject:set': 0.16; 'value",': 0.16; "\xa0it's": 0.16; 'float': 0.16; 'question.': 0.16; 'mon,': 0.17; 'meant': 0.18; 'enormous': 0.19; 'part,': 0.19; 'command': 0.19; 'header:In- Reply-To:1': 0.21; 'interface': 0.21; 'trying': 0.23; 'integer': 0.23; 'received:209.85.210.174': 0.23; 'received:mail- iy0-f174.google.com': 0.23; 'objects': 0.23; '(or': 0.24; 'code': 0.24; 'values': 0.25; 'format,': 0.25; 'function': 0.25; 'message- id:@mail.gmail.com': 0.28; "python's": 0.29; 'rid': 0.29; 'bit': 0.30; "won't": 0.30; '(maybe': 0.30; 'carl': 0.30; 'construct': 0.30; 'exists,': 0.30; 'objects.': 0.30; 'pattern': 0.30; 'it.': 0.31; 'value.': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'list': 0.33; "isn't": 0.33; 'question': 0.34; 'chris': 0.34; 'concepts': 0.34; 'there': 0.35; 'ordered': 0.35; 'recognize': 0.35; 'using': 0.35; 'quite': 0.36; 'certain': 0.36; 'uses': 0.36; 'received:google.com': 0.37; 'something': 0.37; 'change': 0.37; 'received:209.85': 0.37; 'designing': 0.37; 'floating': 0.37; 'reasons': 0.37; 'could': 0.38; 'but': 0.38; 'data': 0.38; 'hardware': 0.38; 'linked': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'case,': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'getting': 0.40; 'worth': 0.60; 'almost': 0.60; 'details': 0.64; 'removal': 0.65; 'special': 0.66; 'refuse': 0.67; 'collection': 0.72; '30,': 0.84; '12:17': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=vKyJthc7J7+Cw52eqt/fbH41i4OZW/S61uEEmm+JNSA=; b=wXuVfUhLf+g4yR9k5PkMxL3OWbp3dgr0maVxDarsxDnSU4XB0WhSqJaqWOdvPK8Vix iIdVgzmXq8Psd2urqXpRGfxsvuS2WQ6yjFCRAk8KLYb02mU+sDH11Togb6T42n0MFeEd Gfq447sHD0rWEclCbId1TpyguM6EzamrqcML0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=WxKiK3y/vmBYqm8V8BDU4QwCwVe2K93HZy8QdpjGOsMD8MWysY7KT63yest5+/UHPJ AuhgNWGsWQ7D0xxv8CxYIOUKV1lvnCtDVYsPEHD45KMvvy0zif9CMsgQsarZc5ILanZq L/DuoVlaA/b6qVXAfDi/loLchduxJKxPGAm20= MIME-Version: 1.0 In-Reply-To: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Date: Mon, 30 May 2011 12:53:59 +1000 Subject: Re: float("nan") in set or as key From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306724043 news.xs4all.nl 49183 [::ffff:82.94.164.166]:42465 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6614 On Mon, May 30, 2011 at 12:17 PM, Carl Banks wro= te: > If I were designing a new floating-point standard for hardware, I would c= onsider getting rid of NaN. =A0However, with the floating point standard th= at exists, that almost all floating point hardware mostly conforms to, ther= e are certain bit pattern that mean NaN. > > Python could refuse to construct float() objects out of NaN (I doubt it w= ould even be a major performance penalty), but there's reasons why you woul= dn't, the main one being to interface with other code that does use NaN. = =A0It's better, then, to recognize the NaN bit patterns and do something re= asonable when trying to operate on it. Okay, here's a question. The Python 'float' value - is it meant to be "a Python representation of an IEEE double-precision floating point value", or "a Python representation of a real number"? For the most part, Python's data types are defined by their abstract concepts - a list isn't defined as a linked list of pointers, it's defined as an ordered collection of objects. Python 3 removes the distinction between 'int' and 'long', where 'int' is <2**32 and 'long' isn't, so now a Py3 integer is... any integer. The sys.float_info struct exposes details of floating point representation. In theory, a Python implementation that uses bignum floats could quite happily set all those values to extremes and work with enormous precision (or could use a REXX-style "numeric digits 100" command to change the internal rounding, and automatically update sys.float_info). And in that case, there would be no NaN value. If Python is interfacing with some other code that uses NaN, that code won't be using Python 'float' objects - it'll be using IEEE binary format, probably. So all it would need to entail is a special return value from an IEEE Binary to Python Float converter function (maybe have it return None), and NaN is no longer a part of Python. The real question is: Would NaN's removal be beneficial? And if so, would it be worth the effort? Chris Angelico