MCPcopy Create free account
hub / github.com/apache/arrow / NeumaierSum

Function NeumaierSum

cpp/src/arrow/util/math_internal.h:45–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43/// https://en.wikipedia.org/wiki/Kahan_summation_algorithm#Further_enhancements
44template <typename Range = std::initializer_list<double>>
45double NeumaierSum(Range&& inputs) {
46 double sum = 0, c = 0;
47 for (const double v : inputs) {
48 double t = sum + v;
49 if (std::isfinite(t)) {
50 if (std::abs(sum) >= std::abs(v)) {
51 // If sum is bigger, low-order digits of v are lost...
52 c += (sum - t) + v;
53 } else {
54 // ... else low-order digits of sum are lost.
55 c += (v - t) + sum;
56 }
57 }
58 sum = t;
59 }
60 return sum + c;
61}
62
63/// Based-2 logarithm that works only on powers of two.
64template <typename T>

Callers 2

TESTFunction · 0.85
MergeMethod · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68