This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug math/13954] New: logb() produces wrong results for subnormal 'double' numbers


http://sourceware.org/bugzilla/show_bug.cgi?id=13954

             Bug #: 13954
           Summary: logb() produces wrong results for subnormal 'double'
                    numbers
           Product: glibc
           Version: 2.11
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
        AssignedTo: unassigned@sourceware.org
        ReportedBy: bruno@clisp.org
    Classification: Unclassified


Created attachment 6324
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6324
test case

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

The function logb() 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 i < DBL_MIN_EXP-1, logb(x) is too
large.

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

Expected result:
0

Actual result:
1

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]