Bug 838191 - Function logb() in math.h produces incorrect results for small inputs
Function logb() in math.h produces incorrect results for small inputs
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
16
x86_64 Linux
unspecified Severity urgent
: ---
: ---
Assigned To: Jeff Law
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-06 22:10 EDT by Andre Kessler
Modified: 2016-11-24 10:45 EST (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-07-10 12:01:22 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Andre Kessler 2012-07-06 22:10:55 EDT
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 12:01:22 EDT
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.