Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] Date: Thu, 21 Jul 2016 00:26:12 +1000 Lines: 21 Message-ID: References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de E1RXhNt3mIMxSpUTjUpn8wgoc2z9jmhftwmAKg/xApAA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'binary': 0.05; 'cc:addr :python-list': 0.09; 'compression': 0.09; 'derived': 0.09; 'rounding': 0.09; 'programs.': 0.11; 'wed,': 0.15; 'subject: \n ': 0.15; '*only*': 0.16; '2016': 0.16; 'decimal.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'rounding.': 0.16; 'subject:Singleton': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'not,': 0.22; 'bit': 0.23; 'second': 0.24; '(this': 0.24; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'values': 0.28; 'arithmetic': 0.29; 'subject: [': 0.29; 'operations': 0.31; 'point': 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'something': 0.35; 'should': 0.36; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'someone': 0.38; 'application': 0.39; 'where': 0.40; 'black': 0.61; 'real': 0.62; 'more': 0.63; 'due': 0.65; '20,': 0.66; 'jul': 0.72; 'introduce': 0.79; 'chrisa': 0.84; 'fought': 0.84; 'to:none': 0.91; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=3TWVYpD9uOoJzMvRrXOsh0FTgw+qpeQN54r5QCayRUc=; b=SzOIQBt9RFNYy6LROSWupSQPaoNFWDJh8Z0L2TVH90VVOqpCemU69+rbdn/DwJL+AQ JVpbjR4xBjVnB1ZjkY8pykx8CpK4Csig24xpI3dA/yiP/tWT9atoBre6m9Fg+cATyd6U m1IvtWqqt3FuCQjwqjOoBLGMGsD3zqPhgsLD3E1c0lwYXLOVZ9e4TG0BTEKb5hQtiMbA TanXYd+YRhpJQ6T9FQR9fZp2WJlJfhQ50SbO6YEkrZPzvlsqfOyDPQOJk31l3QJsnbji BhRkpuvXKnVGh54zXXWFn/SSdciSABwYugsLmccF8e9X/XoGW4KFz7uraAdtNqLs4a6o FS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=3TWVYpD9uOoJzMvRrXOsh0FTgw+qpeQN54r5QCayRUc=; b=gbYFXUoYRMPi0ERbhBw7rHbSfEF9R7zwOYywRamU7yXf5PTVUsXqxmU3w3ZBQKX/kr fboVhsHvVpqRX5+qkDR42Qlld39YSvhfZca9zfaxCSU8N7nr6PycgiyDe0ldclGZGHzM CfKRUzlTYP+PM9luwCoB5RoMLDfIZPr52psqtSR+ELLnD320JFjfgyADAczKNsJziBGO dneaQZlbODAXg5dA5y3pOwrd6ieziAFd9tGFtHjLeAMdPDRikxLf3B+6pVm/inFTE7El sCuRbHvdqp+Q3uB98IaUUowktOrY9HOUrWs916yh+fGvw2/pXRDMkTvjSbtL9xHcJknZ z/rQ== X-Gm-Message-State: ALyK8tLqKlOXzcKrzg2YAuchCgX6096Lu/Nty2/GFLfNRSwGdVt/Vogqq2Q12DuQV4RRQjU9PMrrvNffKZCuAg== X-Received: by 10.194.158.71 with SMTP id ws7mr1784171wjb.47.1469024773096; Wed, 20 Jul 2016 07:26:13 -0700 (PDT) In-Reply-To: <87r3aopg7k.fsf@elektro.pacujo.net> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> Xref: csiph.com comp.lang.python:111674 On Wed, Jul 20, 2016 at 11:54 PM, Marko Rauhamaa wrote: > 2. Floating-point numbers are *imperfect approximations* of real > numbers. Even when real numbers are derived exactly, floating-point > operations may introduce "lossy compression artifacts" that have to > be compensated for in application programs. This is the kind of black FUD that has to be fought off. What "compression artifacts" are introduced? The *only* lossiness in IEEE binary floating-point arithmetic is rounding. (This is the bit where someone like Steven is going to point out that there's something else as well.) Unless you are working with numbers that require more precision than you have available, the result should be perfectly accurate. And there are other systems far less 'simple'. Can you imagine this second assertion failing? assert x <= y # if not, swap the values assert x <= (x+y)/2 <= y Because it can with decimal.Decimal, due to the way rounding happens in decimal. ChrisA