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 math/5857] New: rint is broken on x86_64 systems for values from 262144.75 to 524286.75 stepped by 2


on x86_64 systems, rint (and nearbyint) return incorrect values for every even
double from 262144 (0x40000) thru 524286 (0x7FFFE) with a .75 fractional part.

for example, rint (262144.75) returns 262144, rint (262146.75) returns 262146,
..., rint (524286.75) returns 524286

I've looked at the code and the bug is in
glibc-2.7/sysdeps/ieee754/dbl-64/s_rint.c (this also applies to
glibc-2.7/sysdeps/ieee754/dbl-64/s_nearbyint.c).

The code has a special case for an exponent of 19, but not 18.

I've got a fix that I've tested fairly extensively.  The diff of s_rint.c old to
new is as follows:

70,71c70,74
<                   if(j0==19) i1 = 0x40000000; else
<                   i0 = (i0&(~i))|((0x20000)>>j0);
---
>                   if(j0==19) i1 = 0x40000000; else if (j0<18)
>                   i0 = (i0&(~i))|((0x20000)>>j0); else {
>                       i0 &= ~i;
>                       i1 = 0x80000000;
>                   }

I took a look at the dbl-128 code, and it looks like it has the same problem at
the boundary where the double is split.

This will fix the code, but the real question is "Why isn't rint using the
frndint instruction on x86_64 systems!!??".  I found the frndint instruction in
sysdeps/i386/fpu/s_rint.s.  This function should work on x86_64 systems.

-- 
           Summary: rint is broken on x86_64 systems for values from
                    262144.75 to 524286.75 stepped by 2
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
        AssignedTo: aj at suse dot de
        ReportedBy: mark dot h dot elliott at lmco dot com
                CC: glibc-bugs at sources dot redhat dot com


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

------- 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]