Summator.unsafePut

Adds x to the internal partial sums. This operation doesn't re-establish special value semantics across iterations (i.e. handling -inf + inf). Preconditions: isFinite(x).

struct Summator(T, Summation summation = Summation.Precise)
package
static if(summation == Summation.Precise)
void
unsafePut
()
if (
isMutable!T &&
(
summation == Summation.Precise &&
isFloatingPoint!T
||
summation == Summation.Kahan &&
isSummable!T
||
(
summation == Summation.KBN ||
summation == Summation.KB2
)
&&
(
isFloatingPoint!T ||
isComplex!T
)
)
)

Examples

import std.math, std.algorithm, std.range;
auto r = iota(1000).map!(n => 1.7L.pow(n+1) - 1.7L.pow(n));
Summator!real s = 0.0;
put(s, r);
s -= 1.7L.pow(1000);
assert(s.sum() == -1);

Meta