Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8451

Re: Significant figures calculation

From Chris Torek <nospam@torek.net>
Newsgroups comp.lang.python
Subject Re: Significant figures calculation
Date 2011-06-25 19:04 +0000
Organization None of the Above
Message-ID <iu5bgk01v0@news2.newsguy.com> (permalink)
References <10b8388e-76fc-4a93-aeff-676cdb3d1d12@5g2000yqb.googlegroups.com> <4e04f793$0$29975$c3e8da3$5496439d@news.astraweb.com> <mailman.386.1308949143.1164.python-list@python.org>

Show all headers | View raw


In article <mailman.386.1308949143.1164.python-list@python.org>
Jerry Hill  <malaclypse2@gmail.com> wrote:
>I'm curious.  Is there a way to get the number of significant digits
>for a particular Decimal instance?

Yes:

def sigdig(x):
    "return the number of significant digits in x"
    return len(x.as_tuple()[1])

import decimal
D = decimal.Decimal

for x in (
    '1',
    '1.00',
    '1.23400e-8',
    '0.003'
):
    print 'sigdig(%s): %d' % (x, sigdig(D(x)))
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)      http://web.torek.net/torek/index.html

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Significant figures calculation Harold <dadapapa@googlemail.com> - 2011-06-24 13:05 -0700
  Re: Significant figures calculation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-24 20:46 +0000
    Re: Significant figures calculation Jerry Hill <malaclypse2@gmail.com> - 2011-06-24 16:58 -0400
      Re: Significant figures calculation steve+comp.lang.python@pearwood.info - 2011-06-25 10:31 +1000
      Re: Significant figures calculation Chris Torek <nospam@torek.net> - 2011-06-25 19:04 +0000
        Re: Significant figures calculation Harold <dadapapa@googlemail.com> - 2011-06-26 08:35 -0700
          Re: Significant figures calculation Dave Angel <davea@ieee.org> - 2011-06-27 08:04 -0400
        Re: Significant figures calculation Harold <dadapapa@googlemail.com> - 2011-06-27 06:40 -0700
          Re: Significant figures calculation Ethan Furman <ethan@stoneleaf.us> - 2011-06-27 13:53 -0700
            Re: Significant figures calculation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-28 12:56 +1000
              Re: Significant figures calculation Chris Angelico <rosuav@gmail.com> - 2011-06-28 13:16 +1000
                Re: Significant figures calculation Erik Max Francis <max@alcyone.com> - 2011-06-27 20:45 -0700
                Re: Significant figures calculation Mel <mwilson@the-wire.com> - 2011-06-28 07:47 -0400
                Re: Significant figures calculation Chris Angelico <rosuav@gmail.com> - 2011-06-28 21:57 +1000
                Re: Significant figures calculation Erik Max Francis <max@alcyone.com> - 2011-06-28 11:54 -0700
                Re: Significant figures calculation Mel <mwilson@the-wire.com> - 2011-06-28 16:47 -0400
                Re: Significant figures calculation Erik Max Francis <max@alcyone.com> - 2011-06-28 14:01 -0700
                Re: Significant figures calculation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-28 18:35 +1000
                Re: Significant figures calculation Erik Max Francis <max@alcyone.com> - 2011-06-28 11:59 -0700
              Re: Significant figures calculation Erik Max Francis <max@alcyone.com> - 2011-06-27 20:49 -0700
          Re: Significant figures calculation Ethan Furman <ethan@stoneleaf.us> - 2011-06-27 15:58 -0700
    Re: Significant figures calculation Harold <dadapapa@googlemail.com> - 2011-06-24 18:50 -0700

csiph-web