Mean

Output range to calculate the mean online. Getter for mean costs a branch to check for N == 0. This struct uses O(1) space and does *NOT* store the individual elements.

Note: This struct can implicitly convert to the value of the mean.

Alias This

mean

Allow implicit casting to double, by returning the current mean.

Members

Functions

put
void put(double element)
put
void put(typeof(this) rhs)

Adds the contents of rhs to this instance.

toString
string toString()

Properties

N
double N [@property getter]
mean
double mean [@property getter]
sum
double sum [@property getter]
toMean
Mean toMean [@property getter]

Simply returns this. Useful in generic programming contexts.

Examples

1 Mean summ;
2 summ.put(1);
3 summ.put(2);
4 summ.put(3);
5 summ.put(4);
6 summ.put(5);
7 assert(summ.mean == 3);

Meta