Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'binary': 0.07; 'intermediate': 0.07; 'subject:bug': 0.07; 'issue:': 0.09; 'rounds': 0.09; 'cc:addr:python-list': 0.11; 'missed': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inputs': 0.16; 'precision,': 0.16; 'rounding': 0.16; 'rounding.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'record': 0.27; 'correct': 0.29; 'mode': 0.30; 'message-id:@mail.gmail.com': 0.30; 'assert': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'reduced': 0.31; 'steven': 0.31; 'critical': 0.32; 'fri,': 0.33; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'half': 0.37; 'two': 0.37; 'being': 0.38; 'pm,': 0.38; 'either': 0.39; 'range': 0.61; "you're": 0.61; 'information': 0.63; 'more': 0.64; 'within': 0.65; 'caused': 0.69; 'miss': 0.74; '"high"': 0.84; 'inherent': 0.84; 'to:none': 0.92; 'average': 0.93 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:cc :content-type; bh=+mSDFKU4PtQdB00jZnV+1+56HqnMymVzRbADdi8HqwI=; b=vDsLwFNokTZx+mC1jlxZFpbpSvdcO+GM8L/AgPXO7eStyENbdbif7z4rt5z9DEp7jz 7h/z/nSkwkmlrOhGTawdosxISJORqxKc/QRTbQFqIXF93HGrwxzrrXJXra2bpYHaJMjp capCBSZ7Hg98AgUeVox+UsBdCLlEEc0iEr2vwCOi9GRjKc4bqrSfSPArWFZ0kNueFcpa pGX6/GnXJ4C6IWqxJUAN1CHHQV6TLs6PCZnWZXUpDTjMrOwkpCkTagRM8fLPADaGC8nO xOAXLXkpfBz10pVci39fLRnJJDV12XyjzUBHBEEWBshntn2EqwwEZSXTPkEcZouxQR7C nGDw== MIME-Version: 1.0 X-Received: by 10.221.5.1 with SMTP id oe1mr17608017vcb.10.1403839453189; Thu, 26 Jun 2014 20:24:13 -0700 (PDT) In-Reply-To: <53acdc2d$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <645be4a7-2e1b-44a4-9c45-9184c6df5518@googlegroups.com> <53ab8bc4$0$11121$c3e8da3@news.astraweb.com> <53abe4ad$0$11121$c3e8da3@news.astraweb.com> <53acdc2d$0$29985$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 27 Jun 2014 13:24:13 +1000 Subject: Re: python 3.44 float addition bug? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403839456 news.xs4all.nl 2938 [2001:888:2000:d::a6]:55174 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73650 On Fri, Jun 27, 2014 at 12:51 PM, Steven D'Aprano wrote: > Although you seem to have missed the critical issue: this is a failure > mode which *binary floats cannot exhibit*, but decimal floats can. The > failure being that > > assert x <= (x+y)/2 <= y > > may fail if x and y are base 10 floats. No, I didn't miss that; I said that what you were looking at was *also* caused by intermediate rounding. It happens because .516 + .518 = 1.034, which rounds to 1.03; half of that is .515, which is outside of your original range - but the intermediate rounding really reduced the "effective precision" to two digits, by discarding some of the information in the original. If you accept that your result is now accurate to only two digits of precision, then that result is within one ULP of correct (you'll record the average as either .51 or .52, and your two original inputs are both .52, and the average of .52 and .52 is clearly .52). But you're right that this can be very surprising. And it's inherent to the concept of digits having more range than just "high" or "low", so there's no way you can get this with binary floats. ChrisA