* lib/math.in.h (cbrtf): New declaration.
* lib/cbrtf.c: New file.
* m4/cbrtf.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether cbrtf is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_CBRTF, HAVE_CBRTF,
HAVE_DECL_CBRTF.
* modules/math (Makefile.am): Substitute GNULIB_CBRTF, HAVE_CBRTF,
HAVE_DECL_CBRTF.
* modules/cbrtf: New file.
* tests/test-math-c++.cc: Check the declaration of cbrtf.
* doc/posix-functions/cbrtf.texi: Mention the new module.
+2012-02-29 Bruno Haible <bruno@clisp.org>
+
+ New module 'cbrtf'.
+ * lib/math.in.h (cbrtf): New declaration.
+ * lib/cbrtf.c: New file.
+ * m4/cbrtf.m4: New file.
+ * m4/math_h.m4 (gl_MATH_H): Test whether cbrtf is declared.
+ (gl_MATH_H_DEFAULTS): Initialize GNULIB_CBRTF, HAVE_CBRTF,
+ HAVE_DECL_CBRTF.
+ * modules/math (Makefile.am): Substitute GNULIB_CBRTF, HAVE_CBRTF,
+ HAVE_DECL_CBRTF.
+ * modules/cbrtf: New file.
+ * tests/test-math-c++.cc: Check the declaration of cbrtf.
+ * doc/posix-functions/cbrtf.texi: Mention the new module.
+
2012-02-29 Bruno Haible <bruno@clisp.org>
cbrt: Provide replacement on MSVC and Minix.
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/cbrtf.html}
-Gnulib module: ---
+Gnulib module: cbrtf
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, AIX 5.1, Solaris 9, MSVC 9.
+@item
+This function is not declared on some platforms:
+IRIX 6.5.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 9, MSVC 9.
@end itemize
--- /dev/null
+/* Compute cubic root of float value.
+ Copyright (C) 1997, 2012 Free Software Foundation, Inc.
+
+ Contributed by Dirk Alboth <dirka@uni-paderborn.de> and
+ Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ 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>
+
+/* Code based on glibc/sysdeps/ieee754/flt-32/s_cbrtf.c. */
+
+#define CBRT2 1.2599210498948731648 /* 2^(1/3) */
+#define SQR_CBRT2 1.5874010519681994748 /* 2^(2/3) */
+
+static const double factor[5] =
+{
+ 1.0 / SQR_CBRT2,
+ 1.0 / CBRT2,
+ 1.0,
+ CBRT2,
+ SQR_CBRT2
+};
+
+
+float
+cbrtf (float x)
+{
+ if (isfinite (x) && x != 0.0f)
+ {
+ float xm, ym, u, t2;
+ int xe;
+
+ /* Reduce X. XM now is an range 1.0 to 0.5. */
+ xm = frexpf (fabsf (x), &xe);
+
+ u = (0.492659620528969547
+ + (0.697570460207922770 - 0.191502161678719066 * xm) * xm);
+
+ t2 = u * u * u;
+
+ ym = u * (t2 + 2.0 * xm) / (2.0 * t2 + xm) * factor[2 + xe % 3];
+
+ return ldexpf (x > 0.0 ? ym : -ym, xe / 3);
+ }
+ else
+ return x + x;
+}
#endif
+#if @GNULIB_CBRTF@
+# if !@HAVE_DECL_CBRTF@
+_GL_FUNCDECL_SYS (cbrtf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (cbrtf, float, (float x));
+_GL_CXXALIASWARN (cbrtf);
+#elif defined GNULIB_POSIXCHECK
+# undef cbrtf
+# if HAVE_RAW_DECL_CBRTF
+_GL_WARN_ON_USE (cbrtf, "cbrtf is unportable - "
+ "use gnulib module cbrtf for portability");
+# endif
+#endif
+
#if @GNULIB_CBRT@
# if !@HAVE_CBRT@
_GL_FUNCDECL_SYS (cbrt, double, (double x));
--- /dev/null
+# cbrtf.m4 serial 1
+dnl Copyright (C) 2012 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_CBRTF],
+[
+ AC_REQUIRE([gl_MATH_H_DEFAULTS])
+ AC_REQUIRE([gl_FUNC_CBRT])
+
+ dnl Test whether cbrtf() exists. Assume that cbrtf(), if it exists, is
+ dnl defined in the same library as cbrt().
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $CBRT_LIBM"
+ AC_CHECK_FUNCS([cbrtf])
+ LIBS="$save_LIBS"
+ if test $ac_cv_func_cbrtf = yes; then
+ CBRTF_LIBM="$CBRT_LIBM"
+ dnl Also check whether it's declared.
+ dnl IRIX 6.5 has cbrtf() in libm but doesn't declare it in <math.h>.
+ AC_CHECK_DECL([cbrtf], , [HAVE_DECL_CBRTF=0], [[#include <math.h>]])
+ else
+ HAVE_CBRTF=0
+ HAVE_DECL_CBRTF=0
+ dnl Find libraries needed to link lib/cbrtf.c.
+ AC_REQUIRE([gl_FUNC_FABSF])
+ AC_REQUIRE([gl_FUNC_FREXPF])
+ AC_REQUIRE([gl_FUNC_LDEXPF])
+ CBRTF_LIBM=
+ dnl Append $FABSF_LIBM to CBRTF_LIBM, avoiding gratuitous duplicates.
+ case " $CBRTF_LIBM " in
+ *" $FABSF_LIBM "*) ;;
+ *) CBRTF_LIBM="$CBRTF_LIBM $FABSF_LIBM" ;;
+ esac
+ dnl Append $FREXPF_LIBM to CBRTF_LIBM, avoiding gratuitous duplicates.
+ case " $CBRTF_LIBM " in
+ *" $FREXPF_LIBM "*) ;;
+ *) CBRTF_LIBM="$CBRTF_LIBM $FREXPF_LIBM" ;;
+ esac
+ dnl Append $LDEXPF_LIBM to CBRTF_LIBM, avoiding gratuitous duplicates.
+ case " $CBRTF_LIBM " in
+ *" $LDEXPF_LIBM "*) ;;
+ *) CBRTF_LIBM="$CBRTF_LIBM $LDEXPF_LIBM" ;;
+ esac
+ fi
+ AC_SUBST([CBRTF_LIBM])
+])
-# math_h.m4 serial 76
+# math_h.m4 serial 77
dnl Copyright (C) 2007-2012 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 corresponding gnulib module is not in use.
gl_WARN_ON_USE_PREPARE([[#include <math.h>]],
[acosf acosl asinf asinl atanf atanl
- cbrt ceilf ceill copysign copysignf copysignl cosf cosl coshf
+ cbrt cbrtf ceilf ceill copysign copysignf copysignl cosf cosl coshf
expf expl fabsf fabsl floorf floorl fma fmaf fmal
fmod fmodf fmodl frexpf frexpl hypotf hypotl
ldexpf ldexpl logb logf logl log10f log10l modf modff modfl powf
GNULIB_ATANL=0; AC_SUBST([GNULIB_ATANL])
GNULIB_ATAN2F=0; AC_SUBST([GNULIB_ATAN2F])
GNULIB_CBRT=0; AC_SUBST([GNULIB_CBRT])
+ GNULIB_CBRTF=0; AC_SUBST([GNULIB_CBRTF])
GNULIB_CEIL=0; AC_SUBST([GNULIB_CEIL])
GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF])
GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL])
HAVE_ATANL=1; AC_SUBST([HAVE_ATANL])
HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F])
HAVE_CBRT=1; AC_SUBST([HAVE_CBRT])
+ HAVE_CBRTF=1; AC_SUBST([HAVE_CBRTF])
HAVE_COPYSIGN=1; AC_SUBST([HAVE_COPYSIGN])
HAVE_COPYSIGNF=1; AC_SUBST([HAVE_COPYSIGNF])
HAVE_COPYSIGNL=1; AC_SUBST([HAVE_COPYSIGNL])
HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL])
HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL])
HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL])
+ HAVE_DECL_CBRTF=1; AC_SUBST([HAVE_DECL_CBRTF])
HAVE_DECL_CEILF=1; AC_SUBST([HAVE_DECL_CEILF])
HAVE_DECL_CEILL=1; AC_SUBST([HAVE_DECL_CEILL])
HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL])
--- /dev/null
+Description:
+cbrtf() function: cube root.
+
+Files:
+lib/cbrtf.c
+m4/cbrtf.m4
+m4/cbrt.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+isfinite [test $HAVE_CBRTF = 0]
+fabsf [test $HAVE_CBRTF = 0]
+frexpf [test $HAVE_CBRTF = 0]
+ldexpf [test $HAVE_CBRTF = 0]
+
+configure.ac:
+gl_FUNC_CBRTF
+if test $HAVE_CBRTF = 0; then
+ AC_LIBOBJ([cbrtf])
+fi
+gl_MATH_MODULE_INDICATOR([cbrtf])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(CBRTF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
-e 's/@''GNULIB_ATANL''@/$(GNULIB_ATANL)/g' \
-e 's/@''GNULIB_ATAN2F''@/$(GNULIB_ATAN2F)/g' \
-e 's/@''GNULIB_CBRT''@/$(GNULIB_CBRT)/g' \
+ -e 's/@''GNULIB_CBRTF''@/$(GNULIB_CBRTF)/g' \
-e 's/@''GNULIB_CEIL''@/$(GNULIB_CEIL)/g' \
-e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \
-e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \
-e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \
-e 's|@''HAVE_ATAN2F''@|$(HAVE_ATAN2F)|g' \
-e 's|@''HAVE_CBRT''@|$(HAVE_CBRT)|g' \
+ -e 's|@''HAVE_CBRTF''@|$(HAVE_CBRTF)|g' \
-e 's|@''HAVE_COPYSIGN''@|$(HAVE_COPYSIGN)|g' \
-e 's|@''HAVE_COPYSIGNF''@|$(HAVE_COPYSIGNF)|g' \
-e 's|@''HAVE_COPYSIGNL''@|$(HAVE_COPYSIGNL)|g' \
-e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \
-e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \
-e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \
+ -e 's|@''HAVE_DECL_CBRTF''@|$(HAVE_DECL_CBRTF)|g' \
-e 's|@''HAVE_DECL_CEILF''@|$(HAVE_DECL_CEILF)|g' \
-e 's|@''HAVE_DECL_CEILL''@|$(HAVE_DECL_CEILL)|g' \
-e 's|@''HAVE_DECL_COSL''@|$(HAVE_DECL_COSL)|g' \
#endif
//SIGNATURE_CHECK (GNULIB_NAMESPACE::atan2, double, (double, double));
+#if GNULIB_TEST_CBRTF
+SIGNATURE_CHECK (GNULIB_NAMESPACE::cbrtf, float, (float));
+#endif
#if GNULIB_TEST_CBRT
SIGNATURE_CHECK (GNULIB_NAMESPACE::cbrt, double, (double));
#endif