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

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).