From 1a7d4d2dc17087790c3e540d213fcc7dccc270d4 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sat, 3 Mar 2018 12:14:22 +0100 Subject: [PATCH] added same() method to Kahan summation same() returns true if added value doesn't change the low or high values --- kahan.hh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kahan.hh b/kahan.hh index a169d38..d096ab9 100644 --- a/kahan.hh +++ b/kahan.hh @@ -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; } };