On 10/31/2017 07:49 AM, Martin Liška wrote:
On 10/30/2017 01:35 PM, Nathan Sidwell wrote:
Is the patch fine to be installed?
not quite ...
+ gcov_type divisor = 1;
+ for (unsigned i = 0; i < strlen (units); i++)
+ {
+ if (v < (1000 * divisor))
+ {
+ gcov_type r = (gcov_type)roundf (v / divisor);
+ sprintf (buffer, "%" PRId64 "%c", r, units[i]);
+ return buffer;
+ }
+ divisor *= 1000;
+ }
This doesn't deal with rounding to 1000, which will look a bit odd.
It'll also overflow if we ever get 10^24 counts (yeah, like that'll ever
happen in this universe). We may as well not use floats either.
Excuse the poor formatting
unsigned i;
for (i = 0; units[i+1]; i++, divisor *= 1000) {
if (count + divisor / 2 < 1000 * divisor)
break;
}
gcov_type r = (count + divisor / 2) / divisor;
sprintf (buffer, "%" PRId64 "%c", r, units[i]);
return buffer;
--
Nathan Sidwell