diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index a485000..4ba4088 100644 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -90,7 +90,7 @@ namespace blt { blt::flat_stack nodeStack{}; BST_node* current = root; - while (current != nullptr || !nodeStack.isEmpty()) { + while (current != nullptr || !nodeStack.empty()) { // go all the way to the left subtree while (current != nullptr) { nodeStack.push(current); diff --git a/include/blt/std/format.h b/include/blt/std/format.h index 6ae79cf..fd53a44 100644 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -12,16 +12,30 @@ #include namespace blt::string { + static inline constexpr double _static_pow(int p) { + int collection = 1; + for (int i = 0; i < p; i++) + collection *= 10; + return collection; + } + + template + static inline double round_up(double value) { + constexpr double multiplier = _static_pow(decimal_places); + return ((int)(value * multiplier) + 1) / multiplier; + } + + static inline std::string fromBytes(unsigned long bytes){ if (bytes > 1073741824) { // gigabyte - return std::to_string((double)bytes / 1024.0 / 1024.0 / 1024.0) += "gb"; + return std::to_string(round_up<3>((double) bytes / 1024.0 / 1024.0 / 1024.0)) += "gb"; } else if (bytes > 1048576) { // megabyte - return std::to_string((double)bytes / 1024.0 / 1024.0) += "mb"; + return std::to_string(round_up<3>((double)bytes / 1024.0 / 1024.0)) += "mb"; } else if (bytes > 1024) { // kilobyte - return std::to_string((double)bytes / 1024.0) += "kb"; + return std::to_string(round_up<3>((double)bytes / 1024.0)) += "kb"; } else { return std::to_string(bytes) += "b"; }