Logo ROOT   6.07/09
Reference Guide
Util.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Tue Nov 14 15:44:38 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Utility functions for all ROOT Math classes
12 
13 #ifndef ROOT_Math_Util
14 #define ROOT_Math_Util
15 
16 #include <string>
17 #include <sstream>
18 
19 #include <cmath>
20 #include <limits>
21 
22 
23 // for defining unused variables in the interfaces
24 // and have still them in the documentation
25 #define MATH_UNUSED(var) (void)var
26 
27 
28 namespace ROOT {
29 
30  namespace Math {
31 
32 
33 /**
34  namespace defining Utility functions needed by mathcore
35 */
36 namespace Util {
37 
38 /**
39  Utility function for conversion to strings
40 */
41 template<class T>
42 std::string ToString(const T& val)
43 {
44  std::ostringstream buf;
45  buf << val;
46 
47  std::string ret = buf.str();
48  return ret;
49 }
50 
51 
52 /// safe evaluation of log(x) with a protections against negative or zero argument to the log
53 /// smooth linear extrapolation below function values smaller than epsilon
54 /// (better than a simple cut-off)
55 inline double EvalLog(double x) {
56  // evaluate the log
57 #ifdef __CINT__
58  static const double epsilon = 2.*2.2250738585072014e-308;
59 #else
60  static const double epsilon = 2.*std::numeric_limits<double>::min();
61 #endif
62  if(x<= epsilon)
63  return x/epsilon + std::log(epsilon) - 1;
64  else
65  return std::log(x);
66 }
67 
68 } // end namespace Util
69 
70 
71  } // end namespace Math
72 
73 } // end namespace ROOT
74 
75 
76 
77 #endif /* ROOT_Math_Util */
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
Double_t x[n]
Definition: legend1.C:17
REAL epsilon
Definition: triangle.c:617
Namespace for new Math classes and functions.
double EvalLog(double x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
Definition: Util.h:55
std::string ToString(const T &val)
Utility function for conversion to strings.
Definition: Util.h:42
double log(double)