diff options
author | Joseph Myers <joseph@codesourcery.com> | 2016-12-16 18:03:25 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2016-12-16 18:03:25 +0000 |
commit | c0b4353654e635e280ec0c1972f251bf696abb36 (patch) | |
tree | 0c695b7feecc0397628c89e0f5b02690ef2cc857 | |
parent | 8b1f57f4f2c9c71c51b31fda1c91ca0e36b1fb18 (diff) | |
download | glibc-c0b4353654e635e280ec0c1972f251bf696abb36.tar.gz glibc-c0b4353654e635e280ec0c1972f251bf696abb36.tar.xz glibc-c0b4353654e635e280ec0c1972f251bf696abb36.zip |
Define FE_SNANS_ALWAYS_SIGNAL.
TS 18661-1 defines a macro FE_SNANS_ALWAYS_SIGNAL in <fenv.h>, to indicate that the recommended practice regarding sNaNs (that operations always produce a qNaN output with "invalid" exception, even in the fmax / fmin / hypot / pow cases where a qNaN input would not result in qNaN output) is followed. Now that those functions with C99 special cases for NaNs have been fixed not to apply those special cases to sNaN, only to qNaN, glibc follows that recommended practice. This patch makes it define the corresponding macro. Since compiler optimizations may affect whether sNaNs behave as expected and the macro relates to both language and library features, it is only defined if __SUPPORT_SNAN__ is defined (which GCC defines for -fsignaling-nans). It is also not defined if FE_INVALID is undefined, since the recommended practice specifically refers to raising the "invalid" exception, so it seems inappropriate to define the macro for soft-float cases without support for exceptions. (Further refinement would be possible in cases where bits/fenv.h is shared by configurations both with and without exceptions support.) Tested for x86_64 and x86, and also did compile-only testing for nios2 to cover the no-exceptions case. * math/fenv.h [__GLIBC_USE (IEC_60559_BFP_EXT) && FE_INVALID && __SUPPORT_SNAN__] (FE_SNANS_ALWAYS_SIGNAL): New macro. * math/test-fe-snans-always-signal.c: New file. * math/Makefile (tests): Add test-fe-snans-always-signal. (CFLAGS-test-fe-snans-always-signal.c): New variable. * manual/arith.texi (Infinity and NaN): Document FE_SNANS_ALWAYS_SIGNAL.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | manual/arith.texi | 14 | ||||
-rw-r--r-- | math/Makefile | 5 | ||||
-rw-r--r-- | math/fenv.h | 8 | ||||
-rw-r--r-- | math/test-fe-snans-always-signal.c | 38 |
6 files changed, 77 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index a38bc6c9c5..d15b06d668 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2016-12-16 Joseph Myers <joseph@codesourcery.com> + + * math/fenv.h + [__GLIBC_USE (IEC_60559_BFP_EXT) && FE_INVALID && __SUPPORT_SNAN__] + (FE_SNANS_ALWAYS_SIGNAL): New macro. + * math/test-fe-snans-always-signal.c: New file. + * math/Makefile (tests): Add test-fe-snans-always-signal. + (CFLAGS-test-fe-snans-always-signal.c): New variable. + * manual/arith.texi (Infinity and NaN): Document + FE_SNANS_ALWAYS_SIGNAL. + 2016-12-16 Adhemerval Zanella <adhemerval.zanella@linaro.org> * string/test-memchr.c (do_test): Typo on ‘byte’ and missing closing diff --git a/NEWS b/NEWS index 64ed6593cb..baf46bd4ad 100644 --- a/NEWS +++ b/NEWS @@ -46,8 +46,8 @@ Version 2.25 problem. * New <fenv.h> features from TS 18661-1:2014 are added to libm: the - fesetexcept, fetestexceptflag, fegetmode and fesetmode functions, - the femode_t type and the FE_DFL_MODE macro. + fesetexcept, fetestexceptflag, fegetmode and fesetmode functions, the + femode_t type and the FE_DFL_MODE and FE_SNANS_ALWAYS_SIGNAL macros. * Integer width macros from TS 18661-1:2014 are added to <limits.h>: CHAR_WIDTH, SCHAR_WIDTH, UCHAR_WIDTH, SHRT_WIDTH, USHRT_WIDTH, INT_WIDTH, diff --git a/manual/arith.texi b/manual/arith.texi index f9296a362e..41ab577237 100644 --- a/manual/arith.texi +++ b/manual/arith.texi @@ -720,6 +720,20 @@ These macros, defined by TS 18661-1:2014, are constant expressions for signaling NaNs. @end deftypevr +@comment fenv.h +@comment ISO +@deftypevr Macro int FE_SNANS_ALWAYS_SIGNAL +This macro, defined by TS 18661-1:2014, is defined to @code{1} in +@file{fenv.h} to indicate that functions and operations with signaling +NaN inputs and floating-point results always raise the invalid +exception and return a quiet NaN, even in cases (such as @code{fmax}, +@code{hypot} and @code{pow}) where a quiet NaN input can produce a +non-NaN result. Because some compiler optimizations may not handle +signaling NaNs correctly, this macro is only defined if compiler +support for signaling NaNs is enabled. That support can be enabled +with the GCC option @option{-fsignaling-nans}. +@end deftypevr + @w{IEEE 754} also allows for another unusual value: negative zero. This value is produced when you divide a positive number by negative infinity, or when a negative result is smaller than the limits of diff --git a/math/Makefile b/math/Makefile index 076fd34213..db6ea2932e 100644 --- a/math/Makefile +++ b/math/Makefile @@ -175,7 +175,8 @@ tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \ test-fesetexcept-traps test-fetestexceptflag test-femode \ test-femode-traps test-iszero-excess-precision \ test-iseqsig-excess-precision test-flt-eval-method \ - test-fp-ilogb-constants test-fp-llogb-constants $(tests-static) + test-fp-ilogb-constants test-fp-llogb-constants \ + test-fe-snans-always-signal $(tests-static) tests-static = test-fpucw-static test-fpucw-ieee-static \ test-signgam-uchar-static test-signgam-uchar-init-static \ test-signgam-uint-static test-signgam-uint-init-static \ @@ -290,6 +291,8 @@ CFLAGS-test-iszero-excess-precision.c = -fexcess-precision=standard CFLAGS-test-iseqsig-excess-precision.c = -fexcess-precision=standard CFLAGS-test-flt-eval-method.c = -fexcess-precision=standard +CFLAGS-test-fe-snans-always-signal.c = -fsignaling-nans + # The -lieee module sets the _LIB_VERSION_ switch to IEEE mode # for error handling in the -lm functions. install-lib += libieee.a diff --git a/math/fenv.h b/math/fenv.h index 9006aa2fff..f7834472d8 100644 --- a/math/fenv.h +++ b/math/fenv.h @@ -145,6 +145,14 @@ extern int fesetmode (const femode_t *__modep) __THROW; # include <bits/fenvinline.h> #endif +/* NaN support. */ + +#if (__GLIBC_USE (IEC_60559_BFP_EXT) \ + && defined FE_INVALID \ + && defined __SUPPORT_SNAN__) +# define FE_SNANS_ALWAYS_SIGNAL 1 +#endif + #ifdef __USE_GNU /* Enable individual exceptions. Will not enable more exceptions than diff --git a/math/test-fe-snans-always-signal.c b/math/test-fe-snans-always-signal.c new file mode 100644 index 0000000000..2459febd08 --- /dev/null +++ b/math/test-fe-snans-always-signal.c @@ -0,0 +1,38 @@ +/* Test FE_SNANS_ALWAYS_SIGNAL definition. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <fenv.h> + +#ifdef FE_INVALID +# ifndef FE_SNANS_ALWAYS_SIGNAL +# error "FE_SNANS_ALWAYS_SIGNAL not defined" +# endif +#else +# ifdef FE_SNANS_ALWAYS_SIGNAL +# error "FE_SNANS_ALWAYS_SIGNAL defined, but no FE_INVALID support" +# endif +#endif + +int +do_test (void) +{ + /* This is a compilation test. */ + return 0; +} + +#include <support/test-driver.c> |