diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/math/include.am | 3 | ||||
-rw-r--r-- | src/lib/math/stats.h | 19 |
2 files changed, 21 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..fae93c6213 --- /dev/null +++ b/src/lib/math/stats.h @@ -0,0 +1,19 @@ +/* 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". */ +#define STATS_UPDATE_AVG(avg, value, n) \ + avg = ((avg) * ((n) - 1) + (value)) / (n) + +#endif /* !defined(TOR_STATS_H) */ |