added same() method to Kahan summation

same() returns true if added value doesn't change the low or high values
This commit is contained in:
Ahmet Inan 2018-03-03 12:14:22 +01:00
commit 1a7d4d2dc1

View file

@ -16,6 +16,7 @@ class Kahan
public:
Kahan() : high(0), low(0) {}
Kahan(T init) : high(init), low(0) {}
Kahan(const Kahan &a) : high(a.high), low(a.low) {}
#if __clang__
[[clang::optnone]]
#elif __GNUC__
@ -30,6 +31,16 @@ public:
low = (sum - high) - tmp;
return high = sum;
}
bool operator == (const Kahan &a)
{
return low == a.low && high == a.high;
}
bool same(T input)
{
Kahan tmp(*this);
(*this)(input);
return tmp == *this;
}
T operator ()() { return high; }
};