]> Savannah Git Hosting - gnulib.git/commitdiff
New module 'hypotf'.
authorBruno Haible <bruno@clisp.org>
Wed, 29 Feb 2012 12:22:12 +0000 (13:22 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 29 Feb 2012 12:22:12 +0000 (13:22 +0100)
* lib/math.in.h (hypotf): New declaration.
* lib/hypotf.c: New file.
* m4/hypotf.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether hypotf is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_HYPOTF, HAVE_HYPOTF,
REPLACE_HYPOTF.
* modules/math (Makefile.am): Substitute GNULIB_HYPOTF, HAVE_HYPOTF,
REPLACE_HYPOTF.
* modules/hypotf: New file.
* tests/test-math-c++.cc: Check the hypotf declaration.
* doc/posix-functions/hypotf.texi: Mention the new module.

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

index 7a727f1a8f68d1f168e4fdafc4ac9eb9abc68a3d..a566d06f6d6bca44e172aa5458045ae5e09f5ec0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-02-29  Bruno Haible  <bruno@clisp.org>
 
+       New module 'hypotf'.
+       * lib/math.in.h (hypotf): New declaration.
+       * lib/hypotf.c: New file.
+       * m4/hypotf.m4: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether hypotf is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_HYPOTF, HAVE_HYPOTF,
+       REPLACE_HYPOTF.
+       * modules/math (Makefile.am): Substitute GNULIB_HYPOTF, HAVE_HYPOTF,
+       REPLACE_HYPOTF.
+       * modules/hypotf: New file.
+       * tests/test-math-c++.cc: Check the hypotf declaration.
+       * doc/posix-functions/hypotf.texi: Mention the new module.
+
        hypot: Prepare for hypotf module.
        * m4/hypot.m4: New file.
        * modules/hypot (Files): Add m4/hypot.m4.
index c964e45f3c57d66d0dc1371b7b59aa83e45c0876..debdc5e1d71fc2fd62ff69b247746bca0259a236 100644 (file)
@@ -4,15 +4,18 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/hypotf.html}
 
-Gnulib module: ---
+Gnulib module: hypotf
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 9, MSVC 9.
+@item
+This function produces wrong values on some platforms:
+NetBSD 5.1, OpenBSD 4.9.
 @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, Solaris 9, MSVC 9.
 @end itemize
diff --git a/lib/hypotf.c b/lib/hypotf.c
new file mode 100644 (file)
index 0000000..ad5aa89
--- /dev/null
@@ -0,0 +1,26 @@
+/* Hypotenuse of a right-angled triangle.
+   Copyright (C) 2012 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
+hypotf (float x, float y)
+{
+  return (float) hypot ((double) x, (double) y);
+}
index a2d1489a4f167c7ae604fa10eca980acf7a0a220..d82e720232cf583a7a0c882ccb68d4cd206a0ae3 100644 (file)
@@ -808,6 +808,31 @@ _GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
 #endif
 
 
+/* Return sqrt(x^2+y^2).  */
+#if @GNULIB_HYPOTF@
+# if @REPLACE_HYPOTF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef hypotf
+#   define hypotf rpl_hypotf
+#  endif
+_GL_FUNCDECL_RPL (hypotf, float, (float x, float y));
+_GL_CXXALIAS_RPL (hypotf, float, (float x, float y));
+# else
+#  if !@HAVE_HYPOTF@
+_GL_FUNCDECL_SYS (hypotf, float, (float x, float y));
+#  endif
+_GL_CXXALIAS_SYS (hypotf, float, (float x, float y));
+# endif
+_GL_CXXALIASWARN (hypotf);
+#elif defined GNULIB_POSIXCHECK
+# undef hypotf
+# if HAVE_RAW_DECL_HYPOTF
+_GL_WARN_ON_USE (hypotf, "hypotf is unportable - "
+                 "use gnulib module hypotf for portability");
+# endif
+#endif
+
+
 /* Return x * 2^exp.  */
 #if @GNULIB_LDEXPF@
 # if !@HAVE_LDEXPF@
diff --git a/m4/hypotf.m4 b/m4/hypotf.m4
new file mode 100644 (file)
index 0000000..67eb5e5
--- /dev/null
@@ -0,0 +1,83 @@
+# hypotf.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_HYPOTF],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_HYPOT])
+
+  dnl Test whether hypotf() exists. Assume that hypotf(), if it exists, is
+  dnl defined in the same library as fmod().
+  save_LIBS="$LIBS"
+  LIBS="$LIBS $HYPOT_LIBM"
+  AC_CHECK_FUNCS([hypotf])
+  LIBS="$save_LIBS"
+  if test $ac_cv_func_hypotf = yes; then
+    HYPOTF_LIBM="$HYPOT_LIBM"
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $HYPOTF_LIBM"
+    gl_FUNC_HYPOTF_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_hypotf_works" in
+      *yes) ;;
+      *) REPLACE_HYPOTF=1 ;;
+    esac
+  else
+    HAVE_HYPOTF=0
+  fi
+  if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
+    dnl Find libraries needed to link lib/hypotf.c.
+    HYPOTF_LIBM="$HYPOT_LIBM"
+  fi
+  AC_SUBST([HYPOTF_LIBM])
+])
+
+dnl Test whether hypotf() works.
+dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
+AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <float.h>
+#include <math.h>
+volatile float x;
+volatile float y;
+volatile float z;
+int main ()
+{
+  int result = 0;
+  /* This test fails on NetBSD 5.1.  */
+  {
+    x = FLT_MIN * 2.0f;
+    y = FLT_MIN * 3.0f;
+    z = hypotf (x, y);
+    if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
+      result |= 1;
+  }
+  /* This test fails on OpenBSD 4.9.  */
+  {
+    x = FLT_MAX;
+    y = FLT_MAX * 0.5f;
+    z = hypotf (x, y);
+    if (!(z > 0 && z == z + z))
+      result |= 2;
+  }
+  return result;
+}
+]])],
+        [gl_cv_func_hypotf_works=yes],
+        [gl_cv_func_hypotf_works=no],
+        [case "$host_os" in
+           netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no";;
+           *)                  gl_cv_func_hypotf_works="guessing yes";;
+         esac
+        ])
+    ])
+])
index 6f9389dc1864baec51b7a8d025a4e2c98e0d2980..26878d90366689e3a2b2fe371eee222bddd1944b 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 71
+# math_h.m4 serial 72
 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,
@@ -42,7 +42,7 @@ AC_DEFUN([gl_MATH_H],
     [acosf acosl asinf asinl atanf atanl
      ceilf ceill copysign copysignf copysignl cosf cosl coshf
      expf expl fabsf fabsl floorf floorl fma fmaf fmal
-     fmod fmodf fmodl frexpf frexpl
+     fmod fmodf fmodl frexpf frexpl hypotf
      ldexpf ldexpl logb logf logl log10f log10l modf modff modfl powf
      remainder remainderf remainderl
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
@@ -92,6 +92,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_FREXPF=0;     AC_SUBST([GNULIB_FREXPF])
   GNULIB_FREXP=0;      AC_SUBST([GNULIB_FREXP])
   GNULIB_FREXPL=0;     AC_SUBST([GNULIB_FREXPL])
+  GNULIB_HYPOTF=0;     AC_SUBST([GNULIB_HYPOTF])
   GNULIB_ISFINITE=0;   AC_SUBST([GNULIB_ISFINITE])
   GNULIB_ISINF=0;      AC_SUBST([GNULIB_ISINF])
   GNULIB_ISNAN=0;      AC_SUBST([GNULIB_ISNAN])
@@ -154,6 +155,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_FMODF=1;                AC_SUBST([HAVE_FMODF])
   HAVE_FMODL=1;                AC_SUBST([HAVE_FMODL])
   HAVE_FREXPF=1;               AC_SUBST([HAVE_FREXPF])
+  HAVE_HYPOTF=1;               AC_SUBST([HAVE_HYPOTF])
   HAVE_ISNANF=1;               AC_SUBST([HAVE_ISNANF])
   HAVE_ISNAND=1;               AC_SUBST([HAVE_ISNAND])
   HAVE_ISNANL=1;               AC_SUBST([HAVE_ISNANL])
@@ -220,6 +222,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_FREXP=0;             AC_SUBST([REPLACE_FREXP])
   REPLACE_FREXPL=0;            AC_SUBST([REPLACE_FREXPL])
   REPLACE_HUGE_VAL=0;          AC_SUBST([REPLACE_HUGE_VAL])
+  REPLACE_HYPOTF=0;            AC_SUBST([REPLACE_HYPOTF])
   REPLACE_ISFINITE=0;          AC_SUBST([REPLACE_ISFINITE])
   REPLACE_ISINF=0;             AC_SUBST([REPLACE_ISINF])
   REPLACE_ISNAN=0;             AC_SUBST([REPLACE_ISNAN])
diff --git a/modules/hypotf b/modules/hypotf
new file mode 100644 (file)
index 0000000..82e09aa
--- /dev/null
@@ -0,0 +1,32 @@
+Description:
+hypotf() function: length of a vector in the plane.
+
+Files:
+lib/hypotf.c
+m4/hypotf.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+hypot           [test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1]
+
+configure.ac:
+gl_FUNC_HYPOTF
+if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
+  AC_LIBOBJ([hypotf])
+fi
+gl_MATH_MODULE_INDICATOR([hypotf])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(HYPOTF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index 6ffbe1982a2d03541a74651c3a83ec72807b70e7..0472adbc6d197fede78fef430f6d9e4f07367522 100644 (file)
@@ -60,6 +60,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \
              -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \
              -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \
+             -e 's/@''GNULIB_HYPOTF''@/$(GNULIB_HYPOTF)/g' \
              -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \
              -e 's/@''GNULIB_ISINF''@/$(GNULIB_ISINF)/g' \
              -e 's/@''GNULIB_ISNAN''@/$(GNULIB_ISNAN)/g' \
@@ -122,6 +123,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|g' \
              -e 's|@''HAVE_FMODL''@|$(HAVE_FMODL)|g' \
              -e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \
+             -e 's|@''HAVE_HYPOTF''@|$(HAVE_HYPOTF)|g' \
              -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
              -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
              -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
@@ -189,6 +191,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
              -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \
              -e 's|@''REPLACE_HUGE_VAL''@|$(REPLACE_HUGE_VAL)|g' \
+             -e 's|@''REPLACE_HYPOTF''@|$(REPLACE_HYPOTF)|g' \
              -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
              -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
              -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
index b6534f0268ba760b2a47419c3fbc777f38067741..05ea2144e2b909e6e741ee8b027a060dd7686b75 100644 (file)
@@ -155,6 +155,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::frexp, double, (double, int *));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::frexpl, long double, (long double, int *));
 #endif
 
+#if GNULIB_TEST_HYPOTF
+SIGNATURE_CHECK (GNULIB_NAMESPACE::hypotf, float, (float, float));
+#endif
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::hypot, double, (double, double));
 
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::j0, double, (double));