mirror of
https://github.com/facebook/zstd.git
synced 2025-08-05 19:15:58 +03:00
In Verbose Mode, Preserve Full Precision Where Possible
This commit is contained in:
@@ -305,26 +305,43 @@ U64 UTIL_getFileSizeStat(const stat_t* statbuf)
|
|||||||
|
|
||||||
UTIL_HumanReadableSize_t UTIL_makeHumanReadableSize(U64 size) {
|
UTIL_HumanReadableSize_t UTIL_makeHumanReadableSize(U64 size) {
|
||||||
UTIL_HumanReadableSize_t hrs;
|
UTIL_HumanReadableSize_t hrs;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
/* In regular mode, scale sizes down and use suffixes. */
|
||||||
if (size >= (1ull << 60)) {
|
if (size >= (1ull << 60)) {
|
||||||
hrs.value = (float)size / (1ull << 60);
|
hrs.value = (double)size / (1ull << 60);
|
||||||
hrs.suffix = "E";
|
hrs.suffix = "E";
|
||||||
} else if (size >= (1ull << 50)) {
|
} else if (size >= (1ull << 50)) {
|
||||||
hrs.value = (float)size / (1ull << 50);
|
hrs.value = (double)size / (1ull << 50);
|
||||||
hrs.suffix = "P";
|
hrs.suffix = "P";
|
||||||
} else if (size >= (1ull << 40)) {
|
} else if (size >= (1ull << 40)) {
|
||||||
hrs.value = (float)size / (1ull << 40);
|
hrs.value = (double)size / (1ull << 40);
|
||||||
hrs.suffix = "T";
|
hrs.suffix = "T";
|
||||||
} else if (size >= (1ull << 30)) {
|
} else if (size >= (1ull << 30)) {
|
||||||
hrs.value = (float)size / (1ull << 30);
|
hrs.value = (double)size / (1ull << 30);
|
||||||
hrs.suffix = "G";
|
hrs.suffix = "G";
|
||||||
} else if (size >= (1ull << 20)) {
|
} else if (size >= (1ull << 20)) {
|
||||||
hrs.value = (float)size / (1ull << 20);
|
hrs.value = (double)size / (1ull << 20);
|
||||||
hrs.suffix = "M";
|
hrs.suffix = "M";
|
||||||
} else if (size >= (1ull << 10)) {
|
} else if (size >= (1ull << 10)) {
|
||||||
hrs.value = (float)size / (1ull << 10);
|
hrs.value = (double)size / (1ull << 10);
|
||||||
hrs.suffix = "K";
|
hrs.suffix = "K";
|
||||||
} else {
|
} else {
|
||||||
hrs.value = (float)size;
|
hrs.value = (double)size;
|
||||||
hrs.suffix = "";
|
hrs.suffix = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +354,7 @@ UTIL_HumanReadableSize_t UTIL_makeHumanReadableSize(U64 size) {
|
|||||||
} else {
|
} else {
|
||||||
hrs.precision = 3;
|
hrs.precision = 3;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return hrs;
|
return hrs;
|
||||||
}
|
}
|
||||||
|
@@ -177,7 +177,7 @@ U64 UTIL_getTotalFileSize(const char* const * fileNamesTable, unsigned nbFiles);
|
|||||||
* precision, value, suffix order to a "%.*f%s" format string.
|
* precision, value, suffix order to a "%.*f%s" format string.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float value;
|
double value;
|
||||||
int precision;
|
int precision;
|
||||||
const char* suffix;
|
const char* suffix;
|
||||||
} UTIL_HumanReadableSize_t;
|
} UTIL_HumanReadableSize_t;
|
||||||
|
@@ -1146,8 +1146,9 @@ int main(int const argCount, const char* argv[])
|
|||||||
(void)singleThread; (void)nbWorkers;
|
(void)singleThread; (void)nbWorkers;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UTIL_HAS_CREATEFILELIST
|
|
||||||
g_utilDisplayLevel = g_displayLevel;
|
g_utilDisplayLevel = g_displayLevel;
|
||||||
|
|
||||||
|
#ifdef UTIL_HAS_CREATEFILELIST
|
||||||
if (!followLinks) {
|
if (!followLinks) {
|
||||||
unsigned u, fileNamesNb;
|
unsigned u, fileNamesNb;
|
||||||
unsigned const nbFilenames = (unsigned)filenames->tableSize;
|
unsigned const nbFilenames = (unsigned)filenames->tableSize;
|
||||||
|
Reference in New Issue
Block a user