1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

In Verbose Mode, Preserve Full Precision Where Possible

This commit is contained in:
W. Felix Handte
2021-06-09 15:22:59 -04:00
parent 9b67219b1e
commit 464bfb022e
3 changed files with 50 additions and 31 deletions

View File

@ -305,37 +305,55 @@ U64 UTIL_getFileSizeStat(const stat_t* statbuf)
UTIL_HumanReadableSize_t UTIL_makeHumanReadableSize(U64 size) {
UTIL_HumanReadableSize_t hrs;
if (size >= (1ull << 60)) {
hrs.value = (float)size / (1ull << 60);
hrs.suffix = "E";
} else if (size >= (1ull << 50)) {
hrs.value = (float)size / (1ull << 50);
hrs.suffix = "P";
} else if (size >= (1ull << 40)) {
hrs.value = (float)size / (1ull << 40);
hrs.suffix = "T";
} else if (size >= (1ull << 30)) {
hrs.value = (float)size / (1ull << 30);
hrs.suffix = "G";
} else if (size >= (1ull << 20)) {
hrs.value = (float)size / (1ull << 20);
hrs.suffix = "M";
} else if (size >= (1ull << 10)) {
hrs.value = (float)size / (1ull << 10);
hrs.suffix = "K";
} else {
hrs.value = (float)size;
hrs.suffix = "";
}
if (hrs.value >= 100 || (U64)hrs.value == size) {
hrs.precision = 0;
} else if (hrs.value >= 10) {
hrs.precision = 1;
} else if (hrs.value > 1) {
hrs.precision = 2;
if (g_utilDisplayLevel > 2) {
/* In verbose mode, do not scale sizes down, except in the case of
* values that exceed the integral precision of a double. */
if (size >= (1ull << 53)) {
hrs.value = (double)size / (1ull << 20);
hrs.suffix = "M";
/* At worst, a double representation of a maximal size will be
* accurate to better than tens of kilobytes. */
hrs.precision = 2;
} else {
hrs.value = (double)size;
hrs.suffix = "";
hrs.precision = 0;
}
} else {
hrs.precision = 3;
/* In regular mode, scale sizes down and use suffixes. */
if (size >= (1ull << 60)) {
hrs.value = (double)size / (1ull << 60);
hrs.suffix = "E";
} else if (size >= (1ull << 50)) {
hrs.value = (double)size / (1ull << 50);
hrs.suffix = "P";
} else if (size >= (1ull << 40)) {
hrs.value = (double)size / (1ull << 40);
hrs.suffix = "T";
} else if (size >= (1ull << 30)) {
hrs.value = (double)size / (1ull << 30);
hrs.suffix = "G";
} else if (size >= (1ull << 20)) {
hrs.value = (double)size / (1ull << 20);
hrs.suffix = "M";
} else if (size >= (1ull << 10)) {
hrs.value = (double)size / (1ull << 10);
hrs.suffix = "K";
} else {
hrs.value = (double)size;
hrs.suffix = "";
}
if (hrs.value >= 100 || (U64)hrs.value == size) {
hrs.precision = 0;
} else if (hrs.value >= 10) {
hrs.precision = 1;
} else if (hrs.value > 1) {
hrs.precision = 2;
} else {
hrs.precision = 3;
}
}
return hrs;