diff options
Diffstat (limited to 'src/lib/math/stats.h')
-rw-r--r-- | src/lib/math/stats.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/math/stats.h b/src/lib/math/stats.h new file mode 100644 index 0000000000..328d61a9d6 --- /dev/null +++ b/src/lib/math/stats.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2022, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file stats.h + * + * \brief Header for stats.c + **/ + +#ifndef TOR_STATS_H +#define TOR_STATS_H + +/** Update an average making it a "running average". The "avg" is the current + * value that will be updated to the new one. The "value" is the new value to + * add to the average and "n" is the new count as in including the "value". */ +static inline double +stats_update_running_avg(double avg, double value, double n) +{ + return ((avg * (n - 1)) + value) / n; +} + +#endif /* !defined(TOR_STATS_H) */ |