The statistics module is designed to capture information (raw integers) and process these into useful information. The sample size is arbitrarily large. Samples are double-precision floating point. double sum, // Sum of all values sum2, // Running deviation sum min, // Minimum value max, // Maximum value mean; // Current mean size_t count; // Sample size Initialises a new statistics set. Records a new sample. The standard deviation is calculated using Knuth's algorithm, from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance: double mean = 0; double S = 0; long N; for N = 1 to data.length double delta = data[N] - mean; mean = mean + delta / N; S = S + delta * ( data[N] - mean ); end for return S / ( N - 1 ) // the variance Sample value double delta; // self->sum += value; self->min = self->count? min (value, self->min): value; self->max = max (value, self->max); self->count++; delta = value - self->mean; self->mean += delta / self->count; self->sum2 += delta * (value - self->mean); Returns the minimum sample value. If the sample size is zero, returns zero. // rc = self->min; Returns the maximum sample value. // rc = self->max; Returns the number of samples. // rc = self->count; Returns the sum of all samples. // rc = self->sum; Returns the mean of the sample set. // rc = self->mean; Returns the variance of the sample set. // rc = self->sum2 / (self->count - 1); Returns the standard deviation of the sample set. // rc = sqrt (self->sum2 / (self->count - 1)); Reference to object Return code
$(selfname:upper)_ASSERT_SANE (self);
ipr_stat_t *stat; stat = ipr_stat_new (); ipr_stat_record (stat, 5); ipr_stat_record (stat, 7); ipr_stat_record (stat, 8); ipr_stat_record (stat, 10); ipr_stat_record (stat, 10); assert (ipr_stat_count (stat) == 5); assert (ipr_stat_sum (stat) == 40); assert (ipr_stat_min (stat) == 5); assert (ipr_stat_max (stat) == 10); assert (ipr_stat_mean (stat) == 8); assert (ipr_stat_var (stat) == 4.5); assert (ipr_stat_dev (stat) > 2.12); assert (ipr_stat_dev (stat) < 2.13); ipr_stat_destroy (&stat);