From fa8b67b6c96dcff9e7422dabb29a2945c3a0cc38 Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 16 Feb 2023 00:06:36 -0500 Subject: [PATCH] fix average --- include/blt/std/math.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/blt/std/math.h b/include/blt/std/math.h index 0d6ed4b..bef4b09 100644 --- a/include/blt/std/math.h +++ b/include/blt/std/math.h @@ -565,12 +565,14 @@ namespace blt { private: T* data = new T[Size]; int index = 0; + int m_default = 0; public: averagizer_o_matic(): averagizer_o_matic(0) {} explicit averagizer_o_matic(T default_value){ for (int i = 0; i < Size; i++){ data[i] = default_value; } + m_default = default_value; } void insert(T t){ @@ -581,10 +583,14 @@ namespace blt { T average(){ T total = 0; + int size = 0; for (int i = 0; i < Size; i++){ + if (data[i] == m_default) + continue; total += data[i]; + size++; } - return total / Size; + return total / size; } ~averagizer_o_matic(){