Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'infinite': 0.07; 'type,': 0.07; 'python': 0.08; '754': 0.09; 'manipulate': 0.09; 'values,': 0.09; 'am,': 0.14; 'received:209.85.214.174': 0.14; 'received :mail-iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'angelico': 0.16; 'err': 0.16; 'exponential': 0.16; 'floats': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:key': 0.16; 'subject:set': 0.16; 'header:In-Reply-To:1': 0.21; '(b)': 0.23; "doesn't": 0.25; 'message-id:@mail.gmail.com': 0.28; 'language.': 0.28; 'received:209.85.214': 0.28; 'sat,': 0.29; '"real': 0.30; 'cap': 0.30; 'supposed': 0.31; 'properly': 0.32; 'to:addr:python-list': 0.33; 'chris': 0.34; 'nobody': 0.34; '(a)': 0.35; 'numbers.': 0.35; 'store': 0.35; 'using': 0.35; 'hold': 0.36; 'several': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'floating': 0.37; 'ways': 0.37; 'but': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'should': 0.39; 'received:209': 0.39; 'rest': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'power': 0.61; 'perfectly': 0.65 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; bh=IqD27sMLbQztceNfYsAGugcSG4EBxclurhq2xA5kQ4M=; b=LM/Vmp2dsu/Sr46NeDz8Lh1PwPsdiF/TpZri14EWSwllGkr/82KxFqxA9qRf2+mjvV V00I6RUCceqLupyBt8e9/2+avkGU+Om8qjD8COPDWFnRgyIkr2AH4mzl0iMsidOoI0Bp Cibfm5QQNDlwJpuwLbRax+xnwTRCuqW0gWkd8= 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; b=TAbplcgU/dAMPh29bIt9hNXVz9kwKeIuSSQz9xmY8Ga39HlBNGqjrKCPZy1dJLCKr5 hEODLm9En3Meu/h/6C/EBohaswWAh15X7Q6KNBRV3z+SuqGo4I/zH5JY8ySKO9uNvZ/Q JAwSaNcQcn2mJg3eUSZno5y/nohP67IEYJ8H4= MIME-Version: 1.0 In-Reply-To: References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de75dd5$0$29983$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 4 Jun 2011 09:51:06 +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 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: 18 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307145069 news.xs4all.nl 49044 [::ffff:82.94.164.166]:60092 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6982 On Sat, Jun 4, 2011 at 9:29 AM, Nobody wrote: > Floats are supposed to approximate reals. They're also a Python > data type, and should make some effort to fit in with the rest of > the language. > That's what I thought a week ago. But that's not really true. Floats are supposed to hold non-integral values, but the data type is "IEEE 754 floating point", not "real number". There's several ways to store real numbers, and not one of them is (a) perfectly accurate, or (b) plausibly fast to calculate. Using rationals (fractions) with infinite range leads to exponential performance costs, and still doesn't properly handle irrationals like pi. And if you cap the denominator to a power of 2 and cap the length of the mantissa, err I mean numerator, then you have IEEE 754 floating point. Python offers you a way to store and manipulate floating point numbers, not real numbers. Chris Angelico