Skip to content

Commit

Permalink
Work on check-macos (macOS 12).
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaible committed May 21, 2024
1 parent 2663e24 commit 4d7ce24
Showing 1 changed file with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
From 5565c1835060bb5b347bc37d0602a5155fb8f521 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Tue, 21 May 2024 00:33:55 +0200
Subject: [PATCH] vasnprintf: Don't abort for pseudo-denormal arguments on
macOS 12.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reported by Gaëtan Herfray <g.herfray@gahfy.io> via Erik Blake in
<https://lists.gnu.org/archive/html/bug-m4/2022-03/msg00002.html>
<https://lists.gnu.org/archive/html/bug-gnulib/2022-03/msg00066.html>.

* lib/vasnprintf.c (floorlog10l): On ia64, x86_64, i386, handle
pseudo-denormals without calling frexpl.
---
ChangeLog | 9 +++++++++
lib/vasnprintf.c | 23 +++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 6f06273081..026af60e2a 100644
index 6f06273081..1f28f92fb7 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -86,7 +86,7 @@
Expand All @@ -31,7 +11,35 @@ index 6f06273081..026af60e2a 100644
#if HAVE_NL_LANGINFO
# include <langinfo.h>
#endif
@@ -1445,7 +1445,26 @@ floorlog10l (long double x)
@@ -1018,7 +1018,26 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
if (m.limbs == NULL)
return NULL;
/* Split into exponential part and mantissa. */
- y = frexpl (x, &exp);
+# if LDBL_MANT_DIG == 64 && (defined __ia64 || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+ /* Don't assume that frexpl can handle pseudo-denormals; it does not on
+ macOS 12/x86_64. Therefore test for a pseudo-denormal explicitly. */
+ union
+ {
+ long double value;
+ struct { unsigned int mant_word[2]; unsigned short sign_exp_word; } r;
+ }
+ u;
+ u.value = x;
+ if (u.r.sign_exp_word == 0 && (u.r.mant_word[1] & 0x80000000u) != 0)
+ {
+ /* Pseudo-Denormal. */
+ exp = LDBL_MIN_EXP;
+ u.r.sign_exp_word = 1 - LDBL_MIN_EXP;
+ y = u.value;
+ }
+ else
+# endif
+ y = frexpl (x, &exp);
if (!(y >= 0.0L && y < 1.0L))
abort ();
/* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * 2^LDBL_MANT_BIT), and the
@@ -1445,7 +1464,26 @@ floorlog10l (long double x)
double l;

/* Split into exponential part and mantissa. */
Expand Down Expand Up @@ -59,6 +67,3 @@ index 6f06273081..026af60e2a 100644
if (!(y >= 0.0L && y < 1.0L))
abort ();
if (y == 0.0L)
--
2.34.1

0 comments on commit 4d7ce24

Please sign in to comment.