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

ChangeLog
lib/rint.c
lib/rintl.c
m4/rintl.m4
modules/rintl

index a342bb0..95f2b1d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-10-09  Bruno Haible  <bruno@clisp.org>
 
+       rintl: Simplify for platforms where 'long double' == 'double'.
+       * lib/rintl.c: Include <config.h>.
+       (rintl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New function.
+       * lib/rint.c [!USE_LONG_DOUBLE]: Don't include <config.h> a second
+       time.
+       * m4/rintl.m4 (gl_FUNC_RINTL): Require gl_LONG_DOUBLE_VS_DOUBLE.
+       Determine RINTL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE.
+       * modules/rintl (Depends-on): Add rint. Update conditions.
+
+2011-10-09  Bruno Haible  <bruno@clisp.org>
+
        roundl: Simplify for platforms where 'long double' == 'double'.
        * lib/roundl.c: Include <config.h>.
        (roundl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New function.
index 4ba3fe5..7eefe7a 100644 (file)
@@ -15,7 +15,9 @@
    with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#include <config.h>
+#if ! defined USE_LONG_DOUBLE
+# include <config.h>
+#endif
 
 /* Specification.  */
 #include <math.h>
index 6c0e999..d26935e 100644 (file)
    with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#define USE_LONG_DOUBLE
-#include "rint.c"
+#include <config.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+/* Specification.  */
+# include <math.h>
+
+long double
+rintl (long double x)
+{
+  return rint (x);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "rint.c"
+
+#endif
index df83341..bb88ee8 100644 (file)
@@ -1,4 +1,4 @@
-# rintl.m4 serial 2
+# rintl.m4 serial 3
 dnl Copyright (C) 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,13 +7,20 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_RINTL],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
 
   dnl Determine RINTL_LIBM.
   gl_MATHFUNC([rintl], [long double], [(long double)])
   if test $gl_cv_func_rintl_no_libm = no \
      && test $gl_cv_func_rintl_in_libm = no; then
     HAVE_RINTL=0
-    RINTL_LIBM=
+    dnl Find libraries needed to link lib/rintl.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_RINT])
+      RINTL_LIBM="$RINT_LIBM"
+    else
+      RINTL_LIBM=
+    fi
   fi
   AC_SUBST([RINTL_LIBM])
 ])
index 80a0f52..dac2618 100644 (file)
@@ -9,6 +9,7 @@ m4/mathfunc.m4
 
 Depends-on:
 math
+rint            [test $HAVE_RINTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
 
 configure.ac:
 gl_FUNC_RINTL