Velocity Reviews > Significant figures calculation

# 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
--> 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~

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

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

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

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.

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

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.