From 4b7ece979775e13ba4f1db1e6d9cfe400eff0f01 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 21 Dec 2010 18:05:21 +0100 Subject: [PATCH] New module 'ceil-ieee'. * modules/ceil-ieee: New file. * m4/ceil.m4 (gl_FUNC_CEIL): Require gl_MATH_H_DEFAULTS. If gl_FUNC_CEIL_IEEE is also used, test whether ceil works according to ISO C 99 with IEC 60559. * m4/ceil-ieee.m4: New file. * modules/ceil (Files): Add lib/ceil.c. (Depends-on): Add 'float'. (configure.ac): Invoke gl_MATH_MODULE_INDICATOR. * lib/math.in.h (ceil): New declaration. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_CEIL, REPLACE_CEIL. * modules/math (Makefile.am): Substitute GNULIB_CEIL, REPLACE_CEIL. * modules/ceil-ieee-tests: New file. * tests/test-ceil-ieee.c: New file, based on tests/test-ceilf-ieee.c. * tests/test-math-c++.cc: Check the signature of 'ceil'. * doc/posix-functions/ceil.texi: Mention the new module. --- ChangeLog | 20 ++++++++++++++++++++ doc/posix-functions/ceil.texi | 12 ++++++++++-- lib/math.in.h | 13 +++++++++++++ m4/ceil-ieee.m4 | 15 +++++++++++++++ m4/ceil.m4 | 44 +++++++++++++++++++++++++++++++++++++++++-- m4/math_h.m4 | 4 +++- modules/ceil | 3 +++ modules/ceil-ieee | 27 ++++++++++++++++++++++++++ modules/ceil-ieee-tests | 15 +++++++++++++++ modules/math | 2 ++ tests/test-ceil-ieee.c | 32 +++++++++++++++++++++++++++++++ tests/test-math-c++.cc | 4 ++++ 12 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 m4/ceil-ieee.m4 create mode 100644 modules/ceil-ieee create mode 100644 modules/ceil-ieee-tests create mode 100644 tests/test-ceil-ieee.c diff --git a/ChangeLog b/ChangeLog index 28aab85c4..f00d5d1e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,25 @@ 2010-12-21 Bruno Haible + New module 'ceil-ieee'. + * modules/ceil-ieee: New file. + * m4/ceil.m4 (gl_FUNC_CEIL): Require gl_MATH_H_DEFAULTS. If + gl_FUNC_CEIL_IEEE is also used, test whether ceil works according to + ISO C 99 with IEC 60559. + * m4/ceil-ieee.m4: New file. + * modules/ceil (Files): Add lib/ceil.c. + (Depends-on): Add 'float'. + (configure.ac): Invoke gl_MATH_MODULE_INDICATOR. + * lib/math.in.h (ceil): New declaration. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_CEIL, + REPLACE_CEIL. + * modules/math (Makefile.am): Substitute GNULIB_CEIL, REPLACE_CEIL. + * modules/ceil-ieee-tests: New file. + * tests/test-ceil-ieee.c: New file, based on tests/test-ceilf-ieee.c. + * tests/test-math-c++.cc: Check the signature of 'ceil'. + * doc/posix-functions/ceil.texi: Mention the new module. + +2010-12-21 Bruno Haible + New module 'floor-ieee'. * modules/floor-ieee: New file. * m4/floor.m4 (gl_FUNC_FLOOR): Require gl_MATH_H_DEFAULTS. If diff --git a/doc/posix-functions/ceil.texi b/doc/posix-functions/ceil.texi index c44c77a19..3c5c659a4 100644 --- a/doc/posix-functions/ceil.texi +++ b/doc/posix-functions/ceil.texi @@ -4,12 +4,20 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ceil.html} -Gnulib module: ceil +Gnulib module: ceil or ceil-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{ceil} or @code{ceil-ieee}: @itemize @end itemize +Portability problems fixed by Gnulib module @code{ceil-ieee}: +@itemize +@item +This function returns a positive zero for a minus zero argument +on some platforms: +OSF/1 5.1. +@end itemize + Portability problems not fixed by Gnulib: @itemize @end itemize diff --git a/lib/math.in.h b/lib/math.in.h index 6c5ab9f3d..c933f519c 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -202,6 +202,19 @@ _GL_WARN_ON_USE (ceilf, "ceilf is unportable - " # endif #endif +#if @GNULIB_CEIL@ +# if @REPLACE_CEIL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define ceil rpl_ceil +# endif +_GL_FUNCDECL_RPL (ceil, double, (double x)); +_GL_CXXALIAS_RPL (ceil, double, (double x)); +# else +_GL_CXXALIAS_SYS (ceil, double, (double x)); +# endif +_GL_CXXALIASWARN (ceil); +#endif + #if @GNULIB_CEILL@ # if @REPLACE_CEILL@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/ceil-ieee.m4 b/m4/ceil-ieee.m4 new file mode 100644 index 000000000..e4633afbe --- /dev/null +++ b/m4/ceil-ieee.m4 @@ -0,0 +1,15 @@ +# ceil-ieee.m4 serial 1 +dnl Copyright (C) 2010 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 This macro is in a separate file (not in ceil.m4 and not inlined in the +dnl module description), so that gl_FUNC_CEIL can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_CEIL_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_ceil_required=ieee]) + AC_REQUIRE([gl_FUNC_CEIL]) +]) diff --git a/m4/ceil.m4 b/m4/ceil.m4 index 306e6c751..1f93d4bae 100644 --- a/m4/ceil.m4 +++ b/m4/ceil.m4 @@ -1,16 +1,56 @@ -# ceil.m4 serial 4 -dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. +# ceil.m4 serial 5 +dnl Copyright (C) 2007, 2009-2010 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. AC_DEFUN([gl_FUNC_CEIL], [ + m4_divert_text([DEFAULTS], [gl_ceil_required=plain]) + AC_REQUIRE([gl_MATH_H_DEFAULTS]) dnl Test whether ceil() can be used without libm. gl_FUNC_CEIL_LIBS if test "$CEIL_LIBM" = "?"; then CEIL_LIBM= fi + m4_ifdef([gl_FUNC_CEIL_IEEE], [ + if test $gl_ceil_required = ieee && test $REPLACE_CEIL = 0; then + AC_CACHE_CHECK([whether ceil works according to ISO C 99 with IEC 60559], + [gl_cv_func_ceil_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $CEIL_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include +]gl_DOUBLE_MINUS_ZERO_CODE[ +]gl_DOUBLE_SIGNBIT_CODE[ +int main() +{ + /* Test whether ceil (-0.0) is -0.0. */ + if (signbitd (minus_zerod) && !signbitd (ceil (minus_zerod))) + return 1; + return 0; +} + ]])], + [gl_cv_func_ceil_ieee=yes], + [gl_cv_func_ceil_ieee=no], + [gl_cv_func_ceil_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_ceil_ieee" in + *yes) ;; + *) REPLACE_CEIL=1 ;; + esac + fi + ]) + if test $REPLACE_CEIL = 1; then + AC_LIBOBJ([ceil]) + CEIL_LIBM= + fi AC_SUBST([CEIL_LIBM]) ]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 3825d7a0f..cbe57b213 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 23 +# math_h.m4 serial 24 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -57,6 +57,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_ACOSL=0; AC_SUBST([GNULIB_ACOSL]) GNULIB_ASINL=0; AC_SUBST([GNULIB_ASINL]) GNULIB_ATANL=0; AC_SUBST([GNULIB_ATANL]) + GNULIB_CEIL=0; AC_SUBST([GNULIB_CEIL]) GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF]) GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL]) GNULIB_COSL=0; AC_SUBST([GNULIB_COSL]) @@ -120,6 +121,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC]) HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF]) HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL]) + REPLACE_CEIL=0; AC_SUBST([REPLACE_CEIL]) REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF]) REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL]) REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR]) diff --git a/modules/ceil b/modules/ceil index 5c1630939..90e03fce2 100644 --- a/modules/ceil +++ b/modules/ceil @@ -2,13 +2,16 @@ Description: ceil() function: round towards positive infinity. Files: +lib/ceil.c m4/ceil.m4 Depends-on: math +float configure.ac: gl_FUNC_CEIL +gl_MATH_MODULE_INDICATOR([ceil]) Makefile.am: diff --git a/modules/ceil-ieee b/modules/ceil-ieee new file mode 100644 index 000000000..797069016 --- /dev/null +++ b/modules/ceil-ieee @@ -0,0 +1,27 @@ +Description: +ceil() function according to ISO C 99 with IEC 60559. + +Files: +m4/ceil-ieee.m4 +m4/minus-zero.m4 +m4/signbit.m4 + +Depends-on: +ceil + +configure.ac: +gl_FUNC_CEIL_IEEE + +Makefile.am: + +Include: + + +Link: +$(CEIL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/ceil-ieee-tests b/modules/ceil-ieee-tests new file mode 100644 index 000000000..178ffb758 --- /dev/null +++ b/modules/ceil-ieee-tests @@ -0,0 +1,15 @@ +Files: +tests/test-ceil-ieee.c +tests/minus-zero.h +tests/macros.h + +Depends-on: +float +signbit + +configure.ac: + +Makefile.am: +TESTS += test-ceil-ieee +check_PROGRAMS += test-ceil-ieee +test_ceil_ieee_LDADD = $(LDADD) @FLOOR_LIBM@ diff --git a/modules/math b/modules/math index 560d8e890..a11aeb820 100644 --- a/modules/math +++ b/modules/math @@ -29,6 +29,7 @@ math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_ACOSL''@|$(GNULIB_ACOSL)|g' \ -e 's|@''GNULIB_ASINL''@|$(GNULIB_ASINL)|g' \ -e 's|@''GNULIB_ATANL''@|$(GNULIB_ATANL)|g' \ + -e 's|@''GNULIB_CEIL''@|$(GNULIB_CEIL)|g' \ -e 's|@''GNULIB_CEILF''@|$(GNULIB_CEILF)|g' \ -e 's|@''GNULIB_CEILL''@|$(GNULIB_CEILL)|g' \ -e 's|@''GNULIB_COSL''@|$(GNULIB_COSL)|g' \ @@ -91,6 +92,7 @@ math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_DECL_TRUNC''@|$(HAVE_DECL_TRUNC)|g' \ -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \ -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ + -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \ -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \ diff --git a/tests/test-ceil-ieee.c b/tests/test-ceil-ieee.c new file mode 100644 index 000000000..06cfeff9e --- /dev/null +++ b/tests/test-ceil-ieee.c @@ -0,0 +1,32 @@ +/* Test of rounding towards positive infinity. + Copyright (C) 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include + +#include "minus-zero.h" +#include "macros.h" + +int +main () +{ + /* Zero. */ + ASSERT (!signbit (ceil (0.0))); + ASSERT (!!signbit (ceil (minus_zerod)) == !!signbit (minus_zerod)); + + return 0; +} diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 7ad93c221..49d0ca71b 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -80,6 +80,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::atanl, long double, (long double)); SIGNATURE_CHECK (GNULIB_NAMESPACE::ceilf, float, (float)); #endif +#if GNULIB_TEST_CEIL +SIGNATURE_CHECK (GNULIB_NAMESPACE::ceil, double, (double)); +#endif + #if GNULIB_TEST_CEILL SIGNATURE_CHECK (GNULIB_NAMESPACE::ceill, long double, (long double)); #endif -- 2.11.0