This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gcov-profile/53915] gcov -f rounding problem


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

--- Comment #1 from Vincent LefÃvre <vincent-gcc at vinc17 dot net> 2012-07-10 14:27:28 UTC ---
The problem is probably in gcc/gcov.c, function format_gcov, which has:

      float ratio = bottom ? (float)top / bottom : 0;
      int ix;
      unsigned limit = 100;
      unsigned percent;

      for (ix = dp; ix--; )
    limit *= 10;

      percent = (unsigned) (ratio * limit + (float)0.5);

Using double instead of float would be a first improvement (2 occurrences in
the first line, cast to be removed in the last line). Also, multiplying top by
limit (after a cast to double) before dividing by bottom should be better, as
the first operation (the multiplication) would be done exactly in practice.
Something like that:

  percent = (unsigned) ((double) top * limit / bottom + 0.5);

or even:

  percent = (unsigned) (((double) top * limit + (double) bottom / 2) / bottom);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]