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


Groups > comp.lang.python > #8402 > unrolled thread

Significant figures calculation

Started byHarold <dadapapa@googlemail.com>
First post2011-06-24 13:05 -0700
Last post2011-06-24 18:50 -0700
Articles 20 on this page of 22 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 1 of 2  [1] 2  Next page →


#8402 — Significant figures calculation

FromHarold <dadapapa@googlemail.com>
Date2011-06-24 13:05 -0700
SubjectSignificant figures calculation
Message-ID<10b8388e-76fc-4a93-aeff-676cdb3d1d12@5g2000yqb.googlegroups.com>
Hi,

I am looking for an easy way to do significant figure calculations in
python (which I want to use with a class that does unit calculations).
Significant figure calculations should have the semantics explained,
e.g., here: http://chemistry.about.com/od/mathsciencefundamentals/a/sigfigures.htm

My hope was that the decimal module would provide this functionality,
but:

>>> print Decimal('32.01') + Decimal(5.325) + Decimal('12')
49.335     # instead of 49
>>> print Decimal('25.624') / Decimal('25')
1.02496   # instead of 1.0
>>> print Decimal('1.2') == Decimal('1.23')
False      # actually not sure how the semantics should be

I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but
that did not lead to the correct behavior. Google and this list didn't
yield a good answer yet...  so I'd be happy to get a good
recommendations or pointers.

P.S. I am aware that significant figure calculation is controversial
and makes implicit assumptions on the probability distributions of the
variables. I am simply looking for an implementation of the (well
defined) arithmetics as defined on the cited website.

[toc] | [next] | [standalone]


#8406

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-06-24 20:46 +0000
Message-ID<4e04f793$0$29975$c3e8da3$5496439d@news.astraweb.com>
In reply to#8402
On Fri, 24 Jun 2011 13:05:41 -0700, Harold wrote:

> Hi,
> 
> I am looking for an easy way to do significant figure calculations in
> python (which I want to use with a class that does unit calculations).
> Significant figure calculations should have the semantics explained,
> e.g., here:
> http://chemistry.about.com/od/mathsciencefundamentals/a/sigfigures.htm
> 
> My hope was that the decimal module would provide this functionality,
> but:
> 
>>>> print Decimal('32.01') + Decimal(5.325) + Decimal('12')
> 49.335     # instead of 49
>>>> print Decimal('25.624') / Decimal('25')
> 1.02496   # instead of 1.0
>>>> print Decimal('1.2') == Decimal('1.23')
> False      # actually not sure how the semantics should be
> 
> I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but
> that did not lead to the correct behavior.

Really? It works for me.


>>> import decimal
>>> D = decimal.Decimal
>>> decimal.getcontext().prec = 2
>>>
>>> D('32.01') + D('5.325') + D('12')
Decimal('49')
>>>
>>> D('25.624') / D('25')
Decimal('1.0')

The only thing you have to watch out for is this:

>>> D('1.2') == D('1.23')  # no rounding
False
>>> D('1.2') == +D('1.23')  # force rounding
True



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#8407

FromJerry Hill <malaclypse2@gmail.com>
Date2011-06-24 16:58 -0400
Message-ID<mailman.386.1308949143.1164.python-list@python.org>
In reply to#8406
On Fri, Jun 24, 2011 at 4:46 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Really? It works for me.
>
>>>> import decimal
>>>> D = decimal.Decimal
>>>> decimal.getcontext().prec = 2
>>>>
>>>> D('32.01') + D('5.325') + D('12')
> Decimal('49')

I'm curious.  Is there a way to get the number of significant digits
for a particular Decimal instance?  I spent a few minutes browsing
through the docs, and didn't see anything obvious.  I was thinking
about setting the precision dynamically within a function, based on
the significance of the inputs.

-- 
Jerry

[toc] | [prev] | [next] | [standalone]


#8421

Fromsteve+comp.lang.python@pearwood.info
Date2011-06-25 10:31 +1000
Message-ID<4e052c77$0$29979$c3e8da3$5496439d@news.astraweb.com>
In reply to#8407
Jerry Hill wrote:

> I'm curious.  Is there a way to get the number of significant digits
> for a particular Decimal instance?  I spent a few minutes browsing
> through the docs, and didn't see anything obvious.  I was thinking
> about setting the precision dynamically within a function, based on
> the significance of the inputs.

Not officially, so far as I know, but if you're willing to risk using a
private implementation detail that is subject to change:

>>> decimal.Decimal('000123.45000')._int
'12345000'

However, sometimes you may need to inspect the exponent as well:

>>> zero = decimal.Decimal('0.00000000')
>>> zero._int
'0'
>>> zero._exp
-8



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#8451

FromChris Torek <nospam@torek.net>
Date2011-06-25 19:04 +0000
Message-ID<iu5bgk01v0@news2.newsguy.com>
In reply to#8407
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

[toc] | [prev] | [next] | [standalone]


#8468

FromHarold <dadapapa@googlemail.com>
Date2011-06-26 08:35 -0700
Message-ID<02a78be2-2c11-4068-81a3-cd8744e8eaf2@y30g2000vbu.googlegroups.com>
In reply to#8451
> >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])

Great! that's exactly what I needed.
thanks Chris!

[toc] | [prev] | [next] | [standalone]


#8502

FromDave Angel <davea@ieee.org>
Date2011-06-27 08:04 -0400
Message-ID<mailman.445.1309176278.1164.python-list@python.org>
In reply to#8468
(You top-posted your reply, instead of writing your response following 
the part you were quoting)

On 01/-10/-28163 02:59 PM, Lalitha Prasad K wrote:
> In numerical analysis there is this concept of machine zero, which is
> computed like this:
>
> e=1.0
> while 1.0+e>  1.0:
>      e=e/2.0
> print e
>
> The number e will give you the precision of floating point numbers.
>
> Lalitha Prasad
>

That particular algorithm is designed for binary floating point. The OP 
was asking about Decimal instances.  So you'd want to divide by 10.0 
each time.  And of course you'd want to do it with Decimal objects.
> On Sun, Jun 26, 2011 at 9:05 PM, Harold<dadapapa@googlemail.com>  wrote:
>
>>>> I'm curious.  Is there a way to get the number of significant digits
>>>> for a particular Decimal instance?

DaveA

[toc] | [prev] | [next] | [standalone]


#8506

FromHarold <dadapapa@googlemail.com>
Date2011-06-27 06:40 -0700
Message-ID<db874e1f-a827-459c-aa22-5b915e70b682@a11g2000yqm.googlegroups.com>
In reply to#8451
On Jun 25, 9:04 pm, Chris Torek <nos...@torek.net> 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])

Great, Chris, this is (almost) exactly what I needed.
To make it work for numbers like 1200, that have four digits but only
two of them being significant, I changed your snippet to the
following:

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('1200.').significance
2
>>> Empirical('1200.0').significance
5

now it's only about overriding the numerical operators :)

[toc] | [prev] | [next] | [standalone]


#8514

FromEthan Furman <ethan@stoneleaf.us>
Date2011-06-27 13:53 -0700
Message-ID<mailman.463.1309207197.1164.python-list@python.org>
In reply to#8506
Harold wrote:
> On Jun 25, 9:04 pm, Chris Torek <nos...@torek.net> 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])
> 
> Great, Chris, this is (almost) exactly what I needed.
> To make it work for numbers like 1200, that have four digits but only
> two of them being significant, I changed your snippet to the
> following:
> 
> 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('1200.').significance
> 2
>>>> Empirical('1200.0').significance
> 5

What about when 1200 is actually 4 significant digits? Or 3?

~Ethan~

[toc] | [prev] | [next] | [standalone]


#8518

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-06-28 12:56 +1000
Message-ID<4e0942d1$0$29987$c3e8da3$5496439d@news.astraweb.com>
In reply to#8514
On Tue, 28 Jun 2011 06:53 am Ethan Furman wrote:

> Harold wrote:
[...]
>>>>> Empirical('1200.').significance
>> 2

Well, that's completely wrong. It should be 4.

>>>>> Empirical('1200.0').significance
>> 5
> 
> What about when 1200 is actually 4 significant digits? Or 3?

Then you shouldn't write it as 1200.0. By definition, zeros on the right are
significant. If you don't want zeroes on the right to count, you have to
not show them.

Five sig figures: 1200.0
Four sig figures: 1200
Three sig figures: 1.20e3
Two sig figures: 1.2e3
One sig figure: 1e3
Zero sig figure: 0



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#8519

FromChris Angelico <rosuav@gmail.com>
Date2011-06-28 13:16 +1000
Message-ID<mailman.466.1309231012.1164.python-list@python.org>
In reply to#8518
On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Zero sig figure: 0
>

Is 0.0 one sig fig or two? (Just vaguely curious. Also curious as to
whether a zero sig figures value is ever useful.)

ChrisA

[toc] | [prev] | [next] | [standalone]


#8520

FromErik Max Francis <max@alcyone.com>
Date2011-06-27 20:45 -0700
Message-ID<pfSdnd1Y2YLS05TTnZ2dnUVZ5hidnZ2d@giganews.com>
In reply to#8519
Chris Angelico wrote:
> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> Zero sig figure: 0

That's not really zero significant figures; without further 
qualification, it's one.

> Is 0.0 one sig fig or two?

Two.

> (Just vaguely curious. Also curious as to
> whether a zero sig figures value is ever useful.)

Yes.  They're order of magnitude estimates.  1 x 10^6 has one 
significant figure.  10^6 has zero.

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   I would have liked to have seen Montana.
    -- Cpt. Vasily Borodin

[toc] | [prev] | [next] | [standalone]


#8533

FromMel <mwilson@the-wire.com>
Date2011-06-28 07:47 -0400
Message-ID<iucf07$au9$1@speranza.aioe.org>
In reply to#8520
Erik Max Francis wrote:

> Chris Angelico wrote:
>> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
>> <steve+comp.lang.python@pearwood.info> wrote:
>>> Zero sig figure: 0
> 
> That's not really zero significant figures; without further
> qualification, it's one.
> 
>> Is 0.0 one sig fig or two?
> 
> Two.
> 
>> (Just vaguely curious. Also curious as to
>> whether a zero sig figures value is ever useful.)
> 
> Yes.  They're order of magnitude estimates.  1 x 10^6 has one
> significant figure.  10^6 has zero.

By convention, nobody ever talks about 1 x 9.97^6 .

	Mel.

[toc] | [prev] | [next] | [standalone]


#8534

FromChris Angelico <rosuav@gmail.com>
Date2011-06-28 21:57 +1000
Message-ID<mailman.477.1309262241.1164.python-list@python.org>
In reply to#8533
On Tue, Jun 28, 2011 at 9:47 PM, Mel <mwilson@the-wire.com> wrote:
>
> By convention, nobody ever talks about 1 x 9.97^6 .

Unless you're a British politician of indeterminate party
allegiance.... famous line, quoted as #6 in here:
http://www.telegraph.co.uk/culture/tvandradio/7309332/The-ten-funniest-ever-Yes-Minister-moments.html

But, that would presumably have three sig figs.

ChrisA

[toc] | [prev] | [next] | [standalone]


#8543

FromErik Max Francis <max@alcyone.com>
Date2011-06-28 11:54 -0700
Message-ID<TPidnZ-9RtbOvpfTnZ2dnUVZ5r-dnZ2d@giganews.com>
In reply to#8533
Mel wrote:
> Erik Max Francis wrote:
> 
>> Chris Angelico wrote:
>>> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
>>> <steve+comp.lang.python@pearwood.info> wrote:
>>>> Zero sig figure: 0
>> That's not really zero significant figures; without further
>> qualification, it's one.
>>
>>> Is 0.0 one sig fig or two?
>> Two.
>>
>>> (Just vaguely curious. Also curious as to
>>> whether a zero sig figures value is ever useful.)
>> Yes.  They're order of magnitude estimates.  1 x 10^6 has one
>> significant figure.  10^6 has zero.
> 
> By convention, nobody ever talks about 1 x 9.97^6 .

Not sure what the relevance is, since nobody had mentioned any such thing.

If it was intended as a gag, I don't catch the reference.

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Love is the selfishness of two persons.
    -- Antoine de la Salle

[toc] | [prev] | [next] | [standalone]


#8552

FromMel <mwilson@the-wire.com>
Date2011-06-28 16:47 -0400
Message-ID<iudelu$tql$1@speranza.aioe.org>
In reply to#8543
Erik Max Francis wrote:

> Mel wrote:
>> Erik Max Francis wrote:
>> 
>>> Chris Angelico wrote:
>>>> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
>>>> <steve+comp.lang.python@pearwood.info> wrote:
>>>>> Zero sig figure: 0
>>> That's not really zero significant figures; without further
>>> qualification, it's one.
>>>
>>>> Is 0.0 one sig fig or two?
>>> Two.
>>>
>>>> (Just vaguely curious. Also curious as to
>>>> whether a zero sig figures value is ever useful.)
>>> Yes.  They're order of magnitude estimates.  1 x 10^6 has one
>>> significant figure.  10^6 has zero.
>> 
>> By convention, nobody ever talks about 1 x 9.97^6 .
> 
> Not sure what the relevance is, since nobody had mentioned any such thing.
> 
> If it was intended as a gag, I don't catch the reference.

I get giddy once in a while.. push things to limits.  It doesn't really mean 
anything.  The point was that it's only the 2 in a number like 2e6 that is 
taken to have error bars.  The 6 is always an absolute number.  As is the 10 
in 2*10**6.  The thought also crossed my mind of a kind of continued 
fraction in reverse -- 2e1.3e.7 .  I managed to keep quiet about that one.

	Mel.

[toc] | [prev] | [next] | [standalone]


#8553

FromErik Max Francis <max@alcyone.com>
Date2011-06-28 14:01 -0700
Message-ID<67ednYGA8ICp3JfTnZ2dnUVZ5tOdnZ2d@giganews.com>
In reply to#8552
Mel wrote:
> Erik Max Francis wrote:
>> Mel wrote:
>>> By convention, nobody ever talks about 1 x 9.97^6 .
>> Not sure what the relevance is, since nobody had mentioned any such thing.
>>
>> If it was intended as a gag, I don't catch the reference.
> 
> I get giddy once in a while.. push things to limits.  It doesn't really mean 
> anything.  The point was that it's only the 2 in a number like 2e6 that is 
> taken to have error bars.  The 6 is always an absolute number.  As is the 10 
> in 2*10**6.

They're not absolute numbers.  It's just that the whole convention 
surrounding significant digits means that the figure is accurate to the 
last significant digit, plus or minus the range that would round to it. 
  That would be true for any base, it's just that we use base 10.

If the error bars are something other than that, they're either written 
down explicitly (they need not even be symmetric), or they're written 
with the convention of using parentheses to indicate the (symmetric) 
error in the final set of significant digits.  For instance, RPP 2010* 
has a figure for Newton's gravitational constant of 6.67428(67) x 10^-11 
m^3/(kg s^2), which means (6.67428 +- 0.00067) x 10^-11 m^3/(kg s^2).

.

* http://pdg.lbl.gov/2011/reviews/rpp2011-rev-phys-constants.pdf

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   When in doubt, C4.
    -- Jamie Hyneman

[toc] | [prev] | [next] | [standalone]


#8530

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-06-28 18:35 +1000
Message-ID<4e099259$0$29991$c3e8da3$5496439d@news.astraweb.com>
In reply to#8519
On Tue, 28 Jun 2011 01:16 pm Chris Angelico wrote:

> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> Zero sig figure: 0
>>
> 
> Is 0.0 one sig fig or two? (Just vaguely curious. Also curious as to
> whether a zero sig figures value is ever useful.)

Two. I was actually being slightly silly about zero fig figures.

Although, I suppose, if you genuinely had zero significant figures, you
couldn't tell what the number was at all, so you'd need to use a NaN :)


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#8544

FromErik Max Francis <max@alcyone.com>
Date2011-06-28 11:59 -0700
Message-ID<K9KdnaJWycA0uZfTnZ2dnUVZ5qudnZ2d@giganews.com>
In reply to#8530
Steven D'Aprano wrote:
> On Tue, 28 Jun 2011 01:16 pm Chris Angelico wrote:
> 
>> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
>> <steve+comp.lang.python@pearwood.info> wrote:
>>> Zero sig figure: 0
>>>
>> Is 0.0 one sig fig or two? (Just vaguely curious. Also curious as to
>> whether a zero sig figures value is ever useful.)
> 
> Two. I was actually being slightly silly about zero fig figures.
> 
> Although, I suppose, if you genuinely had zero significant figures, you
> couldn't tell what the number was at all, so you'd need to use a NaN :)

No, values with zero significant figures are just order of magnitude 
estimates.  They're used fairly often when doing very vague estimates, 
but obviously they're subject to pretty atrocious rounding error.

For instance, let's do an order of magnitude estimate for the Planck 
energy.  The most obvious method is to start with the Planck mass.  In 
SI, it's about 2 x 10^-8 kg, or on the order of 10^-8 kg (zero 
significant figures).  To convert to energy, multiply by c^2.  c = 3 x 
10^8 m/s, so c^2 = 9 x 10^16 m^2/s^2, or about 10^17 m^2/s^2, so the 
Planck energy is on the order of 10^9 J.  That's a calculation to zero 
significant figures.

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Love is the selfishness of two persons.
    -- Antoine de la Salle

[toc] | [prev] | [next] | [standalone]


#8521

FromErik Max Francis <max@alcyone.com>
Date2011-06-27 20:49 -0700
Message-ID<_5GdnZSH4tWr0pTTnZ2dnUVZ5rmdnZ2d@giganews.com>
In reply to#8518
Steven D'Aprano wrote:
> On Tue, 28 Jun 2011 06:53 am Ethan Furman wrote:
> 
>> Harold wrote:
> [...]
>>>>>> Empirical('1200.').significance
>>> 2
> 
> Well, that's completely wrong. It should be 4.
> 
>>>>>> Empirical('1200.0').significance
>>> 5
>> What about when 1200 is actually 4 significant digits? Or 3?
> 
> Then you shouldn't write it as 1200.0. By definition, zeros on the right are
> significant. If you don't want zeroes on the right to count, you have to
> not show them.
> 
> Five sig figures: 1200.0
> Four sig figures: 1200
> Three sig figures: 1.20e3
> Two sig figures: 1.2e3
> One sig figure: 1e3
> Zero sig figure: 0

That last one is not true; 0 is a one-significant figure estimate, and 
represents a value between -0.5 and 0.5.  (It's true that zeroes to the 
left are never significant, but not when there's nothing in the figure 
but zeroes.)

A zero-significant figure would be an order of magnitude estimate only. 
  These aren't usually done in the "e" scientific notation, but it would 
be something like 10^3 (if we assume ^ is exponentiation, not the Python 
operator).

c^2 is 9 x 10^16 m^2/s^2 to one significant figure.  It's 10^17 m^2/s^2 
to zero (order of magnitude estimate).

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   I would have liked to have seen Montana.
    -- Cpt. Vasily Borodin

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web