From f8ed74fda5ae944141c5a8828d48269ce753ee0e Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 30 Nov 2022 14:41:35 +0100 Subject: [PATCH] Improve unit representation code --- luna/Units.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/luna/Units.cpp b/luna/Units.cpp index 98eb4e70..1ce0208c 100644 --- a/luna/Units.cpp +++ b/luna/Units.cpp @@ -1,15 +1,14 @@ #include #include -#include Result to_dynamic_unit(usize value, char* buffer, size_t max) { if (value < 1024) { return string_format(buffer, max, "%u bytes", value); } const char* unit_prefixes = "KMGTPE"; - for (int i = 40; i >= 0 && value > (0xfffccccccccccccUL >> i); i -= 10) + while (value > (1024 * 1024)) { - value >>= 10; + value /= 1024; unit_prefixes++; }