Just like we have a module for signed quiet NaNs, let me introduce a module
for signed signalling NaNs. So that we can test signed signalling NaNs as
arguments of various functions.


2023-10-13  Bruno Haible  <br...@clisp.org>

        tests: Make use of signed signalling NaNs.
        * tests/test-signbit.c: Include signed-snan.h instead of snan.h.
        (test_signbitf): Test positive_SNaNf, negative_SNaNf, instead of only
        SNaNf.
        (test_signbitd): Test positive_SNaNd, negative_SNaNd, instead of only
        SNaNd.
        (test_signbitl): Test positive_SNaNl, negative_SNaNl, instead of only
        SNaNl.
        * tests/test-stdio.c: Include signed-snan.h instead of snan.h.
        (main): Test positive_SNaNd, negative_SNaNd, instead of only SNaNd.
        Also, test positive_NaNd, negative_NaNd, instead of NaNd.
        * modules/signbit-tests (Depends-on): Add signed-snan. Remove snan.
        * modules/stdio-tests (Depends-on): Likewise.

2023-10-13  Bruno Haible  <br...@clisp.org>

        signed-snan: New module.
        * lib/snan.h (construct_SNaNf): New function, extracted from SNaNf.
        (SNaNf): Use it.
        (construct_SNaNd): New function, extracted from SNaNd.
        (SNaNd): Use it.
        (construct_SNaNl): New function, extracted from SNaNl.
        (SNaNl): Use it.
        * lib/signed-snan.h: New file.
        * modules/signed-snan: New file.

2023-10-13  Bruno Haible  <br...@clisp.org>

        signed-nan: New module, renamed from qnan.
        * lib/signed-nan.h: Renamed from lib/qnan.h. Update double-inclusion
        guard.
        * modules/signed-nan: Renamed from modules/qnan. Update.
        * tests/test-signbit.c: Update.
        * tests/test-stdio.c: Likewise.
        * tests/test-totalorder.c: Likewise.
        * modules/*-tests: Update.

>From 80f9860e2631345d5e0078f184307dbd6bdf905b Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 13 Oct 2023 13:05:06 +0200
Subject: [PATCH 1/3] signed-nan: New module, renamed from qnan.

* lib/signed-nan.h: Renamed from lib/qnan.h. Update double-inclusion
guard.
* modules/signed-nan: Renamed from modules/qnan. Update.
* tests/test-signbit.c: Update.
* tests/test-stdio.c: Likewise.
* tests/test-totalorder.c: Likewise.
* modules/*-tests: Update.
---
 ChangeLog                    | 11 +++++++++++
 lib/{qnan.h => signed-nan.h} |  6 +++---
 modules/signbit-tests        |  2 +-
 modules/{qnan => signed-nan} |  6 +++---
 modules/stdio-tests          |  2 +-
 modules/totalorder-tests     |  2 +-
 modules/totalorderf-tests    |  2 +-
 modules/totalorderl-tests    |  2 +-
 tests/test-signbit.c         |  2 +-
 tests/test-stdio.c           |  2 +-
 tests/test-totalorder.c      |  2 +-
 11 files changed, 25 insertions(+), 14 deletions(-)
 rename lib/{qnan.h => signed-nan.h} (97%)
 rename modules/{qnan => signed-nan} (71%)

diff --git a/ChangeLog b/ChangeLog
index 0a4be95ecf..7a06938f21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-10-13  Bruno Haible  <br...@clisp.org>
+
+	signed-nan: New module, renamed from qnan.
+	* lib/signed-nan.h: Renamed from lib/qnan.h. Update double-inclusion
+	guard.
+	* modules/signed-nan: Renamed from modules/qnan. Update.
+	* tests/test-signbit.c: Update.
+	* tests/test-stdio.c: Likewise.
+	* tests/test-totalorder.c: Likewise.
+	* modules/*-tests: Update.
+
 2023-10-13  Bruno Haible  <br...@clisp.org>
 
 	access: Fix test failure on native Windows.
diff --git a/lib/qnan.h b/lib/signed-nan.h
similarity index 97%
rename from lib/qnan.h
rename to lib/signed-nan.h
index e6538c227e..1018b58cd0 100644
--- a/lib/qnan.h
+++ b/lib/signed-nan.h
@@ -14,8 +14,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
-#ifndef _QNAN_H
-#define _QNAN_H
+#ifndef _SIGNED_NAN_H
+#define _SIGNED_NAN_H
 
 #include <math.h>
 
@@ -85,4 +85,4 @@ negative_NaNl ()
 }
 
 
-#endif /* _QNAN_H */
+#endif /* _SIGNED_NAN_H */
diff --git a/modules/signbit-tests b/modules/signbit-tests
index c491d7c885..20b18efdf0 100644
--- a/modules/signbit-tests
+++ b/modules/signbit-tests
@@ -6,7 +6,7 @@ tests/macros.h
 
 Depends-on:
 float
-qnan
+signed-nan
 snan
 
 configure.ac:
diff --git a/modules/qnan b/modules/signed-nan
similarity index 71%
rename from modules/qnan
rename to modules/signed-nan
index fd3cbb5097..f544a6c58c 100644
--- a/modules/qnan
+++ b/modules/signed-nan
@@ -2,7 +2,7 @@ Description:
 Macros for quiet not-a-number.
 
 Files:
-lib/qnan.h
+lib/signed-nan.h
 
 Depends-on:
 nan
@@ -11,10 +11,10 @@ signbit
 configure.ac:
 
 Makefile.am:
-lib_SOURCES += qnan.h
+lib_SOURCES += signed-nan.h
 
 Include:
-"qnan.h"
+"signed-nan.h"
 
 Link:
 
diff --git a/modules/stdio-tests b/modules/stdio-tests
index 5f94d3961d..a24433f511 100644
--- a/modules/stdio-tests
+++ b/modules/stdio-tests
@@ -5,7 +5,7 @@ m4/exponentd.m4
 
 Depends-on:
 assert-h
-qnan
+signed-nan
 snan
 stdio-c++-tests
 fgetc-tests
diff --git a/modules/totalorder-tests b/modules/totalorder-tests
index 5ff4c752f0..3741b88d4c 100644
--- a/modules/totalorder-tests
+++ b/modules/totalorder-tests
@@ -5,7 +5,7 @@ tests/infinity.h
 tests/macros.h
 
 Depends-on:
-qnan
+signed-nan
 
 configure.ac:
 
diff --git a/modules/totalorderf-tests b/modules/totalorderf-tests
index 7e2e7938f6..f2801f496f 100644
--- a/modules/totalorderf-tests
+++ b/modules/totalorderf-tests
@@ -6,7 +6,7 @@ tests/infinity.h
 tests/macros.h
 
 Depends-on:
-qnan
+signed-nan
 
 configure.ac:
 
diff --git a/modules/totalorderl-tests b/modules/totalorderl-tests
index 1b6ca5200f..fa25c3e301 100644
--- a/modules/totalorderl-tests
+++ b/modules/totalorderl-tests
@@ -6,7 +6,7 @@ tests/infinity.h
 tests/macros.h
 
 Depends-on:
-qnan
+signed-nan
 
 configure.ac:
 
diff --git a/tests/test-signbit.c b/tests/test-signbit.c
index f89fdf6d05..35b845c6c3 100644
--- a/tests/test-signbit.c
+++ b/tests/test-signbit.c
@@ -30,7 +30,7 @@
 
 #include "minus-zero.h"
 #include "infinity.h"
-#include "qnan.h"
+#include "signed-nan.h"
 #include "snan.h"
 #include "macros.h"
 
diff --git a/tests/test-stdio.c b/tests/test-stdio.c
index cc44250150..6bd100edae 100644
--- a/tests/test-stdio.c
+++ b/tests/test-stdio.c
@@ -39,7 +39,7 @@ va_list t5;
 
 #include <string.h>
 
-#include "qnan.h"
+#include "signed-nan.h"
 #include "snan.h"
 #include "macros.h"
 
diff --git a/tests/test-totalorder.c b/tests/test-totalorder.c
index b63c7c2211..af903c68b5 100644
--- a/tests/test-totalorder.c
+++ b/tests/test-totalorder.c
@@ -21,7 +21,7 @@
 #include "infinity.h"
 #include "macros.h"
 #include "minus-zero.h"
-#include "qnan.h"
+#include "signed-nan.h"
 
 #ifndef TOTALORDER
 # define TOTALORDER totalorder
-- 
2.34.1

>From 2f364b8ddc6729cb93f550cbcb33e50292bb4aef Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 13 Oct 2023 13:46:17 +0200
Subject: [PATCH 2/3] signed-snan: New module.

* lib/snan.h (construct_SNaNf): New function, extracted from SNaNf.
(SNaNf): Use it.
(construct_SNaNd): New function, extracted from SNaNd.
(SNaNd): Use it.
(construct_SNaNl): New function, extracted from SNaNl.
(SNaNl): Use it.
* lib/signed-snan.h: New file.
* modules/signed-snan: New file.
---
 ChangeLog           | 12 +++++++
 lib/signed-snan.h   | 81 +++++++++++++++++++++++++++++++++++++++++++++
 lib/snan.h          | 36 +++++++++++++++-----
 modules/signed-snan | 25 ++++++++++++++
 4 files changed, 145 insertions(+), 9 deletions(-)
 create mode 100644 lib/signed-snan.h
 create mode 100644 modules/signed-snan

diff --git a/ChangeLog b/ChangeLog
index 7a06938f21..710636aff6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2023-10-13  Bruno Haible  <br...@clisp.org>
+
+	signed-snan: New module.
+	* lib/snan.h (construct_SNaNf): New function, extracted from SNaNf.
+	(SNaNf): Use it.
+	(construct_SNaNd): New function, extracted from SNaNd.
+	(SNaNd): Use it.
+	(construct_SNaNl): New function, extracted from SNaNl.
+	(SNaNl): Use it.
+	* lib/signed-snan.h: New file.
+	* modules/signed-snan: New file.
+
 2023-10-13  Bruno Haible  <br...@clisp.org>
 
 	signed-nan: New module, renamed from qnan.
diff --git a/lib/signed-snan.h b/lib/signed-snan.h
new file mode 100644
index 0000000000..f275467567
--- /dev/null
+++ b/lib/signed-snan.h
@@ -0,0 +1,81 @@
+/* Macros for signalling not-a-number.
+   Copyright (C) 2023 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/>.  */
+
+#ifndef _SIGNED_SNAN_H
+#define _SIGNED_SNAN_H
+
+#include "signed-nan.h"
+#include "snan.h"
+
+
+#if HAVE_SNANF
+
+/* Returns a signalling 'float' NaN with sign bit == 0.  */
+_GL_UNUSED static float
+positive_SNaNf ()
+{
+  return construct_SNaNf (positive_NaNf ());
+}
+
+/* Returns a signalling 'float' NaN with sign bit == 1.  */
+_GL_UNUSED static float
+negative_SNaNf ()
+{
+  return construct_SNaNf (negative_NaNf ());
+}
+
+#endif
+
+
+#if HAVE_SNAND
+
+/* Returns a signalling 'double' NaN with sign bit == 0.  */
+_GL_UNUSED static double
+positive_SNaNd ()
+{
+  return construct_SNaNd (positive_NaNd ());
+}
+
+/* Returns a signalling 'double' NaN with sign bit == 1.  */
+_GL_UNUSED static double
+negative_SNaNd ()
+{
+  return construct_SNaNd (negative_NaNd ());
+}
+
+#endif
+
+
+#if HAVE_SNANL
+
+/* Returns a signalling 'long double' NaN with sign bit == 0.  */
+_GL_UNUSED static long double
+positive_SNaNl ()
+{
+  return construct_SNaNl (positive_NaNl ());
+}
+
+/* Returns a signalling 'long double' NaN with sign bit == 1.  */
+_GL_UNUSED static long double
+negative_SNaNl ()
+{
+  return construct_SNaNl (negative_NaNl ());
+}
+
+#endif
+
+
+#endif /* _SIGNED_SNAN_H */
diff --git a/lib/snan.h b/lib/snan.h
index 88950437c8..2e271055c5 100644
--- a/lib/snan.h
+++ b/lib/snan.h
@@ -45,15 +45,14 @@
 
 # define HAVE_SNANF 1
 
-/* Returns a signalling 'float' NaN.  */
 _GL_UNUSED static float
-SNaNf ()
+construct_SNaNf (float quiet_value)
 {
   #define NWORDS \
     ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
   typedef union { float value; unsigned int word[NWORDS]; } memory_float;
   memory_float m;
-  m.value = NaNf ();
+  m.value = quiet_value;
   /* Turn the quiet NaN into a signalling NaN.  */
   #if FLT_EXPBIT0_BIT > 0
     m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
@@ -70,6 +69,13 @@ SNaNf ()
   return m.value;
 }
 
+/* Returns a signalling 'float' NaN.  */
+_GL_UNUSED static float
+SNaNf ()
+{
+  return construct_SNaNf (NaNf ());
+}
+
 #endif
 
 
@@ -77,15 +83,14 @@ SNaNf ()
 
 # define HAVE_SNAND 1
 
-/* Returns a signalling 'double' NaN.  */
 _GL_UNUSED static double
-SNaNd ()
+construct_SNaNd (double quiet_value)
 {
   #define NWORDS \
     ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
   typedef union { double value; unsigned int word[NWORDS]; } memory_double;
   memory_double m;
-  m.value = NaNd ();
+  m.value = quiet_value;
   /* Turn the quiet NaN into a signalling NaN.  */
   #if DBL_EXPBIT0_BIT > 0
     m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
@@ -100,6 +105,13 @@ SNaNd ()
   return m.value;
 }
 
+/* Returns a signalling 'double' NaN.  */
+_GL_UNUSED static double
+SNaNd ()
+{
+  return construct_SNaNd (NaNd ());
+}
+
 #endif
 
 
@@ -107,9 +119,8 @@ SNaNd ()
 
 # define HAVE_SNANL 1
 
-/* Returns a signalling 'long double' NaN.  */
 _GL_UNUSED static long double
-SNaNl ()
+construct_SNaNl (long double quiet_value)
 {
   /* A bit pattern that is different from a Quiet NaN.  With a bit of luck,
      it's a Signalling NaN.  */
@@ -118,7 +129,7 @@ SNaNl ()
   typedef union { unsigned int word[NWORDS]; long double value; }
           memory_long_double;
   memory_long_double m;
-  m.value = NaNl ();
+  m.value = quiet_value;
   #if defined __powerpc__ && LDBL_MANT_DIG == 106
     /* This is PowerPC "double double", a pair of two doubles.  Inf and NaN are
        represented as the corresponding 64-bit IEEE values in the first double;
@@ -143,6 +154,13 @@ SNaNl ()
   return m.value;
 }
 
+/* Returns a signalling 'long double' NaN.  */
+_GL_UNUSED static long double
+SNaNl ()
+{
+  return construct_SNaNl (NaNl ());
+}
+
 #endif
 
 
diff --git a/modules/signed-snan b/modules/signed-snan
new file mode 100644
index 0000000000..492d817d48
--- /dev/null
+++ b/modules/signed-snan
@@ -0,0 +1,25 @@
+Description:
+Macros for signalling not-a-number.
+
+Files:
+lib/signed-snan.h
+
+Depends-on:
+signed-nan
+snan
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += signed-snan.h
+
+Include:
+"signed-snan.h"
+
+Link:
+
+License:
+GPL
+
+Maintainer:
+all
-- 
2.34.1

>From c10222bd07df5673683853f7058b72b97f6e2b96 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 13 Oct 2023 13:54:58 +0200
Subject: [PATCH 3/3] tests: Make use of signed signalling NaNs.

* tests/test-signbit.c: Include signed-snan.h instead of snan.h.
(test_signbitf): Test positive_SNaNf, negative_SNaNf, instead of only
SNaNf.
(test_signbitd): Test positive_SNaNd, negative_SNaNd, instead of only
SNaNd.
(test_signbitl): Test positive_SNaNl, negative_SNaNl, instead of only
SNaNl.
* tests/test-stdio.c: Include signed-snan.h instead of snan.h.
(main): Test positive_SNaNd, negative_SNaNd, instead of only SNaNd.
Also, test positive_NaNd, negative_NaNd, instead of NaNd.
* modules/signbit-tests (Depends-on): Add signed-snan. Remove snan.
* modules/stdio-tests (Depends-on): Likewise.
---
 ChangeLog             | 16 ++++++++++++++++
 modules/signbit-tests |  2 +-
 modules/stdio-tests   |  2 +-
 tests/test-signbit.c  | 11 +++++++----
 tests/test-stdio.c    | 17 ++++++++++++++---
 5 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 710636aff6..db88ac9554 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-10-13  Bruno Haible  <br...@clisp.org>
+
+	tests: Make use of signed signalling NaNs.
+	* tests/test-signbit.c: Include signed-snan.h instead of snan.h.
+	(test_signbitf): Test positive_SNaNf, negative_SNaNf, instead of only
+	SNaNf.
+	(test_signbitd): Test positive_SNaNd, negative_SNaNd, instead of only
+	SNaNd.
+	(test_signbitl): Test positive_SNaNl, negative_SNaNl, instead of only
+	SNaNl.
+	* tests/test-stdio.c: Include signed-snan.h instead of snan.h.
+	(main): Test positive_SNaNd, negative_SNaNd, instead of only SNaNd.
+	Also, test positive_NaNd, negative_NaNd, instead of NaNd.
+	* modules/signbit-tests (Depends-on): Add signed-snan. Remove snan.
+	* modules/stdio-tests (Depends-on): Likewise.
+
 2023-10-13  Bruno Haible  <br...@clisp.org>
 
 	signed-snan: New module.
diff --git a/modules/signbit-tests b/modules/signbit-tests
index 20b18efdf0..f540d949a5 100644
--- a/modules/signbit-tests
+++ b/modules/signbit-tests
@@ -7,7 +7,7 @@ tests/macros.h
 Depends-on:
 float
 signed-nan
-snan
+signed-snan
 
 configure.ac:
 
diff --git a/modules/stdio-tests b/modules/stdio-tests
index a24433f511..0e6d85593f 100644
--- a/modules/stdio-tests
+++ b/modules/stdio-tests
@@ -6,7 +6,7 @@ m4/exponentd.m4
 Depends-on:
 assert-h
 signed-nan
-snan
+signed-snan
 stdio-c++-tests
 fgetc-tests
 fputc-tests
diff --git a/tests/test-signbit.c b/tests/test-signbit.c
index 35b845c6c3..b68bbfa890 100644
--- a/tests/test-signbit.c
+++ b/tests/test-signbit.c
@@ -31,7 +31,7 @@
 #include "minus-zero.h"
 #include "infinity.h"
 #include "signed-nan.h"
-#include "snan.h"
+#include "signed-snan.h"
 #include "macros.h"
 
 float zerof = 0.0f;
@@ -62,7 +62,8 @@ test_signbitf ()
   ASSERT (signbit (negative_NaNf ()));
 #if HAVE_SNANF
   /* Signalling NaN.  */
-  (void) signbit (SNaNf ());
+  ASSERT (!signbit (positive_SNaNf ()));
+  ASSERT (signbit (negative_SNaNf ()));
 #endif
 }
 
@@ -90,7 +91,8 @@ test_signbitd ()
   ASSERT (signbit (negative_NaNd ()));
 #if HAVE_SNAND
   /* Signalling NaN.  */
-  (void) signbit (SNaNd ());
+  ASSERT (!signbit (positive_SNaNd ()));
+  ASSERT (signbit (negative_SNaNd ()));
 #endif
 }
 
@@ -118,7 +120,8 @@ test_signbitl ()
   ASSERT (signbit (negative_NaNl ()));
 #if HAVE_SNANL
   /* Signalling NaN.  */
-  (void) signbit (SNaNl ());
+  ASSERT (!signbit (positive_SNaNl ()));
+  ASSERT (signbit (negative_SNaNl ()));
 #endif
 }
 
diff --git a/tests/test-stdio.c b/tests/test-stdio.c
index 6bd100edae..2836ed18a5 100644
--- a/tests/test-stdio.c
+++ b/tests/test-stdio.c
@@ -40,7 +40,7 @@ va_list t5;
 #include <string.h>
 
 #include "signed-nan.h"
-#include "snan.h"
+#include "signed-snan.h"
 #include "macros.h"
 
 int
@@ -69,11 +69,22 @@ main (void)
     memory_double value2;
     char buf[64];
 
-    value1 = SNaNd();
+    value1 = positive_SNaNd();
     sprintf (buf, "%g", value1);
     ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
 
-    value2.value = NaNd ();
+    value1 = negative_SNaNd();
+    sprintf (buf, "%g", value1);
+    ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
+
+    value2.value = positive_NaNd ();
+    #if DBL_EXPBIT0_BIT == 20
+    value2.word[DBL_EXPBIT0_WORD] ^= 0x54321;
+    #endif
+    sprintf (buf, "%g", value2.value);
+    ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
+
+    value2.value = negative_NaNd ();
     #if DBL_EXPBIT0_BIT == 20
     value2.word[DBL_EXPBIT0_WORD] ^= 0x54321;
     #endif
-- 
2.34.1

Reply via email to