CMS 3D CMS Logo

Public Member Functions

round_string Struct Reference

#include <round_string.h>

List of all members.

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.

                                                   {
    int val_digit(0), err_digit(0);
    
    if(x.first != 0) {
      while( fabs(x.first) / pow(10, val_digit) < 1 ) val_digit--;
      while( fabs(x.first) / pow(10, val_digit) > 10 )val_digit++;
    }
    if(x.second != 0 ) {
      while( x.second / pow(10,err_digit) < 0.95 ) err_digit--;
      while( x.second / pow(10,err_digit) > 9.50 ) err_digit++;
    }
    
    if(val_digit<err_digit) val_digit=err_digit;
    const bool scinot = (val_digit<-1 || err_digit>0);
    
    std::stringstream s;
    s << std::fixed << std::setprecision( scinot? val_digit-err_digit : -err_digit)
      << ( scinot? x.first/pow(10,val_digit) : x.first )
      << "("
      << unsigned(x.second / pow(10,err_digit) + 0.5) << ")";
    if(scinot) s<< "e" << (val_digit>0 ? "+" : "") << val_digit;
    
    return s.str();
  }