* lib/math.in.h (setpayload): New declaration.
* lib/setpayload.c: New file.
* m4/setpayload.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether setpayload is declared.
(gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_SETPAYLOAD.
(gl_MATH_H_DEFAULTS): Initialize HAVE_SETPAYLOAD.
* modules/math (Makefile.am): Substitute GNULIB_SETPAYLOAD,
HAVE_SETPAYLOAD.
* modules/setpayload: New file.
* doc/posix-functions/setpayload.texi: Mention the new module.
+2024-04-16 Bruno Haible <bruno@clisp.org>
+
+ setpayload: New module.
+ * lib/math.in.h (setpayload): New declaration.
+ * lib/setpayload.c: New file.
+ * m4/setpayload.m4: New file.
+ * m4/math_h.m4 (gl_MATH_H): Test whether setpayload is declared.
+ (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_SETPAYLOAD.
+ (gl_MATH_H_DEFAULTS): Initialize HAVE_SETPAYLOAD.
+ * modules/math (Makefile.am): Substitute GNULIB_SETPAYLOAD,
+ HAVE_SETPAYLOAD.
+ * modules/setpayload: New file.
+ * doc/posix-functions/setpayload.texi: Mention the new module.
+
2024-04-15 Collin Funk <collin.funk1@gmail.com>
gnulib-tool.py: Optimize directory creation.
@url{https://www.gnu.org/software/libc/manual/html_node/FP-Bit-Twiddling.html}.
@end ifnotinfo
-Gnulib module: ---
+Gnulib module: setpayload
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_SETPAYLOAD@
+# if !@HAVE_SETPAYLOAD@
+_GL_FUNCDECL_SYS (setpayload, int, (double *, double));
+# endif
+_GL_CXXALIAS_SYS (setpayload, int, (double *, double));
+_GL_CXXALIASWARN (setpayload);
+#elif defined GNULIB_POSIXCHECK
+# undef setpayload
+# if HAVE_RAW_DECL_SETPAYLOAD
+_GL_WARN_ON_USE (setpayload, "setpayload is unportable - "
+ "use gnulib module setpayload for portability");
+# endif
+#endif
+
+
#if @GNULIB_TOTALORDERF@
# if @REPLACE_TOTALORDERF@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# endif
#endif
+
_GL_INLINE_HEADER_END
#endif /* _@GUARD_PREFIX@_MATH_H */
--- /dev/null
+/* Construct a quiet NaN 'double' 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 "signed-nan.h"
+
+int
+setpayload (double *result, double payload)
+{
+#if DBL_MANT_DIG == 53
+ if (
+# if defined __hppa || defined __mips__ || defined __sh__
+ /* A zero payload is not allowed, because that would denote Infinity.
+ Cf. snan.h. */
+ payload > 0.0
+# else
+ payload >= 0.0
+# endif
+ && payload < 2251799813685248.0 /* (double) (1ULL << (DBL_MANT_DIG - 2)) */
+ && payload == (double) (int64_t) payload)
+ {
+ union { uint64_t i; double f; } x;
+ x.f = positive_NaNd ();
+ x.i = (x.i & ~(((uint64_t) 1 << (DBL_MANT_DIG - 2)) - 1))
+ | (int64_t) payload;
+ *result = x.f;
+ return 0;
+ }
+ else
+ {
+ *result = 0.0;
+ return -1;
+ }
+#else
+# error "Please port gnulib setpayload.c to your platform!"
+#endif
+}
# math_h.m4
-# serial 126
+# serial 127
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,
logb logbf logbl
modf modff modfl powf
remainder remainderf remainderl
- rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
+ rint rintf rintl round roundf roundl
+ setpayload
+ sinf sinl sinhf sqrtf sqrtl
tanf tanl tanhf totalorder totalorderf totalorderl trunc truncf truncl])
])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ROUND])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ROUNDF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ROUNDL])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETPAYLOAD])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGNBIT])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINL])
HAVE_REMAINDERF=1; AC_SUBST([HAVE_REMAINDERF])
HAVE_RINT=1; AC_SUBST([HAVE_RINT])
HAVE_RINTL=1; AC_SUBST([HAVE_RINTL])
+ HAVE_SETPAYLOAD=1; AC_SUBST([HAVE_SETPAYLOAD])
HAVE_SINF=1; AC_SUBST([HAVE_SINF])
HAVE_SINL=1; AC_SUBST([HAVE_SINL])
HAVE_SINHF=1; AC_SUBST([HAVE_SINHF])
--- /dev/null
+# setpayload.m4
+# serial 1
+dnl Copyright 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_SETPAYLOADF],
+[
+ AC_REQUIRE([gl_MATH_H_DEFAULTS])
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ gl_MATHFUNC([setpayloadf], [int], [(float *, float)])
+ if test $gl_cv_func_setpayloadf_no_libm != yes \
+ && test $gl_cv_func_setpayloadf_in_libm != yes; then
+ HAVE_SETPAYLOADF=0
+ fi
+ if test $HAVE_SETPAYLOADF = 0; then
+ SETPAYLOADF_LIBM=
+ fi
+ AC_SUBST([SETPAYLOADF_LIBM])
+])
+
+AC_DEFUN_ONCE([gl_FUNC_SETPAYLOAD],
+[
+ AC_REQUIRE([gl_MATH_H_DEFAULTS])
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ gl_MATHFUNC([setpayload], [int], [(double *, double)])
+ if test $gl_cv_func_setpayload_no_libm != yes \
+ && test $gl_cv_func_setpayload_in_libm != yes; then
+ HAVE_SETPAYLOAD=0
+ fi
+ if test $HAVE_SETPAYLOAD = 0; then
+ SETPAYLOAD_LIBM=
+ fi
+ AC_SUBST([SETPAYLOAD_LIBM])
+])
+
+AC_DEFUN([gl_FUNC_SETPAYLOADL],
+[
+ AC_REQUIRE([gl_MATH_H_DEFAULTS])
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+ AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+
+ gl_MATHFUNC([setpayloadl], [int], [(long double *, long double)])
+ if test $gl_cv_func_setpayloadl_no_libm != yes \
+ && test $gl_cv_func_setpayloadl_in_libm != yes; then
+ HAVE_SETPAYLOADL=0
+ fi
+ if test $HAVE_SETPAYLOADL = 0; then
+ dnl Find libraries needed to link lib/setpayloadl.c.
+ if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+ AC_REQUIRE([gl_FUNC_SETPAYLOAD])
+ SETPAYLOADL_LIBM="$SETPAYLOAD_LIBM"
+ else
+ SETPAYLOADL_LIBM=
+ fi
+ dnl Prerequisite of lib/setpayloadl.c.
+ gl_LONG_DOUBLE_EXPONENT_LOCATION
+ fi
+ AC_SUBST([SETPAYLOADL_LIBM])
+])
-e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \
-e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \
-e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \
+ -e 's/@''GNULIB_SETPAYLOAD''@/$(GNULIB_SETPAYLOAD)/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_REMAINDERF''@|$(HAVE_REMAINDERF)|g' \
-e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \
-e 's|@''HAVE_RINTL''@|$(HAVE_RINTL)|g' \
+ -e 's|@''HAVE_SETPAYLOAD''@|$(HAVE_SETPAYLOAD)|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:
+setpayload function: construct a quiet NaN with a given payload
+
+Files:
+lib/setpayload.c
+m4/mathfunc.m4
+m4/setpayload.m4
+
+Depends-on:
+math
+extensions
+float [test $HAVE_SETPAYLOAD = 0]
+stdint [test $HAVE_SETPAYLOAD = 0]
+signed-nan [test $HAVE_SETPAYLOAD = 0]
+
+configure.ac:
+gl_FUNC_SETPAYLOAD
+gl_CONDITIONAL([GL_COND_OBJ_SETPAYLOAD], [test $HAVE_SETPAYLOAD = 0])
+gl_MATH_MODULE_INDICATOR([setpayload])
+
+Makefile.am:
+if GL_COND_OBJ_SETPAYLOAD
+lib_SOURCES += setpayload.c
+endif
+
+Include:
+<math.h>
+
+Link:
+$(SETPAYLOAD_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+all