ceill: Simplify for platforms where 'long double' == 'double'.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2011 23:04:13 +0000 (01:04 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2011 23:04:13 +0000 (01:04 +0200)
* lib/ceill.c: Include <config.h>.
(ceill) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New function.
* lib/ceil.c [!USE_LONG_DOUBLE]: Don't include <config.h> a second
time.
* m4/ceill.m4 (gl_FUNC_CEILL): Require gl_LONG_DOUBLE_VS_DOUBLE.
Determine CEILL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
* modules/ceill (Depends-on): Add ceil. Update conditions.

ChangeLog
lib/ceil.c
lib/ceill.c
m4/ceill.m4
modules/ceill

index 11dc4bb..909a202 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-10-09  Bruno Haible  <bruno@clisp.org>
 
+       ceill: Simplify for platforms where 'long double' == 'double'.
+       * lib/ceill.c: Include <config.h>.
+       (ceill) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New function.
+       * lib/ceil.c [!USE_LONG_DOUBLE]: Don't include <config.h> a second
+       time.
+       * m4/ceill.m4 (gl_FUNC_CEILL): Require gl_LONG_DOUBLE_VS_DOUBLE.
+       Determine CEILL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
+       * modules/ceill (Depends-on): Add ceil. Update conditions.
+
+2011-10-09  Bruno Haible  <bruno@clisp.org>
+
        floorl: Simplify for platforms where 'long double' == 'double'.
        * lib/floorl.c: Include <config.h>.
        (floorl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New function.
index b30902c..4e0354e 100644 (file)
@@ -16,7 +16,9 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
-#include <config.h>
+#if ! defined USE_LONG_DOUBLE
+# include <config.h>
+#endif
 
 /* Specification.  */
 #include <math.h>
index 54a4b50..6181c91 100644 (file)
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
-#define USE_LONG_DOUBLE
-#include "ceil.c"
+#include <config.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+/* Specification.  */
+# include <math.h>
+
+long double
+ceill (long double x)
+{
+  return ceil (x);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "ceil.c"
+
+#endif
index 40adaf1..5f56df3 100644 (file)
@@ -1,4 +1,4 @@
-# ceill.m4 serial 11
+# ceill.m4 serial 12
 dnl Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,8 +8,11 @@ AC_DEFUN([gl_FUNC_CEILL],
 [
   m4_divert_text([DEFAULTS], [gl_ceill_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+
   dnl Persuade glibc <math.h> to declare ceill().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
   dnl Test whether ceill() is declared.
   AC_CHECK_DECLS([ceill], , , [[#include <math.h>]])
   if test "$ac_cv_have_decl_ceill" = yes; then
@@ -60,8 +63,13 @@ int main (int argc, char *argv[])
     HAVE_DECL_CEILL=0
   fi
   if test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; then
-    dnl No libraries are needed to link lib/ceill.c.
-    CEILL_LIBM=
+    dnl Find libraries needed to link lib/ceill.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_CEIL])
+      CEILL_LIBM="$CEIL_LIBM"
+    else
+      CEILL_LIBM=
+    fi
   fi
   AC_SUBST([CEILL_LIBM])
 ])
index 4ab7f38..a5d860f 100644 (file)
@@ -9,7 +9,8 @@ m4/ceill.m4
 Depends-on:
 math
 extensions
-float           [test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1]
+ceil            [{ test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+float           [{ test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_CEILL