Bug 6792 - log1p() does not set errno on error
Summary: log1p() does not set errno on error
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:
: 5680 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-07-31 09:22 UTC by Michael Kerrisk
Modified: 2015-04-14 06:17 UTC (History)
3 users (show)

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


Attachments
test program (2.72 KB, text/plain)
2008-07-31 09:26 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-31 09:22:37 UTC
on a pole error or a domain error, log1p correctly raises an exception.  But
errno is not set.  It should be (respectively: ERANGE and EDOM)

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 09:26:04 UTC
Created attachment 2854 [details]
test program

Sample runs demonstrating the problem

$ /tmp/mt_log1p -- -1
errno == 0
fetestexcept() says:  FE_DIVBYZERO
log1p(-1.00000000000000000e+00)=-inf
0 FE_DIVBYZERO -inf

$ /tmp/mt_log1p -- -2
errno == 0
fetestexcept() says:  FE_INVALID
log1p(-2.00000000000000000e+00)=nan
0 FE_INVALID nan
Comment 2 Joseph Myers 2012-02-29 20:10:06 UTC
Confirmed with current sources, both x86 and x86_64.
Comment 3 Joseph Myers 2012-02-29 20:12:25 UTC
*** Bug 5680 has been marked as a duplicate of this bug. ***
Comment 4 cvs-commit@gcc.gnu.org 2015-04-13 19:20:55 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  de8aadd52c97f9a04d5e8709b16dc5baf9292a09 (commit)
      from  7378b1f8f8ef25017d36af60e2d6a42939d74526 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=de8aadd52c97f9a04d5e8709b16dc5baf9292a09

commit de8aadd52c97f9a04d5e8709b16dc5baf9292a09
Author: Stefan Liebler <stli@linux.vnet.ibm.com>
Date:   Mon Apr 13 21:16:56 2015 +0200

    Set errno for log1p on pole/domain error.
    
    According to bug 6792, errno is not set to ERANGE/EDOM
    by calling log1p/log1pf/log1pl with x = -1 or x < -1.
    
    This patch adds a wrapper which sets errno in those cases
    and returns the value of the existing __log1p function.
    The log1p is now an alias to the wrapper function
    instead of __log1p.
    
    The files in sysdeps are reflecting these changes.
    The ia64 implementation sets errno by itself,
    thus the wrapper-file is empty.
    
    The libm-test is adjusted for log1p-tests to check errno.
    
    	[BZ #6792]
    	* math/w_log1p.c: New file.
    	* math/w_log1pf.c: Likewise.
    	* math/w_log1pl.c: Likewise.
    	* math/Makefile (libm-calls): Add w_log1p.
    	* math/s_log1pl.c (log1pl): Remove weak_alias.
    	* sysdeps/i386/fpu/s_log1p.S (log1p): Likewise.
    	* sysdeps/i386/fpu/s_log1pf.S (log1pf): Likewise.
    	* sysdeps/i386/fpu/s_log1pl.S (log1pl): Likewise.
    	* sysdeps/x86_64/fpu/s_log1pl.S (log1pl): Likewise.
    	* sysdeps/ieee754/dbl-64/s_log1p.c (log1p): Likewise.
    	[NO_LONG_DOUBLE] (log1pl): Likewise.
    	* sysdeps/ieee754/flt-32/s_log1pf.c (log1pf): Likewise.
    	* sysdeps/ieee754/ldbl-128/s_log1pl.c (log1pl): Likewise.
    	* sysdeps/ieee754/ldbl-64-128/s_log1pl.c
    	(log1p): Remove long_double_symbol.
    	* sysdeps/ieee754/ldbl-128ibm/s_log1pl.c (log1pl): Likewise.
    	* sysdeps/ieee754/ldbl-64-128/w_log1pl.c: New file.
    	* sysdeps/ieee754/ldbl-128ibm/w_log1pl.c: Likewise.
    	* sysdeps/m68k/m680x0/fpu/s_log1p.c: Define empty weak_alias to
    	remove weak_alias for corresponding log1p function.
    	* sysdeps/m68k/m680x0/fpu/s_log1pf.c: Likewise.
    	* sysdeps/m68k/m680x0/fpu/s_log1pl.c: Likewise.
    	* sysdeps/ia64/fpu/w_log1p.c: New file.
    	* sysdeps/ia64/fpu/w_log1pf.c: Likewise.
    	* sysdeps/ia64/fpu/w_log1pl.c: Likewise.
    	* math/libm-test.inc (log1p_test_data):	Add errno expectations.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                              |   30 +++++++++++++++++++++++
 NEWS                                   |    2 +-
 math/Makefile                          |    2 +-
 math/libm-test.inc                     |    8 +++---
 math/s_log1pl.c                        |    1 -
 math/w_log1p.c                         |   41 ++++++++++++++++++++++++++++++++
 math/w_log1pf.c                        |   36 ++++++++++++++++++++++++++++
 math/w_log1pl.c                        |   36 ++++++++++++++++++++++++++++
 sysdeps/i386/fpu/s_log1p.S             |    1 -
 sysdeps/i386/fpu/s_log1pf.S            |    1 -
 sysdeps/i386/fpu/s_log1pl.S            |    1 -
 sysdeps/ia64/fpu/w_log1p.c             |   20 +++++++++++++++
 sysdeps/ia64/fpu/w_log1pf.c            |   20 +++++++++++++++
 sysdeps/ia64/fpu/w_log1pl.c            |   20 +++++++++++++++
 sysdeps/ieee754/dbl-64/s_log1p.c       |    5 ----
 sysdeps/ieee754/flt-32/s_log1pf.c      |    1 -
 sysdeps/ieee754/ldbl-128/s_log1pl.c    |    2 -
 sysdeps/ieee754/ldbl-128ibm/s_log1pl.c |    2 -
 sysdeps/ieee754/ldbl-128ibm/w_log1pl.c |   23 ++++++++++++++++++
 sysdeps/ieee754/ldbl-64-128/s_log1pl.c |    3 --
 sysdeps/ieee754/ldbl-64-128/w_log1pl.c |   23 ++++++++++++++++++
 sysdeps/m68k/m680x0/fpu/s_log1p.c      |    2 +
 sysdeps/m68k/m680x0/fpu/s_log1pf.c     |    2 +
 sysdeps/m68k/m680x0/fpu/s_log1pl.c     |    2 +
 sysdeps/x86_64/fpu/s_log1pl.S          |    1 -
 25 files changed, 261 insertions(+), 24 deletions(-)
 create mode 100644 math/w_log1p.c
 create mode 100644 math/w_log1pf.c
 create mode 100644 math/w_log1pl.c
 create mode 100644 sysdeps/ia64/fpu/w_log1p.c
 create mode 100644 sysdeps/ia64/fpu/w_log1pf.c
 create mode 100644 sysdeps/ia64/fpu/w_log1pl.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm/w_log1pl.c
 create mode 100644 sysdeps/ieee754/ldbl-64-128/w_log1pl.c
Comment 5 Stefan Liebler 2015-04-14 06:17:52 UTC
Fixed with commit in comment 4.