silly off by 1 errors

This commit is contained in:
2026-06-07 17:54:38 +02:00
parent 85f87677d7
commit 03c426195e

View File

@@ -49,8 +49,7 @@ inline uint64_t timespec_diff_us(const struct timespec *a, const struct timespec
}
inline char *pretty_num(const double num, char *buf, const size_t bufsz) {
const uint8_t decimals = (num < 10) ? 2 : (num < 100) ? 1
: 0;
const uint8_t decimals = (num <= 10) ? 2 : (num <= 100) ? 1 : 0;
snprintf(buf, bufsz, "%.*f", decimals, num);
return buf;
}
@@ -59,7 +58,7 @@ inline char *pretty_bytes(const uint64_t bytes, int8_t start_suffix, char *buf,
const char suffix_list[] = {'K', 'M', 'G', 'T', 'P', 'E', 'Z'};
start_suffix *= -1;
double bytes_d = (double)bytes;
while (bytes_d > 1024.0) {
while (bytes_d >= 1024.0) {
bytes_d /= 1024.0;
start_suffix++;
}