@matheusbsbs / matheus-bagliano / commits / 66913284f0
Fork 0

progress bar: round to the nearest instead of truncating down

Often the throughput output is requested when the data read so far is one smaller than multiple of 1024; because 1023/1024 is ~0.999, it often shows up as 0.99 because the code currently truncates. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Apr 24, 2009 at 17:46 UTC 66913284f06da58e2243acfad951a57501b8d813
1 file changed +4 -4
progress.c
+4 -4
@@ -121,13 +121,13 @@ static void throughput_string(struct throughput *tp, off_t total,
121 (int)(total >> 30),
122 (int)(total & ((1 << 30) - 1)) / 10737419);
123 } else if (total > 1 << 20) {
124 + int x = total + 5243; /* for rounding */
125 l -= snprintf(tp->display, l, ", %u.%2.2u MiB",
125 - (int)(total >> 20),
126 - ((int)(total & ((1 << 20) - 1)) * 100) >> 20);
126 + x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
127 } else if (total > 1 << 10) {
128 + int x = total + 5; /* for rounding */
129 l -= snprintf(tp->display, l, ", %u.%2.2u KiB",
129 - (int)(total >> 10),
130 - ((int)(total & ((1 << 10) - 1)) * 100) >> 10);
130 + x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
131 } else {
132 l -= snprintf(tp->display, l, ", %u bytes", (int)total);
133 }