CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
round_string Struct Reference

#include <round_string.h>

Public Member Functions

template<class T >
std::string operator() (const std::pair< T, T > x) const
 

Detailed Description

Definition at line 10 of file round_string.h.

Member Function Documentation

template<class T >
std::string round_string::operator() ( const std::pair< T, T x) const
inline

Definition at line 12 of file round_string.h.

References funct::pow(), and alignCSCRings::s.

12  {
13  int val_digit(0), err_digit(0);
14 
15  if(x.first != 0) {
16  while( fabs(x.first) / pow(10, val_digit) < 1 ) val_digit--;
17  while( fabs(x.first) / pow(10, val_digit) > 10 )val_digit++;
18  }
19  if(x.second != 0 ) {
20  while( x.second / pow(10,err_digit) < 0.95 ) err_digit--;
21  while( x.second / pow(10,err_digit) > 9.50 ) err_digit++;
22  }
23 
24  if(val_digit<err_digit) val_digit=err_digit;
25  const bool scinot = (val_digit<-1 || err_digit>0);
26 
27  std::stringstream s;
28  s << std::fixed << std::setprecision( scinot? val_digit-err_digit : -err_digit)
29  << ( scinot? x.first/pow(10,val_digit) : x.first )
30  << "("
31  << unsigned(x.second / pow(10,err_digit) + 0.5) << ")";
32  if(scinot) s<< "e" << (val_digit>0 ? "+" : "") << val_digit;
33 
34  return s.str();
35  }
U second(std::pair< T, U > const &p)
bool first
Definition: L1TdeRCT.cc:94
x
Definition: VDTMath.h:216
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40