Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'binary': 0.07; 'float': 0.07; 'subject:bug': 0.07; '*is*': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'type,': 0.09; '*a*': 0.16; 'binary,': 0.16; 'clockwork': 0.16; 'finite': 0.16; 'finney': 0.16; 'notation.': 0.16; 'operates': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'surprises': 0.16; 'subject:python': 0.16; 'applies': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'all,': 0.19; 'header:User-Agent:1': 0.23; 'supported': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'points': 0.29; '-0700,': 0.31; 'commonly': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'raised': 0.31; 'steven': 0.31; 'writes:': 0.31; 'languages': 0.32; 'limitation': 0.33; "i'd": 0.34; 'point.': 0.35; 'but': 0.35; 'useful': 0.36; 'subject:?': 0.36; 'throughout': 0.37; 'represent': 0.38; 'ben': 0.38; 'saves': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'referred': 0.60; 'save': 0.62; 'such': 0.63; 'refer': 0.63; 'different': 0.65; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; 'subject': 0.69; 'cpu.': 0.84; 'inherent': 0.84; 'received:125': 0.84; 'hong': 0.91; 'kong': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: python 3.44 float addition bug? Date: Thu, 26 Jun 2014 13:39:23 +1000 References: <645be4a7-2e1b-44a4-9c45-9184c6df5518@googlegroups.com> <53ab8bc4$0$11121$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:O493cijO2QP8dOA8mZ+twJ66PHA= 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403753978 news.xs4all.nl 2857 [2001:888:2000:d::a6]:47174 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73603 Steven D'Aprano writes: > On Wed, 25 Jun 2014 14:12:31 -0700, Maciej Dziardziel wrote: > > > Floating points values use finite amount of memory, and cannot > > accurately represent infinite amount of numbers, they are only > > approximations. This is limitation of float type and applies to any > > languages that uses types supported directly by cpu. To deal with it > > you can either use decimal.Decimal type that operates using decimal > > system and saves you from such surprises > > That's a myth. decimal.Decimal *is* a floating point value That's misleading: Decimal uses *a* floating-point representation, but not the one commonly referred to. That is, Decimal does not use IEEE-754 floating point. > and is subject to *exactly* the same surprises as binary floats, Since those “surprises” are the ones inherent to *decimal*, not binary, floating point, I'd say it's also misleading to refer to them as “exactly the same surprises”. They're barely surprises at all, to someone raised on decimal notation. This makes the Decimal functionality starkly different from the built-in ‘float’ type, and it *does* save you from the rather-more-surprising behaviour of the ‘float’ type. This is not mythical. -- \ “Guaranteed to work throughout its useful life.” —packaging for | `\ clockwork toy, Hong Kong | _o__) | Ben Finney