]> Savannah Git Hosting - gnulib.git/commitdiff
New module 'cbrtf'.
authorBruno Haible <bruno@clisp.org>
Thu, 1 Mar 2012 01:03:36 +0000 (02:03 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 1 Mar 2012 01:03:36 +0000 (02:03 +0100)
* 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.

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

index 864175dd0140bb36c357da337db1dde86aeb4dd1..01b4e95eb997e2399c50793abdb893d584f65a34 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
index 4d98051e4ab3cb7cd03b523b0e3373fc98dd9b21..1794bb39673557fcb9130030aa5bd2e603e5511e 100644 (file)
@@ -4,15 +4,18 @@
 
 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
diff --git a/lib/cbrtf.c b/lib/cbrtf.c
new file mode 100644 (file)
index 0000000..6320d0e
--- /dev/null
@@ -0,0 +1,62 @@
+/* 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;
+}
index 9c8e70bd0298a975bbcee15ca1388aee06be7f5b..9515424e4f7b53d457f9b380f0a2e600ac9512e9 100644 (file)
@@ -288,6 +288,20 @@ _GL_WARN_ON_USE (atan2f, "atan2f is unportable - "
 #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));
diff --git a/m4/cbrtf.m4 b/m4/cbrtf.m4
new file mode 100644 (file)
index 0000000..cf2c6b7
--- /dev/null
@@ -0,0 +1,48 @@
+# 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])
+])
index eada1de3dd26714d542dcb4e08fed45355ee05b4..512589867eb424bae0d1c3c1d2df6c1c86e9ecc7 100644 (file)
@@ -1,4 +1,4 @@
-# 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,
@@ -40,7 +40,7 @@ AC_DEFUN([gl_MATH_H],
   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
@@ -68,6 +68,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   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])
@@ -143,6 +144,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   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])
@@ -189,6 +191,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   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])
diff --git a/modules/cbrtf b/modules/cbrtf
new file mode 100644 (file)
index 0000000..8de0368
--- /dev/null
@@ -0,0 +1,36 @@
+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
index 2d5440227d1515af0b4c810adcb5a4456dd8d67f..26507b553dadf7500925219f0657175f2c86f0eb 100644 (file)
@@ -36,6 +36,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \
@@ -111,6 +112,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \
@@ -157,6 +159,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \
index e79cb0b06e25d9cb682477fa9ff9e0cc4c474563..a0a687426b07309990d3a9b7f1053a5baff97e3b 100644 (file)
@@ -68,6 +68,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::atan2f, float, (float, float));
 #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