* lib/math.in.h (setpayloadsigf): New declaration.
* lib/setpayloadsigf.c: New file, based on lib/setpayloadf.c.
* m4/math_h.m4 (gl_MATH_H): Test whether setpayloadsigf is declared.
(gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_SETPAYLOADSIGF.
(gl_MATH_H_DEFAULTS): Initialize HAVE_SETPAYLOADSIGF.
* modules/math (Makefile.am): Substitute GNULIB_SETPAYLOADSIGF,
HAVE_SETPAYLOADSIGF.
* modules/setpayloadsigf: New file.
* doc/posix-functions/setpayloadsigf.texi: Mention the new module.
+2024-04-16 Bruno Haible <bruno@clisp.org>
+
+ setpayloadsigf: New module.
+ * lib/math.in.h (setpayloadsigf): New declaration.
+ * lib/setpayloadsigf.c: New file, based on lib/setpayloadf.c.
+ * m4/math_h.m4 (gl_MATH_H): Test whether setpayloadsigf is declared.
+ (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_SETPAYLOADSIGF.
+ (gl_MATH_H_DEFAULTS): Initialize HAVE_SETPAYLOADSIGF.
+ * modules/math (Makefile.am): Substitute GNULIB_SETPAYLOADSIGF,
+ HAVE_SETPAYLOADSIGF.
+ * modules/setpayloadsigf: New file.
+ * doc/posix-functions/setpayloadsigf.texi: Mention the new module.
+
2024-04-16 Bruno Haible <bruno@clisp.org>
setpayloadsig: Add tests.
@url{https://www.gnu.org/software/libc/manual/html_node/FP-Bit-Twiddling.html}.
@end ifnotinfo
-Gnulib module: ---
+Gnulib module: setpayloadsigf
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on all non-glibc platforms:
+glibc 2.24, macOS 11.1, FreeBSD 14.0, NetBSD 10.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 14.0, NetBSD 10.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
#endif
+#if @GNULIB_SETPAYLOADSIGF@
+# if !@HAVE_SETPAYLOADSIGF@
+_GL_FUNCDECL_SYS (setpayloadsigf, int, (float *, float));
+# endif
+_GL_CXXALIAS_SYS (setpayloadsigf, int, (float *, float));
+_GL_CXXALIASWARN (setpayloadsigf);
+#elif defined GNULIB_POSIXCHECK
+# undef setpayloadsigf
+# if HAVE_RAW_DECL_SETPAYLOADSIGF
+_GL_WARN_ON_USE (setpayloadsigf, "setpayloadsigf is unportable - "
+ "use gnulib module setpayloadsigf for portability");
+# endif
+#endif
+
#if @GNULIB_SETPAYLOADSIG@
# if !@HAVE_SETPAYLOADSIG@
_GL_FUNCDECL_SYS (setpayloadsig, int, (double *, double));
--- /dev/null
+/* Construct a signalling NaN 'float' with a given payload.
+ Copyright 2024 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 3 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/>. */
+
+/* Written by Bruno Haible. */
+
+#include <config.h>
+
+/* Specification. */
+#include <math.h>
+
+#include <float.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "signed-snan.h"
+
+int
+setpayloadsigf (float *result, float payload)
+{
+#if FLT_MANT_DIG == 24
+ if (
+# if defined __hppa || defined __mips__ || defined __sh__
+ payload >= 0.0f
+# else
+ /* A zero payload is not allowed, because that would denote Infinity.
+ Cf. snan.h. */
+ payload > 0.0f
+# endif
+ && payload < 4194304.0f /* (float) (1U << (FLT_MANT_DIG - 2)) */
+ && payload == (float) (int32_t) payload)
+ {
+ memory_float x = memory_positive_SNaNf ();
+ x.word[0] = (x.word[0] & ~((1U << (FLT_MANT_DIG - 2)) - 1))
+ | (int32_t) payload;
+# if 0
+ *result = x.value;
+# else
+ /* On 32-bit x86 processors, as well as on x86_64 processors with
+ CC="gcc -mfpmath=387", the evaluation of *x and *y above is done
+ through an 'flds' instruction, which converts a signalling NaN to
+ a quiet NaN. See
+ <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
+ for details. Use memcpy to avoid this. */
+ memcpy (result, &x.value, sizeof (float));
+# endif
+ return 0;
+ }
+ else
+ {
+ *result = 0.0f;
+ return -1;
+ }
+#else
+# error "Please port gnulib setpayloadsigf.c to your platform!"
+#endif
+}
# math_h.m4
-# serial 130
+# serial 131
dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
remainder remainderf remainderl
rint rintf rintl round roundf roundl
setpayload setpayloadf setpayloadl
- setpayloadsig
+ setpayloadsig setpayloadsigf
sinf sinl sinhf sqrtf sqrtl
tanf tanl tanhf totalorder totalorderf totalorderl trunc truncf truncl])
])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETPAYLOADF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETPAYLOADL])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETPAYLOADSIG])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETPAYLOADSIGF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGNBIT])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINL])
HAVE_SETPAYLOADF=1; AC_SUBST([HAVE_SETPAYLOADF])
HAVE_SETPAYLOADL=1; AC_SUBST([HAVE_SETPAYLOADL])
HAVE_SETPAYLOADSIG=1; AC_SUBST([HAVE_SETPAYLOADSIG])
+ HAVE_SETPAYLOADSIGF=1; AC_SUBST([HAVE_SETPAYLOADSIGF])
HAVE_SINF=1; AC_SUBST([HAVE_SINF])
HAVE_SINL=1; AC_SUBST([HAVE_SINL])
HAVE_SINHF=1; AC_SUBST([HAVE_SINHF])
-e 's/@''GNULIB_SETPAYLOADF''@/$(GNULIB_SETPAYLOADF)/g' \
-e 's/@''GNULIB_SETPAYLOADL''@/$(GNULIB_SETPAYLOADL)/g' \
-e 's/@''GNULIB_SETPAYLOADSIG''@/$(GNULIB_SETPAYLOADSIG)/g' \
+ -e 's/@''GNULIB_SETPAYLOADSIGF''@/$(GNULIB_SETPAYLOADSIGF)/g' \
-e 's/@''GNULIB_SIGNBIT''@/$(GNULIB_SIGNBIT)/g' \
-e 's/@''GNULIB_SINF''@/$(GNULIB_SINF)/g' \
-e 's/@''GNULIB_SINL''@/$(GNULIB_SINL)/g' \
-e 's|@''HAVE_SETPAYLOADF''@|$(HAVE_SETPAYLOADF)|g' \
-e 's|@''HAVE_SETPAYLOADL''@|$(HAVE_SETPAYLOADL)|g' \
-e 's|@''HAVE_SETPAYLOADSIG''@|$(HAVE_SETPAYLOADSIG)|g' \
+ -e 's|@''HAVE_SETPAYLOADSIGF''@|$(HAVE_SETPAYLOADSIGF)|g' \
-e 's|@''HAVE_SINF''@|$(HAVE_SINF)|g' \
-e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \
-e 's|@''HAVE_SINHF''@|$(HAVE_SINHF)|g' \
--- /dev/null
+Description:
+setpayloadsigf function: construct a signalling NaN with a given payload
+
+Files:
+lib/setpayloadsigf.c
+m4/mathfunc.m4
+m4/setpayloadsig.m4
+
+Depends-on:
+math
+extensions
+float [test $HAVE_SETPAYLOADSIGF = 0]
+stdint [test $HAVE_SETPAYLOADSIGF = 0]
+signed-snan [test $HAVE_SETPAYLOADSIGF = 0]
+
+configure.ac:
+gl_FUNC_SETPAYLOADSIGF
+gl_CONDITIONAL([GL_COND_OBJ_SETPAYLOADSIGF], [test $HAVE_SETPAYLOADSIGF = 0])
+gl_MATH_MODULE_INDICATOR([setpayloadsigf])
+
+Makefile.am:
+if GL_COND_OBJ_SETPAYLOADSIGF
+lib_SOURCES += setpayloadsigf.c
+endif
+
+Include:
+<math.h>
+
+Link:
+$(SETPAYLOADSIGF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+all