Bug 838191 - Function logb() in math.h produces incorrect results for small inputs
Summary: Function logb() in math.h produces incorrect results for small inputs
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 16
Hardware: x86_64
OS: Linux
unspecified
urgent
Target Milestone: ---
Assignee: Jeff Law
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-07-07 02:10 UTC by Andre Kessler
Modified: 2016-11-24 15:45 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-07-10 16:01:22 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Andre Kessler 2012-07-07 02:10:55 UTC
Description of problem:
Function double logb(double x) in math.h produces incorrect results when |x| < 1.0 -- specifically, it seems to produce 2^32 - exp(x). 

Version-Release number of selected component (if applicable):


How reproducible:
#include <math.h>
#include <stdio.h>

double ref_logb (double x)
{
    return logb (x);
}

int main ()
{
    printf ("%lf\n", logb (0.5));
    printf ("%lf\n", ref_logb (0.5));
    return 0;
}

Steps to Reproduce:
1. Compile the above program with gcc (in my case gcc-4.6.3)
2. Run
3.
  
Actual results:
-1.0000000000000000e+00
4.2949672950000000e+09

Expected results:
-1.0000000000000000e+00
-1.0000000000000000e+00

Additional info:
The discrepancy seems to occur because the compiler optimizes out logb(0.5), but not the call to ref_logb()

Comment 1 Jeff Law 2012-07-10 16:01:22 UTC
This is fixed in rawhide, tested with glibc-2.15.90-3.fc18.x86_64.

mock -r fedora-rawhide-x86_64 shell
INFO: mock.py version 1.1.22 starting...
State Changed: init plugins
INFO: selinux enabled
State Changed: start
State Changed: lock buildroot
State Changed: shell
<mock-chroot>[root@stumpy /]# rpm -qa | grep glibc
glibc-common-2.15.90-3.fc18.x86_64
glibc-headers-2.15.90-3.fc18.x86_64
glibc-2.15.90-3.fc18.x86_64
glibc-devel-2.15.90-3.fc18.x86_64
<mock-chroot>[root@stumpy /]# cat > foo.c
#include <math.h>
#include <stdio.h>

double ref_logb (double x)
{
    return logb (x);
}

int main ()
{
    printf ("%lf\n", logb (0.5));
    printf ("%lf\n", ref_logb (0.5));
    return 0;
}
<mock-chroot>[root@stumpy /]# gcc foo.c -lm
<mock-chroot>[root@stumpy /]# ./a.out
-1.000000
-1.000000
<mock-chroot>[root@stumpy /]#


Note You need to log in before you can comment on or make changes to this bug.