From 34b42dcea65e16a22255436b214d1fb2b4914b46 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 19 Jun 2024 02:58:34 +0200
Subject: [PATCH] copysignl tests: Avoid failure on Solaris 11.4.

* tests/test-copysignl.c: Include <float.h>.
(LDBL_BYTES): New macro.
(main): Use it instead of sizeof (long double).
* modules/copysignl-tests (Depends-on): Add float.
---
 ChangeLog               |  8 ++++++++
 modules/copysignl-tests |  1 +
 tests/test-copysignl.c  | 17 +++++++++++++----
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 330bf49b32..988f36b6fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-18  Bruno Haible  <bruno@clisp.org>
+
+	copysignl tests: Avoid failure on Solaris 11.4.
+	* tests/test-copysignl.c: Include <float.h>.
+	(LDBL_BYTES): New macro.
+	(main): Use it instead of sizeof (long double).
+	* modules/copysignl-tests (Depends-on): Add float.
+
 2024-06-18  Bruno Haible  <bruno@clisp.org>
 
 	mbsnlen: Add tests.
diff --git a/modules/copysignl-tests b/modules/copysignl-tests
index 1cb5f829aa..e3a5b79c96 100644
--- a/modules/copysignl-tests
+++ b/modules/copysignl-tests
@@ -5,6 +5,7 @@ tests/minus-zero.h
 tests/macros.h
 
 Depends-on:
+float
 
 configure.ac:
 
diff --git a/tests/test-copysignl.c b/tests/test-copysignl.c
index 8f5f188872..f17d045b40 100644
--- a/tests/test-copysignl.c
+++ b/tests/test-copysignl.c
@@ -26,6 +26,7 @@ SIGNATURE_CHECK (copysignl, long double, (long double, long double));
 #include "macros.h"
 #include "minus-zero.h"
 
+#include <float.h>
 #include <string.h>
 
 volatile long double x;
@@ -33,6 +34,14 @@ volatile long double y;
 long double z;
 long double zero = 0.0L;
 
+/* Number of bytes occupied by a 'long double' in memory.  */
+#if (defined __ia64 || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && LDBL_MANT_DIG == 64
+/* 'long double' is little-endian 80-bits "extended precision".  */
+# define LDBL_BYTES 10
+#else
+# define LDBL_BYTES sizeof (long double)
+#endif
+
 int
 main ()
 {
@@ -87,25 +96,25 @@ main ()
   y = 1.0L;
   z = copysignl (x, y);
   ASSERT (z == 0.0L);
-  ASSERT (memcmp (&z, &zero, sizeof z) == 0);
+  ASSERT (memcmp (&z, &zero, LDBL_BYTES) == 0);
 
   x = 0.0L;
   y = -1.0L;
   z = copysignl (x, y);
   ASSERT (z == 0.0L);
-  ASSERT (memcmp (&z, &zero, sizeof z) != 0);
+  ASSERT (memcmp (&z, &zero, LDBL_BYTES) != 0);
 
   x = minus_zerol;
   y = 1.0L;
   z = copysignl (x, y);
   ASSERT (z == 0.0L);
-  ASSERT (memcmp (&z, &zero, sizeof z) == 0);
+  ASSERT (memcmp (&z, &zero, LDBL_BYTES) == 0);
 
   x = minus_zerol;
   y = -1.0L;
   z = copysignl (x, y);
   ASSERT (z == 0.0L);
-  ASSERT (memcmp (&z, &zero, sizeof z) != 0);
+  ASSERT (memcmp (&z, &zero, LDBL_BYTES) != 0);
 
   return test_exit_status;
 }
-- 
2.39.5