Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.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.038 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'programmer': 0.03; 'subject:not': 0.03; 'lesser': 0.07; 'trailing': 0.09; '1.20': 0.16; 'measured': 0.16; 'subject:format': 0.16; 'url:decimal': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'module': 0.19; 'figures': 0.19; 'written': 0.21; 'feb': 0.22; '>>>': 0.22; 'appears': 0.22; 'instance,': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'url:wiki': 0.31; '1.3': 0.31; '13,': 0.31; 'decimal': 0.31; 'url:wikipedia': 0.31; 'url:python': 0.33; 'fri,': 0.33; 'could': 0.34; 'agree': 0.35; 'received:209.85': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'received:209': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'dave': 0.60; 'tell': 0.60; 'places': 0.64; 'kept': 0.65; 'skip:\xe2 10': 0.65; '2015': 0.84; 'angel': 0.91; 'edwards': 0.91; 'notion': 0.91; 'hand,': 0.93; 'taught': 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:to :content-type:content-transfer-encoding; bh=fNuax+Qe82vuUl13sfmZdhlqmIjz/7V8c0Q7trq9JO8=; b=REr09luuzBx2XeUPmQ3O9XxvN72RdjfoE5wsBXzkRpne4HQnKHD5glU0ECsQmIIEYR DM0JYZ6XH6DCox+NpYsMEITKqwafDAwZrO1UNv4uWMa977bXJTQqJ/gv+V8DmnDyB2tW 00myh9N7Qwv4Ytix6rD5jA2nD0UQspTVosaYkTZBU25OBIuJDCLqexrTRvfQSvNHzzDj A9JCXGDo1sulTyBRc8WfD8zhQkhlUvGYZjDxBxLRalTl4dfH+Hx9rG4PtfOYuzup3rRE 6Ij4D3aVvzhxJbGauuVaJ94F28UwG8zZ9Mj80BeceuWEVqh1NPYliTYwa1Whabo4sMUy ye+g== X-Received: by 10.66.124.225 with SMTP id ml1mr9882436pab.142.1423863641348; Fri, 13 Feb 2015 13:40:41 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Fri, 13 Feb 2015 14:40:01 -0700 Subject: Re: Floating point "g" format not stripping trailing zeros To: Python Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423863651 news.xs4all.nl 2845 [2001:888:2000:d::a6]:60743 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85661 On Fri, Feb 13, 2015 at 2:22 PM, Grant Edwards wr= ote: > On 2015-02-13, Dave Angel wrote: >> On the other hand, the Decimal package has a way that the programmer >> can tell how many digits to use at each stage of the calculation. > > That's what surpised me. From TFM: > > https://docs.python.org/2/library/decimal.html: > > * The decimal module incorporates a notion of significant places so that > 1.30 + 1.20 is 2.50. The trailing zero is kept to indicate > significance. This is the customary presentation for monetary > applications. For multiplication, the =E2=80=9Cschoolbook=E2=80=9D app= roach uses > all the figures in the multiplicands. For instance, 1.3 * 1.2 gives > 1.56 while 1.30 * 1.20 gives 1.5600. Huh. That approach for multiplication is definitely not what I was taught in school. I was taught that the number of significant digits in the product is the lesser of the number of significant digits in either of the measured multiplicands. So 1.30 * 1.20 would be 1.56, while 1.3 * 1.2 would just be 1.6. Wikipedia appears to agree with me: http://en.wikipedia.org/wiki/Significance_arithmetic#Multiplication_and_div= ision_using_significance_arithmetic Moreover: >>> D('1.304') * D('1.204') Decimal('1.570016') >>> D('1.295') * D('1.195') Decimal('1.547525') So 1.30 * 1.20 could be written approximately as 1.56 =C2=B1 0.01. Given that, I don't understand how the trailing zeros in 1.5600 could possibly be considered significant.