public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] newlib: switch to autoconf long double wider macro
@ 2022-01-21  5:04 Mike Frysinger
  2022-01-21 11:27 ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2022-01-21  5:04 UTC (permalink / raw)
  To: newlib

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] newlib: switch to autoconf long double wider macro
  2022-01-21  5:04 [PATCH] newlib: switch to autoconf long double wider macro Mike Frysinger
@ 2022-01-21 11:27 ` Corinna Vinschen
  2022-01-21 12:39   ` Mike Frysinger
  0 siblings, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2022-01-21 11:27 UTC (permalink / raw)
  To: newlib

On Jan 21 00:04, Mike Frysinger wrote:
> 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(-)

Looks right to me, please push.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] newlib: switch to autoconf long double wider macro
  2022-01-21 11:27 ` Corinna Vinschen
@ 2022-01-21 12:39   ` Mike Frysinger
  2022-01-21 13:27     ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2022-01-21 12:39 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]

On 21 Jan 2022 12:27, Corinna Vinschen wrote:
> On Jan 21 00:04, Mike Frysinger wrote:
> > 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(-)
> 
> Looks right to me, please push.

for posterity, i'll note that autoconf uses a different (more comprehensive)
testing method that ultimately arrives at a diff answer than what newlib is
atm.  for aarch64, _LDBL_EQ_DBL is now defined when it wasn't before.

newlib today is doing:
#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

while autoconf is doing:
       (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
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] newlib: switch to autoconf long double wider macro
  2022-01-21 12:39   ` Mike Frysinger
@ 2022-01-21 13:27     ` Corinna Vinschen
       [not found]       ` <DM3P110MB0522CE6B7AE8122C7172E18A9A5B9@DM3P110MB0522.NAMP110.PROD.OUTLOOK.COM>
  0 siblings, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2022-01-21 13:27 UTC (permalink / raw)
  To: newlib

On Jan 21 07:39, Mike Frysinger wrote:
> On 21 Jan 2022 12:27, Corinna Vinschen wrote:
> > On Jan 21 00:04, Mike Frysinger wrote:
> > > 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(-)
> > 
> > Looks right to me, please push.
> 
> for posterity, i'll note that autoconf uses a different (more comprehensive)
> testing method that ultimately arrives at a diff answer than what newlib is
> atm.  for aarch64, _LDBL_EQ_DBL is now defined when it wasn't before.
> 
> newlib today is doing:
> #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
> 
> while autoconf is doing:
>        (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
> -mike

Erm... that's kind of weird.  The newlib expression doesn't look wrong.

So, out of curiosity of somebody not being familiar with aarch64,
why is that?


Corinna


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] newlib: switch to autoconf long double wider macro
       [not found]       ` <DM3P110MB0522CE6B7AE8122C7172E18A9A5B9@DM3P110MB0522.NAMP110.PROD.OUTLOOK.COM>
@ 2022-01-21 17:03         ` C Howland
  2022-01-21 22:44           ` Mike Frysinger
  0 siblings, 1 reply; 7+ messages in thread
From: C Howland @ 2022-01-21 17:03 UTC (permalink / raw)
  To: newlib

> ------------------------------
> *From:* Newlib <newlib-bounces+craig.howland=caci.com@sourceware.org> on
> behalf of Corinna Vinschen <vinschen@redhat.com>
> *Sent:* Friday, January 21, 2022 8:27 AM
> *To:* newlib@sourceware.org <newlib@sourceware.org>
> *Subject:* Re: [PATCH] newlib: switch to autoconf long double wider macro
>
>
>
> On Jan 21 07:39, Mike Frysinger wrote:
> > On 21 Jan 2022 12:27, Corinna Vinschen wrote:
> > > On Jan 21 00:04, Mike Frysinger wrote:
> > > > 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(-)
> > >
> > > Looks right to me, please push.
> >
> > for posterity, i'll note that autoconf uses a different (more
> comprehensive)
> > testing method that ultimately arrives at a diff answer than what newlib
> is
> > atm.  for aarch64, _LDBL_EQ_DBL is now defined when it wasn't before.
> >
> > newlib today is doing:
> > #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
> >
> > while autoconf is doing:
> >        (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
> > -mike
>
> Erm... that's kind of weird.  The newlib expression doesn't look wrong.
>
> So, out of curiosity of somebody not being familiar with aarch64,
> why is that?
>
>
> Corinna
>
>
>
Major problem, as that result is wrong, as they are definitely not equal:
$ aarch64-none-elf-cpp -dM null.c | grep DBL | sort
#define __DBL_DECIMAL_DIG__ 17
#define __DBL_DENORM_MIN__
((double)4.94065645841246544176568792868221372e-324L)
#define __DBL_DIG__ 15
#define __DBL_EPSILON__ ((double)2.22044604925031308084726333618164062e-16L)
#define __DBL_HAS_DENORM__ 1
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __DBL_MANT_DIG__ 53
#define __DBL_MAX_10_EXP__ 308
#define __DBL_MAX__ ((double)1.79769313486231570814527423731704357e+308L)
#define __DBL_MAX_EXP__ 1024
#define __DBL_MIN_10_EXP__ (-307)
#define __DBL_MIN__ ((double)2.22507385850720138309023271733240406e-308L)
#define __DBL_MIN_EXP__ (-1021)
#define __DBL_NORM_MAX__
((double)1.79769313486231570814527423731704357e+308L)
#define __LDBL_DECIMAL_DIG__ 36
#define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
#define __LDBL_DIG__ 33
#define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L
#define __LDBL_HAS_DENORM__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __LDBL_HAS_QUIET_NAN__ 1
#define __LDBL_MANT_DIG__ 113
#define __LDBL_MAX_10_EXP__ 4932
#define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L
#define __LDBL_MAX_EXP__ 16384
#define __LDBL_MIN_10_EXP__ (-4931)
#define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
#define __LDBL_MIN_EXP__ (-16381)
#define __LDBL_NORM_MAX__ 1.18973149535723176508575932662800702e+4932L

     I am confused by the patch.  The opening statement says "Now that we
require a recent version of autoconf, we can rely on this macro existing."
But then it proceeds to define a test for it.  If it already exists, why is
a test being defined?  (Or is it just meaning to say that there is now, all
this time later, a macro name that has become a de-facto standard to use?)
     And a question about the test.  There are two main segments in it:

+           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;
+}

What's the first part doing?  Only the second part (main) is performing the
size comparison.
     Lastly, I tried this check with my GCC 10.2.0 aarch64 and it does
compile.  (I hand-made a file to test.  I did not make a configure file to
run.)  I then changed the test_array definition to make it compare LDBL
against LDBL (to force them to be equal) and the compilation does fail, as
expected.  So then what's going on that for Mike aarch64 _LDBL_EQ_DBL is
now defined when it wasn't before?  The answer cannot be both different and
also still correct.  It is critical that _LDBL_EQ_DBL only be defined when
they are indeed the same size, as that gates using the double routines as
being long double.
     Now a secondary item:  the (int) LDBL_EPSILON == 0 term in the check
is degenerate and does nothing.  (By rule (from the standard) the cast to
int discards the fraction so it will always be 0 and it becomes ... && 1.)
   (In a minor quibble I have to disagree with the statement that the new
check is more comprehensive.  In a rough way of looking at it they are both
checking 3 values.  But as noted the one term in the new check does
nothing, so it really is only checking 2 values.  I actually made the
original check and had a positive reason for checking both min and max
exponent--although at the moment I'm not remembering what that reason was.)
                                          Craig

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] newlib: switch to autoconf long double wider macro
  2022-01-21 17:03         ` C Howland
@ 2022-01-21 22:44           ` Mike Frysinger
  2022-06-22  2:52             ` Paul Eggert
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2022-01-21 22:44 UTC (permalink / raw)
  To: C Howland; +Cc: newlib, Paul Eggert

[-- Attachment #1: Type: text/plain, Size: 6455 bytes --]

On 21 Jan 2022 12:03, C Howland wrote:
> > On Jan 21 07:39, Mike Frysinger wrote:
> > > On 21 Jan 2022 12:27, Corinna Vinschen wrote:
> > > > On Jan 21 00:04, Mike Frysinger wrote:
> > > > > 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.
> > > >
> > > > Looks right to me, please push.
> > >
> > > for posterity, i'll note that autoconf uses a different (more
> > comprehensive)
> > > testing method that ultimately arrives at a diff answer than what newlib
> > is
> > > atm.  for aarch64, _LDBL_EQ_DBL is now defined when it wasn't before.
> > >
> > > newlib today is doing:
> > > #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
> > >
> > > while autoconf is doing:
> > >        (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
> >
> > Erm... that's kind of weird.  The newlib expression doesn't look wrong.
> >
> > So, out of curiosity of somebody not being familiar with aarch64,
> > why is that?
> 
> Major problem, as that result is wrong, as they are definitely not equal:
> $ aarch64-none-elf-cpp -dM null.c | grep DBL | sort
> #define __DBL_DECIMAL_DIG__ 17
> #define __DBL_DENORM_MIN__
> ((double)4.94065645841246544176568792868221372e-324L)
> #define __DBL_DIG__ 15
> #define __DBL_EPSILON__ ((double)2.22044604925031308084726333618164062e-16L)
> #define __DBL_HAS_DENORM__ 1
> #define __DBL_HAS_INFINITY__ 1
> #define __DBL_HAS_QUIET_NAN__ 1
> #define __DBL_MANT_DIG__ 53
> #define __DBL_MAX_10_EXP__ 308
> #define __DBL_MAX__ ((double)1.79769313486231570814527423731704357e+308L)
> #define __DBL_MAX_EXP__ 1024
> #define __DBL_MIN_10_EXP__ (-307)
> #define __DBL_MIN__ ((double)2.22507385850720138309023271733240406e-308L)
> #define __DBL_MIN_EXP__ (-1021)
> #define __DBL_NORM_MAX__
> ((double)1.79769313486231570814527423731704357e+308L)
> #define __LDBL_DECIMAL_DIG__ 36
> #define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
> #define __LDBL_DIG__ 33
> #define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L
> #define __LDBL_HAS_DENORM__ 1
> #define __LDBL_HAS_INFINITY__ 1
> #define __LDBL_HAS_QUIET_NAN__ 1
> #define __LDBL_MANT_DIG__ 113
> #define __LDBL_MAX_10_EXP__ 4932
> #define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L
> #define __LDBL_MAX_EXP__ 16384
> #define __LDBL_MIN_10_EXP__ (-4931)
> #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
> #define __LDBL_MIN_EXP__ (-16381)
> #define __LDBL_NORM_MAX__ 1.18973149535723176508575932662800702e+4932L
> 
>      I am confused by the patch.  The opening statement says "Now that we
> require a recent version of autoconf, we can rely on this macro existing."
> But then it proceeds to define a test for it.  If it already exists, why is
> a test being defined?  (Or is it just meaning to say that there is now, all
> this time later, a macro name that has become a de-facto standard to use?)

i don't know what test you're talking about.  the configure.ac just calls the
autoconf macro directly.  it isn't doing it conditionally.  the autoconf macro
is supposed to be testing the same thing we're testing.

>      And a question about the test.  There are two main segments in it:
> 
> +           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;
> +}
> 
> What's the first part doing?  Only the second part (main) is performing the
> size comparison.
>      Lastly, I tried this check with my GCC 10.2.0 aarch64 and it does
> compile.  (I hand-made a file to test.  I did not make a configure file to
> run.)  I then changed the test_array definition to make it compare LDBL
> against LDBL (to force them to be equal) and the compilation does fail, as
> expected.  So then what's going on that for Mike aarch64 _LDBL_EQ_DBL is
> now defined when it wasn't before?  The answer cannot be both different and
> also still correct.  It is critical that _LDBL_EQ_DBL only be defined when
> they are indeed the same size, as that gates using the double routines as
> being long double.
>      Now a secondary item:  the (int) LDBL_EPSILON == 0 term in the check
> is degenerate and does nothing.  (By rule (from the standard) the cast to
> int discards the fraction so it will always be 0 and it becomes ... && 1.)
>    (In a minor quibble I have to disagree with the statement that the new
> check is more comprehensive.  In a rough way of looking at it they are both
> checking 3 values.  But as noted the one term in the new check does
> nothing, so it really is only checking 2 values.  I actually made the
> original check and had a positive reason for checking both min and max
> exponent--although at the moment I'm not remembering what that reason was.)

to be clear, this code is all from autoconf.  questions about it would be best
answered by the authors/maintainers of it.  if there is a problem, it affects
many more projects than newlib.

autoconf used to have the same (or pretty close) test as newlib before it was
changed to what it is now back in 2004.
http://git.savannah.gnu.org/cgit/autoconf.git/commit/?h=9a76187b8c387598f63a9349a281d8b70963654e

let's loop in Paul.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] newlib: switch to autoconf long double wider macro
  2022-01-21 22:44           ` Mike Frysinger
@ 2022-06-22  2:52             ` Paul Eggert
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Eggert @ 2022-06-22  2:52 UTC (permalink / raw)
  To: C Howland; +Cc: newlib

On 1/21/22 16:44, Mike Frysinger wrote:
> On 21 Jan 2022 12:03, C Howland wrote:
> And a question about the test. There are two main segments in it:
>> +           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;
>> +}
>>
>> What's the first part doing?  Only the second part (main) is performing the
>> size comparison.

The first part is making sure you can use macros like DBL_MIN where 
constant expressions are required. Some old nonstandard compilers don't 
support that.


>>       Now a secondary item:  the (int) LDBL_EPSILON == 0 term in the check
>> is degenerate and does nothing.  (By rule (from the standard) the cast to
>> int discards the fraction so it will always be 0 and it becomes ... && 1.)


That's true on standard compilers. But there may be old nonstandard 
compilers where (int) LDBL_EPSILON == 0 is not an integer constant 
expression, and that part detects the bug in those compilers.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-22  2:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21  5:04 [PATCH] newlib: switch to autoconf long double wider macro Mike Frysinger
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

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).