diff --git a/.gitignore b/.gitignore index 3e7e415..d6fd42d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ tags mtrace-test mtrace-test.trace mtrace-test.txt +av-variance diff --git a/Makefile b/Makefile index d0d6529..9ed1d75 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CFLAGS=-std=c99 -Wextra -pedantic -g -O2 CFLAGS=-std=c99 -Wextra -pedantic -g -O0 -TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs ncurses-pong bit-fuckery bit-fuckery2 checkcheck multibrot bloom wo-lernen lua-foo binsearch test-inline-assembly uiowa-threads-example mtrace-test +TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs ncurses-pong bit-fuckery bit-fuckery2 checkcheck multibrot bloom wo-lernen lua-foo binsearch test-inline-assembly uiowa-threads-example mtrace-test av-variance EXTRAS=mandelbrot.bmp multibrot.png test-inline-assembly.s tags mtrace-test.trace mtrace-test.txt .PHONY: all diff --git a/av-variance.c b/av-variance.c new file mode 100644 index 0000000..7bfabd0 --- /dev/null +++ b/av-variance.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +double mean(double set[], int set_n) { + double sum = 0.0; + for(int i=0; i= 0.0); + return fabs(x-c) < epsilon; +} + +int main() { + // Some data + double d[] = {7, 8, 5, 1, 6, 2}; + const int d_n = 6; + + double e[] = {-10, 0, 10, 11, 12, 13, 14, 8, 9, 10, 11, 10, 10}; + const int e_n = 13; + + // Some tests + assert(isalmost(mean(d, d_n), 4.833, 0.001)); + assert(isalmost(mean(e, e_n), 8.307, 0.001)); + + // XXX assert(isalmost(median(d, d_n), 5.5, 0.001)); + // XXX assert(isalmost(median(e, e_n), XXX, 0.001)); + // XXX Variance + // XXX Stddev + // XXX Range + // XXX Mode + // XXX Percentile +}