Returns true if current sum is finite (not infinite or NaN).
Returns true if current sum is finite (not infinite or NaN).
Returns true if current sum is ±∞.
Returns true if current sum is ±∞.
Returns true if current sum is a NaN.
Returns true if current sum is a NaN.
Operator overloading.
Returns Summator with extended internal partial sums.
cast(C) operator overloading. Returns cast(C)sum(). See also: cast
Operator overloading.
Adds x to the internal partial sums.
Returns the value of the sum.
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).
import std.range; import std.algorithm: swap; ///Moving mean class MovingAverage { Summator!double summator; double[] circularBuffer; size_t frontIndex; double avg() @property { return summator.sum() / circularBuffer.length; } this(double[] buffer) { assert(!buffer.empty); circularBuffer = buffer; summator = 0; .put(summator, buffer); } ///operation without rounding void put(double x) { summator += x; swap(circularBuffer[frontIndex++], x); summator -= x; frontIndex %= circularBuffer.length; } } /// ma always keeps pricese average of last 1000 elements auto ma = new MovingAverage(iota(0.0, 1000.0).array); assert(ma.avg == (1000*999/2) / 1000.0); /// move by 10 elements put(ma, iota(1000.0, 1010.0)); assert(ma.avg == (1010*1009/2 - 10*9/2) / 1000.0);
move by 10 elements
Summator!double d; assert(d.isNaN()); assert(d.sum().isNaN()); d += 100; assert(d.isNaN()); assert(d.sum().isNaN()); d = 1; d += 1000; assert(d.sum == 1001);
Output range for summation. Precise, KB2, KBN and Kahan algorithms are supported.