From a7645d9ddec57ecaad525b48a30f8001adcf75e8 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 2 Sep 2024 12:38:50 -0400 Subject: [PATCH] silly --- CMakeLists.txt | 2 +- include/blt/math/averages.h | 36 +++++++++++++++++++++++++++--------- include/blt/std/format.h | 5 +++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 767cda6..9ccdaff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.19.4) +set(BLT_VERSION 0.19.5) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/math/averages.h b/include/blt/math/averages.h index cb7ca24..03918f4 100644 --- a/include/blt/math/averages.h +++ b/include/blt/math/averages.h @@ -7,43 +7,61 @@ #ifndef BLT_TESTS_AVERAGES_H #define BLT_TESTS_AVERAGES_H -namespace blt { +namespace blt +{ template - class averagizer_o_matic { + class averagizer_o_matic + { private: T* data; int index = 0; int m_default = 0; public: - averagizer_o_matic(): averagizer_o_matic(0) {} - explicit averagizer_o_matic(T default_value){ + averagizer_o_matic(): averagizer_o_matic(0) + {} + + explicit averagizer_o_matic(T default_value) + { data = new T[Size]; - for (int i = 0; i < Size; i++){ + for (int i = 0; i < Size; i++) + { data[i] = default_value; } m_default = default_value; } - void insert(T t){ + void insert(T t) + { data[index++] = t; if (index >= Size) index = 0; } - T average(){ + T average() + { T total = 0; - for (int i = 0; i < Size; i++){ + for (int i = 0; i < Size; i++) + { total += data[i]; } return total / Size; } - ~averagizer_o_matic(){ + ~averagizer_o_matic() + { delete[] data; } }; + template + double average(A a, B b) + { + if (b == 0) + return 0; + return static_cast(a) / static_cast(b); + } + } #endif //BLT_TESTS_AVERAGES_H diff --git a/include/blt/std/format.h b/include/blt/std/format.h index 47cd739..1b8ec60 100644 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -158,6 +158,11 @@ namespace blt::string return std::to_string(convert.getConvertedRound()) + convert.type_string(); } + static inline std::string bytes_to_pretty(blt::u64 bytes) + { + return byte_convert_t(bytes).convert_to_nearest_type().to_pretty_string(); + } + // TODO: update table formatter to use these! /** * creates a line starting/ending with ending char filled between with spacing char