Logo ROOT   6.10/09
Reference Guide
testKahan.cxx
Go to the documentation of this file.
1 #include "Math/Util.h"
2 #include <vector>
3 
4 int KahanTest()
5 {
6  std::vector<double> numbers = {0.01, 0.001, 0.0001, 0.000001, 0.00000000001};
8  k.Add(numbers.begin(), numbers.end());
9  auto result = ROOT::Math::KahanSum<double>::Accumulate(numbers.begin(), numbers.end());
10  if (k.Result() != result) return 1;
11 
14  k2.Add(1);
15  k2.Add(numbers.begin(), numbers.end());
16  k3.Add(numbers.begin(), numbers.end());
17  if (k2.Result() != k3.Result()) return 2;
18 
19  return 0;
20 }
21 
22 int main()
23 {
24  return KahanTest();
25 }
int KahanTest()
Definition: testKahan.cxx:4
int main()
Definition: testKahan.cxx:22
T Result()
Return the result.
Definition: Util.h:121
The Kahan compensate summation algorithm significantly reduces the numerical error in the total obtai...
Definition: Util.h:85
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...
Definition: Util.h:111
double result[121]
void Add(const T &x)
Single element accumulated addition.
Definition: Util.h:91