This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug gcov-profile/53915] gcov -f rounding problem
- From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 10 Jul 2012 14:27:28 +0000
- Subject: [Bug gcov-profile/53915] gcov -f rounding problem
- Auto-submitted: auto-generated
- References: <bug-53915-4@http.gcc.gnu.org/bugzilla/>
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);