glibc/sysdeps
Joseph Myers 4629c866ad Fix atan / atan2 missing underflows (bug 15319).
This patch fixes bug 15319, missing underflows from atan / atan2 when
the result of atan is very close to its small argument (or that of
atan2 is very close to the ratio of its arguments, which may be an
exact division).

The usual approach of doing an underflowing computation if the
computed result is subnormal is followed.  For 32-bit x86, there are
extra complications: the inline __ieee754_atan2 in bits/mathinline.h
needs to be disabled for float and double because other libm functions
using it generally rely on getting proper underflow exceptions from
it, while the out-of-line functions have to remove excess range and
precision from the underflowing result so as to return an exact 0 in
the case where errno should be set for underflow to 0.  (The failures
I saw without that are similar to those Carlos reported for other
functions, where I haven't seen a response to
<https://sourceware.org/ml/libc-alpha/2015-01/msg00485.html>
confirming if my diagnosis is correct.  Arguably all libm functions
with float and double returns should remove excess range and
precision, but that's a separate matter.)

The x86_64 long double case reported in a comment in bug 15319 is not
a bug (it's an argument of LDBL_MIN, and x86_64 is an after-rounding
architecture so the correct IEEE result is not to raise underflow in
the given rounding mode, in addition to treating the result as an
exact LDBL_MIN being within the newly clarified documentation of
accuracy goals).  I'm presuming that the fpatan instruction can be
trusted to raise appropriate exceptions when the (long double) result
underflows (after rounding) and so no changes are needed for x86 /
x86_64 long double functions here; empirically this is the case for
the cases covered in the testsuite, on my system.

Tested for x86_64, x86, powerpc and mips64.  Only 32-bit x86 needs
ulps updates (for the changes to inlines meaning some functions no
longer get excess precision from their __ieee754_atan2* calls).

	[BZ #15319]
	* sysdeps/i386/fpu/e_atan2.S (dbl_min): New object.
	(MO): New macro.
	(__ieee754_atan2): For results with small absolute value, force
	underflow exception and remove excess range and precision from
	return value.
	* sysdeps/i386/fpu/e_atan2f.S (flt_min): New object.
	(MO): New macro.
	(__ieee754_atan2f): For results with small absolute value, force
	underflow exception and remove excess range and precision from
	return value.
	* sysdeps/i386/fpu/s_atan.S (dbl_min): New object.
	(MO): New macro.
	(__atan): For results with small absolute value, force underflow
	exception and remove excess range and precision from return value.
	* sysdeps/i386/fpu/s_atanf.S (flt_min): New object.
	(MO): New macro.
	(__atanf): For results with small absolute value, force underflow
	exception and remove excess range and precision from return value.
	* sysdeps/ieee754/dbl-64/e_atan2.c: Include <float.h> and
	<math.h>.
	(__ieee754_atan2): Force underflow exception for results with
	small absolute value.
	* sysdeps/ieee754/dbl-64/s_atan.c: Include <float.h> and
	<math_private.h>.
	(atan): Force underflow exception for results with small absolute
	value.
	* sysdeps/ieee754/flt-32/s_atanf.c: Include <float.h>.
	(__atanf): Force underflow exception for results with small
	absolute value.
	* sysdeps/ieee754/ldbl-128/s_atanl.c: Include <float.h> and
	<math.h>.
	(__atanl): Force underflow exception for results with small
	absolute value.
	* sysdeps/ieee754/ldbl-128ibm/s_atanl.c: Include <float.h>.
	(__atanl): Force underflow exception for results with small
	absolute value.
	* sysdeps/x86/fpu/bits/mathinline.h
	[!__SSE2_MATH__ && !__x86_64__ && __LIBC_INTERNAL_MATH_INLINES]
	(__ieee754_atan2): Only define inline for long double.
	* sysdeps/x86_64/fpu/multiarch/e_atan2.c
	[HAVE_FMA4_SUPPORT || HAVE_AVX_SUPPORT]: Include <math.h>.
	* math/auto-libm-test-in: Do not mark underflow exceptions as
	possibly missing for bug 15319.  Add more tests of atan2.
	* math/auto-libm-test-out: Regenerated.
	* math/libm-test.inc (casin_test_data): Do not mark underflow
	exceptions as possibly missing for bug 15319.
	(casinh_test_data): Likewise.
	* sysdeps/i386/fpu/libm-test-ulps: Update.
2015-02-18 21:10:49 +00:00
..
aarch64 Clean up sysdep-dl-routines variable. 2015-02-06 10:42:08 -08:00
alpha Fix libm feupdateenv namespace (bug 17748). 2015-01-07 19:01:20 +00:00
arm Use -Werror=undef for assembly code. 2015-02-12 13:57:32 -08:00
generic Add placeholder c++-types.data and *.abilist files. 2015-02-13 15:41:34 -08:00
gnu hurd: fix unwind-resume.c build 2015-02-08 18:46:00 +01:00
hppa Clean up sysdep-dl-routines variable. 2015-02-06 10:42:08 -08:00
i386 Fix atan / atan2 missing underflows (bug 15319). 2015-02-18 21:10:49 +00:00
ia64 Clean up sysdep-dl-routines variable. 2015-02-06 10:42:08 -08:00
ieee754 Fix atan / atan2 missing underflows (bug 15319). 2015-02-18 21:10:49 +00:00
init_array NPTL: Initializer for .init_array-only configurations. 2015-02-13 13:19:11 -08:00
m68k m68k: fix missing definition of __feraiseexcept 2015-01-25 23:36:02 +01:00
mach hurd: fix tls.h build 2015-02-08 05:06:17 +01:00
microblaze MicroBlaze: Avoid pointer to integer conversion warning 2015-01-09 14:49:27 +10:00
mips 2015-02-18 Steve Ellcey <sellcey@imgtec.com> 2015-02-18 10:51:37 -08:00
nios2 glibc 2.21 pre-release update. 2015-02-05 23:14:38 -05:00
nptl Include <signal.h> in sysdeps/nptl/allocrtsig.c 2015-01-29 10:00:25 +01:00
posix Fix posix_spawn getrlimit64 namespace (bug 17991). 2015-02-18 00:26:35 +00:00
powerpc Fix powerpc software sqrtf (bug 17967). 2015-02-13 16:20:36 +00:00
pthread hurd: fix build with pthread aio 2015-02-07 21:48:32 +01:00
s390 S390: Get rid of linknamespace failures for string functions. 2015-01-16 09:17:32 +01:00
sh Fix libm feupdateenv namespace (bug 17748). 2015-01-07 19:01:20 +00:00
sparc Fix two bugs in sparc atomics. 2015-01-31 23:39:50 -08:00
tile tilegx32: set __HAVE_64B_ATOMICS to 0 2015-01-28 14:51:21 -05:00
unix 2015-02-18 Steve Ellcey <sellcey@imgtec.com> 2015-02-18 10:51:37 -08:00
wordsize-32 Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
wordsize-64 Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
x86 Fix atan / atan2 missing underflows (bug 15319). 2015-02-18 21:10:49 +00:00
x86_64 Fix atan / atan2 missing underflows (bug 15319). 2015-02-18 21:10:49 +00:00