[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new module 'hypotl'
From: |
Bruno Haible |
Subject: |
new module 'hypotl' |
Date: |
Wed, 29 Feb 2012 15:49:37 +0100 |
User-agent: |
KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; ) |
The hypotl module has no surprises.
2012-02-29 Bruno Haible <address@hidden>
New module 'hypotl'.
* lib/math.in.h (hypotl): New declaration.
* lib/hypotl.c: New file.
* m4/hypotl.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether hypotf is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_HYPOTL, HAVE_HYPOTL.
* modules/math (Makefile.am): Substitute GNULIB_HYPOTL, HAVE_HYPOTL.
* modules/hypotl: New file.
* tests/test-math-c++.cc: Check the hypotl declaration.
* doc/posix-functions/hypotl.texi: Mention the new module.
================================ lib/hypotl.c ================================
/* 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/>. */
/* Written by Bruno Haible <address@hidden>, 2012. */
#include <config.h>
/* Specification. */
#include <math.h>
#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
long double
hypotl (long double x, long double y)
{
return hypot (x, y);
}
#else
long double
hypotl (long double x, long double y)
{
if (isfinite (x) && isfinite (y))
{
/* Determine absolute values. */
x = fabsl (x);
y = fabsl (y);
{
/* Find the bigger and the smaller one. */
long double a;
long double b;
if (x >= y)
{
a = x;
b = y;
}
else
{
a = y;
b = x;
}
/* Now 0 <= b <= a. */
{
int e;
long double an;
long double bn;
/* Write a = an * 2^e, b = bn * 2^e with 0 <= bn <= an < 1. */
an = frexpl (a, &e);
bn = ldexpl (b, - e);
{
long double cn;
/* Through the normalization, no unneeded overflow or underflow
will occur here. */
cn = sqrtl (an * an + bn * bn);
return ldexpl (cn, e);
}
}
}
}
else
{
if (isinf (x) || isinf (y))
/* x or y is infinite. Return +Infinity. */
return HUGE_VALL;
else
/* x or y is NaN. Return NaN. */
return x + y;
}
}
#endif
================================ m4/hypotl.m4 ================================
# hypotl.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_HYPOTL],
[
AC_REQUIRE([gl_MATH_H_DEFAULTS])
AC_REQUIRE([gl_FUNC_HYPOT])
dnl Test whether hypotl() exists. Assume that hypotl(), if it exists, is
dnl defined in the same library as hypot().
save_LIBS="$LIBS"
LIBS="$LIBS $HYPOT_LIBM"
AC_CHECK_FUNCS([hypotl])
LIBS="$save_LIBS"
if test $ac_cv_func_hypotl = yes; then
HYPOTL_LIBM="$HYPOT_LIBM"
else
HAVE_HYPOTL=0
dnl Find libraries needed to link lib/hypotl.c.
if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
HYPOTL_LIBM="$HYPOT_LIBM"
else
AC_REQUIRE([gl_FUNC_FABSL])
AC_REQUIRE([gl_FUNC_FREXPL])
AC_REQUIRE([gl_FUNC_LDEXPL])
AC_REQUIRE([gl_FUNC_SQRTL])
HYPOTL_LIBM=
dnl Append $FABSL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
case " $HYPOTL_LIBM " in
*" $FABSL_LIBM "*) ;;
*) HYPOTL_LIBM="$HYPOTL_LIBM $FABSL_LIBM" ;;
esac
dnl Append $FREXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
case " $HYPOTL_LIBM " in
*" $FREXPL_LIBM "*) ;;
*) HYPOTL_LIBM="$HYPOTL_LIBM $FREXPL_LIBM" ;;
esac
dnl Append $LDEXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
case " $HYPOTL_LIBM " in
*" $LDEXPL_LIBM "*) ;;
*) HYPOTL_LIBM="$HYPOTL_LIBM $LDEXPL_LIBM" ;;
esac
dnl Append $SQRTL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
case " $HYPOTL_LIBM " in
*" $SQRTL_LIBM "*) ;;
*) HYPOTL_LIBM="$HYPOTL_LIBM $SQRTL_LIBM" ;;
esac
fi
fi
AC_SUBST([HYPOTL_LIBM])
])
=============================== modules/hypotl ===============================
Description:
hypotl() function: length of a vector in the plane.
Files:
lib/hypotl.c
m4/hypotl.m4
m4/mathfunc.m4
Depends-on:
math
hypot [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 1]
isfinite [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 0]
fabsl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 0]
frexpl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 0]
ldexpl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 0]
sqrtl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 0]
isinf [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
= 0]
configure.ac:
gl_FUNC_HYPOTL
if test $HAVE_HYPOTL = 0; then
AC_LIBOBJ([hypotl])
fi
gl_MATH_MODULE_INDICATOR([hypotl])
Makefile.am:
Include:
<math.h>
Link:
$(HYPOTL_LIBM)
License:
LGPL
Maintainer:
Bruno Haible
==============================================================================
--- doc/posix-functions/hypotl.texi.orig Wed Feb 29 15:43:23 2012
+++ doc/posix-functions/hypotl.texi Wed Feb 29 15:42:21 2012
@@ -4,15 +4,15 @@
POSIX specification:@*
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/hypotl.html}
-Gnulib module: ---
+Gnulib module: hypotl
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX
6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX
6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
@end itemize
--- lib/math.in.h.orig Wed Feb 29 15:43:23 2012
+++ lib/math.in.h Wed Feb 29 14:33:08 2012
@@ -832,6 +832,21 @@
# endif
#endif
+/* Return sqrt(x^2+y^2). */
+#if @GNULIB_HYPOTL@
+# if address@hidden@
+_GL_FUNCDECL_SYS (hypotl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y));
+_GL_CXXALIASWARN (hypotl);
+#elif defined GNULIB_POSIXCHECK
+# undef hypotl
+# if HAVE_RAW_DECL_HYPOTL
+_GL_WARN_ON_USE (hypotl, "hypotl is unportable - "
+ "use gnulib module hypotl for portability");
+# endif
+#endif
+
/* Return x * 2^exp. */
#if @GNULIB_LDEXPF@
--- m4/math_h.m4.orig Wed Feb 29 15:43:23 2012
+++ m4/math_h.m4 Wed Feb 29 14:35:29 2012
@@ -1,4 +1,4 @@
-# math_h.m4 serial 72
+# math_h.m4 serial 73
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 @@
[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 hypotf
+ fmod fmodf fmodl frexpf frexpl hypotf hypotl
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
@@ -93,6 +93,7 @@
GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP])
GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL])
GNULIB_HYPOTF=0; AC_SUBST([GNULIB_HYPOTF])
+ GNULIB_HYPOTL=0; AC_SUBST([GNULIB_HYPOTL])
GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE])
GNULIB_ISINF=0; AC_SUBST([GNULIB_ISINF])
GNULIB_ISNAN=0; AC_SUBST([GNULIB_ISNAN])
@@ -156,6 +157,7 @@
HAVE_FMODL=1; AC_SUBST([HAVE_FMODL])
HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF])
HAVE_HYPOTF=1; AC_SUBST([HAVE_HYPOTF])
+ HAVE_HYPOTL=1; AC_SUBST([HAVE_HYPOTL])
HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF])
HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND])
HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL])
--- modules/math.orig Wed Feb 29 15:43:23 2012
+++ modules/math Wed Feb 29 14:36:03 2012
@@ -61,6 +61,7 @@
-e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \
-e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \
-e 's/@''GNULIB_HYPOTF''@/$(GNULIB_HYPOTF)/g' \
+ -e 's/@''GNULIB_HYPOTL''@/$(GNULIB_HYPOTL)/g' \
-e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \
-e 's/@''GNULIB_ISINF''@/$(GNULIB_ISINF)/g' \
-e 's/@''GNULIB_ISNAN''@/$(GNULIB_ISNAN)/g' \
@@ -124,6 +125,7 @@
-e 's|@''HAVE_FMODL''@|$(HAVE_FMODL)|g' \
-e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \
-e 's|@''HAVE_HYPOTF''@|$(HAVE_HYPOTF)|g' \
+ -e 's|@''HAVE_HYPOTL''@|$(HAVE_HYPOTL)|g' \
-e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
-e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
-e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
--- tests/test-math-c++.cc.orig Wed Feb 29 15:43:23 2012
+++ tests/test-math-c++.cc Wed Feb 29 15:43:14 2012
@@ -159,6 +159,10 @@
SIGNATURE_CHECK (GNULIB_NAMESPACE::hypotf, float, (float, float));
#endif
//SIGNATURE_CHECK (GNULIB_NAMESPACE::hypot, double, (double, double));
+#if GNULIB_TEST_HYPOTL
+SIGNATURE_CHECK (GNULIB_NAMESPACE::hypotl, long double,
+ (long double, long double));
+#endif
//SIGNATURE_CHECK (GNULIB_NAMESPACE::j0, double, (double));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- new module 'hypotl',
Bruno Haible <=