FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
kahan_accumulator.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8namespace FEAT
9{
18 template<typename DT_>
20 {
21 public:
23 DT_ value;
26
29 value(DT_(0)),
30 correction(DT_(0))
31 {
32 }
33
35 explicit KahanAccumulator(DT_ val) :
36 value(val),
37 correction(DT_(0))
38 {
39 }
40
42 void clear()
43 {
44 value = correction = DT_(0);
45 }
46
49 {
50 DT_ y = val - this->correction;
51 DT_ t = this->value + y;
52 this->correction = (t - this->value) - y;
53 this->value = t;
54 return *this;
55 }
56
58 operator DT_() const
59 {
60 return value;
61 }
62 }; // class KahanAccumulator<...>
63} // namespace FEAT
Kahan Summation accumulator class template.
KahanAccumulator(DT_ val)
constructor
KahanAccumulator()
default constructor
DT_ value
the current sum value
DT_ correction
the current correction
void clear()
clears the accumulator, i.e. sets all values to zero
KahanAccumulator & operator+=(DT_ val)
updates the summed accumulator with a new summand
FEAT namespace.
Definition: adjactor.hpp:12