On 10/26/2017 04:11 AM, marxin wrote:
Human readable format is quite useful in my opinion. There's example:

         -:    1:unsigned
    14.00K:    2:loop (unsigned n, int value)

My first thought is 'why 2 decimal places'? That seems excessive. Zero surely suffices?

Question is do we want to do it by default, or a new option is fine?
Note that all external tools using gcov should use intermediate format
which is obviously unchanged.

I don't think other tools do it by default.


+     [@option{-j}|@option{--human-numbers}]

man ls:
      -h, --human-readable
with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)

Sadly '-h' is help (IIRC).  but we could at least copy the long form.


+  const char *units[] = {"", "K", "M", "G", "Y", "P", "E", "Z"};

Those aren't right  KMGTPEZY
http://www.npl.co.uk/reference/measurement-units/si-prefixes/


+  for (unsigned i = 0; i < sizeof (units); i++)
+    {
+      if (v < 1000.0f)
+       {
+         sprintf (buffer, "%3.2f%s", v, units[i]);
+         return buffer;
+       }
+
+      v /= 1000.0f;
+    }

that's going to fail on certain roundings. You're doing multiple divisions by 1000, which itself will have roundings. But more importantly, numbers after scaling like 999.999 will round to 1000, and you probably don't want that. This kind of formatting is tricky. My inclination is to keep it in the integer domain. Determine a scaling factor. Divide once by that and then explicitly round to nearest even[*] with a check for the 999.9 case. Then print as an unsigned.

nathan

[*] I presume you're familiar with RNE? That's probably overkill and plain RN would be adequate.

--
Nathan Sidwell

Reply via email to