kahan_sum overloads

Synopses

Declared in <folly/math/KahanSummation.h>

Computes the Kahan compensated sum over a range.

template<std::ranges::input_range R>
requires std::floating_point<std::ranges::range_value_t<R>>
std::ranges::range_value_t<R>
kahan_sum(R&& range);

Computes the Kahan compensated sum over an iterator range.

template<
    std::input_iterator I,
    std::sentinel_for<I> S>
requires std::floating_point<std::iter_value_t<I>>
std::iter_value_t<I>
kahan_sum(
    I first,
    S last);

Return Value

  • The compensated sum of all elements in the range.

  • The compensated sum of all elements in [first, last).]

Template Parameters

Name

Description

R

An input range whose value type is a floating‐point type.

I

An input iterator whose value type is a floating‐point type.

S

A sentinel for I.

Parameters

Name

Description

range

The range to sum.

first

Iterator to the first element.

last

Sentinel past the last element.

Created with MrDocs