* lib/fenv.in.h (fetestexceptflag): New declaration.
* lib/fenv-except-state-test.c: New file, based on glibc.
* m4/fenv-exceptions-state-c23.m4: New file.
* modules/fenv-exceptions-state-c23: New file.
* doc/posix-functions/fetestexceptflag.texi: Mention the new module.
+2023-10-30 Bruno Haible <bruno@clisp.org>
+
+ fenv-exceptions-state-c23: New module.
+ * lib/fenv.in.h (fetestexceptflag): New declaration.
+ * lib/fenv-except-state-test.c: New file, based on glibc.
+ * m4/fenv-exceptions-state-c23.m4: New file.
+ * modules/fenv-exceptions-state-c23: New file.
+ * doc/posix-functions/fetestexceptflag.texi: Mention the new module.
+
2023-10-30 Bruno Haible <bruno@clisp.org>
fenv-exceptions-state-c99: Add tests.
fenv-exceptions-state-c99: New module.
* lib/fenv.in.h (fegetexceptflag, fesetexceptflag): New declarations.
- * lib/fenv-except-state-get.c: New file, baed on glibc.
- * lib/fenv-except-state-set.c: New file, baed on glibc.
+ * lib/fenv-except-state-get.c: New file, based on glibc.
+ * lib/fenv-except-state-set.c: New file, based on glibc.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fexcept_t *' type.
* m4/fenv-exceptions-state.m4: New file.
* modules/fenv-exceptions-state-c99: New file.
@url{https://www.gnu.org/software/libc/manual/html_node/Status-bit-operations.html}.
@end ifnotinfo
-Gnulib module: ---
+Gnulib module: fenv-exceptions-state-c23
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on all non-glibc platforms:
+glibc 2.24, macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on all non-glibc platforms:
-glibc 2.24, macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
@end itemize
--- /dev/null
+/* Functions for saving the floating-point exception status flags.
+ Copyright (C) 1997-2023 Free Software Foundation, Inc.
+
+ This file 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.
+
+ This file 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 this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Based on glibc/math/fetestexceptflag.c
+ together with glibc/sysdeps/<cpu>/{fpu_control.h,fenv_private.h,fenv_libc.h}. */
+
+#include <config.h>
+
+/* Specification. */
+#include <fenv.h>
+
+#if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __aarch64__ /* arm64 */
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned long flags = (unsigned long) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __arm__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __alpha
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned long flags = (unsigned long) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __hppa
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __ia64__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned long flags = (unsigned long) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __m68k__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __mips__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __loongarch__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __powerpc__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __riscv
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __s390__ || defined __s390x__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __sh__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned int flags = (unsigned int) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __sparc
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ unsigned long flags = (unsigned long) *saved_flags;
+ return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#else
+
+# if defined __GNUC__ || defined __clang__
+# warning "Unknown CPU / architecture. Please report your platform and compiler to <bug-gnulib@gnu.org>."
+# endif
+# define NEED_FALLBACK 1
+
+#endif
+
+#if NEED_FALLBACK
+
+/* A dummy fallback. */
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+ return 0;
+}
+
+#endif
_GL_CXXALIASWARN (fesetexceptflag);
#endif
+/* Added in ISO C 23 ยง 7.6.4 Floating-point exceptions. */
+
+#if @GNULIB_FETESTEXCEPTFLAG@
+/* Copies the flags denoted by EXCEPTIONS from *SAVED_FLAGS to the
+ floating-point exception status flags. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fetestexceptflag
+# define fetestexceptflag rpl_fetestexceptflag
+# endif
+_GL_FUNCDECL_RPL (fetestexceptflag, int,
+ (fexcept_t const *saved_flags, int exceptions));
+_GL_CXXALIAS_RPL (fetestexceptflag, int,
+ (fexcept_t const *saved_flags, int exceptions));
+# else
+# if !@HAVE_FETESTEXCEPTFLAG@
+_GL_FUNCDECL_SYS (fetestexceptflag, int,
+ (fexcept_t const *saved_flags, int exceptions));
+# endif
+_GL_CXXALIAS_SYS (fetestexceptflag, int,
+ (fexcept_t const *saved_flags, int exceptions));
+# endif
+_GL_CXXALIASWARN (fetestexceptflag);
+#elif defined GNULIB_POSIXCHECK
+# undef fetestexceptflag
+# if HAVE_RAW_DECL_FETESTEXCEPTFLAG
+_GL_WARN_ON_USE (fetestexceptflag, "fetestexceptflag is unportable - "
+ "use gnulib module fenv-exceptions-state-c23 for portability");
+# endif
+#endif
+
#endif /* _@GUARD_PREFIX@_FENV_H */
#endif /* _@GUARD_PREFIX@_FENV_H */
--- /dev/null
+# fenv-exceptions-state-c23.m4 serial 1
+dnl Copyright (C) 2023 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FENV_EXCEPTIONS_STATE_C23],
+[
+ AC_REQUIRE([gl_FENV_H_DEFAULTS])
+
+ gl_MATHFUNC([fetestexceptflag], [int], [(fexcept_t const *, int)],
+ [#include <fenv.h>
+ fexcept_t fx_ret;
+ ])
+ if test $gl_cv_func_fetestexceptflag_no_libm != yes \
+ && test $gl_cv_func_fetestexceptflag_in_libm != yes; then
+ HAVE_FETESTEXCEPTFLAG=0
+ fi
+])
--- /dev/null
+Description:
+Functions for saving the floating-point exception status flags:
+fegetexceptflag, fesetexceptflag, fetestexceptflag.
+
+Files:
+lib/fenv-except-state-test.c
+m4/fenv-exceptions-state-c23.m4
+m4/mathfunc.m4
+
+Depends-on:
+fenv
+fenv-exceptions-state-c99
+
+configure.ac:
+gl_FENV_EXCEPTIONS_STATE_C23
+gl_CONDITIONAL([GL_COND_OBJ_FENV_EXCEPTIONS_STATE_C23],
+ [test $HAVE_FETESTEXCEPTFLAG = 0])
+gl_FENV_MODULE_INDICATOR([fetestexceptflag])
+
+Makefile.am:
+if GL_COND_OBJ_FENV_EXCEPTIONS_STATE_C23
+lib_SOURCES += fenv-except-state-test.c
+endif
+
+Include:
+#include <fenv.h>
+
+Link:
+$(FENV_EXCEPTIONS_STATE_LIBM)
+
+License:
+LGPLv2+
+
+Maintainer:
+all