From 01731e6e89d44ac7e7ab675e4e597474d1b5180a Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Thu, 11 Apr 2024 21:12:12 +0200 Subject: move print_bytes to font.c --- stage3/font.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'stage3/font.c') diff --git a/stage3/font.c b/stage3/font.c index 4c99137..9022fbd 100644 --- a/stage3/font.c +++ b/stage3/font.c @@ -235,3 +235,21 @@ void print_dbl(double d, u8 points) print_char('.'); print_num_pad((d - (double) i) * (double) ipow(10, points), 10, points, '0'); } + +void print_bytes(usize bytes) +{ + static char fmt[] = { ' ', 'K', 'M', 'G', 'T' }; + usize unit = ipow(1000, LEN(fmt)-1); + for (usize i = 0; i < LEN(fmt); i++) { + if (bytes >= unit || unit == 1) { + print_num_pad(bytes/unit, 10, 3, ' '); + print_char('.'); + print_dec((bytes%unit)*10/unit); + print_char(' '); + print_char(fmt[LEN(fmt)-1-i]); + print_char('B'); + break; + } + unit /= 1000; + } +} -- cgit v1.2.3