From: Bruno Haible Date: Tue, 21 Dec 2010 13:32:25 +0000 (+0100) Subject: New module 'ceilf-ieee'. X-Git-Tag: v0.1~3509 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=f10ca7e0a421ace0dd6124bd8f0ba8e7570ebec3;p=gnulib.git New module 'ceilf-ieee'. * modules/ceilf-ieee: New file. * m4/ceilf.m4 (gl_FUNC_FLOORF): If gl_FUNC_CEILF_IEEE is also used, test whether ceilf works according to ISO C 99 with IEC 60559. * m4/ceilf-ieee.m4: New file. * modules/ceilf-ieee-tests: New file. * tests/test-ceilf-ieee.c: New file, based on tests/test-ceilf1.c. * tests/test-ceilf1.c (main): Remove signbit tests. * modules/ceilf-tests (Depends-on): Remove 'signbit'. * doc/posix-functions/ceilf.texi: Mention the new module. --- diff --git a/ChangeLog b/ChangeLog index 9bfeeb89f..9ad8d220e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2010-12-21 Bruno Haible + New module 'ceilf-ieee'. + * modules/ceilf-ieee: New file. + * m4/ceilf.m4 (gl_FUNC_FLOORF): If gl_FUNC_CEILF_IEEE is also used, + test whether ceilf works according to ISO C 99 with IEC 60559. + * m4/ceilf-ieee.m4: New file. + * modules/ceilf-ieee-tests: New file. + * tests/test-ceilf-ieee.c: New file, based on tests/test-ceilf1.c. + * tests/test-ceilf1.c (main): Remove signbit tests. + * modules/ceilf-tests (Depends-on): Remove 'signbit'. + * doc/posix-functions/ceilf.texi: Mention the new module. + +2010-12-21 Bruno Haible + New module 'floorf-ieee'. * modules/floorf-ieee: New file. * m4/floorf.m4 (gl_FUNC_FLOORF): If gl_FUNC_FLOORF_IEEE is also used, diff --git a/doc/posix-functions/ceilf.texi b/doc/posix-functions/ceilf.texi index a7c1e0f92..cc85fc8b5 100644 --- a/doc/posix-functions/ceilf.texi +++ b/doc/posix-functions/ceilf.texi @@ -4,15 +4,23 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ceilf.html} -Gnulib module: ceilf +Gnulib module: ceilf or ceilf-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{ceilf} or @code{ceilf-ieee}: @itemize @item This function is missing on some platforms: AIX 5.1, HP-UX 11, Solaris 9. @end itemize +Portability problems fixed by Gnulib module @code{ceilf-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/m4/ceilf-ieee.m4 b/m4/ceilf-ieee.m4 new file mode 100644 index 000000000..cdc07c3cf --- /dev/null +++ b/m4/ceilf-ieee.m4 @@ -0,0 +1,15 @@ +# ceilf-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 ceilf.m4 and not inlined in the +dnl module description), so that gl_FUNC_CEILF can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_CEILF_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_ceilf_required=ieee]) + AC_REQUIRE([gl_FUNC_CEILF]) +]) diff --git a/m4/ceilf.m4 b/m4/ceilf.m4 index a33b9aa7e..7b9bbcc24 100644 --- a/m4/ceilf.m4 +++ b/m4/ceilf.m4 @@ -1,4 +1,4 @@ -# ceilf.m4 serial 7 +# ceilf.m4 serial 8 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, @@ -6,6 +6,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_CEILF], [ + m4_divert_text([DEFAULTS], [gl_ceilf_required=plain]) AC_REQUIRE([gl_MATH_H_DEFAULTS]) dnl Persuade glibc to declare ceilf(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) @@ -19,6 +20,40 @@ AC_DEFUN([gl_FUNC_CEILF], dnl libm.so, but not in the libm.so that the compiler uses. REPLACE_CEILF=1 fi + m4_ifdef([gl_FUNC_CEILF_IEEE], [ + if test $gl_ceilf_required = ieee && test $REPLACE_CEILF = 0; then + AC_CACHE_CHECK([whether ceilf works according to ISO C 99 with IEC 60559], + [gl_cv_func_ceilf_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $CEILF_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include +]gl_FLOAT_MINUS_ZERO_CODE[ +]gl_FLOAT_SIGNBIT_CODE[ +int main() +{ + /* Test whether ceilf (-0.0f) is -0.0f. */ + if (signbitf (minus_zerof) && !signbitf (ceilf (minus_zerof))) + return 1; + return 0; +} + ]])], + [gl_cv_func_ceilf_ieee=yes], + [gl_cv_func_ceilf_ieee=no], + [gl_cv_func_ceilf_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_ceilf_ieee" in + *yes) ;; + *) REPLACE_CEILF=1 ;; + esac + fi + ]) else HAVE_DECL_CEILF=0 fi diff --git a/modules/ceilf-ieee b/modules/ceilf-ieee new file mode 100644 index 000000000..199154898 --- /dev/null +++ b/modules/ceilf-ieee @@ -0,0 +1,27 @@ +Description: +ceilf() function according to ISO C 99 with IEC 60559. + +Files: +m4/ceilf-ieee.m4 +m4/minus-zero.m4 +m4/signbit.m4 + +Depends-on: +ceilf + +configure.ac: +gl_FUNC_CEILF_IEEE + +Makefile.am: + +Include: + + +Link: +$(CEILF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/ceilf-ieee-tests b/modules/ceilf-ieee-tests new file mode 100644 index 000000000..4b8766794 --- /dev/null +++ b/modules/ceilf-ieee-tests @@ -0,0 +1,15 @@ +Files: +tests/test-ceilf-ieee.c +tests/minus-zero.h +tests/macros.h + +Depends-on: +float +signbit + +configure.ac: + +Makefile.am: +TESTS += test-ceilf-ieee +check_PROGRAMS += test-ceilf-ieee +test_ceilf_ieee_LDADD = $(LDADD) @CEILF_LIBM@ diff --git a/modules/ceilf-tests b/modules/ceilf-tests index a0472a7c4..040fd1bbf 100644 --- a/modules/ceilf-tests +++ b/modules/ceilf-tests @@ -9,7 +9,6 @@ tests/macros.h Depends-on: float isnanf-nolibm -signbit stdbool stdint diff --git a/tests/test-ceilf-ieee.c b/tests/test-ceilf-ieee.c new file mode 100644 index 000000000..475e4f416 --- /dev/null +++ b/tests/test-ceilf-ieee.c @@ -0,0 +1,45 @@ +/* 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" + +/* If IEEE compliance was not requested, the ICC compiler inlines its + own ceilf assembly that turns -0.0f to 0.0f; but that is a correct + result when IEEE is not enforced. To avoid spurious failure, we + have to provide this dummy function in order to outsmart ICC's + inlining, and call our ceilf through a function pointer. */ +static float +dummy (float f) +{ + return 0; +} + +int +main (int argc, char **argv _GL_UNUSED) +{ + float (*my_ceilf) (float) = argc ? ceilf : dummy; + + /* Zero. */ + ASSERT (!signbit (my_ceilf (0.0f))); + ASSERT (!!signbit (my_ceilf (minus_zerof)) == !!signbit (minus_zerof)); + + return 0; +} diff --git a/tests/test-ceilf1.c b/tests/test-ceilf1.c index a77641f9b..74a5f536a 100644 --- a/tests/test-ceilf1.c +++ b/tests/test-ceilf1.c @@ -46,9 +46,7 @@ main (int argc, char **argv _GL_UNUSED) /* Zero. */ ASSERT (my_ceilf (0.0f) == 0.0f); - ASSERT (!signbit (my_ceilf (0.0f))); ASSERT (my_ceilf (minus_zerof) == 0.0f); - ASSERT (!!signbit (minus_zerof) == !!signbit (my_ceilf (minus_zerof))); /* Positive numbers. */ ASSERT (my_ceilf (0.3f) == 1.0f); ASSERT (my_ceilf (0.7f) == 1.0f);