Browse Source

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.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
2aa5163b8b
  1. 14
      cgminer.c

14
cgminer.c

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

Loading…
Cancel
Save