Bug 5794 - expm1l(x) overflows when 11356.1768 < x <= 11356.5234
Summary: expm1l(x) overflows when 11356.1768 < x <= 11356.5234
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: unspecified
: P2 minor
Target Milestone: ---
Assignee: Andreas Jaeger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-26 07:03 UTC by Ani
Modified: 2014-07-02 07:02 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ani 2008-02-26 07:03:50 UTC
The value of (e^x - 1) is representable as a long double when x <=
11356.5234, but expm1l(x) overflows to infinity when x > 11356.1768
(approximately).

Steps to Reproduce:
Compile and run the following program:

#include <stdio.h>
#include <math.h>

main ()
{
  long double a, b;
  const long double x = 11356.35L;

  a = expl (x) - 1.0L;
  b = expm1l (x);
  if (a == b) {
    printf ("e^%.2Lf - 1 = %Lg\n", b);
    return 0;
  } else {
    printf ("e^%.2Lf - 1 = %Lg; but expm1l(%.2Lf) returned %Lg\n",
	    x, a, x, b);
    return 1;
  }
}


Actual Results:  e^11356.35 - 1 = 1.00032e+4932; but expm1l(11356.35)
returned inf


Expected Results:  e^11356.35 - 1 = 1.00032e+4932


Additional info:

This bug probably isn't even worth reporting, except for completeness. 
expm1l is designed to compute e^x-1 more accurately when x is negative, so
[at least the i386 version] uses a slightly different algorithm than expl. 
This algorithm overflows for large x where expl would not.  But then, expm1
really isn't intended for large x anyway.

In my own port of the math library, I circumvent the problem by calling
__ieee754_expl when x >= 64, because at that magnitude, -1 is too small to
affect the result.  This is probably overkill, but it works.
Comment 1 Ani 2008-02-26 07:08:36 UTC
original bug filed at https://bugzilla.redhat.com/show_bug.cgi?id=43354
Comment 2 Denis Vlasenko 2008-07-30 10:07:23 UTC
I submitted a fix, see RH bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=43354
Comment 3 Ulrich Drepper 2008-08-05 22:09:58 UTC
Fixed in cvs.
Comment 4 Joseph Myers 2012-02-29 17:49:28 UTC
This was fixed by:

2008-08-05  Ulrich Drepper  <drepper@redhat.com>

        [BZ #5794]
        * sysdeps/i386/fpu/s_expm1l.S: Simply use exp implementation for large
        parameters.
        * sysdeps/x86_64/fpu/s_expm1l.S: Likewise.
        Patch by Denys Vlasenko <dvlasenk@redhat.com>.

A testcase wasn't added to the testsuite at the time.  I've now proposed adding one: http://sourceware.org/ml/libc-alpha/2012-02/msg00773.html