"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 > 0.00103 --> 5 > 0.000103 --> 6 > 0.0000103 --> 7 > > Thanks in advance! > --Steve ([EMAIL PROTECTED])
As a lot of the responders have pointed out, it's effectively impossible to do so in any meaningful fashion if all you have is the binary representation of the number. One way of doing it is the ScientificDouble class in PyFit (and in all other versions of FIT, for that matter.) That provides a class that saves the original string representation so it can be used to determine precision for compares. It's a niche approach: it works well for FIT's purposes, but it's not a general purpose method of estimating precision throughout a lengthy calculation. That requires quite different techniques. See: fit.c2.com www.fitnesse.org FitNesse Yahoo mailing list (see the files section for PyFit.) John Roth > -- http://mail.python.org/mailman/listinfo/python-list