mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
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:
parent
c6de7e95e0
commit
1a7d4d2dc1
1 changed files with 11 additions and 0 deletions
11
kahan.hh
11
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; }
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue