Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32259
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'float': 0.05; 'modify': 0.05; 'expressions': 0.07; 'counting': 0.09; 'errors,': 0.09; 'cases': 0.15; 'sat,': 0.15; 'value.': 0.15; 'away!': 0.16; 'comparison.': 0.16; 'digits.': 0.16; 'enough.': 0.16; 'equality.': 0.16; 'ever!': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hint:': 0.16; 'oct': 0.16; 'subject:fails': 0.16; 'wrote:': 0.17; 'mathematical': 0.17; 'otherwise,': 0.20; 'received:209.85.214.174': 0.21; 'large,': 0.22; 'example': 0.23; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'am,': 0.27; 'replace': 0.27; 'small,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; "d'aprano": 0.29; 'decimal': 0.29; 'equality': 0.29; "people's": 0.29; 'statements': 0.29; 'steven': 0.29; 'use?': 0.29; 'normally': 0.30; 'point': 0.31; 'not.': 0.32; 'asked': 0.33; 'museum': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'should': 0.36; 'too': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'days': 0.60; 'evaluate': 0.62; 'close': 0.63; 'fulfill': 0.65; 'of:': 0.65; 'account': 0.67; 'you:': 0.75; 'age': 0.83; 'old,': 0.83; 'actually,': 0.84; 'correctly?': 0.84; 'flame': 0.84; 'hardly': 0.84; 'old.': 0.95; 'taught': 0.97 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=T/64xK0PcqZ9w5RaqOn8tpnr3z+nJlYLCOk1tKxb7O4=; b=aQGdmPepTDhKEMHvgS4O3TlDwDdxNCUmwggF03MGWqT2pcgepLoMAevCroeOq/mG+l W291mpQkfEUhjY8HkB9CJy8nHD55CtkKHFsKh36vBGQ+qTbB/O9tkXDlHkYdp3mZ1aQw jmfBnvdEkal7VRYhSNMNVJciBQkN8SHyt546Klm3iNWZfZCD/CNl3MnF4btMOSoN4vSJ M8vnUOWe2c4IaMM/miX/n5SDpPSIfRWCUw0CNsJSe3jlrna/nu10JmU+mERABKUMRFrl RWLwlEvWkJGNPi82VIe65y/IkDO6mPkXdfXQOFjyT+HtFEjEpa/CGMPObXkxp98dCtuY whdA== |
| MIME-Version | 1.0 |
| In-Reply-To | <508ad937$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| References | <bd80bfd0-b423-418f-a338-fea626d50093@googlegroups.com> <k6cr4c$4md$1@ger.gmane.org> <5089F33A.8010804@mrabarnett.plus.com> <mailman.2886.1351238424.27098.python-list@python.org> <508ab917$0$29967$c3e8da3$5496439d@news.astraweb.com> <mailman.2898.1351269949.27098.python-list@python.org> <508ad937$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| Date | Sat, 27 Oct 2012 12:29:46 +1100 |
| Subject | Re: a.index(float('nan')) fails |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2927.1351301389.27098.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351301389 news.xs4all.nl 6946 [2001:888:2000:d::a6]:33109 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32259 |
Show key headers only | View raw
On Sat, Oct 27, 2012 at 5:40 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > On Sat, 27 Oct 2012 03:45:46 +1100, Chris Angelico wrote: >> >> Actually, as I see it, there's only one principle to take note of: the >> "HMS Pinafore Floating Point Rule"... >> >> ** Floating point expressions should never be tested for equality ** >> ** What, never? ** >> ** Well, hardly ever! ** >> >> The problem isn't with the associativity, it's with the equality >> comparison. Replace "x == y" with "abs(x-y)<epsilon" for some epsilon >> and all your statements fulfill people's expectations. > > O RYLY? > > Would you care to tell us which epsilon they should use? > > Hint: *whatever* epsilon you pick, there will be cases where that is > either stupidly too small, stupidly too large, or one that degenerates to > float equality. And you may not be able to tell if you have one of those > cases or not. > > Here's a concrete example for you: > > What *single* value of epsilon should you pick such that the following > two expressions evaluate correctly? > > sum([1e20, 0.1, -1e20, 0.1]*1000) == 200 > sum([1e20, 99.9, -1e20, 0.1]*1000) != 200 Your epsilon value needs to take into account the precisions of the values involved, and each operation needs to modify the precision/error value. That's how I was taught to do it in mathematical calculations. Well, I was taught "significant digits", counting decimal digits, and a computer would normally want to count "bits of precision", but close enough. So here's my heresy: When you add 1e20 and 0.1, the value should be equal to the original 1e20 unless it has at least 21 significant digits. Otherwise, you get stupidly accurate errors, like in the old anecdote about the age of a museum piece: It's 1001 years, 2 months, and 3 days old, because I asked last year how old it was and it was a thousand years old. Flame away! ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a.index(float('nan')) fails mamboknave@gmail.com - 2012-10-25 18:46 -0700
Re: a.index(float('nan')) fails Terry Reedy <tjreedy@udel.edu> - 2012-10-25 22:04 -0400
Re: a.index(float('nan')) fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 02:44 +0000
Re: a.index(float('nan')) fails Terry Reedy <tjreedy@udel.edu> - 2012-10-26 03:54 -0400
Re: a.index(float('nan')) fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 15:26 +0000
Re: a.index(float('nan')) fails Terry Reedy <tjreedy@udel.edu> - 2012-10-26 14:49 -0400
Re: a.index(float('nan')) fails Nobody <nobody@nowhere.com> - 2012-10-27 17:40 +0100
Re: a.index(float('nan')) fails Cameron Simpson <cs@zip.com.au> - 2012-10-26 13:15 +1100
Re: a.index(float('nan')) fails mamboknave@gmail.com - 2012-10-25 19:22 -0700
Re: a.index(float('nan')) fails mamboknave@gmail.com - 2012-10-25 19:22 -0700
Re: a.index(float('nan')) fails MRAB <python@mrabarnett.plus.com> - 2012-10-26 03:19 +0100
Re: a.index(float('nan')) fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 02:33 +0000
Re: a.index(float('nan')) fails Ethan Furman <ethan@stoneleaf.us> - 2012-10-28 06:07 -0700
Re: a.index(float('nan')) fails Terry Reedy <tjreedy@udel.edu> - 2012-10-26 04:00 -0400
Re: a.index(float('nan')) fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 16:23 +0000
Re: a.index(float('nan')) fails MRAB <python@mrabarnett.plus.com> - 2012-10-26 17:43 +0100
Re: a.index(float('nan')) fails Chris Angelico <rosuav@gmail.com> - 2012-10-27 03:45 +1100
Re: a.index(float('nan')) fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 18:40 +0000
Re: a.index(float('nan')) fails Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 15:17 -0400
Re: a.index(float('nan')) fails Chris Angelico <rosuav@gmail.com> - 2012-10-27 12:29 +1100
Re: a.index(float('nan')) fails Terry Reedy <tjreedy@udel.edu> - 2012-10-26 14:58 -0400
Re: a.index(float('nan')) fails Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-27 00:48 -0400
Re: a.index(float('nan')) fails Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-27 08:56 +0200
Re: a.index(float('nan')) fails Nobody <nobody@nowhere.com> - 2012-10-27 17:45 +0100
Re: a.index(float('nan')) fails Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-27 13:07 -0400
Re: a.index(float('nan')) fails Mark Adam <dreamingforward@gmail.com> - 2012-10-27 13:33 -0500
csiph-web