Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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; 'wed,': 0.03; 'instance,': 0.05; 'int': 0.05; 'ascii': 0.07; 'defines': 0.07; 'imply': 0.07; 'python': 0.08; 'establishes': 0.09; 'float.': 0.09; "it'd": 0.09; 'none:': 0.09; 'underlying': 0.09; 'pm,': 0.10; 'def': 0.12; 'binary': 0.14; 'wrote:': 0.14; 'defined': 0.14; 'library': 0.15; "'int'": 0.16; "'long'": 0.16; "'real": 0.16; "2's": 0.16; '8-bit': 0.16; 'angelico': 0.16; 'bitwise': 0.16; 'bytes),': 0.16; 'changed,': 0.16; 'elsewhere,': 0.16; 'extensible': 0.16; 'integers.': 0.16; "isn't.": 0.16; 'message- id:@glegroupsg2000goo.googlegroups.com': 0.16; 'precision,': 0.16; 'reply-to:addr:comp.lang.python': 0.16; 'saying.': 0.16; 'subject:key': 0.16; 'subject:set': 0.16; 'to:addr:comp.lang.python': 0.16; 'trivially': 0.16; 'float': 0.16; 'question.': 0.16; 'cc:addr:python-list': 0.17; 'obviously': 0.17; 'language': 0.18; 'operations.': 0.19; '(which': 0.20; 'header:In-Reply-To:1': 0.21; "aren't": 0.22; 'right.': 0.22; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; '(where': 0.23; 'differ': 0.23; 'library.': 0.25; 'point,': 0.25; 'function': 0.25; 'definition': 0.26; "i'm": 0.27; 'wondering': 0.28; '(the': 0.28; 'character': 0.29; 'are.': 0.29; "python's": 0.29; 'true,': 0.29; 'instead': 0.29; 'cc:addr:python.org': 0.30; 'fact': 0.30; 'carl': 0.30; 'looks': 0.31; 'define': 0.31; 'seem': 0.32; "can't": 0.32; 'scale': 0.32; 'does': 0.33; 'asking': 0.33; 'too': 0.33; 'things': 0.33; 'rather': 0.34; 'question': 0.34; 'received:209.85.212': 0.34; 'chris': 0.34; 'characters': 0.34; 'done.': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'defining': 0.35; 'numbers.': 0.35; 'sense,': 0.35; 'using': 0.35; 'several': 0.36; 'uses': 0.36; 'running': 0.37; 'received:google.com': 0.37; 'something': 0.37; 'received:209.85': 0.37; 'comparing': 0.37; 'floating': 0.37; 'model': 0.37; 'pretty': 0.37; 'reasons': 0.37; 'put': 0.37; 'think': 0.38; 'could': 0.38; 'but': 0.38; 'data': 0.38; 'implemented': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'skip:s 20': 0.39; 'should': 0.39; 'called': 0.39; 'received:209': 0.39; 'system.': 0.39; 'add': 0.39; 'current': 0.40; "couldn't": 0.40; 'meaning': 0.40; 'really': 0.40; 'more': 0.60; 'best': 0.60; 'your': 0.60; 'power': 0.61; 'therefore,': 0.63; 'to:addr:googlegroups.com': 0.63; 'details': 0.64; '31,': 0.65; 'square': 0.67; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'care': 0.72; 'reply- to:addr:googlegroups.com': 0.73; 'problematic': 0.84; 'sets,': 0.84; 'thereof': 0.84; 'received:209.85.212.56': 0.91; 'received :mail-vw0-f56.google.com': 0.91 Newsgroups: comp.lang.python Date: Tue, 31 May 2011 23:09:36 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=74.37.53.32; posting-account=XFEWnwoAAADNO10m3Wcmq_SWdmyZuXff User-Agent: G2/1.0 X-Google-Web-Client: true MIME-Version: 1.0 Subject: Re: float("nan") in set or as key From: Carl Banks To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: comp.lang.python@googlegroups.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 83 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306908579 news.xs4all.nl 49176 [::ffff:82.94.164.166]:51286 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6788 On Tuesday, May 31, 2011 8:57:57 PM UTC-7, Chris Angelico wrote: > On Wed, Jun 1, 2011 at 1:30 PM, Carl Banks=20 > wrote: > > I think you misunderstood what I was saying. > > > > It's not *possible* to represent a real number abstractly in any digita= l computer. =A0Python couldn't have an "abstract real number" type even it = wanted to. >=20 > True, but why should the "non-integer number" type be floating point > rather than (say) rational? Python has several non-integer number types in the standard library. The o= ne we are talking about is called float. If the type we were talking about= had instead been called real, then your question might make some sense. B= ut the fact that it's called float really does imply that that underlying r= epresentation is floating point. > Actually, IEEE floating point could mostly > be implemented in a two-int rationals system (where the 'int' is > arbitrary precision, so it'd be Python 2's 'long' rather than its > 'int'); in a sense, the mantissa is the numerator, and the scale > defines the denominator (which will always be a power of 2). Yes, > there are very good reasons for going with the current system. But are > those reasons part of the details of implementation, or are they part > of the definition of the data type? Once again, Python float is an IEEE double-precision floating point number.= This is part of the language; it is not an implementation detail. As I m= entioned elsewhere, the Python library establishes this as part of the lang= uage because it includes several functions that operate on IEEE numbers. And, by the way, the types you're comparing it to aren't as abstract as you= say they are. Python's int type is required to have a two's-compliment bi= nary representation and support bitwise operations. > > (Math aside: Real numbers are not countable, meaning they=20 > > cannot be put into one-to-one correspondence with integers. > > =A0A digital computer can only represent countable things > > exactly, for obvious reasons; therefore, to model > > non-countable things like real numbers, one must use a > > countable approximation like floating-point.) >=20 > Right. Obviously a true 'real number' representation can't be done. > But there are multiple plausible approximations thereof (the best > being rationals). That's a different question. I don't care to discuss it, except to say tha= t your default real-number type would have to be called something other tha= n float, if it were not a floating point. > Not asking for Python to be changed, just wondering why it's defined > by what looks like an implementation detail. It's like defining that a > 'character' is an 8-bit number using the ASCII system, which then > becomes problematic with Unicode. It really isn't. Unlike with characters (which are trivially extensible to= larger character sets, just add more bytes), different real number approxi= mations differ in details too important to be left to the implementation. For instance, say you are using an implementation that uses floating point,= and you define a function that uses Newton's method to find a square root: def square_root(N,x=3DNone): if x is None: x =3D N/2 for i in range(100): x =3D (x + N/x)/2 return x It works pretty well on your floating-point implementation. Now try runnin= g it on an implementation that uses fractions by default.... (Seriously, try running this function with N as a Fraction.) So I'm going to opine that the representation does not seem like an impleme= ntation detail. Carl Banks