public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs
@ 2012-07-10  2:14 akessler at mit dot edu
  2012-07-10  2:15 ` [Bug math/14343] " akessler at mit dot edu
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: akessler at mit dot edu @ 2012-07-10  2:14 UTC (permalink / raw)
  To: glibc-bugs

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

             Bug #: 14343
           Summary: Function logb() in math.h produces incorrect results
                    for small inputs
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: critical
          Priority: P2
         Component: math
        AssignedTo: unassigned@sourceware.org
        ReportedBy: akessler@mit.edu
    Classification: Unclassified


The function double logb (double x) produces results that are wildly incorrect
for values of x with |x| < 1 (equivalently, when logb(x) should return a
negative result). If x is written as MANTISSA * 10^EXP, logb is expected to
return EXP. Instead, for inputs with EXP < 0, logb seems to return the value
2^32 + EXP.

This is very easily reproduced on all 64-bit systems I have tried (certainly
for Linux 3.4.4, and earlier versions too) with GLIBC 2.15. I do not know if
2.16 or later have this issue, but versions prior to GLIBC 2.15 (certainly 2.13
or earlier) do not have this issue.

Steps to reproduce:

1. Compile the following program with "gcc -otest test.c -lm"
2. Run

#include <math.h>
#include <stdio.h>

int main ()
{
        int i;
        double x = 0.5;
        // Following two lines should be the same!
        printf ("%lf\n", logb (0.5));
        printf ("%lf\n", logb (x));

        return 0;
}

Actual output:
-1.000000
4294967295.000000

Expected output:
-1.000000
-1.000000

It is clear that something about the logb() function from math.h is at fault
here. The reason that the first line of this output is correct seems to be
compiler optimization -- GCC optimizes out the logb() call for the constant 0.5
and replaces it with -1, but the other call to logb is left as-is.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
@ 2012-07-10  2:15 ` akessler at mit dot edu
  2012-07-10  8:38 ` philomath868 at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: akessler at mit dot edu @ 2012-07-10  2:15 UTC (permalink / raw)
  To: glibc-bugs

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

Andre Kessler <akessler at mit dot edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |akessler at mit dot edu

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
  2012-07-10  2:15 ` [Bug math/14343] " akessler at mit dot edu
@ 2012-07-10  8:38 ` philomath868 at gmail dot com
  2012-07-10  8:40 ` philomath868 at gmail dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: philomath868 at gmail dot com @ 2012-07-10  8:38 UTC (permalink / raw)
  To: glibc-bugs

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

philomath868 at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |philomath868 at gmail dot
                   |                            |com

--- Comment #1 from philomath868 at gmail dot com 2012-07-10 08:38:43 UTC ---
Works correctly on glibc-2.16, x86_64 GNU/Linux 3.4.4
(releated to #13954 ?).

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
  2012-07-10  2:15 ` [Bug math/14343] " akessler at mit dot edu
  2012-07-10  8:38 ` philomath868 at gmail dot com
@ 2012-07-10  8:40 ` philomath868 at gmail dot com
  2012-07-24  2:30 ` carlos_odonell at mentor dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: philomath868 at gmail dot com @ 2012-07-10  8:40 UTC (permalink / raw)
  To: glibc-bugs

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

philomath868 at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|philomath868 at gmail dot   |
                   |com                         |

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (2 preceding siblings ...)
  2012-07-10  8:40 ` philomath868 at gmail dot com
@ 2012-07-24  2:30 ` carlos_odonell at mentor dot com
  2012-07-24  8:11 ` akessler at mit dot edu
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: carlos_odonell at mentor dot com @ 2012-07-24  2:30 UTC (permalink / raw)
  To: glibc-bugs

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

Carlos O'Donell <carlos_odonell at mentor dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING
   Last reconfirmed|                            |2012-07-23
                 CC|                            |carlos_odonell at mentor
                   |                            |dot com

--- Comment #2 from Carlos O'Donell <carlos_odonell at mentor dot com> 2012-07-24 02:30:18 UTC ---
Do you need a fix for this on the 2.15 stable branch?

Is it enough that 2.16 has the fix?

If you are compiling glibc yourself you can upgrade to 2.16.

If you use your distro provided glibc then you'll eventually ugprade to 2.16
and get the fix.

Confirmed that 2.15 has this bug.

carlos@domU-12-31-39-06-F5-7B:~$ ./test1
-1.000000
4294967295.000000

Confirmed that 2.16 does not have this bug.

carlos@domU-12-31-39-06-F5-7B:~/build/glibc-2.16$ ./elf/ld.so --library-path
/home/carlos/build/glibc-2.16/:/home/carlos/build/glibc-2.16/math
/home/carlos/test1
-1.000000
-1.000000

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (3 preceding siblings ...)
  2012-07-24  2:30 ` carlos_odonell at mentor dot com
@ 2012-07-24  8:11 ` akessler at mit dot edu
  2012-07-24 13:32 ` carlos_odonell at mentor dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: akessler at mit dot edu @ 2012-07-24  8:11 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #3 from Andre Kessler <akessler at mit dot edu> 2012-07-24 08:10:56 UTC ---
(In reply to comment #2)
> Do you need a fix for this on the 2.15 stable branch?
> 
> Is it enough that 2.16 has the fix?
> 
> If you are compiling glibc yourself you can upgrade to 2.16.

For some computers I use, it's fine that 2.16 has the fix, but I also have to
deal with some enterprise machines that will be using glibc 2.15 for quite a
while (the bug was discovered while testing some internal math libraries on
these machines). Since this problem is quite widespread -- anyone with 64-bit
glibc 2.15 will have an issue -- and this affects basic math functionality,
there really should be a fix on the 2.15 stable branch...

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (4 preceding siblings ...)
  2012-07-24  8:11 ` akessler at mit dot edu
@ 2012-07-24 13:32 ` carlos_odonell at mentor dot com
  2012-12-04  0:00 ` carlos at systemhalted dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: carlos_odonell at mentor dot com @ 2012-07-24 13:32 UTC (permalink / raw)
  To: glibc-bugs

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

Carlos O'Donell <carlos_odonell at mentor dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |SUSPENDED

--- Comment #4 from Carlos O'Donell <carlos_odonell at mentor dot com> 2012-07-24 13:32:11 UTC ---
(In reply to comment #3)
> (In reply to comment #2)
> > Do you need a fix for this on the 2.15 stable branch?
> > 
> > Is it enough that 2.16 has the fix?
> > 
> > If you are compiling glibc yourself you can upgrade to 2.16.
> 
> For some computers I use, it's fine that 2.16 has the fix, but I also have to
> deal with some enterprise machines that will be using glibc 2.15 for quite a
> while (the bug was discovered while testing some internal math libraries on
> these machines). Since this problem is quite widespread -- anyone with 64-bit
> glibc 2.15 will have an issue -- and this affects basic math functionality,
> there really should be a fix on the 2.15 stable branch...

Andre,

Thanks for the response. If you would like to see progress made on this I would
suggest the following course of action:
* Checkout glibc 2.15
* Apply the change made for BZ #13954 e.g.
http://sourceware.org/git/?p=glibc.git;a=commit;h=89c9aa491a7cee97bf78a29cddbf0a25c902a671
* Build glibc and run the testsuite.
* Build your application against the newly built glibc using -Wl,-rpath and
-Wl,--dynamic-linker and see if it fixes your issue.

If the newly built glibc 2.15 fixes your issue then do the following:
* Add the keyword glibc_2.15 to this issue indicating that you are requesting a
backport to the 2.15 stable branch.
* Mention the exact commit that you backported and tested, and include your
testsuite results and the machine you tested on.

At that point the 2.15 stable release branch manager can *easily* pickup the
fix for inclusion in the next 2.15 stable release e.g. 2.15.1.

I'm marking this bug as suspended pending help from someone to work on
backporting and testing a fix.

If you have *any* questions about how to do any of the above steps we would be
more than welcome to walk you through it on libc-help@sourceware.org. Please
don't hesitate to ask, no question is wrong :-)

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (5 preceding siblings ...)
  2012-07-24 13:32 ` carlos_odonell at mentor dot com
@ 2012-12-04  0:00 ` carlos at systemhalted dot org
  2013-03-20 12:47 ` [Bug math/14343] [2.15] " jsm28 at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: carlos at systemhalted dot org @ 2012-12-04  0:00 UTC (permalink / raw)
  To: glibc-bugs

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

Carlos O'Donell <carlos at systemhalted dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|carlos_odonell at mentor    |carlos at systemhalted dot
                   |dot com                     |org

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] [2.15] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (6 preceding siblings ...)
  2012-12-04  0:00 ` carlos at systemhalted dot org
@ 2013-03-20 12:47 ` jsm28 at gcc dot gnu.org
  2013-09-22 18:03 ` carlos at redhat dot com
  2014-06-13 14:01 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2013-03-20 12:47 UTC (permalink / raw)
  To: glibc-bugs

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

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Function logb() in math.h   |[2.15] Function logb() in
                   |produces incorrect results  |math.h produces incorrect
                   |for small inputs            |results for small inputs

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] [2.15] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (7 preceding siblings ...)
  2013-03-20 12:47 ` [Bug math/14343] [2.15] " jsm28 at gcc dot gnu.org
@ 2013-09-22 18:03 ` carlos at redhat dot com
  2014-06-13 14:01 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: carlos at redhat dot com @ 2013-09-22 18:03 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=14343

Carlos O'Donell <carlos at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #5 from Carlos O'Donell <carlos at redhat dot com> ---
Needs backported patch. Reopen once you have a backported patch ready.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug math/14343] [2.15] Function logb() in math.h produces incorrect results for small inputs
  2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
                   ` (8 preceding siblings ...)
  2013-09-22 18:03 ` carlos at redhat dot com
@ 2014-06-13 14:01 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 14:01 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=14343

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-13 14:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-10  2:14 [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs akessler at mit dot edu
2012-07-10  2:15 ` [Bug math/14343] " akessler at mit dot edu
2012-07-10  8:38 ` philomath868 at gmail dot com
2012-07-10  8:40 ` philomath868 at gmail dot com
2012-07-24  2:30 ` carlos_odonell at mentor dot com
2012-07-24  8:11 ` akessler at mit dot edu
2012-07-24 13:32 ` carlos_odonell at mentor dot com
2012-12-04  0:00 ` carlos at systemhalted dot org
2013-03-20 12:47 ` [Bug math/14343] [2.15] " jsm28 at gcc dot gnu.org
2013-09-22 18:03 ` carlos at redhat dot com
2014-06-13 14:01 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).