Re: How to detect a double's significant digits

2005-05-22 Thread AnswerGuy
James Stroud wrote: > Significant digits are an accounting concept. As such, it is up to the > accountant to keep track of these as only she knows the precision of her > measurements. > > Koan for the day: > What are the significant digits of 0.1? > Hint: > >>> `0.1` > James > On Thursday 05 M

Re: How to detect a double's significant digits

2005-05-06 Thread Jeremy Bowers
On Fri, 06 May 2005 08:27:03 +0200, Fredrik Lundh wrote: > Jeremy Bowers wrote: > >> > A step which will require him to tell the printing routine how many >> > digits he wants printed. >> >> Not necessarily; consider the str() of a float in Python, especially >> given the "significant digits" asp

Re: How to detect a double's significant digits

2005-05-06 Thread John Roth
"mrstephengross" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all... How can I find out the number of significant digits (to the > right of the decimal place, that is) in a double? At least, I *think* > that's what I'm asking for. For instance: > > 0.103 --> 3 > 0.0103 --> 4 >

Re: How to detect a double's significant digits

2005-05-06 Thread Fredrik Lundh
Jeremy Bowers wrote: > > A step which will require him to tell the printing routine how many digits > > he wants printed. > > Not necessarily; consider the str() of a float in Python, especially given > the "significant digits" aspect (it may be ill-defined, but I can think of > several well-defin

Re: How to detect a double's significant digits

2005-05-05 Thread Jeremy Bowers
On Thu, 05 May 2005 20:08:46 -0700, Erik Max Francis wrote: > Grant's point was that as significance is used in scientific studies, > there's no way to answer the question without having the number in > advance. My point was that the original poster never defined "significance" in that manner, and

Re: How to detect a double's significant digits

2005-05-05 Thread Dan Bishop
Fredrik Lundh wrote: > "mrstephengross" wrote: > > > >But, assuming you have your numbers as strings, I would suggest > > looking > > at str.split() and len(). > > > > Well, the numbers are in fact stored as numbers, so string processing > > won't work. > > if they're not strings, your question is

Re: How to detect a double's significant digits

2005-05-05 Thread Erik Max Francis
Jeremy Bowers wrote: > Not necessarily; consider the str() of a float in Python, especially given > the "significant digits" aspect (it may be ill-defined, but I can think of > several well-defined ways to mean that, where str() embodies one of them). > The easiest way to tell how long the number

Re: How to detect a double's significant digits

2005-05-05 Thread Jeremy Bowers
On Fri, 06 May 2005 02:44:43 +, Grant Edwards wrote: > On 2005-05-05, Jeremy Bowers <[EMAIL PROTECTED]> wrote: > >> Since I think he mentioned something about predicting how much space it >> will take to print out, my suggestion is to run through whatever >> printing routines there are and ge

Re: How to detect a double's significant digits

2005-05-05 Thread Grant Edwards
On 2005-05-05, mrstephengross <[EMAIL PROTECTED]> wrote: >>This doesn't look like Python to me. Are you sure you're on the right > newsgroup? > > Er, ok, I'm an idiot. This was all supposed to be on > comp.lang.c++, but obviously I posted on the wrong one. Sorry > for all the hassle. In python, th

Re: How to detect a double's significant digits

2005-05-05 Thread Grant Edwards
On 2005-05-05, Erik Max Francis <[EMAIL PROTECTED]> wrote: > Especially since all of his examples have the same number of > significant digits (3), as the term is usually meant. Zeroes > to the right are significant, not zeroes to the left. And only the person who performed the measurement knows

Re: How to detect a double's significant digits

2005-05-05 Thread Grant Edwards
On 2005-05-05, Jeremy Bowers <[EMAIL PROTECTED]> wrote: > Since I think he mentioned something about predicting how much > space it will take to print out, my suggestion is to run > through whatever printing routines there are and get a string > out, A step which will require him to tell the prin

Re: How to detect a double's significant digits

2005-05-05 Thread Erik Max Francis
Jeremy Bowers wrote: > Step one for mrstephengross is to *rigorously* define what he means by > "significant digits", then go from there. Since I think he mentioned > something about predicting how much space it will take to print out, my > suggestion is to run through whatever printing routines t

Re: How to detect a double's significant digits

2005-05-05 Thread Jeremy Bowers
On Thu, 05 May 2005 18:42:17 +, Charles Krug wrote: > On 5 May 2005 10:37:00 -0700, mrstephengross <[EMAIL PROTECTED]> > wrote: >> Hi all... How can I find out the number of significant digits (to the >> right of the decimal place, that is) in a double? At least, I *think* >> that's what I'm a

Re: How to detect a double's significant digits

2005-05-05 Thread Fredrik Lundh
"mrstephengross" wrote: > >But, assuming you have your numbers as strings, I would suggest > looking > at str.split() and len(). > > Well, the numbers are in fact stored as numbers, so string processing > won't work. if they're not strings, your question is meaningless. as others have pointed ou

Re: How to detect a double's significant digits

2005-05-05 Thread Peter Otten
mrstephengross wrote: > This was all supposed to be on comp.lang.c++, but You may still want to read the following thread on Python-Dev: http://mail.python.org/pipermail/python-dev/2004-March/043703.html A link mentioned by Andrew Koenig may be helpful: http://www.netlib.org/fp/ """ fileg_f

Re: How to detect a double's significant digits

2005-05-05 Thread phil
Bollocks, works here. That looks like Java!!! Aaaihh! mrstephengross wrote: > Ok, that won't work. First of all, str() is not a function. If I want > to convert the float into a string, the conversion function will have > to use some kind of numeric precision, which will screw things up. > Cons

Re: How to detect a double's significant digits

2005-05-05 Thread mrstephengross
>This doesn't look like Python to me. Are you sure you're on the right newsgroup? Er, ok, I'm an idiot. This was all supposed to be on comp.lang.c++, but obviously I posted on the wrong one. Sorry for all the hassle. In python, this stuff is a heck of a lot easier. --Steve -- http://mail.pytho

Re: How to detect a double's significant digits

2005-05-05 Thread Grant Edwards
On 2005-05-05, mrstephengross <[EMAIL PROTECTED]> wrote: >>But, assuming you have your numbers as strings, I would suggest > looking > at str.split() and len(). > > Well, the numbers are in fact stored as numbers, Then your question is in fact meaningless. The related question that can be answere

Re: How to detect a double's significant digits

2005-05-05 Thread Charles Krug
On 5 May 2005 10:37:00 -0700, mrstephengross <[EMAIL PROTECTED]> wrote: > Hi all... How can I find out the number of significant digits (to the > right of the decimal place, that is) in a double? At least, I *think* > that's what I'm asking for. For instance: > > 0.103 --> 3 > 0.0103 --> 4 > 0.001

Re: How to detect a double's significant digits

2005-05-05 Thread Steven Bethard
mrstephengross wrote: >>But, assuming you have your numbers as strings, I would suggest > > looking > at str.split() and len(). > > Well, the numbers are in fact stored as numbers, so string processing > won't work. How about: py> def digits(f): ... return len(str(f).split('.')[1].rstrip('0

Re: How to detect a double's significant digits

2005-05-05 Thread Steven Bethard
mrstephengross wrote: > Well, the numbers are in fact stored as numbers, so string processing > won't work. What kind of numbers? Python floats? STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: How to detect a double's significant digits

2005-05-05 Thread mrstephengross
>But, assuming you have your numbers as strings, I would suggest looking at str.split() and len(). Well, the numbers are in fact stored as numbers, so string processing won't work. >I'd give you an example, but this sounds kinda like a homework assignment. The task may sound like it comes from c

Re: How to detect a double's significant digits

2005-05-05 Thread Steven Bethard
mrstephengross wrote: > First of all, str() is not a function. Yes it is. > float f = 1.004; > ostringstream s; > s << f; > cout << s.str(); This doesn't look like Python to me. Are you sure you're on the right newsgroup? STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: How to detect a double's significant digits

2005-05-05 Thread Steven Bethard
mrstephengross wrote: > So how can I get the kind of information I want then? > > For example: > > 0.103 --> 3 > 0.0103 --> 4 > 0.00103 --> 5 > 0.000103 --> 6 > 0.103 --> 7 Beware that this is probably only relevant if you have your numbers as strings, not as floats: py> 0.103 0.102

Re: How to detect a double's significant digits

2005-05-05 Thread mrstephengross
Ok, that won't work. First of all, str() is not a function. If I want to convert the float into a string, the conversion function will have to use some kind of numeric precision, which will screw things up. Consider this: float f = 1.004; ostringstream s; s << f; cout << s.str(); The above code m

Re: How to detect a double's significant digits

2005-05-05 Thread phil
fl = 1.0002 x = str(fl) pos = x.find('.') print len( x[pos+1:] ) >>> 4 mrstephengross wrote: > Hi all... How can I find out the number of significant digits (to the > right of the decimal place, that is) in a double? At least, I *think* > that's what I'm asking for. For instance: > > 0.103 -->

Re: How to detect a double's significant digits

2005-05-05 Thread mrstephengross
So how can I get the kind of information I want then? For example: 0.103 --> 3 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.103 --> 7 Any ideas? --Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: How to detect a double's significant digits

2005-05-05 Thread James Stroud
Significant digits are an accounting concept. As such, it is up to the accountant to keep track of these as only she knows the precision of her measurements. Koan for the day: What are the significant digits of 0.1? Hint: >>> `0.1` James On Thursday 05 May 2005 10:37 am, so sayeth mrstephe

How to detect a double's significant digits

2005-05-05 Thread mrstephengross
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 --> 3 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.103 --> 7 Thanks in advance! --Steve ([EMAIL PROTECTED]