changeset 15928:c3916f7594b5

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.
author Bruno Haible <bruno@clisp.org>
date Mon, 10 Oct 2011 01:08:51 +0200
parents afd47902c4b4
children 7649c55d7d4c
files ChangeLog lib/rint.c lib/rintl.c m4/rintl.m4 modules/rintl
diffstat 5 files changed, 43 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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'.
--- a/lib/rint.c
+++ b/lib/rint.c
@@ -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>
--- a/lib/rintl.c
+++ b/lib/rintl.c
@@ -15,5 +15,22 @@
    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
--- a/m4/rintl.m4
+++ b/m4/rintl.m4
@@ -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 @@
 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])
 ])
--- a/modules/rintl
+++ b/modules/rintl
@@ -9,6 +9,7 @@
 
 Depends-on:
 math
+rint            [test $HAVE_RINTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
 
 configure.ac:
 gl_FUNC_RINTL