Re: Significant figures calculation

2011-06-28 Thread Erik Max Francis
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 doe

Re: Significant figures calculation

2011-06-28 Thread Mel
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 wrote: > Zero sig figure: 0 >>> That's not really zero significant figures; without further >>> qualification, it's one. >>> Is 0.0 on

Re: Significant figures calculation

2011-06-28 Thread Erik Max Francis
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 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

Re: Significant figures calculation

2011-06-28 Thread Erik Max Francis
Mel wrote: Erik Max Francis wrote: Chris Angelico wrote: On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano 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

Re: Significant figures calculation

2011-06-28 Thread Chris Angelico
On Tue, Jun 28, 2011 at 9:47 PM, Mel 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-

Re: Significant figures calculation

2011-06-28 Thread Mel
Erik Max Francis wrote: > Chris Angelico wrote: >> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano >> 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.

Re: Significant figures calculation

2011-06-28 Thread Steven D'Aprano
On Tue, 28 Jun 2011 01:16 pm Chris Angelico wrote: > On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano > 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 slightl

Re: Significant figures calculation

2011-06-27 Thread Erik Max Francis
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 should

Re: Significant figures calculation

2011-06-27 Thread Erik Max Francis
Chris Angelico wrote: On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano 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 v

Re: Significant figures calculation

2011-06-27 Thread Chris Angelico
On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano 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 -- http://mail.python.org/mailman/listinfo/python-list

Re: Significant figures calculation

2011-06-27 Thread Steven D'Aprano
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

Re: Significant figures calculation

2011-06-27 Thread Ethan Furman
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 foll

Re: Significant figures calculation

2011-06-27 Thread Ethan Furman
Harold wrote: On Jun 25, 9:04 pm, Chris Torek 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)

Re: Significant figures calculation

2011-06-27 Thread Harold
On Jun 25, 9:04 pm, Chris Torek 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) ex

Re: Significant figures calculation

2011-06-27 Thread Dave Angel
(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 numb

Re: Significant figures calculation

2011-06-26 Thread Lalitha Prasad K
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 On Sun, Jun 26, 2011 at 9:05 PM, Harold wrote: > > >I'm curious. Is there

Re: Significant figures calculation

2011-06-26 Thread Harold
> >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! -- http://mail.python

Re: Significant figures calculation

2011-06-25 Thread Chris Torek
In article Jerry Hill 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',

Re: Significant figures calculation

2011-06-24 Thread Harold
> > 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. You are right, I did something wrong when attempting to set the precision. And the trick with rounding the decimal with the unary + is neat. It's th

Re: Significant figures calculation

2011-06-24 Thread steve+comp . lang . python
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 >

Re: Significant figures calculation

2011-06-24 Thread Jerry Hill
On Fri, Jun 24, 2011 at 4:46 PM, Steven D'Aprano 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

Re: Significant figures calculation

2011-06-24 Thread Steven D'Aprano
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://

Significant figures calculation

2011-06-24 Thread Harold
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