GeographicLib 2.1.2
|
An accumulator for sums. More...
#include <GeographicLib/Accumulator.hpp>
Public Member Functions | |
Accumulator (T y=T(0)) | |
Accumulator & | operator= (T y) |
T | operator() () const |
T | operator() (T y) const |
Accumulator & | operator+= (T y) |
Accumulator & | operator-= (T y) |
Accumulator & | operator*= (int n) |
Accumulator & | operator*= (T y) |
Accumulator & | remainder (T y) |
bool | operator== (T y) const |
bool | operator!= (T y) const |
bool | operator< (T y) const |
bool | operator<= (T y) const |
bool | operator> (T y) const |
bool | operator>= (T y) const |
An accumulator for sums.
This allows many numbers of floating point type T to be added together with twice the normal precision. Thus if T is double, the effective precision of the sum is 106 bits or about 32 decimal places.
The implementation follows J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3) 305–363 (1997).
Approximate timings (summing a vector<double>)
In the documentation of the member functions, sum stands for the value currently held in the accumulator.
Example of use:
Definition at line 40 of file Accumulator.hpp.
|
inline |
Construct from a T. This is not declared explicit, so that you can write Accumulator<double> a = 5;
.
[in] | y | set sum = y. |
Definition at line 102 of file Accumulator.hpp.
|
inline |
Set the accumulator to a number.
[in] | y | set sum = y. |
Definition at line 111 of file Accumulator.hpp.
|
inline |
Return the value held in the accumulator.
Definition at line 117 of file Accumulator.hpp.
|
inline |
Return the result of adding a number to sum (but don't change sum).
[in] | y | the number to be added to the sum. |
Definition at line 125 of file Accumulator.hpp.
|
inline |
Add a number to the accumulator.
[in] | y | set sum += y. |
Definition at line 131 of file Accumulator.hpp.
|
inline |
Subtract a number from the accumulator.
[in] | y | set sum -= y. |
Definition at line 137 of file Accumulator.hpp.
|
inline |
Multiply accumulator by an integer. To avoid loss of accuracy, use only integers such that n × T is exactly representable as a T (i.e., ± powers of two). Use n = −1 to negate sum.
[in] | n | set sum *= n. |
Definition at line 145 of file Accumulator.hpp.
|
inline |
Multiply accumulator by a number. The fma (fused multiply and add) instruction is used (if available) in order to maintain accuracy.
[in] | y | set sum *= y. |
Definition at line 152 of file Accumulator.hpp.
|
inline |
Reduce accumulator to the range [-y/2, y/2].
[in] | y | the modulus. |
Definition at line 164 of file Accumulator.hpp.
|
inline |
Test equality of an Accumulator with a number.
Definition at line 173 of file Accumulator.hpp.
|
inline |
Test inequality of an Accumulator with a number.
Definition at line 177 of file Accumulator.hpp.
|
inline |
Less operator on an Accumulator and a number.
Definition at line 181 of file Accumulator.hpp.
|
inline |
Less or equal operator on an Accumulator and a number.
Definition at line 185 of file Accumulator.hpp.
|
inline |
Greater operator on an Accumulator and a number.
Definition at line 189 of file Accumulator.hpp.
|
inline |
Greater or equal operator on an Accumulator and a number.
Definition at line 193 of file Accumulator.hpp.