DATRW++ library: seismic data I/O with multiple formats

◆ nsignificantdigits()

int datrw::util::nsignificantdigits ( double  v,
const bool &  debug 
)

return number of significant digits

Examples:
writetest.cc.

Definition at line 49 of file util.cc.

Referenced by main(), ntrailingdigits(), and datrw::su::ScalCoo::set().

50  {
51  const double epsilon=1.e-30;
52  if (debug)
53  {
54  std::cerr << "DEBUG (nsignificantdigits): "
55  << "entered function for value:" << v << std::endl;
56  }
57  if (v<0) { v = -v; }
58  int n=0;
59  if (v<epsilon)
60  {
61  n=2;
62  }
63  else
64  {
65  double basefactor=pow(10.,-floor(log10(v)));
66  double v1,v2;
67  if (debug)
68  {
69  std::cerr << "DEBUG (nsignificantdigits): "
70  << "basefactor: " << basefactor << " "
71  << "v: " << v << " "
72  << std::endl;
73  }
74  do
75  {
76  double factor=basefactor*pow(10.,n);
77  v1=v*factor;
78  v2=floor(v1);
79  n++;
80  if (debug)
81  {
82  std::cerr << "DEBUG (nsignificantdigits): "
83  << "factor: " << factor << " "
84  << "n: " << n << " "
85  << "v1: " << v1 << " "
86  << "v2: " << v2 << " "
87  << std::endl;
88  }
89  }
90  while (v1 != v2);
91  }
92  return (n);
93  } // int nsignificantdigits(const double& v)
Here is the caller graph for this function: