Bug 13956 - logbl() produces wrong results for subnormal 'long double' numbers
Summary: logbl() produces wrong results for subnormal 'long double' numbers
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.11
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-06 14:22 UTC by Bruno Haible
Modified: 2014-06-25 11:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
test case (220 bytes, text/x-csrc)
2012-04-06 14:22 UTC, Bruno Haible
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Haible 2012-04-06 14:22:48 UTC
Created attachment 6326 [details]
test case

Seen on glibc 2.11 Linux/PowerPC,
on glibc 2.7 Linux/SPARC,
on glibc 2.7 Linux/HP-PA.

The function logbl() produces a wrong result for subnormal (denormalized)
arguments.

POSIX:2008 specifies the behaviour of this function for subnormal numbers:
<http://pubs.opengroup.org/onlinepubs/9699919799/>.
In particular, if x = 2^i is > 0, logb(x) must be = i.

But in glibc on the specified platforms, for some values of i < LDBL_MIN_EXP-1, logb(x) is too large.

How to reproduce:
================================== foo.c ==================================
#include <float.h>
#include <math.h>
volatile long double x;
int main ()
{
  int i;
  for (i = 0, x = 1.0L; i >= LDBL_MIN_EXP - 55; i--, x *= 0.5L)
    /* Either x = 2^i or x = 0.0.  */
    if ((i == LDBL_MIN_EXP - 2 || i == LDBL_MIN_EXP - 55)
        && (x > 0.0L && !(logbl (x) == (long double)i)))
      return 1;
  return 0;
}
===========================================================================
$ gcc foo.c -Wall -lm
$ ./a.out; echo $?

Expected result:
0

Actual result:
1
Comment 1 Adhemerval Zanella Netto 2012-05-10 23:47:04 UTC
Fix commited to master (89c9aa491a7cee97bf78a29cddbf0a25c902a671).
Comment 2 Joseph Myers 2012-05-11 09:25:46 UTC
I presume you intended to close this as fixed....