|
|
@ -2,6 +2,7 @@
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <values.h>
|
|
|
|
|
|
|
|
|
|
|
|
double mean(double set[], int set_n) {
|
|
|
|
double mean(double set[], int set_n) {
|
|
|
|
double sum = 0.0;
|
|
|
|
double sum = 0.0;
|
|
|
@ -35,6 +36,30 @@ double sample_stddev(double set[], int set_n) {
|
|
|
|
return sqrt(sample_variance(set, set_n));
|
|
|
|
return sqrt(sample_variance(set, set_n));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double set_min(double set[], int set_n) {
|
|
|
|
|
|
|
|
double min = MAXDOUBLE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<set_n; i++) {
|
|
|
|
|
|
|
|
min=fmin(set[i], min);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return min;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double set_max(double set[], int set_n) {
|
|
|
|
|
|
|
|
double max = MINDOUBLE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<set_n; i++) {
|
|
|
|
|
|
|
|
max=fmax(set[i], max);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return max;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double range(double set[], int set_n) {
|
|
|
|
|
|
|
|
return set_max(set, set_n) - set_min(set, set_n);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int main() {
|
|
|
|
// Some data
|
|
|
|
// Some data
|
|
|
|
double d[] = {7, 8, 5, 1, 6, 2};
|
|
|
|
double d[] = {7, 8, 5, 1, 6, 2};
|
|
|
@ -56,7 +81,14 @@ int main() {
|
|
|
|
assert(isalmost(sample_stddev(d, d_n), 2.787, 0.001));
|
|
|
|
assert(isalmost(sample_stddev(d, d_n), 2.787, 0.001));
|
|
|
|
assert(isalmost(sample_stddev(e, e_n), 6.447, 0.001));
|
|
|
|
assert(isalmost(sample_stddev(e, e_n), 6.447, 0.001));
|
|
|
|
|
|
|
|
|
|
|
|
// XXX Range
|
|
|
|
assert(isalmost(set_min(d, d_n), 1.0, 0.001));
|
|
|
|
|
|
|
|
assert(isalmost(set_max(d, d_n), 8.0, 0.001));
|
|
|
|
|
|
|
|
assert(isalmost(set_min(e, e_n), -10.0, 0.001));
|
|
|
|
|
|
|
|
assert(isalmost(set_max(e, e_n), +14.0, 0.001));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(isalmost(range(d, d_n), 7.0, 0.001));
|
|
|
|
|
|
|
|
assert(isalmost(range(e, e_n), 24.0, 0.001));
|
|
|
|
|
|
|
|
|
|
|
|
// XXX Mode
|
|
|
|
// XXX Mode
|
|
|
|
// XXX Percentile
|
|
|
|
// XXX Percentile
|
|
|
|
}
|
|
|
|
}
|
|
|
|