diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/math/include.am | 3 | ||||
-rw-r--r-- | src/lib/math/stats.h | 22 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/lib/math/include.am b/src/lib/math/include.am index b2ca280f47..f68b265da7 100644 --- a/src/lib/math/include.am +++ b/src/lib/math/include.am @@ -20,4 +20,5 @@ src_lib_libtor_math_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) noinst_HEADERS += \ src/lib/math/fp.h \ src/lib/math/laplace.h \ - src/lib/math/prob_distr.h + src/lib/math/prob_distr.h \ + src/lib/math/stats.h 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) */ |