floorl: Simplify for platforms where 'long double' == 'double'.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2011 22:29:05 +0000 (00:29 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2011 22:59:52 +0000 (00:59 +0200)
* lib/floorl.c: Include <config.h>.
(floorl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New function.
* lib/floor.c [!USE_LONG_DOUBLE]: Don't include <config.h> a second
time.
* m4/floorl.m4 (gl_FUNC_FLOORL): Require gl_LONG_DOUBLE_VS_DOUBLE.
Determine FLOORL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
* modules/floorl (Depends-on): Add floor. Update conditions.

ChangeLog
lib/floor.c
lib/floorl.c
m4/floorl.m4
modules/floorl

index bf00c05..11dc4bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 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.
+       * lib/floor.c [!USE_LONG_DOUBLE]: Don't include <config.h> a second
+       time.
+       * m4/floorl.m4 (gl_FUNC_FLOORL): Require gl_LONG_DOUBLE_VS_DOUBLE.
+       Determine FLOORL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
+       * modules/floorl (Depends-on): Add floor. Update conditions.
+
+2011-10-09  Bruno Haible  <bruno@clisp.org>
+
        rint: Fix ordering constraints.
        * m4/rint.m4 (gl_FUNC_RINT): Require gl_MATH_H_DEFAULTS.
        * m4/rintf.m4 (gl_FUNC_RINTF): Likewise.
index df5e6dd..71a5b30 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 bf5044f..aa62294 100644 (file)
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
-#define USE_LONG_DOUBLE
-#include "floor.c"
+#include <config.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+/* Specification.  */
+# include <math.h>
+
+long double
+floorl (long double x)
+{
+  return floor (x);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "floor.c"
+
+#endif
index 5a20b8b..a90c693 100644 (file)
@@ -1,4 +1,4 @@
-# floorl.m4 serial 9
+# floorl.m4 serial 10
 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,
@@ -7,8 +7,11 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_FLOORL],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+
   dnl Persuade glibc <math.h> to declare floorl().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
   dnl Test whether floorl() is declared.
   AC_CHECK_DECLS([floorl], , , [[#include <math.h>]])
   if test "$ac_cv_have_decl_floorl" = yes; then
@@ -23,8 +26,13 @@ AC_DEFUN([gl_FUNC_FLOORL],
     HAVE_DECL_FLOORL=0
   fi
   if test $HAVE_DECL_FLOORL = 0 || test $REPLACE_FLOORL = 1; then
-    dnl No libraries are needed to link lib/floorl.c.
-    FLOORL_LIBM=
+    dnl Find libraries needed to link lib/floorl.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_FLOOR])
+      FLOORL_LIBM="$FLOOR_LIBM"
+    else
+      FLOORL_LIBM=
+    fi
   fi
   AC_SUBST([FLOORL_LIBM])
 ])
index 9d1bac2..fe6fdb6 100644 (file)
@@ -9,7 +9,8 @@ m4/floorl.m4
 Depends-on:
 math
 extensions
-float           [test $HAVE_DECL_FLOORL = 0 || test $REPLACE_FLOORL = 1]
+floor           [{ test $HAVE_DECL_FLOORL = 0 || test $REPLACE_FLOORL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+float           [{ test $HAVE_DECL_FLOORL = 0 || test $REPLACE_FLOORL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_FLOORL