From: Bruno Haible Date: Thu, 6 Oct 2011 09:28:38 +0000 (+0200) Subject: New module 'frexpf'. X-Git-Tag: v0.1~1685 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=df8ad3525d27df0b821539df90af26c7fa6d3188;p=gnulib.git New module 'frexpf'. * lib/math.in.h (frexpf): New declaration. * lib/frexpf.c: New file. * m4/frexpf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether frexpf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_FREXPF, HAVE_FREXPF. * modules/math (Makefile.am): Substitute GNULIB_FREXPF, HAVE_FREXPF. * modules/frexpf: New file. * tests/test-math-c++.cc: Check the declaration of frexpf. * doc/posix-functions/frexpf.texi: Mention the new module. --- diff --git a/ChangeLog b/ChangeLog index 6dd6ac821..74fc7bf84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2011-10-06 Bruno Haible + New module 'frexpf'. + * lib/math.in.h (frexpf): New declaration. + * lib/frexpf.c: New file. + * m4/frexpf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether frexpf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_FREXPF, HAVE_FREXPF. + * modules/math (Makefile.am): Substitute GNULIB_FREXPF, HAVE_FREXPF. + * modules/frexpf: New file. + * tests/test-math-c++.cc: Check the declaration of frexpf. + * doc/posix-functions/frexpf.texi: Mention the new module. + +2011-10-06 Bruno Haible + math: Sort function declarations of math.in.h. * lib/math.in.h (frexp, logb): Move declarations. diff --git a/doc/posix-functions/frexpf.texi b/doc/posix-functions/frexpf.texi index b246bc066..2955bb7ce 100644 --- a/doc/posix-functions/frexpf.texi +++ b/doc/posix-functions/frexpf.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/frexpf.html} -Gnulib module: --- +Gnulib module: frexpf Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9. @@ -19,3 +15,7 @@ Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9. This function is only defined as a macro with arguments on some platforms: MSVC 9. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/lib/frexpf.c b/lib/frexpf.c new file mode 100644 index 000000000..2bd5f51ec --- /dev/null +++ b/lib/frexpf.c @@ -0,0 +1,26 @@ +/* Split a float into fraction and mantissa. + Copyright (C) 2011 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 + +/* Specification. */ +#include + +float +frexpf (float x, int *expptr) +{ + return (float) frexp ((double) x, expptr); +} diff --git a/lib/math.in.h b/lib/math.in.h index 80bc78c98..ba4b3b07b 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -342,6 +342,28 @@ _GL_WARN_ON_USE (fmodf, "fmodf is unportable - " If x is zero: mantissa = x, exp = 0. If x is infinite or NaN: mantissa = x, exp unspecified. Store exp in *EXPPTR and return mantissa. */ +#if @GNULIB_FREXPF@ +# if !@HAVE_FREXPF@ +# undef frexpf +_GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr)); +_GL_CXXALIASWARN (frexpf); +#elif defined GNULIB_POSIXCHECK +# undef frexpf +# if HAVE_RAW_DECL_FREXPF +_GL_WARN_ON_USE (frexpf, "frexpf is unportable - " + "use gnulib module frexpf for portability"); +# endif +#endif + +/* Write x as + x = mantissa * 2^exp + where + If x finite and nonzero: 0.5 <= |mantissa| < 1.0. + If x is zero: mantissa = x, exp = 0. + If x is infinite or NaN: mantissa = x, exp unspecified. + Store exp in *EXPPTR and return mantissa. */ #if @GNULIB_FREXP@ # if @REPLACE_FREXP@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/frexpf.m4 b/m4/frexpf.m4 new file mode 100644 index 000000000..7928011c3 --- /dev/null +++ b/m4/frexpf.m4 @@ -0,0 +1,25 @@ +# frexpf.m4 serial 1 +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, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_FREXPF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_FREXP]) + + dnl Test whether frexpf() exists. Assume that frexpf(), if it exists, is + dnl defined in the same library as frexp(). + save_LIBS="$LIBS" + LIBS="$LIBS $FREXP_LIBM" + AC_CHECK_FUNCS([frexpf]) + LIBS="$save_LIBS" + if test $ac_cv_func_frexpf = yes; then + FREXPF_LIBM="$FREXP_LIBM" + else + HAVE_FREXPF=0 + FREXPF_LIBM="$FREXP_LIBM" + fi + AC_SUBST([FREXPF_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index e3b29fe50..c0c497a7b 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 28 +# math_h.m4 serial 29 dnl Copyright (C) 2007-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, @@ -39,7 +39,8 @@ AC_DEFUN([gl_MATH_H], dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include ]], - [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf frexpl + [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf + frexpf frexpl ldexpl logb logl modff round roundf roundl sinl sqrtl tanl trunc truncf truncl]) ]) @@ -68,6 +69,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF]) + GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF]) GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL]) GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE]) @@ -98,6 +100,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_EXPL=1; AC_SUBST([HAVE_EXPL]) HAVE_FABSF=1; AC_SUBST([HAVE_FABSF]) HAVE_FMODF=1; AC_SUBST([HAVE_FMODF]) + HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF]) HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF]) HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND]) HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL]) diff --git a/modules/frexpf b/modules/frexpf new file mode 100644 index 000000000..bd0d27383 --- /dev/null +++ b/modules/frexpf @@ -0,0 +1,31 @@ +Description: +frexpf() function: split a float into its constituents. + +Files: +lib/frexpf.c +m4/frexpf.m4 + +Depends-on: +math +frexp [test $HAVE_FREXPF = 0] + +configure.ac: +gl_FUNC_FREXPF +if test $HAVE_FREXPF = 0; then + AC_LIBOBJ([frexpf]) +fi +gl_MATH_MODULE_INDICATOR([frexpf]) + +Makefile.am: + +Include: + + +Link: +$(FREXPF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index b40edb165..cd0eb93c8 100644 --- a/modules/math +++ b/modules/math @@ -41,6 +41,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \ -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \ -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \ + -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \ -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \ -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \ -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \ @@ -71,6 +72,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \ -e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \ -e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|g' \ + -e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \ -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \ -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \ -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 1782a25b0..8b2e970a8 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -43,6 +43,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::fabsf, float, (float)); SIGNATURE_CHECK (GNULIB_NAMESPACE::fmodf, float, (float, float)); #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::fmod, double, (double, double)); +#if GNULIB_TEST_FREXPF +SIGNATURE_CHECK (GNULIB_NAMESPACE::frexpf, float, (float, int *)); +#endif #if GNULIB_TEST_FREXP SIGNATURE_CHECK (GNULIB_NAMESPACE::frexp, double, (double, int *)); #endif