[Top][All Lists]
[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: |
Sun, 21 Oct 2007 18:27:21 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Bruno Haible <address@hidden> writes:
>> > 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.
>
> OK, I can provide a macro that just tests whether floorf() needs libm.
OK. For now, I have invented an m4 macro AC_CHECK_MATH_LIB for
testing whether a function or functions need -lm. It seems to
work pretty well.
> Compiling the roundf and roundl modules on HP-UX 11, with CC="cc -Ae -O",
> I see these failures:
Ouch. Thank you for reporting this. Now that I look over my own
m4 code a little more critically, I can see problems. So I
rewrote it in a fashion that make the operation a little more
obvious, and then I tested it by forcing failure of
AC_CHECK_DECLS, so that I could demonstrate that roundf and
roundl working properly in all three possible cases.
I tested that it works properly on HP-UX 11 now, with the default
C compiler, on td192.testdrive.hp.com.
I made these commits:
commit 7094a1e0d56aa303077cc0bccaa559a28e613ade
Author: Ben Pfaff <address@hidden>
Date: Sun Oct 21 17:28:32 2007 -0700
Fix bugs in round modules reported by Bruno Haible.
diff --git a/ChangeLog b/ChangeLog
index 37217c9..d9170af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-10-21 Ben Pfaff <address@hidden>
+
+ * m4/check-libm-func.m4: Removed.
+ * m4/check-math-lib.m4: New file.
+ * m4/round.m4: Rewrite to use gl_CHECK_MATH_LIB.
+ * m4/roundf.m4: Ditto, and fix lack of HAVE_DECL_ROUNDF
+ definition and lack of AC_LIBOBJ([roundf]).
+ * m4/roundl.m4: Ditto, and similarly for roundl.
+ * modules/round: Reference new m4 file.
+ * modules/roundf: Ditto.
+ * modules/roundl: Ditto.
+ * tests/test-round2.c (main): Use ROUND instead of round.
+ Bug report from Bruno Haible.
+
2007-10-21 Bruno Haible <address@hidden>
* lib/printf-parse.c: Don't assume <stdint.h> exists in IN_LIBASPRINTF
@@ -69,6 +83,7 @@
* doc/functions/roundf.texi: Mention roundf module.
* doc/functions/roundl.texi: Mention roundl module.
* MODULES.html.sh: Mention new modules.
+ Thanks to Bruno Haible for suggestions.
2007-10-20 Jim Meyering <address@hidden>
diff --git a/m4/check-libm-func.m4 b/m4/check-libm-func.m4
deleted file mode 100644
index e375558..0000000
--- a/m4/check-libm-func.m4
+++ /dev/null
@@ -1,51 +0,0 @@
-# check-libm.m4 serial 1
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-dnl
-dnl AC_CHECK_LIBM_FUNC (MATH_FUNCTION, INVOCATION,
-dnl [RUN-IF-FOUND], [RUN-IF-NOT-FOUND])
-dnl
-dnl Checks for a declaration of the given MATH_FUNCTION in <math.h>, and
-dnl substitutes HAVE_DECL_<func> accordingly. If a declaration is found,
-dnl determines the needed library (if any), assigns it to <func>_LIBM, and
-dnl executes RUN-IF-FOUND; otherwise, executes RUN-IF-NOT-FOUND.
-dnl
-dnl INVOCATION should be a C statement that invokes MATH_FUNCTION, both
-dnl using and assigning back to double variable 'x', e.g. "x = floor
-dnl (x);".
-AC_DEFUN([gl_CHECK_LIBM_FUNC],
-[
-m4_pushdef([FUNC_LIBM], m4_toupper([$1])[_LIBM])dnl
-m4_pushdef([HAVE_DECL_FUNC], HAVE_DECL_[]m4_toupper([$1]))dnl
- AC_CHECK_DECLS([$1], , , [#include <math.h>])
- if test "$ac_cv_have_decl_$1" = yes; then
- save_LIBS=$LIBS
- FUNC_LIBM=?
- for libm in "" "-lm"; do
- LIBS="$save_LIBS $libm"
- AC_TRY_LINK([
- #ifndef __NO_MATH_INLINES
- # define __NO_MATH_INLINES 1 /* for glibc */
- #endif
- #include <math.h>
- double x;],
- [$2],
- [FUNC_LIBM=$libm
-break])
- done
- LIBS=$save_LIBS
- if test "$FUNC_LIBM" = "?"; then
- FUNC_LIBM=
- fi
-m4_ifvaln([$3], [$3])dnl
- else
- HAVE_DECL_FUNC=
- FUNC_LIBM=
-m4_ifvaln([$4], [$4])dnl
- fi
- AC_SUBST(HAVE_DECL_FUNC)
- AC_SUBST(FUNC_LIBM)
-m4_popdef([FUNC_LIBM])
-m4_popdef([HAVE_DECL_FUNC])])
diff --git a/m4/check-math-lib.m4 b/m4/check-math-lib.m4
new file mode 100644
index 0000000..fb9cb94
--- /dev/null
+++ b/m4/check-math-lib.m4
@@ -0,0 +1,32 @@
+# check-math-lib.m4 serial 1
+dnl Copyright (C) 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl AC_CHECK_MATH_LIB (VARIABLE, EXPRESSION)
+dnl
+dnl Checks whether EXPRESSION requires -lm to compile and link. If so, sets
+dnl the shell VARIABLE to -lm, otherwise to the empty string.
+dnl
+dnl Example: AC_CHECK_MATH_LIB([ROUNDF_LIBM], [x = roundf (x);])
+AC_DEFUN([gl_CHECK_MATH_LIB], [
+ save_LIBS=$LIBS
+ $1=?
+ for libm in "" "-lm"; do
+ LIBS="$save_LIBS $libm"
+ AC_TRY_LINK([
+ #ifndef __NO_MATH_INLINES
+ # define __NO_MATH_INLINES 1 /* for glibc */
+ #endif
+ #include <math.h>
+ double x;],
+ [$2],
+ [$1=$libm
+break])
+ done
+ LIBS=$save_LIBS
+ if test "$$1" = "?"; then
+ $1=
+ fi
+])
diff --git a/m4/round.m4 b/m4/round.m4
index edd9e89..6e7e739 100644
--- a/m4/round.m4
+++ b/m4/round.m4
@@ -1,4 +1,4 @@
-# round.m4 serial 1
+# round.m4 serial 2
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -9,7 +9,13 @@ AC_DEFUN([gl_FUNC_ROUND],
AC_REQUIRE([gl_MATH_H_DEFAULTS])
dnl Persuade glibc <math.h> to declare round().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- gl_CHECK_LIBM_FUNC([round], [x = round(x);], [], [
- AC_REQUIRE([gl_FUNC_FLOOR])
- ROUND_LIBM=$FLOOR_LIBM
- AC_LIBOBJ([round])])])
+ AC_CHECK_DECLS([round], , , [#include <math.h>])
+ if test "$ac_cv_have_decl_round" = yes; then
+ gl_CHECK_MATH_LIB([ROUND_LIBM], [x = round (x);])
+ else
+ gl_CHECK_MATH_LIB([ROUND_LIBM], [x = floor (x) + ceil (x);])
+ HAVE_DECL_ROUND=0
+ AC_LIBOBJ([round])
+ fi
+ AC_SUBST([HAVE_DECL_ROUND])
+ AC_SUBST([ROUND_LIBM])])
diff --git a/m4/roundf.m4 b/m4/roundf.m4
index 57778a8..d1f4183 100644
--- a/m4/roundf.m4
+++ b/m4/roundf.m4
@@ -1,4 +1,4 @@
-# roundf.m4 serial 1
+# roundf.m4 serial 2
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -9,14 +9,20 @@ AC_DEFUN([gl_FUNC_ROUNDF],
AC_REQUIRE([gl_MATH_H_DEFAULTS])
dnl Persuade glibc <math.h> to declare roundf().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- dnl Test whether roundf() is declared.
- gl_CHECK_LIBM_FUNC([roundf], [x = roundf(x);], [], [
- dnl No. Are both floorf() and ceilf() available? If so then we can use
- dnl them to implement roundf(), on the assumption that they're fast.
- gl_CHECK_LIBM_FUNC([floorf], [x = floorf(x);], [
- AC_CHECK_DECL([ceilf],
- [dnl Yes. Both are declared. Link against the necessary library.
- ROUNDF_LIBM="$FLOORF_LIBM"],
- [: dnl No. We will use an implementation that doesn't need them.
-], [#include <math.h>
-])])])])
+ AC_CHECK_DECLS([roundf], , , [#include <math.h>])
+ if test "$ac_cv_have_decl_roundf" = yes; then
+ gl_CHECK_MATH_LIB([ROUNDF_LIBM], [x = roundf (x);])
+ else
+ AC_CHECK_DECLS([ceilf, floorf], , , [#include <math.h>])
+ if test "$ac_cv_have_decl_floorf" = yes &&
+ test "$ac_cv_have_decl_ceilf" = yes; then
+ gl_CHECK_MATH_LIB([ROUNDF_LIBM], [x = floorf (x) + ceilf (x);])
+ else
+ ROUNDF_LIBM=
+ fi
+ HAVE_DECL_ROUNDF=0
+ AC_LIBOBJ([roundf])
+ fi
+ AC_SUBST([HAVE_DECL_ROUNDF])
+ AC_SUBST([ROUNDF_LIBM])
+])
diff --git a/m4/roundl.m4 b/m4/roundl.m4
index 6bec36b..25ee1f8 100644
--- a/m4/roundl.m4
+++ b/m4/roundl.m4
@@ -1,4 +1,4 @@
-# roundl.m4 serial 1
+# roundl.m4 serial 2
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -9,14 +9,20 @@ AC_DEFUN([gl_FUNC_ROUNDL],
AC_REQUIRE([gl_MATH_H_DEFAULTS])
dnl Persuade glibc <math.h> to declare roundl().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- dnl Test whether roundl() is declared.
- gl_CHECK_LIBM_FUNC([roundl], [x = roundl(x);], [], [
- dnl No. Are both floorl() and ceill() available? If so then we can use
- dnl them to implement roundl(), on the assumption that they're fast.
- gl_CHECK_LIBM_FUNC([floorl], [x = floorl(x);], [
- AC_CHECK_DECL([ceill],
- [dnl Yes. Both are declared. Link against the necessary library.
- ROUNDL_LIBM="$FLOORL_LIBM"],
- [: dnl No. We will use an implementation that doesn't need them.
-], [#include <math.h>
-])])])])
+ AC_CHECK_DECLS([roundl], , , [#include <math.h>])
+ if test "$ac_cv_have_decl_roundl" = yes; then
+ gl_CHECK_MATH_LIB([ROUNDL_LIBM], [x = roundl (x);])
+ else
+ AC_CHECK_DECLS([ceill, floorl], , , [#include <math.h>])
+ if test "$ac_cv_have_decl_floorl" = yes &&
+ test "$ac_cv_have_decl_ceill" = yes; then
+ gl_CHECK_MATH_LIB([ROUNDL_LIBM], [x = floorl (x) + ceill (x);])
+ else
+ ROUNDL_LIBM=
+ fi
+ HAVE_DECL_ROUNDL=0
+ AC_LIBOBJ([roundl])
+ fi
+ AC_SUBST([HAVE_DECL_ROUNDL])
+ AC_SUBST([ROUNDL_LIBM])
+])
diff --git a/modules/round b/modules/round
index 0dd2526..7d1110f 100644
--- a/modules/round
+++ b/modules/round
@@ -3,7 +3,7 @@ round() function: round toward nearest, breaking ties away from
zero.
Files:
lib/round.c
-m4/check-libm-func.m4
+m4/check-math-lib.m4
m4/round.m4
Depends-on:
diff --git a/modules/roundf b/modules/roundf
index f24e347..d3098f7 100644
--- a/modules/roundf
+++ b/modules/roundf
@@ -4,7 +4,7 @@ roundf() function: round toward nearest, breaking ties away
from zero.
Files:
lib/round.c
lib/roundf.c
-m4/check-libm-func.m4
+m4/check-math-lib.m4
m4/roundf.m4
Depends-on:
diff --git a/modules/roundl b/modules/roundl
index 3533d0f..1edce04 100644
--- a/modules/roundl
+++ b/modules/roundl
@@ -4,7 +4,7 @@ roundl() function: round toward nearest, breaking ties away
from zero.
Files:
lib/round.c
lib/roundl.c
-m4/check-libm-func.m4
+m4/check-math-lib.m4
m4/roundl.m4
Depends-on:
diff --git a/tests/test-round2.c b/tests/test-round2.c
index 1da0d9f..47d818c 100644
--- a/tests/test-round2.c
+++ b/tests/test-round2.c
@@ -74,7 +74,7 @@ check (DOUBLE x)
{
DOUBLE ref1 = round_reference1 (x);
DOUBLE ref2 = round_reference2 (x);
- DOUBLE result = round (x);
+ DOUBLE result = ROUND (x);
/* If the reference implementations disagree, bail out immediately. */
if (!equal ("reference implementations disagree", x, ref1, ref2))
commit 8dd18ff0f921e2044afddac1c9eb2714dca90a83
Author: Ben Pfaff <address@hidden>
Date: Sun Oct 21 18:23:37 2007 -0700
Make roundf-tests module depend on floorf, ceilf.
diff --git a/ChangeLog b/ChangeLog
index d9170af..3d1cc93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2007-10-21 Ben Pfaff <address@hidden>
+ * modules/roundf-tests: Add dependency on floorf, ceilf to allow
+ round.c roundf implementation that depends on floorf and ceilf to
+ be tested unconditionally.
+
+2007-10-21 Ben Pfaff <address@hidden>
+
* m4/check-libm-func.m4: Removed.
* m4/check-math-lib.m4: New file.
* m4/round.m4: Rewrite to use gl_CHECK_MATH_LIB.
diff --git a/modules/roundf-tests b/modules/roundf-tests
index 9fc69eb..6aa6372 100644
--- a/modules/roundf-tests
+++ b/modules/roundf-tests
@@ -4,6 +4,8 @@ tests/test-round2.c
tests/test-roundf2.c
Depends-on:
+ceilf
+floorf
isnanf-nolibm
stdbool
stdint
--
Ben Pfaff
http://benpfaff.org
- modules 'round', 'roundf', 'roundl' for review, Ben Pfaff, 2007/10/06
- Re: modules 'round', 'roundf', 'roundl' for review, Bruno Haible, 2007/10/07
- Re: modules 'round', 'roundf', 'roundl' for review, Ben Pfaff, 2007/10/07
- Re: modules 'round', 'roundf', 'roundl' for review, Bruno Haible, 2007/10/12
- 'round' modules takes 3 (was: Re: modules 'round', 'roundf', 'roundl' for review), Ben Pfaff, 2007/10/19
- Re: 'round' modules takes 3 (was: Re: modules 'round', 'roundf', 'roundl' for review), Bruno Haible, 2007/10/20
- Re: 'round' modules takes 3, Ben Pfaff, 2007/10/20
- Re: 'round' modules takes 3, Bruno Haible, 2007/10/21
- Re: 'round' modules takes 3, Bruno Haible, 2007/10/21
- Re: 'round' modules takes 3, Ben Pfaff, 2007/10/21
- Re: 'round' modules takes 3,
Ben Pfaff <=
- Re: 'round' modules takes 3, Bruno Haible, 2007/10/23
- Re: 'round' modules takes 3, Bruno Haible, 2007/10/28
- Re: 'round' modules takes 3, Ben Pfaff, 2007/10/28
- Re: 'round' modules takes 3, Bruno Haible, 2007/10/28
- Re: 'round' modules takes 3, Ralf Wildenhues, 2007/10/29
- Re: 'round' modules takes 3, Bruno Haible, 2007/10/29
Re: modules 'round', 'roundf', 'roundl' for review, Bruno Haible, 2007/10/07