From 7e405a27eeb7849d9c3d029ec93e9ef82aaa7c31 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 11 Mar 2024 12:05:37 -0400 Subject: [PATCH] changes to how formatter works --- CMakeLists.txt | 2 +- include/blt/math/math.h | 11 ++++++++--- include/blt/std/allocator.h | 7 ++++++- include/blt/std/format.h | 7 ++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2976fe..a34f5a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) include(cmake/color.cmake) -set(BLT_VERSION 0.14.13) +set(BLT_VERSION 0.14.14) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/math/math.h b/include/blt/math/math.h index 0882199..a2e73a8 100644 --- a/include/blt/math/math.h +++ b/include/blt/math/math.h @@ -73,10 +73,15 @@ namespace blt * @return */ template - static inline double round_up(double value) + constexpr static inline double round_up(double value) { - constexpr double multiplier = pow(10, decimal_places); - return ((int) (value * multiplier) + 1) / multiplier; + if constexpr (decimal_places < 0) + return value; + else + { + constexpr double multiplier = pow(10, decimal_places); + return ((int) (value * multiplier) + 1) / multiplier; + } } /*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) { diff --git a/include/blt/std/allocator.h b/include/blt/std/allocator.h index b2cd0ff..2b31871 100644 --- a/include/blt/std/allocator.h +++ b/include/blt/std/allocator.h @@ -970,7 +970,12 @@ namespace blt deallocate(p); } - inline const auto& getStats() + inline void resetStats() + { + stats = {}; + } + + inline const auto& getStats() const { return stats; } diff --git a/include/blt/std/format.h b/include/blt/std/format.h index 2b57c9e..d0a6e8a 100644 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -39,20 +39,21 @@ namespace blt::string return ret; } + template static inline std::string fromBytes(unsigned long bytes) { if (bytes > 1073741824) { // gigabyte - return std::to_string(round_up<3>((double) bytes / 1024.0 / 1024.0 / 1024.0)) += "gb"; + return std::to_string(round_up((double) bytes / 1024.0 / 1024.0 / 1024.0)) += "gb"; } else if (bytes > 1048576) { // megabyte - return std::to_string(round_up<3>((double) bytes / 1024.0 / 1024.0)) += "mb"; + return std::to_string(round_up((double) bytes / 1024.0 / 1024.0)) += "mb"; } else if (bytes > 1024) { // kilobyte - return std::to_string(round_up<3>((double) bytes / 1024.0)) += "kb"; + return std::to_string(round_up((double) bytes / 1024.0)) += "kb"; } else { return std::to_string(bytes) += "b";