Bug 6805

Summary: j0(), j1(), jn() do not raise exceptions on underflow error
Product: glibc Reporter: Michael Kerrisk <mtk.manpages>
Component: mathAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: test program
test program
test program

Description Michael Kerrisk 2008-07-31 11:27:39 UTC
On an underflow error, j0(), j1(), and jn() correctly set errno to ERANGE, but
do not raise an IEEE exception.  They should raise the FE_UNDERFLOW exception.

Background: 
On error, many glibc math functions both set errno and raise an exception
(fetestexcept(3)).  For example, the following  function all do this: acos(),
asin(), cosh(), sinh(), acosh(), asinh(), exp(), exp2(), ldexp(), log(),
log10(), log2().  However, there is much inconsistency.  Some functions raise an
exception, but don't set errno.  Some functions set errno for some errors, but
not others.  A few set errno, but don't raise an exception.  This series of bug
reports documents deviations from what I consider the ideal: all functions
should BOTH set errno AND raise an exception for all errors.

All of these reports relate to tests on glibc 2.8 (as provided by SUSE 11.0).
Comment 1 Michael Kerrisk 2008-07-31 11:28:09 UTC
Created attachment 2871 [details]
test program
Comment 2 Michael Kerrisk 2008-07-31 11:28:36 UTC
Created attachment 2872 [details]
test program
Comment 3 Michael Kerrisk 2008-07-31 11:29:50 UTC
Created attachment 2873 [details]
test program

Sample runs demonstrating the problem:

$ /tmp/mt_j0 1e100
errno == ERANGE
fetestexcept() says:  FE_INEXACT
j0(1.00000000000000002e+100)=0.00000000000000000e+00
ERANGE 0 +0

$ /tmp/mt_j1 1e100
errno == ERANGE
fetestexcept() says:  FE_INEXACT
j1(1.00000000000000002e+100)=0.00000000000000000e+00
ERANGE 0 +0

$ /tmp/mt_jn 10 1e100
errno == ERANGE
fetestexcept() says:  FE_INEXACT
jn(10,1.00000000000000002e+100)=0.00000000000000000e+00
ERANGE 0 +0
Comment 4 Joseph Myers 2012-03-01 17:50:32 UTC
See http://sourceware.org/ml/libc-alpha/2012-02/msg00512.html - the correct result won't underflow in these cases but in whatever cases TLOSS errors are given I suppose underflow should be raised as well.
Comment 5 Joseph Myers 2013-11-28 16:55:25 UTC
It's now documented that exceptions may not be raised when libm is in the (deprecated) error-handling modes that use matherr, which are the only cases where TLOSS errors may occur (since 
commit c36e1d2369f149a64c759f3ad6f4cc5a03b03b62).