Bug 13923

Summary: expm1l (-LDBL_MAX) wrongly returns NaN and raises exceptions on x86
Product: glibc Reporter: Joseph Myers <jsm28>
Component: mathAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal Flags: fweimer: security-
Priority: P2    
Version: 2.15   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Joseph Myers 2012-03-28 00:26:50 UTC
On x86, expm1l (-LDBL_MAX) returns NaN and raises INVALID and OVERFLOW exceptions; it should return -1 without raising those exceptions.  Testcase:

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
#include <float.h>

volatile long double d = -LDBL_MAX;

int
main (void)
{
  feclearexcept (FE_ALL_EXCEPT);
  errno = 0;
  volatile long double r = expm1l (d);
  if (fetestexcept (FE_DIVBYZERO))
    printf ("DIVBYZERO ");
  if (fetestexcept (FE_INEXACT))
    printf ("INEXACT ");
  if (fetestexcept (FE_INVALID))
    printf ("INVALID ");
  if (fetestexcept (FE_OVERFLOW))
    printf ("OVERFLOW ");
  if (fetestexcept (FE_UNDERFLOW))
    printf ("UNDERFLOW ");
  printf ("%.18Lg %m\n", r);
  return 0;
}
Comment 1 Joseph Myers 2012-05-07 19:22:11 UTC
Fixed by:

commit 495fd99f3a119e5c0c542ccc6cf9c93b1fb9e892
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Mon May 7 19:13:08 2012 +0000

    Fix x86/x86_64 expm1l inaccuracy and exceptions (bugs 13885, 13923).