1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-22 20:44:19 +00:00

Cope with dval being zero in suffix_string and display a single decimal place when significant digits is not specified but the value is greater than 1000.

This commit is contained in:
Con Kolivas 2012-10-16 22:04:05 +11:00
parent 54d2999d77
commit 2aa5163b8b

View File

@ -1471,6 +1471,7 @@ static void suffix_string(uint64_t val, char *buf, int sigdigits)
const uint64_t peta = 1000000000000000ull;
const uint64_t exa = 1000000000000000000ull;
char suffix[2] = "";
bool decimal = true;
double dval;
if (val >= exa) {
@ -1496,15 +1497,20 @@ static void suffix_string(uint64_t val, char *buf, int sigdigits)
} else if (val >= kilo) {
dval = (double)val / dkilo;
sprintf(suffix, "K");
} else
} else {
dval = val;
decimal = false;
}
if (!sigdigits)
sprintf(buf, "%d%s", (unsigned int)dval, suffix);
else {
if (!sigdigits) {
if (decimal)
sprintf(buf, "%.1f%s", dval, suffix);
else
sprintf(buf, "%d%s", (unsigned int)dval, suffix);
} else {
/* Always show sigdigits + 1, padded on right with zeroes
* followed by suffix */
int ndigits = (sigdigits - 1 - floor(log10 (dval)));
int ndigits = sigdigits - 1 - (dval > 0.0 ? floor(log10(dval)) : 0);
sprintf(buf, "%*.*f%s", sigdigits + 1, ndigits, dval, suffix);
}