]> Savannah Git Hosting - gnulib.git/commitdiff
setpayloadf: New module.
authorBruno Haible <bruno@clisp.org>
Tue, 16 Apr 2024 12:39:16 +0000 (14:39 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 16 Apr 2024 14:21:07 +0000 (16:21 +0200)
* lib/math.in.h (setpayloadf): New declaration.
* lib/setpayloadf.c: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether setpayloadf is declared.
(gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_SETPAYLOADF.
(gl_MATH_H_DEFAULTS): Initialize HAVE_SETPAYLOADF.
* modules/math (Makefile.am): Substitute GNULIB_SETPAYLOADF,
HAVE_SETPAYLOADF.
* modules/setpayloadf: New file.
* doc/posix-functions/setpayloadf.texi: Mention the new module.

ChangeLog
doc/posix-functions/setpayloadf.texi
lib/math.in.h
lib/setpayloadf.c [new file with mode: 0644]
m4/math_h.m4
modules/math
modules/setpayloadf [new file with mode: 0644]

index 97d8a3d64f7af9dfdfcdebc6a657334ae719eadc..9640eb8ef1a376f86f721029a8bd7a029a70ed6f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-04-16  Bruno Haible  <bruno@clisp.org>
+
+       setpayloadf: New module.
+       * lib/math.in.h (setpayloadf): New declaration.
+       * lib/setpayloadf.c: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether setpayloadf is declared.
+       (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_SETPAYLOADF.
+       (gl_MATH_H_DEFAULTS): Initialize HAVE_SETPAYLOADF.
+       * modules/math (Makefile.am): Substitute GNULIB_SETPAYLOADF,
+       HAVE_SETPAYLOADF.
+       * modules/setpayloadf: New file.
+       * doc/posix-functions/setpayloadf.texi: Mention the new module.
+
 2024-04-16  Bruno Haible  <bruno@clisp.org>
 
        setpayload: Add tests.
index c225c1b1f456750478958e3a6ee09f7d6772ac66..05616f9d4116db449e756d087fe7d3b5a776279b 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @url{https://www.gnu.org/software/libc/manual/html_node/FP-Bit-Twiddling.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: setpayloadf
 
 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
index 3a2fb5cde7739493c7fa9240c2282092f24d2a7e..1fd41c27223b2f740017039d370efb7eff28d603 100644 (file)
@@ -2774,6 +2774,20 @@ _GL_WARN_REAL_FLOATING_DECL (signbit);
 #endif
 
 
+#if @GNULIB_SETPAYLOADF@
+# if !@HAVE_SETPAYLOADF@
+_GL_FUNCDECL_SYS (setpayloadf, int, (float *, float));
+# endif
+_GL_CXXALIAS_SYS (setpayloadf, int, (float *, float));
+_GL_CXXALIASWARN (setpayloadf);
+#elif defined GNULIB_POSIXCHECK
+# undef setpayloadf
+# if HAVE_RAW_DECL_SETPAYLOADF
+_GL_WARN_ON_USE (setpayloadf, "setpayloadf is unportable - "
+                 "use gnulib module setpayloadf for portability");
+# endif
+#endif
+
 #if @GNULIB_SETPAYLOAD@
 # if !@HAVE_SETPAYLOAD@
 _GL_FUNCDECL_SYS (setpayload, int, (double *, double));
diff --git a/lib/setpayloadf.c b/lib/setpayloadf.c
new file mode 100644 (file)
index 0000000..1f02bc4
--- /dev/null
@@ -0,0 +1,59 @@
+/* Construct a quiet 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 "signed-nan.h"
+
+int
+setpayloadf (float *result, float payload)
+{
+#if FLT_MANT_DIG == 24
+  if (
+# if defined __hppa || defined __mips__ || defined __sh__
+      /* A zero payload is not allowed, because that would denote Infinity.
+         Cf. snan.h.  */
+      payload > 0.0f
+# else
+      payload >= 0.0f
+# endif
+      && payload < 4194304.0f /* (float) (1U << (FLT_MANT_DIG - 2)) */
+      && payload == (float) (int32_t) payload)
+    {
+      union { uint32_t i; float f; } x;
+      x.f = positive_NaNf ();
+      x.i = (x.i & ~(((uint32_t) 1 << (FLT_MANT_DIG - 2)) - 1))
+            | (int32_t) payload;
+      *result = x.f;
+      return 0;
+    }
+  else
+    {
+      *result = 0.0f;
+      return -1;
+    }
+#else
+# error "Please port gnulib setpayloadf.c to your platform!"
+#endif
+}
index 2fa5d9fb28856ed6f93bad0953b866af20d8dd26..ee32128089f71314abb62b7e8faf9a60b3b76813 100644 (file)
@@ -1,5 +1,5 @@
 # math_h.m4
-# serial 127
+# serial 128
 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,
@@ -51,7 +51,7 @@ AC_DEFUN_ONCE([gl_MATH_H],
      modf modff modfl powf
      remainder remainderf remainderl
      rint rintf rintl round roundf roundl
-     setpayload
+     setpayload setpayloadf
      sinf sinl sinhf sqrtf sqrtl
      tanf tanl tanhf totalorder totalorderf totalorderl trunc truncf truncl])
 ])
@@ -160,6 +160,7 @@ AC_DEFUN([gl_MATH_H_REQUIRE_DEFAULTS],
     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_SETPAYLOADF])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGNBIT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINF])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINL])
@@ -243,6 +244,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_RINT=1;                      AC_SUBST([HAVE_RINT])
   HAVE_RINTL=1;                     AC_SUBST([HAVE_RINTL])
   HAVE_SETPAYLOAD=1;                AC_SUBST([HAVE_SETPAYLOAD])
+  HAVE_SETPAYLOADF=1;               AC_SUBST([HAVE_SETPAYLOADF])
   HAVE_SINF=1;                      AC_SUBST([HAVE_SINF])
   HAVE_SINL=1;                      AC_SUBST([HAVE_SINL])
   HAVE_SINHF=1;                     AC_SUBST([HAVE_SINHF])
index 8f61f70ae1c1d3062d6e8714025c8d750ba0f40d..f0233b94c4cffd686160aa49c7a5bac048f643d5 100644 (file)
@@ -121,6 +121,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \
              -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \
              -e 's/@''GNULIB_SETPAYLOAD''@/$(GNULIB_SETPAYLOAD)/g' \
+             -e 's/@''GNULIB_SETPAYLOADF''@/$(GNULIB_SETPAYLOADF)/g' \
              -e 's/@''GNULIB_SIGNBIT''@/$(GNULIB_SIGNBIT)/g' \
              -e 's/@''GNULIB_SINF''@/$(GNULIB_SINF)/g' \
              -e 's/@''GNULIB_SINL''@/$(GNULIB_SINL)/g' \
@@ -197,6 +198,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \
              -e 's|@''HAVE_RINTL''@|$(HAVE_RINTL)|g' \
              -e 's|@''HAVE_SETPAYLOAD''@|$(HAVE_SETPAYLOAD)|g' \
+             -e 's|@''HAVE_SETPAYLOADF''@|$(HAVE_SETPAYLOADF)|g' \
              -e 's|@''HAVE_SINF''@|$(HAVE_SINF)|g' \
              -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \
              -e 's|@''HAVE_SINHF''@|$(HAVE_SINHF)|g' \
diff --git a/modules/setpayloadf b/modules/setpayloadf
new file mode 100644 (file)
index 0000000..05856e6
--- /dev/null
@@ -0,0 +1,36 @@
+Description:
+setpayloadf function: construct a quiet NaN with a given payload
+
+Files:
+lib/setpayloadf.c
+m4/mathfunc.m4
+m4/setpayload.m4
+
+Depends-on:
+math
+extensions
+float           [test $HAVE_SETPAYLOADF = 0]
+stdint          [test $HAVE_SETPAYLOADF = 0]
+signed-nan      [test $HAVE_SETPAYLOADF = 0]
+
+configure.ac:
+gl_FUNC_SETPAYLOADF
+gl_CONDITIONAL([GL_COND_OBJ_SETPAYLOADF], [test $HAVE_SETPAYLOADF = 0])
+gl_MATH_MODULE_INDICATOR([setpayloadf])
+
+Makefile.am:
+if GL_COND_OBJ_SETPAYLOADF
+lib_SOURCES += setpayloadf.c
+endif
+
+Include:
+<math.h>
+
+Link:
+$(SETPAYLOADF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+all