Browse Source

Fixes column alignment in decimal fields.
Workaround for printf rounding up when formatting decimals into limited width.

Conflicts:
miner.c

Josh Lehan 13 years ago
parent
commit
7d847b3b1d
1 changed files with 7 additions and 3 deletions
  1. 7 3
      miner.c

+ 7 - 3
miner.c

@@ -2199,7 +2199,9 @@ hashrate_pick_unit(float hashrate, unsigned char*unit)
 	unsigned char i;
 	for (i = 0; i <= *unit; ++i)
 		hashrate /= 1e3;
-	while (hashrate >= 1000)
+	
+	// 1000 but with tolerance for floating-point rounding, avoid showing "1000.0"
+	while (hashrate >= 999.95)
 	{
 		hashrate /= 1e3;
 		if (likely(_unitchar[*unit] != '?'))
@@ -2239,10 +2241,12 @@ hashrate_to_bufstr(char*buf, float hashrate, signed char unitin, enum h2bs_fmt f
 	
 	for (i = 0; i <= unit; ++i)
 		hashrate /= 1000;
-	if (hashrate >= 100 || unit < 2)
+	// 100 but with tolerance for floating-point rounding, max "99.99" then "100.0"
+	if (hashrate >= 99.995 || unit < 2)
 		prec = 1;
 	else
-	if (hashrate >= 10)
+	// 10 but with tolerance for floating-point rounding, max "9.999" then "10.00"
+	if (hashrate >= 9.9995)
 		prec = 2;
 	else
 		prec = 3;