This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/4943] Inconsistent rounding behaviour for sprintf and IEEE doubles
- From: "vincent+libc at vinc17 dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 19 Sep 2007 21:22:32 -0000
- Subject: [Bug libc/4943] Inconsistent rounding behaviour for sprintf and IEEE doubles
- References: <20070820142205.4943.paul@inet.co.za>
- Reply-to: sourceware-bugzilla at sourceware dot org
------- 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.