Path: csiph.com!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Kaynor Newsgroups: comp.lang.python Subject: Re: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] Date: Thu, 21 Jul 2016 17:43:15 -0700 Lines: 40 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> <8760rybl8k.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de vVYayD0sBvzWXMjX0l66pwuO6lCAGQUOqZ+JmStUJAHA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '21,': 0.07; 'bits': 0.07; 'javascript,': 0.07; 'storage.': 0.09; 'stored': 0.10; '>>>': 0.15; 'applies': 0.15; 'subject: \n ': 0.15; 'thu,': 0.15; '2016': 0.16; 'bounds': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'stored.': 0.16; 'subject:Singleton': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'odd': 0.18; '>': 0.18; 'language': 0.19; '>>>': 0.20; 'to:name:python-list@python.org': 0.20; 'bit': 0.23; 'header:In-Reply-To:1': 0.24; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.27; 'implied': 0.29; 'subject: [': 0.29; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'skip:9 10': 0.37; 'to:addr:python.org': 0.40; 'still': 0.40; 'field': 0.60; 'within': 0.64; 'limit': 0.65; 'jul': 0.72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zindagigames-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=lmh0PXvSta53Z89DGizImxBZlCKxp1YwAB9RF2ivhuA=; b=JjbOZQF+zHopcxQEsEaiDq4BZfNEzWCCPsiZy3iF2zHqpBOVH9G+YeIAm/cVqhcyAb izP8qKTYQGod1YNS+ctraDFkjD5OOrbq6Ub4ViJmHA27DCflc3mjv+Qpj75sln4Ev7Ba 7qsaxHzCMD/RwltL2gUtuZ498t2mSxV8YwYs8hydVEdkWVNRWf7DGhwNmYdErQ59fyIZ GYrw7F/P4+ayrbXJksxBhXjPyzflPMKrm7AX61eGCCGO6TkRaFnt4Dbv0XB+1AyCEWId jatTuD5zxOrsLrYoVpx8DRi1C49ThHg1ruwJb6x5zx9FzmpggOFf+uUdI0TBi9EmDcX8 n6mg== 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:to; bh=lmh0PXvSta53Z89DGizImxBZlCKxp1YwAB9RF2ivhuA=; b=av80eSrQo62DyDmsxz/PSKzBZfJV8dTWOKVOHv9uhlQoQJuRDyCxy/51o7xwg60C3q wg3IKhx/23V9W5ctVA3Out4in8+2iTqDqHjNcmlmu4Q0VWOmjh6anmZp5ssgZV1nFZ6S YVf+THayMl1Ytruu72HbO9EyIag2sTCULXniIXIwdB/JIzxlcVWQLRN6pVr1MZdhpj0Z 7SaTdNp+QUWffDkpspLvMJRQYZM8a2nuBP6RXq6ghFdlQLjEavD+cxyezhd3fEpdQBss BmQWnoaittqUcQR5HxhH2iTpnkzwRmITVSRAE29Lz1CPkXNppFoJ6t3phZ/X8ZqAAA9F 5QiQ== X-Gm-Message-State: AEkoouv6maSAcr/VlvJXmQj8mk9Yc1xgf/jj6GdiAWSo/7Yc9vRCIUWW8MAvATG0wbOdGiB0wlInGnQjS5Ivlg== X-Received: by 10.55.214.135 with SMTP id p7mr1450433qkl.195.1469148215161; Thu, 21 Jul 2016 17:43:35 -0700 (PDT) In-Reply-To: <8760rybl8k.fsf@bsb.me.uk> X-Content-Filtered-By: Mailman/MimeDel 2.1.22 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> <8760rybl8k.fsf@bsb.me.uk> Xref: csiph.com comp.lang.python:111730 On Thu, Jul 21, 2016 at 4:54 PM, Ben Bacarisse wrote= : > Steven D'Aprano writes: > > > Or you might be using a language like Javascript, which intentionally h= as > > only floats for numbers. That's okay, you can still perform exact integ= er > > arithmetic, so long as you stay within the bounds of =C2=B12**16. > > Small point: it's 2**52. > If you really want to be picky, it is 2**53, inclusive: >>> 2**53-2.0 9007199254740990.0 >>> 2**53-1.0 9007199254740991.0 >>> 2**53+0.0 # Can no longer store odd numbers, but 2**53 is even so it can still be stored. 9007199254740992.0 >>> 2**53+1.0 9007199254740992.0 >>> 2**53+2.0 9007199254740994.0 This works as there is an implied one bit in the field for floats, giving 53 bits of storage despite only having 52 bits of storage. As the sign is stored in a separate bit, the same limit applies to both positive and negative numbers.