Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Significant figures calculation

Reply
Thread Tools

Significant figures calculation

 
 
Ethan Furman
Guest
Posts: n/a
 
      06-27-2011
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~
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      06-28-2011
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

 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      06-28-2011
On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
<(E-Mail Removed)> 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
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      06-28-2011
On Tue, 28 Jun 2011 01:16 pm Chris Angelico wrote:

> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
> <(E-Mail Removed)> 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

 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      06-28-2011
Erik Max Francis wrote:

> Chris Angelico wrote:
>> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano
>> <(E-Mail Removed)> 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.

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      06-28-2011
On Tue, Jun 28, 2011 at 9:47 PM, Mel <(E-Mail Removed)> 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/t...r-moments.html

But, that would presumably have three sig figs.

ChrisA
 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      06-28-2011
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
>>>> <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding any number (int or float) to 3 significant figures Max Williams Ruby 6 05-16-2009 01:25 PM
Significant Digits (Significant Figures) SMH Javascript 0 01-07-2007 09:52 AM
Re: Round to significant figures (C++) Alf P. Steinbach C++ 0 05-01-2006 09:15 AM
more than 16 significant figures Jeremy Watts Java 32 07-15-2005 02:21 PM
round up to nearest number and significant figures Steve Java 5 05-17-2004 01:30 AM



Advertisments