This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs
- From: "akessler at mit dot edu" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Tue, 10 Jul 2012 02:14:09 +0000
- Subject: [Bug math/14343] New: Function logb() in math.h produces incorrect results for small inputs
- Auto-submitted: auto-generated
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.