public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: newlib@sourceware.org
Subject: [PATCH] newlib: switch to autoconf long double wider macro
Date: Fri, 21 Jan 2022 00:04:11 -0500	[thread overview]
Message-ID: <20220121050411.23094-1-vapier@gentoo.org> (raw)

Now that we require a recent version of autoconf, we can rely on this
macro existing.  It has inverted semantics from the existing test (it
looks for "is wider" instead of "is equal"), so we have to invert the
check when creating our _LDBL_EQ_DBL.
---
 newlib/configure    | 72 +++++++++++++++++++++++++++++----------------
 newlib/configure.ac | 22 ++------------
 newlib/newlib.hin   |  4 +++
 3 files changed, 53 insertions(+), 45 deletions(-)

diff --git a/newlib/configure b/newlib/configure
index 3d9427f6b592..c06805a3ef03 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -13379,37 +13379,59 @@ else
 fi
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether long double equals double" >&5
-$as_echo_n "checking whether long double equals double... " >&6; }
-if ${newlib_cv_ldbl_eq_dbl+:} false; then :
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long double with more range or precision than double" >&5
+$as_echo_n "checking for long double with more range or precision than double... " >&6; }
+if ${ac_cv_type_long_double_wider+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  cat > conftest.c <<EOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
 #include <float.h>
-#if DBL_MANT_DIG == LDBL_MANT_DIG  &&  LDBL_MIN_EXP == DBL_MIN_EXP  && \
-    LDBL_MAX_EXP == DBL_MAX_EXP
-  #define _LDBL_EQ_DBL
- #else
-  #error "LDBL != DBL"
-#endif
-EOF
-if { ac_try='${CC} $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c
-							1>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }
-then
-  newlib_cv_ldbl_eq_dbl=yes;
+	    long double const a[] =
+	      {
+		 0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON,
+		 LDBL_MIN, LDBL_MAX, LDBL_EPSILON
+	      };
+	    long double
+	    f (long double x)
+	    {
+	       return ((x + (unsigned long int) 10) * (-1 / x) + a[0]
+			+ (x ? f (x) : 'c'));
+	    }
+
+int
+main ()
+{
+static int test_array [1 - 2 * !((0 < ((DBL_MAX_EXP < LDBL_MAX_EXP)
+		   + (DBL_MANT_DIG < LDBL_MANT_DIG)
+		   - (LDBL_MAX_EXP < DBL_MAX_EXP)
+		   - (LDBL_MANT_DIG < DBL_MANT_DIG)))
+	    && (int) LDBL_EPSILON == 0
+	  )];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_type_long_double_wider=yes
 else
-  newlib_cv_ldbl_eq_dbl=no;
+  ac_cv_type_long_double_wider=no
 fi
-rm -f conftest*
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $newlib_cv_ldbl_eq_dbl" >&5
-$as_echo "$newlib_cv_ldbl_eq_dbl" >&6; }
-if test $newlib_cv_ldbl_eq_dbl = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_double_wider" >&5
+$as_echo "$ac_cv_type_long_double_wider" >&6; }
+  if test $ac_cv_type_long_double_wider = yes; then
+
+$as_echo "#define HAVE_LONG_DOUBLE_WIDER 1" >>confdefs.h
+
+  fi
+
+if test $ac_cv_type_long_double_wider = no; then
 
 $as_echo "#define _LDBL_EQ_DBL 1" >>confdefs.h
 
diff --git a/newlib/configure.ac b/newlib/configure.ac
index 3394e5c89b3c..5760f21844c2 100644
--- a/newlib/configure.ac
+++ b/newlib/configure.ac
@@ -694,26 +694,8 @@ if test $ac_cv_type_long_double = yes; then
 fi
 AM_CONDITIONAL(HAVE_LONG_DOUBLE, test x"$ac_cv_type_long_double" = x"yes")
 
-AC_CACHE_CHECK(whether long double equals double,
-	       newlib_cv_ldbl_eq_dbl, [dnl
-cat > conftest.c <<EOF
-#include <float.h>
-#if DBL_MANT_DIG == LDBL_MANT_DIG  &&  LDBL_MIN_EXP == DBL_MIN_EXP  && \
-    LDBL_MAX_EXP == DBL_MAX_EXP
-  #define _LDBL_EQ_DBL
- #else
-  #error "LDBL != DBL"
-#endif
-EOF
-if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c
-							1>&AS_MESSAGE_LOG_FD])
-then
-  newlib_cv_ldbl_eq_dbl=yes;
-else
-  newlib_cv_ldbl_eq_dbl=no;
-fi
-rm -f conftest*])
-if test $newlib_cv_ldbl_eq_dbl = yes; then
+AC_TYPE_LONG_DOUBLE_WIDER
+if test $ac_cv_type_long_double_wider = no; then
   AC_DEFINE(_LDBL_EQ_DBL, 1, [Define if the platform long double type is equal to double.])
 fi
 
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index feeb409bbeaf..d2c960dd2a42 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -17,6 +17,10 @@
 /* Define to 1 if the system has the type `long double'. */
 #undef HAVE_LONG_DOUBLE
 
+/* Define to 1 if the type `long double' works and has more range or precision
+   than `double'. */
+#undef HAVE_LONG_DOUBLE_WIDER
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
-- 
2.34.1


             reply	other threads:[~2022-01-21  5:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21  5:04 Mike Frysinger [this message]
2022-01-21 11:27 ` Corinna Vinschen
2022-01-21 12:39   ` Mike Frysinger
2022-01-21 13:27     ` Corinna Vinschen
     [not found]       ` <DM3P110MB0522CE6B7AE8122C7172E18A9A5B9@DM3P110MB0522.NAMP110.PROD.OUTLOOK.COM>
2022-01-21 17:03         ` C Howland
2022-01-21 22:44           ` Mike Frysinger
2022-06-22  2:52             ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220121050411.23094-1-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).