numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::util::kahan_adder< T > Class Template Reference

Class to add numbers using Kahan summation [14]. More...

#include <num_collect/util/kahan_adder.h>

+ Collaboration diagram for num_collect::util::kahan_adder< T >:

Public Member Functions

 kahan_adder ()
 Constructor.
 
 kahan_adder (const T &zero)
 Construct with zero number.
 
auto add (const T &value) -> kahan_adder &
 Add a number.
 
 operator T () const
 Get sum.
 
auto operator+= (const T &value) -> kahan_adder &
 Add a number.
 
auto operator-= (const T &value) -> kahan_adder &
 Subtract a number.
 
auto sub (const T &value) -> kahan_adder &
 Subtract a number.
 
auto sum () const noexcept -> const T &
 Get sum.
 

Private Attributes

prev_sum_
 Previous sum.
 
rem_
 Remaining.
 
sum_
 Sum.
 

Detailed Description

template<concepts::kahan_addable T>
class num_collect::util::kahan_adder< T >

Class to add numbers using Kahan summation [14].

Template Parameters
TType of numbers.

Definition at line 32 of file kahan_adder.h.

Constructor & Destructor Documentation

◆ kahan_adder() [1/2]

template<concepts::kahan_addable T>
num_collect::util::kahan_adder< T >::kahan_adder ( )
inline

Constructor.

Note
This won't work for Eigen's vectors and matrices. Use another constructor for them.

Definition at line 40 of file kahan_adder.h.

◆ kahan_adder() [2/2]

template<concepts::kahan_addable T>
num_collect::util::kahan_adder< T >::kahan_adder ( const T & zero)
inlineexplicit

Construct with zero number.

This constructor is useful for Eigen's vectors and matrices.

Parameters
[in]zeroZero.

Definition at line 49 of file kahan_adder.h.

Member Function Documentation

◆ add()

template<concepts::kahan_addable T>
auto num_collect::util::kahan_adder< T >::add ( const T & value) -> kahan_adder&
inline

Add a number.

Parameters
[in]valueAdded value.
Returns
This.

Definition at line 58 of file kahan_adder.h.

◆ operator T()

template<concepts::kahan_addable T>
num_collect::util::kahan_adder< T >::operator T ( ) const
inline

Get sum.

Returns
Sum.

Definition at line 114 of file kahan_adder.h.

◆ operator+=()

template<concepts::kahan_addable T>
auto num_collect::util::kahan_adder< T >::operator+= ( const T & value) -> kahan_adder&
inline

Add a number.

Parameters
[in]valueAdded value.
Returns
This.

Definition at line 86 of file kahan_adder.h.

◆ operator-=()

template<concepts::kahan_addable T>
auto num_collect::util::kahan_adder< T >::operator-= ( const T & value) -> kahan_adder&
inline

Subtract a number.

Parameters
[in]valueAdded value.
Returns
This.

Definition at line 97 of file kahan_adder.h.

◆ sub()

template<concepts::kahan_addable T>
auto num_collect::util::kahan_adder< T >::sub ( const T & value) -> kahan_adder&
inline

Subtract a number.

Parameters
[in]valueAdded value.
Returns
This.

Definition at line 72 of file kahan_adder.h.

◆ sum()

template<concepts::kahan_addable T>
auto num_collect::util::kahan_adder< T >::sum ( ) const -> const T&
inlinenodiscardnoexcept

Get sum.

Returns
Sum.

Definition at line 107 of file kahan_adder.h.

Member Data Documentation

◆ prev_sum_

template<concepts::kahan_addable T>
T num_collect::util::kahan_adder< T >::prev_sum_
private

Previous sum.

Definition at line 126 of file kahan_adder.h.

◆ rem_

template<concepts::kahan_addable T>
T num_collect::util::kahan_adder< T >::rem_
private

Remaining.

Definition at line 123 of file kahan_adder.h.

◆ sum_

template<concepts::kahan_addable T>
T num_collect::util::kahan_adder< T >::sum_
private

Sum.

Definition at line 120 of file kahan_adder.h.


The documentation for this class was generated from the following file: