22#ifndef LSST_AFW_MATH_POLYNOMIALS_SafeSum_h_INCLUDED
23#define LSST_AFW_MATH_POLYNOMIALS_SafeSum_h_INCLUDED
27namespace lsst {
namespace geom {
namespace polynomials {
65 explicit SafeSum(T initial=
static_cast<T
>(0)) noexcept :
67 _correction(static_cast<T>(0))
72 _correction =
static_cast<T
>(0);
80 if (std::abs(_sum) >= std::abs(value)) {
81 _correction += (_sum - t) + value;
83 _correction += (value - t) + _sum;
93 explicit operator T() const noexcept {
94 return _sum + _correction;
A numerically stable summation algorithm for floating-point numbers.
SafeSum & operator-=(T value) noexcept
SafeSum & operator+=(T value) noexcept
SafeSum(T initial=static_cast< T >(0)) noexcept
SafeSum & operator=(T value) noexcept
SumMode
Enum used to control how to sum polynomial terms.
@ SAFE
Compensated summation using SafeSum. Involves ~4x as many floating point operations.
@ FAST
Summation using regular floating-point addition.