summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-11-08 12:36:44 -0500
committerDavid Goulet <dgoulet@torproject.org>2022-11-08 12:36:44 -0500
commit2adc73afdb0d7beeeb086e276c409d7cc5904a91 (patch)
tree5bf40b60313811abaf2db63202b4eb9ffc9a6c64 /src/lib
parentfb206d284cdba8bd68691a531aba4c7a7362c7c1 (diff)
parentfde87096c35259f9cda42fc5cc812b0bb122a82e (diff)
downloadtor-2adc73afdb0d7beeeb086e276c409d7cc5904a91.tar.gz
tor-2adc73afdb0d7beeeb086e276c409d7cc5904a91.zip
Merge branch 'maint-0.4.7'
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/math/include.am3
-rw-r--r--src/lib/math/stats.h22
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) */