mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Improve numerical accuracy with Kahan summation algorithm
This commit is contained in:
parent
f76f84d687
commit
a0277b6320
1 changed files with 7 additions and 2 deletions
|
@ -26,8 +26,13 @@ public:
|
|||
explicit Statistics(ContainerType&& existing_container)
|
||||
: m_values(forward<ContainerType>(existing_container))
|
||||
{
|
||||
for (auto const& value : m_values)
|
||||
m_sum += value;
|
||||
T c = 0.0; // correction term
|
||||
for (auto const& value : m_values) {
|
||||
T const y = value - c;
|
||||
T const t = m_sum + y;
|
||||
c = (t - m_sum) - y;
|
||||
m_sum = t;
|
||||
}
|
||||
}
|
||||
|
||||
void add(T const& value)
|
||||
|
|
Loading…
Reference in a new issue