Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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; '"this': 0.03; 'say,': 0.05; 'binary': 0.07; 'float': 0.07; 'subject:bug': 0.07; 'get.': 0.09; 'cc:addr:python-list': 0.11; 'itself.': 0.14; 'bases,': 0.16; 'binary,': 0.16; 'caveat': 0.16; 'decimal.': 0.16; 'floats;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'likewise': 0.16; 'surprising': 0.16; 'vulgar': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'written': 0.21; 'saying': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'certainly': 0.24; 'regardless': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'decimal': 0.31; 'occurs': 0.31; 'steven': 0.31; 'everyone': 0.33; 'basic': 0.35; "can't": 0.35; 'common': 0.35; 'except': 0.35; 'equal': 0.35; "who's": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'subject:?': 0.36; 'problems': 0.38; 'depends': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'use.': 0.39; 'sure': 0.39; 'most': 0.60; 'issues,': 0.61; 'numbers': 0.61; "you're": 0.61; 'more': 0.64; '26,': 0.68; 'repeat': 0.74; 'surprise': 0.74; 'to:none': 0.92 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=JW1mOiW8WUgY5v28+TxlT24gnBKPCpZTCK2faCIFxVw=; b=hOmw92e6URbqkSEDiKemlE84csuBH4tPEUfHS9xRrggd4GIvLt+P9TkD0jHdvll8Iy 9jdRgl5A4xRKGFoy4bFHQWlIrgg9L7mBvVuukA7SmT73+srGbG+hfnuEvTVjeT8jK1er D84B5PoHNiI99mnV+BE29xNxCP1AcD7NAqT/be1twrWET1QdliZFNn5RYSiPr5/pzH0+ xqm6k6lXgwZrT5mQZZ10GWUxlrpdQCz74viUEY92nw8VceM294GPWy3GVNH6hgyDXFrf vQdaqc6spfxcc6z6P/PZT+cWZR1cxH8Q1maU79EYdXDS5hKBsKAdiDMz7uN9E4BBYZoO VLhw== MIME-Version: 1.0 X-Received: by 10.52.29.236 with SMTP id n12mr9239023vdh.38.1403757665538; Wed, 25 Jun 2014 21:41:05 -0700 (PDT) In-Reply-To: <53ab9ee6$0$11121$c3e8da3@news.astraweb.com> References: <645be4a7-2e1b-44a4-9c45-9184c6df5518@googlegroups.com> <53ab8bc4$0$11121$c3e8da3@news.astraweb.com> <53ab9ee6$0$11121$c3e8da3@news.astraweb.com> Date: Thu, 26 Jun 2014 14:41:05 +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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403757673 news.xs4all.nl 2833 [2001:888:2000:d::a6]:50543 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73606 On Thu, Jun 26, 2014 at 2:17 PM, Steven D'Aprano wrote: > I'm not sure if you're agreeing with me or disagreeing with me. > > "Repeats" is a property of a number *in a specific base*, not of the > number itself. So 1/3 does not repeat in base 3, where it would be > written as the terminating trinary number 0.1. Likewise, 11/10 repeats in > base 2, but not in base 10. > > What I am I saying is that regardless of whether you use binary floats or > base-10 Decimals, not all rational numbers x/y can be represented > exactly. I certainly wasn't saying that the same rationals are inexact in > both bases, just that the surprise "x/y is not exact" occurs whether you > have binary or decimal floating point numbers. > > Likewise for all other floating point issues, except the surprise "this > base-2 float is not exactly equal to the base-10 number I typed". Because > Decimal is base-10, what you type is what you get. Broadly agreeing, but with the caveat that, as you say, "repeats" depends on the base - and there's one base that most humans use, and it's not the base that IEEE floats use. So when I said that 11/10 repeats, I mean that it repeats in binary, which causes precision problems with binary floats; but everyone who's done basic work with vulgar and decimal fractions understands that 1/3 can't be perfectly represented in decimal. So the problems with floating point representations are indeed common to float and decimal.Decimal, but they're more surprising with float because humans aren't used to tenths repeating. ChrisA