bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'round' modules takes 3


From: Ben Pfaff
Subject: Re: 'round' modules takes 3
Date: Sat, 20 Oct 2007 13:06:47 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Bruno Haible <address@hidden> writes:

> In m4/round.m4, the test whether floor() is available without libm is useful
> for any uses of floor(). I'm therefore putting it into a separate module
> 'floor' which you can then depend on.

Thanks, done.

> In m4/roundf.m4 you need an AC_REQUIRE([gl_FUNC_FLOORF]), so that the
> determination of FLOORF_LIBM comes before it is used in the assignment to
> ROUNDF_LIBM, not afterwards. Likewise for m4/roundl.m4.

I am not sure about this.  gl_FUNC_FLOORF checks for floorf and
provides a substitute if it is not available.  But for roundf I
was planning to use the system floorf if it was available and, if
not, use the roundf implementation that does not need floorf.
Thus, gl_FUNC_FLOORF does more than what roundf needs.

> In tests/test-round2.c the include of <assert.h> is not necessary.

Actually, there is one assertion in there, to verify that DOUBLE
and DOUBLE_UINT are the same size.  But this can be done at
compile time, so I changed it to use the "verify" macro instead
(and added a dependency on verify to round{,f}-tests).

> tests/test-round2.c seems to have a tab/whitespace indentation problem.
> Apply sed -e 's,^        ,    ,'

Fixed.

I always have a hard time telling what people expect,
indentation-wise.  I now work with a group of anti-tab bigots and
another group of pro-tab bigots.  To please both groups, perhaps
I should write my code so that no line is ever indented past
column 6 ;-)

> In tests/test-round2.c, midbits is a constant. I would move it into the
> loop (also since it's confusingly named: lowbits is the low bits of
> janus.i. highbits is the high bits of janus.i. But the middle bits of janus.i
> are not midbits but either midbits or 0.)

OK, done.

>> my m4 code can use some looking over.
>
> I haven't looked over this part; I trust that you have looked at the
> expansion in the configure file.

Yes, I did.

I pushed this to the repository, after making the following
changes relative to the previous patch:

diff --git a/ChangeLog b/ChangeLog
index aa77450..c8f01a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2007-10-20  Ben Pfaff  <address@hidden>
+
+       * lib/math.in.h: Declare round, roundf, roundl if we are providing
+       implementations.
+       * m4/math_h.m4: New substitutions for round, roundf, roundl modules.
+       * lib/round.c: New file.
+       * lib/roundf.c: New file.
+       * lib/roundl.c: New file.
+       * m4/round.m4: New file.
+       * m4/roundf.m4: New file.
+       * m4/roundl.m4: New file.
+       * m4/check-libm-func-m4: New file.
+       * modules/math: Replace round, roundf, roundl related @VARS@ in
+       math.in.h.
+       * modules/round: New file.
+       * modules/round-tests: New file.
+       * modules/roundf: New file.
+       * modules/roundf-tests: New file.
+       * modules/roundl: New file.
+       * modules/roundl-tests: New file.
+       * tests/test-round1.c: New file.
+       * tests/test-round2.c: New file.
+       * tests/test-roundf1.c: New file.
+       * tests/test-roundf2.c: New file.
+       * tests/test-roundl.c: New file.
+       * doc/functions/round.texi: Mention round module.
+       * doc/functions/roundf.texi: Mention roundf module.
+       * doc/functions/roundl.texi: Mention roundl module.
+       * MODULES.html.sh: Mention new modules.
+
 2007-10-20  Jim Meyering  <address@hidden>
 
        * lib/xprintf.c: Include <config.h> unconditionally.
diff --git a/lib/round.c b/lib/round.c
index a9fd393..5758fb7 100644
--- a/lib/round.c
+++ b/lib/round.c
@@ -20,7 +20,7 @@
 
 #include <config.h>
 
-/* Specification.  */
+#include <float.h>
 #include <math.h>
 
 #ifdef USE_LONG_DOUBLE
diff --git a/m4/round.m4 b/m4/round.m4
index 4914aac..edd9e89 100644
--- a/m4/round.m4
+++ b/m4/round.m4
@@ -10,30 +10,6 @@ AC_DEFUN([gl_FUNC_ROUND],
   dnl Persuade glibc <math.h> to declare round().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   gl_CHECK_LIBM_FUNC([round], [x = round(x);], [], [
-    dnl Test whether floor() can be used without libm.
-    ROUND_LIBM=?
-    AC_TRY_LINK([
-       #ifndef __NO_MATH_INLINES
-       # define __NO_MATH_INLINES 1 /* for glibc */
-       #endif
-       #include <math.h>
-       double x;],
-      [x = floor(x);],
-      [ROUND_LIBM=])
-    if test "$ROUND_LIBM" = "?"; then
-      save_LIBS="$LIBS"
-      LIBS="$LIBS -lm"
-      AC_TRY_LINK([
-         #ifndef __NO_MATH_INLINES
-         # define __NO_MATH_INLINES 1 /* for glibc */
-         #endif
-         #include <math.h>
-         double x;],
-        [x = floor(x);],
-        [ROUND_LIBM="-lm"])
-      LIBS="$save_LIBS"
-    fi
-    if test "$ROUND_LIBM" = "?"; then
-      ROUND_LIBM=
-    fi
+    AC_REQUIRE([gl_FUNC_FLOOR])
+    ROUND_LIBM=$FLOOR_LIBM
     AC_LIBOBJ([round])])])
diff --git a/modules/round b/modules/round
index 4bb01a9..0dd2526 100644
--- a/modules/round
+++ b/modules/round
@@ -8,6 +8,7 @@ m4/round.m4
 
 Depends-on:
 float
+floor
 math
 extensions
 
diff --git a/modules/round-tests b/modules/round-tests
index 2ba583e..d061431 100644
--- a/modules/round-tests
+++ b/modules/round-tests
@@ -7,6 +7,7 @@ isnan-nolibm
 stdbool
 stdint
 fprintf-posix
+verify
 
 configure.ac:
 
diff --git a/modules/roundf-tests b/modules/roundf-tests
index 8f9ef53..9fc69eb 100644
--- a/modules/roundf-tests
+++ b/modules/roundf-tests
@@ -8,6 +8,7 @@ isnanf-nolibm
 stdbool
 stdint
 fprintf-posix
+verify
 
 configure.ac:
 
diff --git a/tests/test-round2.c b/tests/test-round2.c
index 9c07a5f..1da0d9f 100644
--- a/tests/test-round2.c
+++ b/tests/test-round2.c
@@ -25,15 +25,15 @@
 #define FLOOR_FREE_ROUND round_reference2
 #include "round.c"
 
-#include <assert.h>
 #include <math.h>
-
 #include <float.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "verify.h"
+
 #ifdef USE_LONG_DOUBLE
 # error Long double not supported.
 #elif ! defined USE_FLOAT
@@ -63,7 +63,7 @@ equal (const char *message, DOUBLE x, DOUBLE y0, DOUBLE y1)
   else 
     {
       fprintf (stderr, "%s: "FUNCTION"(%g(%a)) = %g(%a) or %g(%a)?\n",
-               message, x, x, y0, y0, y1, y1);
+              message, x, x, y0, y0, y1, y1);
       return false;
     }
 }
@@ -87,21 +87,22 @@ check (DOUBLE x)
 int
 main (void)
 {
-  DOUBLE_UINT highbits, lowbits, midbits;
+  DOUBLE_UINT highbits, lowbits;
   int error = 0;
-  midbits = ((DOUBLE_UINT) -1) >> (NUM_LOWBITS + NUM_HIGHBITS) << NUM_LOWBITS;
   for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++)
     for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++)
       {
        /* Combine highbits and lowbits into a floating-point number,
-          sign-extending the lowbits to DOUBLE_BITS-NUM_HIGHBITS bits.  */
+          sign-extending the lowbits to DOUBLE_BITS-NUM_HIGHBITS bits.  */
        union { DOUBLE f; DOUBLE_UINT i; } janus;
-        assert (sizeof janus.f == sizeof janus.i);
-        janus.i = lowbits | (highbits << (DOUBLE_BITS - NUM_HIGHBITS));
-        if (lowbits >> (NUM_LOWBITS - 1))
-          janus.i |= midbits;
+       verify (sizeof janus.f == sizeof janus.i);
+       janus.i = lowbits | (highbits << (DOUBLE_BITS - NUM_HIGHBITS));
+       if (lowbits >> (NUM_LOWBITS - 1))
+         janus.i |= ((DOUBLE_UINT) -1
+                     >> (NUM_LOWBITS + NUM_HIGHBITS)
+                     << NUM_LOWBITS);
        if (!check (janus.f))
-          error = true;
+         error = true;
       }
   return (error ? 1 : 0);
 }

-- 
Ben Pfaff 
http://benpfaff.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]