Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.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.048 X-Spam-Evidence: '*H*': 0.90; '*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; 'wording': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'module': 0.19; 'figures': 0.19; 'result.': 0.19; 'written': 0.21; 'seems': 0.21; 'feb': 0.22; '>>>': 0.22; 'appears': 0.22; 'instance,': 0.24; 'fine': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'returned': 0.30; 'message- id:@mail.gmail.com': 0.30; 'gives': 0.31; 'url:wiki': 0.31; '1.3': 0.31; '13,': 0.31; '>>>>': 0.31; 'decimal': 0.31; 'though.': 0.31; 'url:wikipedia': 0.31; 'url:python': 0.33; 'fri,': 0.33; 'guess': 0.33; 'could': 0.34; 'agree': 0.35; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; '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; 'ian': 0.60; 'tell': 0.60; 'places': 0.64; 'kept': 0.65; 'skip:\xe2 10': 0.65; 'talking': 0.65; 'here': 0.66; '2015': 0.84; 'confusing': 0.84; 'significance': 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=jZQ6GF6E6z+Vn0HI6ra4uJitS6f6+cNd6IQfQvyx+qs=; b=T/J+84sK/J0j32jEsIxc90t8H1qnXhqxeg4FNYMfF598iiDMj1h7UPXRowOJtFhw3J QheDzjQTGhx5HoJYsvFALPAAed32YOz1tgNZbdXFR/6Y+fXR/jxoKXrl6bq3hE8ZsZDM PfiWY/e1F3kd6JLEXqcbenFoLjl2Fr0rwy0KXjImB0zZF0v205Bd6/HR9fOFD3QCReGQ x+shGN/Smva2yRle3HfduxkqQ6+e7hqVzsf71AxCmQLXlJW8Urkyi1gEZb55xzThE9Ro jGXya2aGFpj0eUXRsGCPYFuUiBa2cKrSuu6mDGFQ8Ah+ZSUZPY0jKWgBg26Cd9HKCvTX qMzw== X-Received: by 10.68.239.69 with SMTP id vq5mr18712631pbc.96.1423864194150; Fri, 13 Feb 2015 13:49:54 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Fri, 13 Feb 2015 14:49:13 -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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423864203 news.xs4all.nl 2882 [2001:888:2000:d::a6]:37633 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85662 On Fri, Feb 13, 2015 at 2:40 PM, Ian Kelly wrote: > On Fri, Feb 13, 2015 at 2:22 PM, Grant Edwards = wrote: >> 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 tha= t >> 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 ap= proach 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_d= ivision_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. I guess the point here is that the paragraph isn't really talking about significance arithmetic; it's explaining how it decides how many digits to keep in the result. It may be fine for 1.30 * 1.20 to return 1.56, but it would be very confusing if 1.35 * 1.25 returned 1.69 instead of 1.6875. The wording of the paragraph seems misleading, though.