glibc/sysdeps/ieee754/ldbl-96
Joseph Myers d0d286d32d Fix lrint, llrint missing exceptions close to overflow threshold (bug 19094).
The dbl-64, ldbl-96 and ldbl-128 implementations of lrint and llrint
fail to produce "invalid" exceptions in cases where the rounded result
overflows the target type, but truncating the floating-point argument
to the next integer towards zero does not overflow it (so in
particular casts do not produce such exceptions).  (This issue cannot
arise for float, or for double with 64-bit target type, or for ldbl-96
with 64-bit target type and negative arguments, because of
insufficient precision in the floating-point type for arguments with
the relevant property to exist.  It also obviously cannot arise in
FE_TOWARDZERO mode.)

This patch fixes these problems by inserting checks for the special
cases that can occur in each implementation, and explicitly raising
FE_INVALID (and avoiding the cast if it might raise spurious
FE_INEXACT, while raising FE_INEXACT explicitly in the cases where it
is needed; unlike lround and llround, FE_INEXACT is required, not
optional, for these functions for a within-range inexact result).

The fixes are conditional on FE_INVALID or FE_INEXACT being defined.
If any future architecture supports one but not both of those
exceptions, the code will fail to compile and need fixing to handle
that case (this seemed better than conditioning on both macros being
defined, resulting in code that would compile but quietly miss
exceptions on such a system).

Tested for x86_64, x86 and mips64.  Tested the ldbl-96 changes (only
relevant for ia64, it appears) on x86_64 by removing the x86_64
versions of lrintl / llrintl.

	[BZ #19094]
	* sysdeps/ieee754/dbl-64/s_lrint.c: Include <fenv.h> and
	<limits.h>.
	(__lrint) [FE_INVALID || FE_INEXACT]: Force FE_INVALID exception
	when result overflows but exception would not result from cast.
	* sysdeps/ieee754/ldbl-128/s_llrintl.c: Include <fenv.h> and
	<limits.h>.
	(__llrintl) [FE_INVALID || FE_INEXACT]: Force FE_INVALID exception
	when result overflows but exception would not result from cast.
	* sysdeps/ieee754/ldbl-128/s_lrintl.c: Include <fenv.h> and
	<limits.h>.
	(__lrintl) [FE_INVALID || FE_INEXACT]: Force FE_INVALID exception
	when result overflows but exception would not result from cast.
	* sysdeps/ieee754/ldbl-96/s_llrintl.c: Include <fenv.h> and
	<limits.h>.
	(__llrintl) [FE_INVALID || FE_INEXACT]: Force FE_INVALID exception
	when result overflows but exception would not result from cast.
	* sysdeps/ieee754/ldbl-96/s_lrintl.c: Include <fenv.h> and
	<limits.h>.
	(__lrintl) [FE_INVALID || FE_INEXACT]: Force FE_INVALID exception
	when result overflows but exception would not result from cast.
	* math/libm-test.inc (lrint_test_data): Add more tests.
	(llrint_test_data): Likewise.
2015-10-08 22:17:45 +00:00
..
e_acoshl.c Fix acosh (1) in round-downward mode (bug 16927). 2014-05-14 12:35:40 +00:00
e_asinl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_atanhl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_coshl.c Fix cosh spurious underflows from expm1 (bug 16354), inaccurate results near 0 (bug 17061). 2014-06-23 20:20:10 +00:00
e_gammal_r.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_hypotl.c Fix hypot missing underflows (bug 18803). 2015-09-24 23:43:57 +00:00
e_j0l.c Avoid uninitialized warnings in Bessel functions. 2015-02-26 21:49:19 +00:00
e_j1l.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_jnl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
e_lgammal_r.c Fix lgamma (negative) inaccuracy (bug 2542, bug 2543, bug 2558). 2015-09-10 22:27:58 +00:00
e_rem_pio2l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
e_sinhl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
gamma_product.c Use math_narrow_eval more consistently. 2015-09-23 18:14:57 +00:00
gamma_productl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
k_cosl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
k_sinl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
k_tanl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
ldbl2mpn.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lgamma_negl.c Fix lgamma (negative) inaccuracy (bug 2542, bug 2543, bug 2558). 2015-09-10 22:27:58 +00:00
lgamma_product.c Fix lgamma (negative) inaccuracy (bug 2542, bug 2543, bug 2558). 2015-09-10 22:27:58 +00:00
lgamma_productl.c Fix lgamma (negative) inaccuracy (bug 2542, bug 2543, bug 2558). 2015-09-10 22:27:58 +00:00
math_ldbl.h Fix a typo. 2000-12-21 23:30:28 +00:00
mpn2ldbl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
printf_fphex.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
s_asinhl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
s_cbrtl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
s_copysignl.c Use <> for math.h and math_private.h everywhere. 2012-03-09 16:09:10 -08:00
s_cosl.c Implement ldbl-96 sinl / cosl / sincosl (bug 13851). 2012-03-16 12:30:05 +00:00
s_erfl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
s_fma.c Replace finite with isfinite. 2015-06-03 16:35:44 +01:00
s_fmal.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
s_frexpl.c Use <> for math.h and math_private.h everywhere. 2012-03-09 16:09:10 -08:00
s_issignalingl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
s_llrintl.c Fix lrint, llrint missing exceptions close to overflow threshold (bug 19094). 2015-10-08 22:17:45 +00:00
s_llroundl.c Fix lround, llround missing exceptions close to overflow threshold (bug 19088). 2015-10-07 23:45:29 +00:00
s_lrintl.c Fix lrint, llrint missing exceptions close to overflow threshold (bug 19094). 2015-10-08 22:17:45 +00:00
s_lroundl.c Fix lround, llround missing exceptions close to overflow threshold (bug 19088). 2015-10-07 23:45:29 +00:00
s_modfl.c Use <> for math.h and math_private.h everywhere. 2012-03-09 16:09:10 -08:00
s_nexttoward.c Fix nexttoward overflow in non-default rounding modes (bug 19059). 2015-10-02 17:11:13 +00:00
s_nexttowardf.c Fix nexttoward overflow in non-default rounding modes (bug 19059). 2015-10-02 17:11:13 +00:00
s_remquol.c Fix ldbl-96 remquol (finite, Inf) (bug 18244). 2015-05-19 23:44:28 +00:00
s_roundl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
s_scalblnl.c Fix ldbl-96 scalblnl underflowing results (bug 17803). 2015-01-12 23:02:14 +00:00
s_signbitl.c Use the GCC builtin functions for the non-inlined signbit implementations. 2015-09-18 16:39:08 +01:00
s_sincosl.c Since we now inline isinf, isnan and isfinite in math.h, replace uses of __isinf_ns(l/f) 2015-09-18 20:51:52 +01:00
s_sinl.c Implement ldbl-96 sinl / cosl / sincosl (bug 13851). 2012-03-16 12:30:05 +00:00
s_tanhl.c Refactor code forcing underflow exceptions. 2015-09-23 22:42:30 +00:00
s_tanl.c Fix tan, tanl for large inputs. 2012-03-16 20:05:37 +00:00
strtold_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
t_sincosl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
w_expl.c This patch renames all uses of __isinf*, __isnan*, __finite* and __signbit* to use standard C99 macros. This has no effect on generated code. 2015-06-03 15:41:36 +01:00
x2y2m1.c Fix clog, clog10 inaccuracy (bug 19016). 2015-09-28 22:11:22 +00:00
x2y2m1l.c Fix clog, clog10 inaccuracy (bug 19016). 2015-09-28 22:11:22 +00:00