New module 'frexpf'.
authorBruno Haible <bruno@clisp.org>
Thu, 6 Oct 2011 09:28:38 +0000 (11:28 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 6 Oct 2011 09:28:38 +0000 (11:28 +0200)
* 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.

ChangeLog
doc/posix-functions/frexpf.texi
lib/frexpf.c [new file with mode: 0644]
lib/math.in.h
m4/frexpf.m4 [new file with mode: 0644]
m4/math_h.m4
modules/frexpf [new file with mode: 0644]
modules/math
tests/test-math-c++.cc

index 6dd6ac8..74fc7bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2011-10-06  Bruno Haible  <bruno@clisp.org>
 
+       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  <bruno@clisp.org>
+
        math: Sort function declarations of math.in.h.
        * lib/math.in.h (frexp, logb): Move declarations.
 
index b246bc0..2955bb7 100644 (file)
@@ -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 (file)
index 0000000..2bd5f51
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <math.h>
+
+float
+frexpf (float x, int *expptr)
+{
+  return (float) frexp ((double) x, expptr);
+}
index 80bc78c..ba4b3b0 100644 (file)
@@ -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 (file)
index 0000000..7928011
--- /dev/null
@@ -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])
+])
index e3b29fe..c0c497a 100644 (file)
@@ -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 <math.h>]],
-    [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 (file)
index 0000000..bd0d273
--- /dev/null
@@ -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:
+<math.h>
+
+Link:
+$(FREXPF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index b40edb1..cd0eb93 100644 (file)
@@ -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' \
index 1782a25..8b2e970 100644 (file)
@@ -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