]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
setpayloadl: Add tests.
authorBruno Haible <bruno@clisp.org>
Tue, 16 Apr 2024 12:58:57 +0000 (14:58 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 16 Apr 2024 14:21:13 +0000 (16:21 +0200)
* tests/test-setpayloadl.c: New file.
* modules/setpayloadl-tests: New file.

ChangeLog
modules/setpayloadl-tests [new file with mode: 0644]
tests/test-setpayloadl.c [new file with mode: 0644]

index baa0043a46262ccf489cb35099cea9f80e4bdc1e..b14171a863d2bc5cf9338cf60e2831068613cdc2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-04-16  Bruno Haible  <bruno@clisp.org>
 
+       setpayloadl: Add tests.
+       * tests/test-setpayloadl.c: New file.
+       * modules/setpayloadl-tests: New file.
+
        setpayloadl: New module.
        * lib/math.in.h (setpayloadl): New declaration.
        * lib/setpayloadl.c: New file.
diff --git a/modules/setpayloadl-tests b/modules/setpayloadl-tests
new file mode 100644 (file)
index 0000000..3b05d04
--- /dev/null
@@ -0,0 +1,15 @@
+Files:
+tests/test-setpayloadl.c
+tests/infinity.h
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+isnanl-nolibm
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-setpayloadl
+check_PROGRAMS += test-setpayloadl
+test_setpayloadl_LDADD = $(LDADD) @SETPAYLOADL_LIBM@
diff --git a/tests/test-setpayloadl.c b/tests/test-setpayloadl.c
new file mode 100644 (file)
index 0000000..86139a5
--- /dev/null
@@ -0,0 +1,97 @@
+/* Test setpayloadl.
+   Copyright 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <math.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (setpayloadl, int, (long double *, long double));
+
+#include <float.h>
+
+#include "infinity.h"
+#include "isnanl-nolibm.h"
+#include "macros.h"
+
+#if defined __powerpc__ && LDBL_MANT_DIG == 106
+  /* This is PowerPC "double double", a pair of two doubles.  NaN is represented
+     as the corresponding 64-bit IEEE value in the first double; the second is
+     irrelevant and therefore does not contain a payload.  */
+# define PAYLOAD_BITS (DBL_MANT_DIG - 2)
+#else
+# define PAYLOAD_BITS (LDBL_MANT_DIG - 2)
+#endif
+
+int
+main ()
+{
+  int i;
+  long double p;
+
+  {
+    /* Test valid payloads.  */
+    for (i = 0, p = 1.0L; i < PAYLOAD_BITS; i++, p *= 2.0L)
+      {
+        int ret;
+        long double x;
+
+        ret = setpayloadl (&x, p);
+        ASSERT (ret == 0);
+        ASSERT (isnanl (x));
+      }
+    /* Test out-of-range payload.  */
+    int ret;
+    long double x;
+
+    ret = setpayloadl (&x, p);
+    ASSERT (ret != 0);
+    ASSERT (x == 0.0L);
+  }
+
+  /* Test infinite payload.  */
+  {
+    int ret;
+    long double x;
+
+    ret = setpayloadl (&x, Infinityl ());
+    ASSERT (ret != 0);
+    ASSERT (x == 0.0L);
+  }
+
+  /* Test negative payload.  */
+  {
+    int ret;
+    long double x;
+
+    ret = setpayloadl (&x, -1.0L);
+    ASSERT (ret != 0);
+    ASSERT (x == 0.0L);
+  }
+
+  /* Test fractional payload.  */
+  {
+    int ret;
+    long double x;
+
+    ret = setpayloadl (&x, 1.4L);
+    ASSERT (ret != 0);
+    ASSERT (x == 0.0L);
+  }
+
+  return 0;
+}