This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
[Bug math/602] New: powerpc rint() function is buggy in the rounding toward -inf and +inf modes
- From: "vincent+libc at vinc17 dot org" <sourceware-bugzilla at sources dot redhat dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: 8 Dec 2004 16:33:13 -0000
- Subject: [Bug math/602] New: powerpc rint() function is buggy in the rounding toward -inf and +inf modes
- Reply-to: sourceware-bugzilla at sources dot redhat dot com
The rint function for the powerpc gives wrong values for negative arguments in
the rounding toward -inf and +inf modes, and probably an incorrect sign in the
rounding to -inf mode for values between 0 and 1 (-0.0 instead of +0.0). The
(generic) nearbyint function is correct however.
For instance, rint(-0.5) gives 0.0 instead of -1.0 in the rounding toward -inf mode.
sysdeps/powerpc/fpu/s_rint.c (from CVS) currently contains:
if (fabs (x) < TWO52)
{
if (x > 0.0)
{
x += TWO52;
x -= TWO52;
}
else if (x < 0.0)
{
x = TWO52 - x;
x = -(x - TWO52);
}
}
I suggest the following code:
if (fabs (x) < TWO52)
{
if (x > 0.0)
{
x += TWO52;
x -= TWO52;
if (x == 0.0)
x = 0.0;
}
else if (x < 0.0)
{
x -= TWO52;
x += TWO52;
if (x == 0.0)
x = -0.0;
}
}
The tests with 0.0 correct the sign of the result (I don't know if this is
standardized, but this is more consistent like that).
I have a testing program and the above implementation here:
http://www.vinc17.org/software/nearestint.c
For instance, try: ./nearestint 4.5 1
Note: I reported this bug (with the proposed patch) to the Debian BTS more than
a year ago[*], but it received no comments.
[*] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=216800
--
Summary: powerpc rint() function is buggy in the rounding toward
-inf and +inf modes
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: math
AssignedTo: aj at suse dot de
ReportedBy: vincent+libc at vinc17 dot org
CC: glibc-bugs at sources dot redhat dot com
http://sources.redhat.com/bugzilla/show_bug.cgi?id=602
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.