Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'binary': 0.07; 'float': 0.07; 'string': 0.09; 'converted': 0.09; 'indicates': 0.09; 'lost.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'trailing': 0.09; 'translate': 0.10; "wouldn't": 0.14; '(heck,': 0.16; '>does': 0.16; 'confuse': 0.16; 'digits.': 0.16; "he'll": 0.16; 'internally': 0.16; 'message- id:@4ax.com': 0.16; 'precision,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'differ': 0.19; '2.2': 0.24; 'url:home': 0.24; 'math': 0.24; 'source': 0.25; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; "d'aprano": 0.31; 'decimal': 0.31; 'steven': 0.31; 'strip': 0.31; 'class': 0.32; "i'd": 0.34; 'could': 0.34; 'knowledge': 0.35; 'agree': 0.35; 'convert': 0.35; 'one,': 0.35; 'but': 0.35; 'acceptable': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'half': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'course': 0.61; 'high': 0.63; 'skip:6 10': 0.63; 'school': 0.64; 'physics': 0.68; 'upper': 0.74; 'float,': 0.84; 'significance': 0.84; 'sterling': 0.84; 'trig': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Significant digits in a float? Date: Tue, 29 Apr 2014 20:33:55 -0400 Organization: IISS Elusive Unicorn References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-218-225.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398818045 news.xs4all.nl 2930 [2001:888:2000:d::a6]:33226 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70744 On 29 Apr 2014 05:43:19 GMT, Steven D'Aprano declaimed the following: >does differ from value to value, I don't think he'll have much luck: >given a float like 23.0, all we can say is that it has *at least* zero >significant decimal places. 23.1 has at least one, 23.1111 has at least >four. > I wouldn't even give it that... Since internally they (ignore binary conversion) translate into 2.30E1, 2.31E1, and 2.31111E1 I'd claim 3-significant digits, 3-significant digits, and 6-significant digits. (Heck, as I recall classical FORTRAN, they would be 0.230E2...) >If you can put an upper bound on the precision, as Roy indicates he can, >then perhaps a reasonable approach is to convert to a string rounded to >four decimal places, then strip trailing zeroes: > That I'd agree with... once the data has been converted to binary float, all knowledge of the source significant digits has been lost. Then confuse matters with the facet that in a math class 1.1 * 2.2 => 2.42 but in a physics or chemistry class the recommended result is 1.1 * 2.2 => 2.4 (one reason slide-rules were acceptable for so long -- and even my high school trig course only required slide-rule significance even though half the class had scientific calculators [costing >$100, when a Sterling slide-rule could still be had for <$10]) -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/