Summator.opAssign

Operator overloading.

struct Summator(T, Summation summation = Summation.Precise)
void
opAssign
(
T rhs
)
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 r1 = iota(500).map!(a => 1.7L.pow(a+1) - 1.7L.pow(a));
auto r2 = iota(500, 1000).map!(a => 1.7L.pow(a+1) - 1.7L.pow(a));
Summator!real s1 = 0, s2 = 0.0;
foreach (e; r1) s1 += e;
foreach (e; r2) s2 -= e;
s1 -= s2;
s1 -= 1.7L.pow(1000);
assert(s1.sum() == -1);

Meta