From 8938f22cb374f04f265ac3a9d2cefdc44524d6e2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 21 Dec 2010 17:41:03 +0100 Subject: [PATCH] New module 'floor-ieee'. * modules/floor-ieee: New file. * m4/floor.m4 (gl_FUNC_FLOOR): Require gl_MATH_H_DEFAULTS. If gl_FUNC_FLOOR_IEEE is also used, test whether floor works according to ISO C 99 with IEC 60559. * m4/floor-ieee.m4: New file. * modules/floor (Files): Add lib/floor.c. (Depends-on): Add 'float'. (configure.ac): Invoke gl_MATH_MODULE_INDICATOR. * lib/math.in.h (floor): New declaration. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_FLOOR, REPLACE_FLOOR. * modules/math (Makefile.am): Substitute GNULIB_FLOOR, REPLACE_FLOOR. * modules/floor-ieee-tests: New file. * tests/test-floor-ieee.c: New file, based on tests/test-floorf-ieee.c. * tests/test-math-c++.cc: Check the signature of 'floor'. * doc/posix-functions/floor.texi: Mention the new module. --- ChangeLog | 20 +++++++++++++++++++ doc/posix-functions/floor.texi | 12 ++++++++++-- lib/math.in.h | 13 +++++++++++++ m4/floor-ieee.m4 | 15 ++++++++++++++ m4/floor.m4 | 44 ++++++++++++++++++++++++++++++++++++++++-- m4/math_h.m4 | 4 +++- modules/floor | 3 +++ modules/floor-ieee | 27 ++++++++++++++++++++++++++ modules/floor-ieee-tests | 15 ++++++++++++++ modules/math | 2 ++ tests/test-floor-ieee.c | 32 ++++++++++++++++++++++++++++++ tests/test-math-c++.cc | 4 ++++ 12 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 m4/floor-ieee.m4 create mode 100644 modules/floor-ieee create mode 100644 modules/floor-ieee-tests create mode 100644 tests/test-floor-ieee.c diff --git a/ChangeLog b/ChangeLog index 188c1e386..28aab85c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,25 @@ 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 + gl_FUNC_FLOOR_IEEE is also used, test whether floor works according to + ISO C 99 with IEC 60559. + * m4/floor-ieee.m4: New file. + * modules/floor (Files): Add lib/floor.c. + (Depends-on): Add 'float'. + (configure.ac): Invoke gl_MATH_MODULE_INDICATOR. + * lib/math.in.h (floor): New declaration. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_FLOOR, + REPLACE_FLOOR. + * modules/math (Makefile.am): Substitute GNULIB_FLOOR, REPLACE_FLOOR. + * modules/floor-ieee-tests: New file. + * tests/test-floor-ieee.c: New file, based on tests/test-floorf-ieee.c. + * tests/test-math-c++.cc: Check the signature of 'floor'. + * doc/posix-functions/floor.texi: Mention the new module. + +2010-12-21 Bruno Haible + New module 'roundf-ieee'. * modules/roundf-ieee: New file. * m4/roundf.m4 (gl_FUNC_ROUNDF): If gl_FUNC_ROUNDF_IEEE is also used, diff --git a/doc/posix-functions/floor.texi b/doc/posix-functions/floor.texi index 794bac2f6..77491dec4 100644 --- a/doc/posix-functions/floor.texi +++ b/doc/posix-functions/floor.texi @@ -4,12 +4,20 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/floor.html} -Gnulib module: floor +Gnulib module: floor or floor-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{floor} or @code{floor-ieee}: @itemize @end itemize +Portability problems fixed by Gnulib module @code{floor-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 fe2830b9c..6c5ab9f3d 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -277,6 +277,19 @@ _GL_WARN_ON_USE (floorf, "floorf is unportable - " # endif #endif +#if @GNULIB_FLOOR@ +# if @REPLACE_FLOOR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define floor rpl_floor +# endif +_GL_FUNCDECL_RPL (floor, double, (double x)); +_GL_CXXALIAS_RPL (floor, double, (double x)); +# else +_GL_CXXALIAS_SYS (floor, double, (double x)); +# endif +_GL_CXXALIASWARN (floor); +#endif + #if @GNULIB_FLOORL@ # if @REPLACE_FLOORL@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/floor-ieee.m4 b/m4/floor-ieee.m4 new file mode 100644 index 000000000..8f6554fb6 --- /dev/null +++ b/m4/floor-ieee.m4 @@ -0,0 +1,15 @@ +# floor-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 floor.m4 and not inlined in the +dnl module description), so that gl_FUNC_FLOOR can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_FLOOR_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_floor_required=ieee]) + AC_REQUIRE([gl_FUNC_FLOOR]) +]) diff --git a/m4/floor.m4 b/m4/floor.m4 index 754133582..74f742a1e 100644 --- a/m4/floor.m4 +++ b/m4/floor.m4 @@ -1,16 +1,56 @@ -# floor.m4 serial 4 -dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. +# floor.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_FLOOR], [ + m4_divert_text([DEFAULTS], [gl_floor_required=plain]) + AC_REQUIRE([gl_MATH_H_DEFAULTS]) dnl Test whether floor() can be used without libm. gl_FUNC_FLOOR_LIBS if test "$FLOOR_LIBM" = "?"; then FLOOR_LIBM= fi + m4_ifdef([gl_FUNC_FLOOR_IEEE], [ + if test $gl_floor_required = ieee && test $REPLACE_FLOOR = 0; then + AC_CACHE_CHECK([whether floor works according to ISO C 99 with IEC 60559], + [gl_cv_func_floor_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $FLOOR_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 floor (-0.0) is -0.0. */ + if (signbitd (minus_zerod) && !signbitd (floor (minus_zerod))) + return 1; + return 0; +} + ]])], + [gl_cv_func_floor_ieee=yes], + [gl_cv_func_floor_ieee=no], + [gl_cv_func_floor_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_floor_ieee" in + *yes) ;; + *) REPLACE_FLOOR=1 ;; + esac + fi + ]) + if test $REPLACE_FLOOR = 1; then + AC_LIBOBJ([floor]) + FLOOR_LIBM= + fi AC_SUBST([FLOOR_LIBM]) ]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 0cca37e76..3825d7a0f 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 22 +# math_h.m4 serial 23 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, @@ -61,6 +61,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL]) GNULIB_COSL=0; AC_SUBST([GNULIB_COSL]) GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL]) + GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR]) GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) @@ -121,6 +122,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL]) REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF]) REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL]) + REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR]) REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF]) REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL]) REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP]) diff --git a/modules/floor b/modules/floor index f0eaef843..ee898d3cd 100644 --- a/modules/floor +++ b/modules/floor @@ -2,13 +2,16 @@ Description: floor() function: round towards negative infinity. Files: +lib/floor.c m4/floor.m4 Depends-on: math +float configure.ac: gl_FUNC_FLOOR +gl_MATH_MODULE_INDICATOR([floor]) Makefile.am: diff --git a/modules/floor-ieee b/modules/floor-ieee new file mode 100644 index 000000000..670de32a5 --- /dev/null +++ b/modules/floor-ieee @@ -0,0 +1,27 @@ +Description: +floor() function according to ISO C 99 with IEC 60559. + +Files: +m4/floor-ieee.m4 +m4/minus-zero.m4 +m4/signbit.m4 + +Depends-on: +floor + +configure.ac: +gl_FUNC_FLOOR_IEEE + +Makefile.am: + +Include: + + +Link: +$(FLOOR_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/floor-ieee-tests b/modules/floor-ieee-tests new file mode 100644 index 000000000..e71dead88 --- /dev/null +++ b/modules/floor-ieee-tests @@ -0,0 +1,15 @@ +Files: +tests/test-floor-ieee.c +tests/minus-zero.h +tests/macros.h + +Depends-on: +float +signbit + +configure.ac: + +Makefile.am: +TESTS += test-floor-ieee +check_PROGRAMS += test-floor-ieee +test_floor_ieee_LDADD = $(LDADD) @FLOOR_LIBM@ diff --git a/modules/math b/modules/math index 6944646e1..560d8e890 100644 --- a/modules/math +++ b/modules/math @@ -33,6 +33,7 @@ math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_CEILL''@|$(GNULIB_CEILL)|g' \ -e 's|@''GNULIB_COSL''@|$(GNULIB_COSL)|g' \ -e 's|@''GNULIB_EXPL''@|$(GNULIB_EXPL)|g' \ + -e 's|@''GNULIB_FLOOR''@|$(GNULIB_FLOOR)|g' \ -e 's|@''GNULIB_FLOORF''@|$(GNULIB_FLOORF)|g' \ -e 's|@''GNULIB_FLOORL''@|$(GNULIB_FLOORL)|g' \ -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \ @@ -92,6 +93,7 @@ math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ + -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \ -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \ -e 's|@''REPLACE_FLOORL''@|$(REPLACE_FLOORL)|g' \ -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \ diff --git a/tests/test-floor-ieee.c b/tests/test-floor-ieee.c new file mode 100644 index 000000000..0051d67f2 --- /dev/null +++ b/tests/test-floor-ieee.c @@ -0,0 +1,32 @@ +/* Test of rounding towards negative 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 (floor (0.0))); + ASSERT (!!signbit (floor (minus_zerod)) == !!signbit (minus_zerod)); + + return 0; +} diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 8be774b81..7ad93c221 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -96,6 +96,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::expl, long double, (long double)); SIGNATURE_CHECK (GNULIB_NAMESPACE::floorf, float, (float)); #endif +#if GNULIB_TEST_FLOOR +SIGNATURE_CHECK (GNULIB_NAMESPACE::floor, double, (double)); +#endif + #if GNULIB_TEST_FLOORL SIGNATURE_CHECK (GNULIB_NAMESPACE::floorl, long double, (long double)); #endif -- 2.11.0