Bug 1663489

Summary: Math functions missing errno settings on underflow
Product: Red Hat Enterprise Linux 8 Reporter: Joe Wright <jwright>
Component: glibcAssignee: glibc team <glibc-bugzilla>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: high Docs Contact:
Priority: unspecified    
Version: 8.1CC: ashankar, codonell, dj, fweimer, mnewsome, pfrankli
Target Milestone: rc   
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-01-14 20:20:38 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
reproducer none

Description Joe Wright 2019-01-04 14:05:20 UTC
Created attachment 1518405 [details]
reproducer

Description of problem:
- errno is not being set for bessel functions such as j0, j1, jn, and also exp2.  In the case of exp2 it IS setting the fe exception – so we can catch that one.  But the j0-n are a problem since the man page documentation on RHEL 6 specifically states they do NOT set the IEEE fe exception for fetestexcept(), but they should be setting errno.

This seems to match this bug report:
https://sourceware.org/bugzilla/show_bug.cgi?id=18611

Version-Release number of selected component (if applicable):
- beta

How reproducible:
- see attached jtest.tar

Steps to Reproduce:
1.
2.
3.

Actual results:
] cat /etc/redhat-release
Red Hat Enterprise Linux release 8.0 Beta (Ootpa)
] g++ --version
g++ (GCC) 8.2.1 20180905 (Red Hat 8.2.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

] g++ jtest.C -o jtest.rhel8
] jtest.rhel8
Testing J0:
  Before function call, errno = 0, exception query returns 0
  Calling j0( 1e+256 )
  After function call, errno = 0, exception query returns 0
  Returned function value = 2.04732e-131
Testing J1:
  Before function call, errno = 0, exception query returns 0
  Calling j1( 1e+256 )
  After function call, errno = 0, exception query returns 0
  Returned function value = 7.97882e-129
Testing JN:
  Before function call, errno = 0, exception query returns 0
  Calling jn( 1, 1e+24 )
  After function call, errno = 0, exception query returns 0
  Returned function value = -7.83133e-13
Testing EXP2:
  Before function call, errno = 0, exception query returns 0
  Calling exp2( -1222 )
  After function call, errno = 34, exception query returns 16
  Returned function value = 0

Following is running the RHEL6-compiled binary on RHEL8 beta, which gets the same wrong answers as running the RHEL8b-compiled binary on RHEL8b:

] jtest.rhel6
Testing J0:
  Before function call, errno = 0, exception query returns 0
  Calling j0( 1e+256 )
  After function call, errno = 0, exception query returns 0
  Returned function value = 2.04732e-131
Testing J1:
  Before function call, errno = 0, exception query returns 0
  Calling j1( 1e+256 )
  After function call, errno = 0, exception query returns 0
  Returned function value = 7.97882e-129
Testing JN:
  Before function call, errno = 0, exception query returns 0
  Calling jn( 1, 1e+24 )
  After function call, errno = 0, exception query returns 0
  Returned function value = -7.83133e-13
Testing EXP2:
  Before function call, errno = 0, exception query returns 0
  Calling exp2( -1222 )
  After function call, errno = 34, exception query returns 16
  Returned function value = 0

Expected results:

RHEL 6 glibc provides results which are expected by the user.
[alanm@vmw102 C02014182]$ ./jtest
Testing J0:
  Before function call, errno = 0, exception query returns 0
  Calling j0( 1e+256 )
  After function call, errno = 34, exception query returns 0
  Returned function value = 0
Testing J1:
  Before function call, errno = 0, exception query returns 0
  Calling j1( 1e+256 )
  After function call, errno = 34, exception query returns 0
  Returned function value = 0
Testing JN:
  Before function call, errno = 0, exception query returns 0
  Calling jn( 1, 1e+24 )
  After function call, errno = 34, exception query returns 0
  Returned function value = 0
Testing EXP2:
  Before function call, errno = 0, exception query returns 0
  Calling exp2( -1222 )
  After function call, errno = 34, exception query returns 0
  Returned function value = 0
[alanm@vmw102 C02014182]$ rpm -qf /lib64/libm.so.6
glibc-2.12-1.209.el6_9.2.x86_64

Additional info:

Comment 1 Florian Weimer 2019-01-04 14:24:13 UTC
The glibc manual says this (under Math Error Reporting):

“
When underflow occurs, the underflow exception is raised, and zero
(appropriately signed) or a subnormal value, as appropriate for the
mathematical result of the function and the rounding mode, is returned.
ERRNO may be set to ‘ERANGE’, but this is not guaranteed; it is intended
that the GNU C Library should set it when the underflow is to an
appropriately signed zero, but not necessarily for other underflows.
”

<https://www.gnu.org/software/libc/manual/html_node/Math-Error-Reporting.html>

So I don't think this is a bug in glibc.

Comment 2 Matt Newsome 2019-01-14 20:20:38 UTC
Closing this bug out as it doesn't, on the basis of the information provided, appear to be a bug. If you disagree, please reopen the bug with further supporting information and we'll take a look. Thanks.