Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '3.2': 0.05; 'python': 0.08; 'defined.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'though:': 0.09; '~ethan~': 0.09; 'win32': 0.12; 'wrote:': 0.15; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '@property': 0.16; 'negatives': 0.16; 'received:69.41.248.83': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'received:gateway01.websitewelcome.com': 0.16; '>>>': 0.16; 'def': 0.16; 'work,': 0.20; 'cc:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.23; 'appear': 0.23; 'code': 0.24; 'skip:l 30': 0.25; 'bit': 0.28; 'import': 0.29; 'class': 0.31; 'actually': 0.33; 'header:User-Agent:1': 0.34; 'to:addr:python-list': 0.34; 'rules': 0.36; 'but': 0.37; '1200': 0.38; 'subject:: ': 0.38; 'else': 0.38; 'should': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'your': 0.61; 'received:websitewelcome.com': 0.65; 'received:184': 0.67; 'digits?': 0.84; 'ethan,': 0.84; 'them:': 0.84; '-->': 0.91 Date: Mon, 27 Jun 2011 15:58:54 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Python Subject: Re: Significant figures calculation References: <10b8388e-76fc-4a93-aeff-676cdb3d1d12@5g2000yqb.googlegroups.com> <4e04f793$0$29975$c3e8da3$5496439d@news.astraweb.com> <4E08EDBD.4060803@stoneleaf.us> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1276 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 2 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== Cc: Harold Fellermann X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309214754 news6.xs4all.nl 4363 [2001:888:2000:d::a6]:35612 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8517 Harold Fellermann wrote: > Hi Ethan, > >>>>>> Empirical('1200.').significance >>> 2 >>>>>> Empirical('1200.0').significance >>> 5 >> What about when 1200 is actually 4 significant digits? Or 3? > > Then you'd simply write 1.200e3 and 1.20e3, respectively. > That's just how the rules are defined. But your code is not following them: Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. --> from decimal import Decimal --> class Empirical(Decimal) : ... @property ... def significance(self) : ... t = self.as_tuple() ... if t[2] < 0 : ... return len(t[1]) ... else : ... return len(''.join(map(str,t[1])).rstrip('0')) ... --> Empirical('1.200E+3').significance 2 # should be four --> Empirical('1.20E+3').significance 2 # should be three --> Empirical('1.20E+4').significance 2 # should be three The negatives appear to work, though: --> Empirical('1.20E-4').significance 3 --> Empirical('1.2819E-3').significance 5 --> Empirical('1.2819E-1').significance 5 --> Empirical('1.281900E-1').significance 7 ~Ethan~