changeset 16405:e393287b3d95

New module 'fabsl'. * lib/math.in.h (fabsl): New declaration. * lib/fabsl.c: New file. * m4/fabsl.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether fabsl is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_FABSL, HAVE_FABSL, REPLACE_FABSL. * modules/math (Makefile.am): Substitute GNULIB_FABSL, HAVE_FABSL, REPLACE_FABSL. * modules/fabsl: New file. * doc/posix-functions/fabsl.texi: Mention the new module.
author Bruno Haible <bruno@clisp.org>
date Sat, 25 Feb 2012 13:18:33 +0100
parents fc64dbadc964
children cf418c889016
files ChangeLog doc/posix-functions/fabsl.texi lib/fabsl.c lib/math.in.h m4/fabsl.m4 m4/math_h.m4 modules/fabsl modules/math
diffstat 8 files changed, 199 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2012-02-25  Bruno Haible  <bruno@clisp.org>
+
+	New module 'fabsl'.
+	* lib/math.in.h (fabsl): New declaration.
+	* lib/fabsl.c: New file.
+	* m4/fabsl.m4: New file.
+	* m4/math_h.m4 (gl_MATH_H): Test whether fabsl is declared.
+	(gl_MATH_H_DEFAULTS): Initialize GNULIB_FABSL, HAVE_FABSL,
+	REPLACE_FABSL.
+	* modules/math (Makefile.am): Substitute GNULIB_FABSL, HAVE_FABSL,
+	REPLACE_FABSL.
+	* modules/fabsl: New file.
+	* doc/posix-functions/fabsl.texi: Mention the new module.
+
 2012-02-25  Bruno Haible  <bruno@clisp.org>
 
 	fabs tests: More tests.
--- a/doc/posix-functions/fabsl.texi
+++ b/doc/posix-functions/fabsl.texi
@@ -4,18 +4,21 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/fabsl.html}
 
-Gnulib module: ---
+Gnulib module: fabsl
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This function is missing on some platforms:
 NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
 @item
 This function is only defined as a macro with arguments on some platforms:
 MSVC 9.
+@item
+This function returns a minus zero for a minus zero argument on some platforms:
+IRIX 6.5 with gcc 4.2.4.
 @end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
new file mode 100644
--- /dev/null
+++ b/lib/fabsl.c
@@ -0,0 +1,41 @@
+/* Absolute value.
+   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>
+
+/* fabsl (x) can be defined as copysignl (x, 1.0L).
+   Or, more directly, as (signbit (x) ? - x : x).  */
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+long double
+fabsl (long double x)
+{
+  return fabs (x);
+}
+
+#else
+
+long double
+fabsl (long double x)
+{
+  return (signbit (x) ? - x : x);
+}
+
+#endif
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -453,6 +453,30 @@
 # endif
 #endif
 
+#if @GNULIB_FABSL@
+# if @REPLACE_FABSL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fabsl
+#   define fabsl rpl_fabsl
+#  endif
+_GL_FUNCDECL_RPL (fabsl, long double, (long double x));
+_GL_CXXALIAS_RPL (fabsl, long double, (long double x));
+# else
+#  if !@HAVE_FABSL@
+#   undef fabsl
+_GL_FUNCDECL_SYS (fabsl, long double, (long double x));
+#  endif
+_GL_CXXALIAS_SYS (fabsl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (fabsl);
+#elif defined GNULIB_POSIXCHECK
+# undef fabsl
+# if HAVE_RAW_DECL_FABSL
+_GL_WARN_ON_USE (fabsl, "fabsl is unportable - "
+                 "use gnulib module fabsl for portability");
+# endif
+#endif
+
 
 #if @GNULIB_FLOORF@
 # if @REPLACE_FLOORF@
new file mode 100644
--- /dev/null
+++ b/m4/fabsl.m4
@@ -0,0 +1,71 @@
+# fabsl.m4 serial 1
+dnl Copyright (C) 2011-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_FABSL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+
+  dnl Determine FABSL_LIBM.
+  gl_MATHFUNC([fabsl], [long double], [(long double)])
+  if test $gl_cv_func_fabsl_no_libm = yes \
+     || test $gl_cv_func_fabsl_in_libm = yes; then
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $FABSL_LIBM"
+    gl_FUNC_FABSL_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_fabsl_works" in
+      *yes) ;;
+      *) REPLACE_FABSL=1 ;;
+    esac
+  else
+    HAVE_FABSL=0
+  fi
+  if test $HAVE_FABSL = 0 || test $REPLACE_FABSL = 1; then
+    dnl Find libraries needed to link lib/fabsl.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_FABS])
+      FABSL_LIBM="$FABS_LIBM"
+    else
+      FABSL_LIBM=
+    fi
+  fi
+  AC_SUBST([FABSL_LIBM])
+])
+
+dnl Test whether fabsl() works on a minus zero.
+dnl On IRIX 6.5, with gcc 4.2.4 and without -fno-builtin-fabsl, the value is a
+dnl minus zero rather than a positive zero.
+AC_DEFUN([gl_FUNC_FABSL_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether fabsl works], [gl_cv_func_fabsl_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <float.h>
+#include <math.h>
+#include <string.h>
+volatile long double x;
+long double y;
+long double zero = 0.0L;
+int main ()
+{
+  x = - (LDBL_MIN * LDBL_MIN * LDBL_MIN);
+  y = fabsl (x);
+  return (memcmp (&y, &zero, sizeof y) != 0);
+}
+]])],
+        [gl_cv_func_fabsl_works=yes],
+        [gl_cv_func_fabsl_works=no],
+        [case "$host_os" in
+           irix*) gl_cv_func_fabsl_works="guessing no";;
+           *)     gl_cv_func_fabsl_works="guessing yes";;
+         esac
+        ])
+    ])
+])
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 56
+# math_h.m4 serial 57
 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,
@@ -41,7 +41,7 @@
   gl_WARN_ON_USE_PREPARE([[#include <math.h>]],
     [acosf acosl asinf asinl atanf atanl
      ceilf ceill copysign copysignf copysignl cosf cosl coshf
-     expf expl fabsf floorf floorl fma fmaf fmal fmodf frexpf frexpl
+     expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf frexpf frexpl
      ldexpf ldexpl logb logf logl log10f modff powf
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
      tanf tanl tanhf trunc truncf truncl])
@@ -77,6 +77,7 @@
   GNULIB_EXPF=0;      AC_SUBST([GNULIB_EXPF])
   GNULIB_EXPL=0;      AC_SUBST([GNULIB_EXPL])
   GNULIB_FABSF=0;     AC_SUBST([GNULIB_FABSF])
+  GNULIB_FABSL=0;     AC_SUBST([GNULIB_FABSL])
   GNULIB_FLOOR=0;     AC_SUBST([GNULIB_FLOOR])
   GNULIB_FLOORF=0;    AC_SUBST([GNULIB_FLOORF])
   GNULIB_FLOORL=0;    AC_SUBST([GNULIB_FLOORL])
@@ -136,6 +137,7 @@
   HAVE_EXPF=1;                 AC_SUBST([HAVE_EXPF])
   HAVE_EXPL=1;                 AC_SUBST([HAVE_EXPL])
   HAVE_FABSF=1;                AC_SUBST([HAVE_FABSF])
+  HAVE_FABSL=1;                AC_SUBST([HAVE_FABSL])
   HAVE_FMA=1;                  AC_SUBST([HAVE_FMA])
   HAVE_FMAF=1;                 AC_SUBST([HAVE_FMAF])
   HAVE_FMAL=1;                 AC_SUBST([HAVE_FMAL])
@@ -186,6 +188,7 @@
   REPLACE_CEIL=0;              AC_SUBST([REPLACE_CEIL])
   REPLACE_CEILF=0;             AC_SUBST([REPLACE_CEILF])
   REPLACE_CEILL=0;             AC_SUBST([REPLACE_CEILL])
+  REPLACE_FABSL=0;             AC_SUBST([REPLACE_FABSL])
   REPLACE_FLOOR=0;             AC_SUBST([REPLACE_FLOOR])
   REPLACE_FLOORF=0;            AC_SUBST([REPLACE_FLOORF])
   REPLACE_FLOORL=0;            AC_SUBST([REPLACE_FLOORL])
new file mode 100644
--- /dev/null
+++ b/modules/fabsl
@@ -0,0 +1,33 @@
+Description:
+fabsl() function: absolute value.
+
+Files:
+lib/fabsl.c
+m4/fabsl.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+fabs            [{ test $HAVE_FABSL = 0 || test $REPLACE_FABSL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+signbit         [{ test $HAVE_FABSL = 0 || test $REPLACE_FABSL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+
+configure.ac:
+gl_FUNC_FABSL
+if test $HAVE_FABSL = 0 || test $REPLACE_FABSL = 1; then
+  AC_LIBOBJ([fabsl])
+fi
+gl_MATH_MODULE_INDICATOR([fabsl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(FABSL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
--- a/modules/math
+++ b/modules/math
@@ -47,6 +47,7 @@
 	      -e 's/@''GNULIB_EXPF''@/$(GNULIB_EXPF)/g' \
 	      -e 's/@''GNULIB_EXPL''@/$(GNULIB_EXPL)/g' \
 	      -e 's/@''GNULIB_FABSF''@/$(GNULIB_FABSF)/g' \
+	      -e 's/@''GNULIB_FABSL''@/$(GNULIB_FABSL)/g' \
 	      -e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \
 	      -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \
 	      -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \
@@ -106,6 +107,7 @@
 	      -e 's|@''HAVE_EXPF''@|$(HAVE_EXPF)|g' \
 	      -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \
 	      -e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \
+	      -e 's|@''HAVE_FABSL''@|$(HAVE_FABSL)|g' \
 	      -e 's|@''HAVE_FMA''@|$(HAVE_FMA)|g' \
 	      -e 's|@''HAVE_FMAF''@|$(HAVE_FMAF)|g' \
 	      -e 's|@''HAVE_FMAL''@|$(HAVE_FMAL)|g' \
@@ -157,6 +159,7 @@
 	  sed -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \
 	      -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \
 	      -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \
+	      -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \
 	      -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \
 	      -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \
 	      -e 's|@''REPLACE_FLOORL''@|$(REPLACE_FLOORL)|g' \