This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc 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 libc/4943] Inconsistent rounding behaviour for sprintf and IEEE doubles


------- Additional Comments From vincent+libc at vinc17 dot org  2007-09-19 21:22 -------
I don't see any inconsistency. The round, trunc, floor and ceil functions have
their own rules. In the round-to-nearest mode (i.e. the default rounding mode),
the glibc chooses to use the IEEE-754 even-rounding rule to round halfway cases
for printf, as shown by the following program:

#include <stdio.h>
int main (void)
{
  double x;
  for (x = -8.5; x <= 8.5; x += 1.0)
    printf ("%4g %.0f\n", x, x);
  return 0;
}

which outputs:

-8.5 -8
-7.5 -8
-6.5 -6
-5.5 -6
-4.5 -4
-3.5 -4
-2.5 -2
-1.5 -2
-0.5 -0
 0.5 0
 1.5 2
 2.5 2
 3.5 4
 4.5 4
 5.5 6
 6.5 6
 7.5 8
 8.5 8

This seems to be perfectly correct for me.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=4943

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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