vstat
Loading...
Searching...
No Matches
compensated_sum.hpp
1
// SPDX-License-Identifier: MIT
2
// SPDX-FileCopyrightText: Copyright 2020-2024 Heal Research
3
4
#ifndef VSTAT_COMPENSATED_SUM_HPP
5
#define VSTAT_COMPENSATED_SUM_HPP
6
7
#include <eve/module/core.hpp>
8
9
namespace
VSTAT_NAMESPACE
10
{
11
26
template
<
typename
T>
27
struct
compensated_sum
28
{
29
constexpr
void
operator()(T x)
noexcept
30
{
31
auto
[t, e] = eve::two_add(sum_, x);
32
comp_ += e;
33
sum_ = t;
34
}
35
36
[[nodiscard]]
constexpr
auto
value()
const
noexcept
-> T {
return
sum_ + comp_; }
37
38
private
:
39
T sum_ {0};
40
T comp_ {0};
41
};
42
43
}
// namespace VSTAT_NAMESPACE
44
45
#endif
VSTAT_NAMESPACE::compensated_sum
Knuth TwoSum compensated accumulator.
Definition
compensated_sum.hpp:28
include
vstat
compensated_sum.hpp
Generated by
1.9.8