diff options
author | Wolfgang Draxinger <Wolfgang.Draxinger@draxit.de> | 2016-04-24 23:52:45 +0200 |
---|---|---|
committer | Wolfgang Draxinger <Wolfgang.Draxinger@draxit.de> | 2016-04-24 23:52:45 +0200 |
commit | 2ca04fbe7985ee944f3fa6302886a252a51add0c (patch) | |
tree | b373879928a1060e564d29d44f6e20b620b272e9 /stats.h | |
download | pointoverdrawbench-2ca04fbe7985ee944f3fa6302886a252a51add0c.tar.gz pointoverdrawbench-2ca04fbe7985ee944f3fa6302886a252a51add0c.tar.bz2 |
initial commit
Diffstat (limited to 'stats.h')
-rw-r--r-- | stats.h | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,35 @@ +#pragma once +#ifndef STATS_H +#define STATS_H + +#include <math.h> + +struct stats_running { + unsigned n; + double S; + double m; +}; +#define STATS_RUNNING_INIT {0, NAN, NAN} + +void stats_running_reset(struct stats_running *s); +void stats_running_push(struct stats_running *s, double value); + +static inline +unsigned stats_running_N(struct stats_running const *s) +{ + return s ? s->n : 0; +} + +static inline +double stats_running_mean(struct stats_running const *s) +{ + return s && (0 < s->n) ? s->m : NAN; +} + +static inline +double stats_running_variance(struct stats_running const *s) +{ + return s && (1 < s->n) ? s->S/s->n : NAN; +} + +#endif/*STATS_H*/ |