From: Bruno Haible Date: Sat, 25 Feb 2012 12:18:33 +0000 (+0100) Subject: New module 'fabsl'. X-Git-Tag: v0.1~1121 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=653b905f9a93de7280216e1f58be6068fb21acf4;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 3d40c0cc2..02bfcc9a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2012-02-25 Bruno Haible + 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 + fabs tests: More tests. * tests/test-fabs.c: Include , minus-zero.h. (zero): New variable. diff --git a/doc/posix-functions/fabsl.texi b/doc/posix-functions/fabsl.texi index b1eb63b6e..35ede8040 100644 --- 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 diff --git a/lib/fabsl.c b/lib/fabsl.c new file mode 100644 index 000000000..ca89631fa --- /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 . */ + +#include + +/* Specification. */ +#include + +/* 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 diff --git a/lib/math.in.h b/lib/math.in.h index 555f848d1..d7b0e3d87 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -453,6 +453,30 @@ _GL_WARN_ON_USE (fabsf, "fabsf is unportable - " # 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@ diff --git a/m4/fabsl.m4 b/m4/fabsl.m4 new file mode 100644 index 000000000..fa4825bb3 --- /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 +#include +#include +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 + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 5d7d52bba..2dad99970 100644 --- 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 @@ AC_DEFUN([gl_MATH_H], gl_WARN_ON_USE_PREPARE([[#include ]], [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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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]) diff --git a/modules/fabsl b/modules/fabsl new file mode 100644 index 000000000..686ddaa31 --- /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: + + +Link: +$(FABSL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index 5bca0e10f..d450afa4d 100644 --- a/modules/math +++ b/modules/math @@ -47,6 +47,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -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 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -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 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( 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' \