From 33f47a8259736ab62fb8f2a3b548e2c0f67ddd97 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 5 Oct 2007 03:33:31 +0200 Subject: [PATCH] New module 'floorl'. --- ChangeLog | 12 ++++++++++++ doc/functions/floorl.texi | 8 ++++---- lib/floorl.c | 35 +++++----------------------------- lib/math.in.h | 10 ++++++---- m4/floorl.m4 | 48 +++++++++++++++++++++++++++++++++++++++++++++++ m4/math_h.m4 | 1 + modules/floorl | 31 ++++++++++++++++++++++++++++++ modules/math | 1 + modules/mathl | 2 +- 9 files changed, 109 insertions(+), 39 deletions(-) create mode 100644 m4/floorl.m4 create mode 100644 modules/floorl diff --git a/ChangeLog b/ChangeLog index 4d97b77a1..d7033bf1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2007-10-04 Bruno Haible + * modules/floorl: New file. + * lib/floorl.c: Replace entire file. + * m4/floorl.m4: New file. + * lib/math.in.h (floorl): Replace declaration. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_FLOORL. + * modules/math (Makefile.am): Substitute also GNULIB_FLOORL. + * doc/functions/floorl.texi: Mention the 'floorl' module. + * modules/mathl (Files): Remove lib/floorl.c. + (Depends-on): Add floorl. + +2007-10-04 Bruno Haible + * modules/floorf-tests: New file. * tests/test-floorf.c: New file. diff --git a/doc/functions/floorl.texi b/doc/functions/floorl.texi index 90ea9d140..63508006e 100644 --- a/doc/functions/floorl.texi +++ b/doc/functions/floorl.texi @@ -4,15 +4,15 @@ POSIX specification: @url{http://www.opengroup.org/susv3xsh/floorl.html} -Gnulib module: --- +Gnulib module: floorl Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +FreeBSD 5.2.1, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -FreeBSD 5.2.1, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS. @end itemize diff --git a/lib/floorl.c b/lib/floorl.c index 84b212e9e..71d6b4f5b 100644 --- a/lib/floorl.c +++ b/lib/floorl.c @@ -1,9 +1,5 @@ -/* Emulation for floorl. - Contributed by Paolo Bonzini - - Copyright 2002, 2003, 2007 Free Software Foundation, Inc. - - This file is part of gnulib. +/* Round towards negative infinity. + Copyright (C) 2007 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 @@ -19,28 +15,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include - -/* Specification. */ -#include - -#include - -/* To compute the integer part of X, sum a big enough - integer so that the precision of the floating point - number is exactly 1. */ - -long double -floorl(long double x) -{ - long double y; - if (x < 0.0L) - y = -(1.0L / LDBL_EPSILON - x - 1.0 / LDBL_EPSILON); - else - y = 1.0L / LDBL_EPSILON + x - 1.0 / LDBL_EPSILON; +/* Written by Bruno Haible , 2007. */ - if (y > x) - return y - 1.0L; - else - return y; -} +#define USE_LONG_DOUBLE +#include "floor.c" diff --git a/lib/math.in.h b/lib/math.in.h index 179e0c542..490524276 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -139,14 +139,16 @@ extern float floorf (float x); floorf (x)) #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_FLOORL@ +#if @GNULIB_FLOORL@ +# if !@HAVE_DECL_FLOORL@ +# define floorl rpl_floorl extern long double floorl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +# endif +#elif defined GNULIB_POSIXCHECK # undef floorl # define floorl(x) \ (GL_LINK_WARNING ("floorl is unportable - " \ - "use gnulib module mathl for portability"), \ + "use gnulib module floorl for portability"), \ floorl (x)) #endif diff --git a/m4/floorl.m4 b/m4/floorl.m4 new file mode 100644 index 000000000..0a5ecb76a --- /dev/null +++ b/m4/floorl.m4 @@ -0,0 +1,48 @@ +# floorl.m4 serial 1 +dnl Copyright (C) 2007 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_FLOORL], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + dnl Persuade glibc to declare floorl(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + dnl Test whether floorl() is declared. + AC_CHECK_DECLS([floorl], , , [#include ]) + if test "$ac_cv_have_decl_floorl" = yes; then + dnl Test whether floorl() can be used without libm. + FLOORL_LIBM=? + AC_TRY_LINK([ + #ifndef __NO_MATH_INLINES + # define __NO_MATH_INLINES 1 /* for glibc */ + #endif + #include + long double x;], + [x = floorl(x);], + [FLOORL_LIBM=]) + if test "$FLOORL_LIBM" = "?"; then + save_LIBS="$LIBS" + LIBS="$LIBS -lm" + AC_TRY_LINK([ + #ifndef __NO_MATH_INLINES + # define __NO_MATH_INLINES 1 /* for glibc */ + #endif + #include + long double x;], + [x = floorl(x);], + [FLOORL_LIBM="-lm"]) + LIBS="$save_LIBS" + fi + if test "$FLOORL_LIBM" = "?"; then + FLOORL_LIBM= + fi + else + HAVE_DECL_FLOORL=0 + AC_LIBOBJ([floorl]) + FLOORL_LIBM= + fi + AC_SUBST([HAVE_DECL_FLOORL]) + AC_SUBST([FLOORL_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index d5ef0b682..3d12eb3be 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -20,6 +20,7 @@ AC_DEFUN([gl_MATH_MODULE_INDICATOR], AC_DEFUN([gl_MATH_H_DEFAULTS], [ GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) + GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL]) GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) diff --git a/modules/floorl b/modules/floorl new file mode 100644 index 000000000..66c13621a --- /dev/null +++ b/modules/floorl @@ -0,0 +1,31 @@ +Description: +floorl() function: round towards negative infinity. + +Files: +lib/floorl.c +lib/floor.c +m4/floorl.m4 + +Depends-on: +math +extensions +float + +configure.ac: +gl_FUNC_FLOORL +gl_MATH_MODULE_INDICATOR([floorl]) + +Makefile.am: + +Include: + + +Link: +$(FLOORL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/math b/modules/math index a5ae2795c..a892db301 100644 --- a/modules/math +++ b/modules/math @@ -23,6 +23,7 @@ math.h: math.in.h sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ -e 's|@''NEXT_MATH_H''@|$(NEXT_MATH_H)|g' \ -e 's|@''GNULIB_FLOORF''@|$(GNULIB_FLOORF)|g' \ + -e 's|@''GNULIB_FLOORL''@|$(GNULIB_FLOORL)|g' \ -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \ -e 's|@''GNULIB_FREXPL''@|$(GNULIB_FREXPL)|g' \ -e 's|@''GNULIB_LDEXPL''@|$(GNULIB_LDEXPL)|g' \ diff --git a/modules/mathl b/modules/mathl index 892eea441..1008cba64 100644 --- a/modules/mathl +++ b/modules/mathl @@ -8,7 +8,6 @@ lib/atanl.c lib/ceill.c lib/cosl.c lib/expl.c -lib/floorl.c lib/logl.c lib/sincosl.c lib/sinl.c @@ -24,6 +23,7 @@ math frexpl isnanl ldexpl +floorl configure.ac: gl_FUNC_LONG_DOUBLE_MATH -- 2.11.0