free.c - correct conversion to decimal multiples

This commit is contained in:
getzze 2016-11-04 01:09:58 +00:00 committed by Craig Small
parent 91df65b9e7
commit 77590f75a1

38
free.c
View File

@ -130,17 +130,10 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
snprintf(buf, sizeof(buf), "%lld", ((long long int)size) * 1024); snprintf(buf, sizeof(buf), "%lld", ((long long int)size) * 1024);
return buf; return buf;
} }
if (args.exponent == 2) { if (args.exponent > 1) {
if (!(flags & FREE_SI))
snprintf(buf, sizeof(buf), "%ld", size);
else
snprintf(buf, sizeof(buf), "%ld", (long int)(size / 0.9765625));
return buf;
}
if (args.exponent > 2) {
/* In desired scale. */ /* In desired scale. */
snprintf(buf, sizeof(buf), "%ld", snprintf(buf, sizeof(buf), "%ld",
(long int)(size / power(base, args.exponent - 2)) (long int)((size / 1024) * base / power(base, args.exponent - 2))
); );
return buf; return buf;
} }
@ -155,29 +148,18 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
return buf; return buf;
break; break;
case 2: case 2:
if (!(flags & FREE_SI)) {
if (4 >= snprintf(buf, sizeof(buf), "%ld%c", size, *up))
return buf;
} else {
if (4 >=
snprintf(buf, sizeof(buf), "%ld%c",
(long)(size / 0.9765625), *up))
return buf;
}
break;
case 3: case 3:
case 4: case 4:
case 5: case 5:
case 6: case 6:
if (4 >= if (4 >=
snprintf(buf, sizeof(buf), "%.1f%c", snprintf(buf, sizeof(buf), "%.1f%c",
(float)(size / power(base, i - 2)), *up)) (float)((size / 1024) * base / power(base, i - 2)), *up))
return buf; return buf;
if (4 >= if (4 >=
snprintf(buf, sizeof(buf), "%ld%c", snprintf(buf, sizeof(buf), "%ld%c",
(long)(size / power(base, i - 2)), *up)) (long)((size / 1024) * base / power(base, i - 2)), *up))
return buf; return buf;
break; break;
case 7: case 7:
break; break;