13 #ifndef ROOT_Math_Util 14 #define ROOT_Math_Util 24 #define MATH_UNUSED(var) (void)var 42 std::ostringstream buf;
45 std::string ret = buf.str();
56 static const double epsilon = 2. * 2.2250738585072014e-308;
58 static const double epsilon = 2. * std::numeric_limits<double>::min();
61 return x / epsilon +
std::log(epsilon) - 1;
88 KahanSum(
const T &initialValue =
T{}) : fSum(initialValue) {}
93 auto y = x - fCorrection;
95 fCorrection = (t - fSum) - y;
100 template <
class Iterator>
101 void Add(
const Iterator begin,
const Iterator end)
103 static_assert(!std::is_same<decltype(*begin),
T>::value,
104 "Iterator points to an element of the different type than the KahanSum class");
105 for (
auto it = begin; it != end; it++) this->
Add(*it);
110 template <
class Iterator>
111 static T Accumulate(
const Iterator begin,
const Iterator end,
const T &initialValue =
T{})
113 static_assert(!std::is_same<decltype(*begin),
T>::value,
114 "Iterator points to an element of the different type than the KahanSum class");
116 init.
Add(begin, end);
Namespace for new ROOT classes and functions.
KahanSum(const T &initialValue=T{})
Constructor accepting a initial value for the summation as parameter.
T Result()
Return the result.
The Kahan compensate summation algorithm significantly reduces the numerical error in the total obtai...
void Add(const Iterator begin, const Iterator end)
Iterate over a datastructure referenced by a pointer and accumulate on the exising result...
static T Accumulate(const Iterator begin, const Iterator end, const T &initialValue=T{})
Iterate over a datastructure referenced by a pointer and return the result of its accumulation...
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
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...
std::string ToString(const T &val)
Utility function for conversion to strings.
void Add(const T &x)
Single element accumulated addition.