Util.h

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: Util.h 26079 2008-11-05 09:40:15Z pcanal $
00002 // Author: L. Moneta Tue Nov 14 15:44:38 2006
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Utility functions for all ROOT Math classes 
00012 
00013 #ifndef ROOT_Math_Util
00014 #define ROOT_Math_Util
00015 
00016 #include <string> 
00017 #include <sstream> 
00018 
00019 #include <cmath>
00020 #include <limits>
00021 
00022 namespace ROOT { 
00023 
00024    namespace Math { 
00025 
00026 
00027 
00028 /** 
00029    namespace defining Utility functions needed by mathcore 
00030 */ 
00031 namespace Util { 
00032 
00033 /**
00034    Utility function for conversion to strings
00035 */
00036 template<class T>
00037 std::string ToString(const T& val)
00038 {
00039    std::ostringstream buf;
00040    buf << val;
00041    
00042    std::string ret = buf.str();
00043    return ret;
00044 }
00045 
00046 
00047 /// safe evaluation of log(x) with a protections against negative or zero argument to the log 
00048 /// smooth linear extrapolation below function values smaller than  epsilon
00049 /// (better than a simple cut-off)
00050 inline double EvalLog(double x) { 
00051    // evaluate the log 
00052 #ifdef __CINT__
00053    static const double epsilon = 2.*2.2250738585072014e-308;
00054 #else
00055    static const double epsilon = 2.*std::numeric_limits<double>::min();
00056 #endif
00057    if(x<= epsilon) 
00058       return x/epsilon + std::log(epsilon) - 1; 
00059    else      
00060       return std::log(x);
00061 }
00062  
00063 }  // end namespace Util
00064 
00065 
00066    } // end namespace Math
00067 
00068 } // end namespace ROOT
00069 
00070 
00071 #endif /* ROOT_Math_Util */

Generated on Tue Jul 5 14:25:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1