Bug 6778 - expm1() raises bogus underflow exception for -large
Summary: expm1() raises bogus underflow exception for -large
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-30 11:05 UTC by Michael Kerrisk
Modified: 2020-05-23 10:35 UTC (History)
1 user (show)

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


Attachments
test program (2.72 KB, text/plain)
2008-07-31 08:29 UTC, Michael Kerrisk
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Kerrisk 2008-07-30 11:05:27 UTC
(glibc 2.8)
When expm1(x) is given a large negative x value (e.g., in the range -1e5 through
to -1e308), it correctly returns -1.

However, it also raises an underflow exception.  This is bogus.  The result has
not underflowed: the result is asymptotically close to 1 (not zero).
Comment 1 Michael Kerrisk 2008-07-31 08:29:06 UTC
Created attachment 2843 [details]
test program

Example runs showing problem:

$ /tmp/mt_expm1 -- -1e5
errno == 0
fetestexcept() says:  FE_UNDERFLOW FE_INEXACT
expm1(-1.00000000000000000e+05)=-1.00000000000000000e+00
0 FE_UNDERFLOW normal

$ /tmp/mt_expm1 -- -1e308
errno == 0
fetestexcept() says:  FE_UNDERFLOW FE_INEXACT
expm1(-1.00000000000000001e+308)=-1.00000000000000000e+00
0 FE_UNDERFLOW normal
Comment 2 Joseph Myers 2012-02-29 20:59:11 UTC
Confirmed on x86 with current sources.  Does not appear on x86_64.  This is a quality-of-implementation issue only, since C99 and C11 permit spurious underflow exceptions (as well as spurious inexact exceptions, and raising inexact even when the result is exact).
Comment 3 Joseph Myers 2012-07-06 11:19:45 UTC
Fixed for 2.17 by:

commit f17ac40d7cb8e8c462476b6ab703262f6b8f6da8
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Fri Jul 6 11:17:41 2012 +0000

    Fix expm1 spurious underflow exceptions (bug 6778).
Comment 4 Michael Kerrisk 2020-05-23 10:35:39 UTC
Fix documented for man-pages-5.07.

commit 4f16aab8244518d9f46fb6e8d4dc8e6e73266771
Author: Michael Kerrisk <mtk.manpages@gmail.com>
Date:   Sat May 23 11:45:36 2020 +0200

    expm1.3: The expm1() bogus underflow floating-point exception has been fixed
    
    Fixed in glibc 2.17.
    
    See https://www.sourceware.org/bugzilla/show_bug.cgi?id=6778
    
    Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>

diff --git a/man3/expm1.3 b/man3/expm1.3
index a1fe0f7b2..460068a6d 100644
--- a/man3/expm1.3
+++ b/man3/expm1.3
@@ -144,13 +144,14 @@ T}        Thread safety   MT-Safe
 C99, POSIX.1-2001, POSIX.1-2008.
 .\" BSD.
 .SH BUGS
-For some large negative
+Before glibc 2.17,
+.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6778
+on certain architectures (e.g., x86, but not x86_64)
+.BR expm1 ()
+raised a bogus underflow floating-point exception
+for some large negative
 .I x
 values (where the function result approaches \-1),
-.BR expm1 ()
-raises a bogus underflow floating-point exception.
-.\" FIXME .
-.\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6778
 .PP
 For some large positive
 .I x