]> Savannah Git Hosting - gnulib.git/commitdiff
getpayloadf: Add tests.
authorBruno Haible <bruno@clisp.org>
Wed, 17 Apr 2024 09:03:53 +0000 (11:03 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 17 Apr 2024 13:39:05 +0000 (15:39 +0200)
* tests/test-getpayloadf.c: New file.
* modules/getpayloadf-tests: New file.

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

index 6f97325216594f4372627344e00ac89d0c5285b6..863442a26343fe92080438fb3cc1fd59b0035a70 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-04-17  Bruno Haible  <bruno@clisp.org>
 
+       getpayloadf: Add tests.
+       * tests/test-getpayloadf.c: New file.
+       * modules/getpayloadf-tests: New file.
+
        getpayloadf: New module.
        * lib/math.in.h (getpayloadf): New declaration.
        * lib/getpayloadf.c: New file.
diff --git a/modules/getpayloadf-tests b/modules/getpayloadf-tests
new file mode 100644 (file)
index 0000000..1901fc4
--- /dev/null
@@ -0,0 +1,18 @@
+Files:
+tests/test-getpayloadf.c
+tests/minus-zero.h
+tests/infinity.h
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+setpayloadf
+setpayloadsigf
+signed-snan
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-getpayloadf
+check_PROGRAMS += test-getpayloadf
+test_getpayloadf_LDADD = $(LDADD) @GETPAYLOADF_LIBM@ $(SETPAYLOADF_LIBM) $(SETPAYLOADSIGF_LIBM)
diff --git a/tests/test-getpayloadf.c b/tests/test-getpayloadf.c
new file mode 100644 (file)
index 0000000..f0ec047
--- /dev/null
@@ -0,0 +1,112 @@
+/* Test getpayloadf.
+   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 (getpayloadf, float, (const float *));
+
+#include "minus-zero.h"
+#include "infinity.h"
+#include "signed-snan.h"
+#include "macros.h"
+
+#define PAYLOAD_BITS (24 - 2) /* = (FLT_MANT_DIG - 2) */
+
+int
+main ()
+{
+  float arg;
+  float ret;
+
+  /* Test non-NaN arguments.  */
+
+  arg = 2.718281828459045f;
+  ret = getpayloadf (&arg);
+  ASSERT (ret == -1.0f);
+
+  arg = -3.141592653589793f;
+  ret = getpayloadf (&arg);
+  ASSERT (ret == -1.0f);
+
+  arg = 0.0f;
+  ret = getpayloadf (&arg);
+  ASSERT (ret == -1.0f);
+
+  arg = minus_zerof;
+  ret = getpayloadf (&arg);
+  ASSERT (ret == -1.0f);
+
+  arg = Infinityf ();
+  ret = getpayloadf (&arg);
+  ASSERT (ret == -1.0f);
+
+  arg = - Infinityf ();
+  ret = getpayloadf (&arg);
+  ASSERT (ret == -1.0f);
+
+  /* Test quiet NaNs.  */
+  {
+    int i;
+    float p;
+
+    for (i = 0, p = 1.0f; i < PAYLOAD_BITS; i++, p *= 2.0f)
+      {
+        ASSERT (setpayloadf (&arg, p) == 0);
+        ret = getpayloadf (&arg);
+        ASSERT (ret == p);
+        /* Test quiet NaNs with sign bit == 1.  */
+        arg = - arg;
+        ret = getpayloadf (&arg);
+        ASSERT (ret == p);
+      }
+
+    p = 2300902.0f;
+    ASSERT (setpayloadf (&arg, p) == 0);
+    ret = getpayloadf (&arg);
+    ASSERT (ret == p);
+  }
+
+  /* Test signalling NaNs.  */
+  {
+    int i;
+    float p;
+
+    for (i = 0, p = 1.0f; i < PAYLOAD_BITS; i++, p *= 2.0f)
+      {
+        ASSERT (setpayloadsigf (&arg, p) == 0);
+        ret = getpayloadf (&arg);
+        ASSERT (ret == p);
+      }
+
+    p = 2300902.0f;
+    ASSERT (setpayloadsigf (&arg, p) == 0);
+    ret = getpayloadf (&arg);
+    ASSERT (ret == p);
+
+    /* Test signalling NaNs with sign bit == 1.  */
+    memory_float pos_arg = memory_positive_SNaNf ();
+    memory_float neg_arg = memory_negative_SNaNf ();
+    float pos_ret = getpayloadf (&pos_arg.value);
+    float neg_ret = getpayloadf (&neg_arg.value);
+    ASSERT (neg_ret == pos_ret);
+  }
+
+  return 0;
+}