mirror of
https://github.com/jarun/nnn.git
synced 2024-12-01 02:49:44 +00:00
Integer calculation-only coolsize()
This commit is contained in:
parent
928699d4a4
commit
91ef394dbd
49
nnn.c
49
nnn.c
|
@ -1439,10 +1439,8 @@ coolsize(off_t size)
|
|||
{
|
||||
static const char * const U = "BKMGTPEZY";
|
||||
static char size_buf[12]; /* Buffer to hold human readable size */
|
||||
static int i;
|
||||
|
||||
static off_t rem;
|
||||
static const double div_2_pow_10 = 1.0 / 1024.0;
|
||||
static int i;
|
||||
|
||||
i = 0;
|
||||
rem = 0;
|
||||
|
@ -1453,7 +1451,47 @@ coolsize(off_t size)
|
|||
++i;
|
||||
}
|
||||
|
||||
snprintf(size_buf, 12, "%.*f%c", i, size + (float)rem * div_2_pow_10, U[i]);
|
||||
if (i == 1) {
|
||||
rem = (rem * 1000) >> 10;
|
||||
|
||||
rem /= 10;
|
||||
if (rem % 10 >= 5) {
|
||||
rem = (rem / 10) + 1;
|
||||
if (rem == 10) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem /= 10;
|
||||
} else if (i == 2) {
|
||||
rem = (rem * 1000) >> 10;
|
||||
|
||||
if (rem % 10 >= 5) {
|
||||
rem = (rem / 10) + 1;
|
||||
if (rem == 100) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem /= 10;
|
||||
} else if (i > 0) {
|
||||
rem = (rem * 10000) >> 10;
|
||||
|
||||
if (rem % 10 >= 5) {
|
||||
rem = (rem / 10) + 1;
|
||||
if (rem == 1000) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem /= 10;
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
snprintf(size_buf, 12, "%lu.%0*lu%c", (ulong)size, i, (ulong)rem, U[i]);
|
||||
else
|
||||
snprintf(size_buf, 12, "%lu%c", (ulong)size, U[i]);
|
||||
|
||||
return size_buf;
|
||||
}
|
||||
|
||||
|
@ -3151,7 +3189,8 @@ nochange:
|
|||
case SEL_QUIT:
|
||||
dentfree(dents);
|
||||
return;
|
||||
}
|
||||
} /* switch (sel) */
|
||||
|
||||
/* Screensaver */
|
||||
if (idletimeout != 0 && idle == idletimeout) {
|
||||
idle = 0;
|
||||
|
|
Loading…
Reference in a new issue