MCFilePOTInfoHelper Namespace Reference

Functions

bool AreDoublesSame (double a, double b)
std::string trim (const std::string &str, const std::string &whitespace=" \t")

Function Documentation

bool MCFilePOTInfoHelper::AreDoublesSame ( double  a,
double  b 
)

Definition at line 27 of file MCFilePOTInfo.cxx.

00027                                           {
00028     // For float or double, need to determine equality while 
00029     // accounting for some degree of imprecision
00030     // The method applied here is adopted from Theodore C. Belding's
00031     // fcmp implementation of Donald Knuth's algorithm. 
00032     double value[2] = {a,b};
00033     double epsilon = 10.*FLT_EPSILON;
00034     //      if ( isDouble[0] || isDouble[1] ) epsilon = DBL_EPSILON;
00035     int exponent;
00036     frexp(fabs(value[0]) > fabs(value[1]) ? value[0] : value[1], &exponent);
00037     double delta = ldexp(epsilon,exponent);
00038     double difference = value[0] - value[1];
00039     if ( difference > delta || difference < -delta ) {
00040       return false;
00041     }
00042     return true;
00043   }

std::string MCFilePOTInfoHelper::trim ( const std::string &  str,
const std::string &  whitespace = " \t" 
)

Definition at line 45 of file MCFilePOTInfo.cxx.

Referenced by operator>>().

00047   {
00048     const size_t strBegin = str.find_first_not_of(whitespace);
00049     if (strBegin == std::string::npos)
00050       return ""; // no content
00051     
00052     const size_t strEnd = str.find_last_not_of(whitespace);
00053     const size_t strRange = strEnd - strBegin + 1;
00054     
00055     return str.substr(strBegin, strRange);
00056   }


Generated on 3 Oct 2018 for loon by  doxygen 1.6.1