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

Function NeumaierSum

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

Source from the content-addressed store, hash-verified

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

Callers 2

TESTFunction · 0.85
MergeMethod · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68