Mercurial > hg > octave-kai > gnulib-hg
changeset 16042:40ce19578aff
New module 'fmal'.
* lib/math.in.h (fmal): New declaration.
* lib/fmal.c: New file.
* m4/fmal.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whethern fmal is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_FMAL, HAVE_FMAL, REPLACE_FMAL.
* modules/math (Makefile.am): Substitute GNULIB_FMAL, HAVE_FMAL,
REPLACE_FMAL.
* modules/fmal: New file.
* doc/posix-functions/fmal.texi: Mention the new module and the various
bugs.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 17 Oct 2011 23:54:37 +0200 |
parents | cff43a01d7dc |
children | 031ad3dbbe05 |
files | ChangeLog doc/posix-functions/fmal.texi lib/fmal.c lib/math.in.h m4/fmal.m4 m4/math_h.m4 modules/fmal modules/math |
diffstat | 8 files changed, 499 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2011-11-05 Bruno Haible <bruno@clisp.org> + New module 'fmal'. + * lib/math.in.h (fmal): New declaration. + * lib/fmal.c: New file. + * m4/fmal.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whethern fmal is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_FMAL, HAVE_FMAL, REPLACE_FMAL. + * modules/math (Makefile.am): Substitute GNULIB_FMAL, HAVE_FMAL, + REPLACE_FMAL. + * modules/fmal: New file. + * doc/posix-functions/fmal.texi: Mention the new module and the various + bugs. + Tests for module 'fmaf'. * modules/fmaf-tests: New file. * tests/test-fmaf1.c: New file.
--- a/doc/posix-functions/fmal.texi +++ b/doc/posix-functions/fmal.texi @@ -4,15 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/fmal.html} -Gnulib module: --- +Gnulib module: fmal Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS. +@item +This function produces wrong results on some platforms: +glibc 2.11, MacOS X 10.5, FreeBSD 6.4/x86, OSF/1 5.1, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS. @end itemize
new file mode 100644 --- /dev/null +++ b/lib/fmal.c @@ -0,0 +1,37 @@ +/* Fused multiply-add. + Copyright (C) 2011 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 <bruno@clisp.org>, 2011. */ + +#include <config.h> + +#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE + +/* Specification. */ +# include <math.h> + +long double +fmal (long double x, long double y, long double z) +{ + return fma (x, y, z); +} + +#else + +# define USE_LONG_DOUBLE +# include "fma.c" + +#endif
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -553,6 +553,33 @@ # endif #endif +#if @GNULIB_FMAL@ +# if @REPLACE_FMAL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fmal +# define fmal rpl_fmal +# endif +_GL_FUNCDECL_RPL (fmal, long double, + (long double x, long double y, long double z)); +_GL_CXXALIAS_RPL (fmal, long double, + (long double x, long double y, long double z)); +# else +# if !@HAVE_FMAL@ +_GL_FUNCDECL_SYS (fmal, long double, + (long double x, long double y, long double z)); +# endif +_GL_CXXALIAS_SYS (fmal, long double, + (long double x, long double y, long double z)); +# endif +_GL_CXXALIASWARN (fmal); +#elif defined GNULIB_POSIXCHECK +# undef fmal +# if HAVE_RAW_DECL_FMAL +_GL_WARN_ON_USE (fmal, "fmal is unportable - " + "use gnulib module fmal for portability"); +# endif +#endif + #if @GNULIB_FMODF@ # if !@HAVE_FMODF@
new file mode 100644 --- /dev/null +++ b/m4/fmal.m4 @@ -0,0 +1,365 @@ +# fmal.m4 serial 1 +dnl Copyright (C) 2011 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_FMAL], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) + + dnl Determine FMAL_LIBM. + gl_MATHFUNC([fmal], [long double], [(long double, long double, long double)]) + if test $gl_cv_func_fmal_no_libm = yes \ + || test $gl_cv_func_fmal_in_libm = yes; then + gl_FUNC_FMAL_WORKS + case "$gl_cv_func_fmal_works" in + *no) REPLACE_FMAL=1 ;; + esac + else + HAVE_FMAL=0 + fi + if test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; then + dnl Find libraries needed to link lib/fmal.c. + if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then + AC_REQUIRE([gl_FUNC_FMA]) + FMAL_LIBM="$FMA_LIBM" + else + AC_REQUIRE([gl_FUNC_FREXPL]) + AC_REQUIRE([gl_FUNC_LDEXPL]) + AC_REQUIRE([gl_FUNC_FEGETROUND]) + FMAL_LIBM= + dnl Append $FREXPL_LIBM to FMAL_LIBM, avoiding gratuitous duplicates. + case " $FMAL_LIBM " in + *" $FREXPL_LIBM "*) ;; + *) FMAL_LIBM="$FMAL_LIBM $FREXPL_LIBM" ;; + esac + dnl Append $LDEXPL_LIBM to FMAL_LIBM, avoiding gratuitous duplicates. + case " $FMAL_LIBM " in + *" $LDEXPL_LIBM "*) ;; + *) FMAL_LIBM="$FMAL_LIBM $LDEXPL_LIBM" ;; + esac + dnl Append $FEGETROUND_LIBM to FMAL_LIBM, avoiding gratuitous duplicates. + case " $FMAL_LIBM " in + *" $FEGETROUND_LIBM "*) ;; + *) FMAL_LIBM="$FMAL_LIBM $FEGETROUND_LIBM" ;; + esac + fi + fi + AC_SUBST([FMAL_LIBM]) +]) + +dnl Test whether fmal() has any of the 15 known bugs of glibc 2.11.3 on x86_64. +AC_DEFUN([gl_FUNC_FMAL_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_FUNC_LDEXPL]) + save_LIBS="$LIBS" + LIBS="$LIBS $FMAL_LIBM $LDEXPL_LIBM" + AC_CACHE_CHECK([whether fmal works], [gl_cv_func_fmal_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <float.h> +#include <math.h> +/* Override the values of <float.h>, like done in float.in.h. */ +#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 64 +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +# undef LDBL_MAX_EXP +# define LDBL_MAX_EXP 16384 +#endif +#if defined __i386__ && defined __FreeBSD__ +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 64 +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +# undef LDBL_MAX_EXP +# define LDBL_MAX_EXP 16384 +#endif +#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +#endif +#if defined __sgi && (LDBL_MANT_DIG >= 106) +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 106 +# if defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +# endif +#endif +long double p0 = 0.0L; +int main() +{ + int failed_tests = 0; + /* This test fails on glibc 2.11 powerpc. */ + { + volatile long double x = 1.5L; /* 3 * 2^-1 */ + volatile long double y = x; + volatile long double z = ldexpl (1.0L, LDBL_MANT_DIG + 1); /* 2^65 */ + /* x * y + z with infinite precision: 2^65 + 9 * 2^-2. + Lies between (2^63 + 0) * 2^2 and (2^63 + 1) * 2^2 + and is closer to (2^63 + 1) * 2^2, therefore the rounding + must round up and produce (2^63 + 1) * 2^2. */ + volatile long double expected = z + 4.0L; + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 1; + } + /* This test fails on glibc 2.11 powerpc. */ + { + volatile long double x = 1.25L; /* 2^0 + 2^-2 */ + volatile long double y = - x; + volatile long double z = ldexpl (1.0L, LDBL_MANT_DIG + 1); /* 2^65 */ + /* x * y + z with infinite precision: 2^65 - 2^0 - 2^-1 - 2^-4. + Lies between (2^64 - 1) * 2^1 and 2^64 * 2^1 + and is closer to (2^64 - 1) * 2^1, therefore the rounding + must round down and produce (2^64 - 1) * 2^1. */ + volatile long double expected = (ldexpl (1.0L, LDBL_MANT_DIG) - 1.0L) * 2.0L; + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 1; + } + /* This test fails on glibc 2.11 x86,x86_64,powerpc, glibc 2.7 hppa,sparc, + OSF/1 5.1, mingw. */ + { + volatile long double x = 1.0L + ldexpl (1.0L, 1 - LDBL_MANT_DIG); /* 2^0 + 2^-63 */ + volatile long double y = x; + volatile long double z = 4.0L; /* 2^2 */ + /* x * y + z with infinite precision: 2^2 + 2^0 + 2^-62 + 2^-126. + Lies between (2^63 + 2^61) * 2^-61 and (2^63 + 2^61 + 1) * 2^-61 + and is closer to (2^63 + 2^61 + 1) * 2^-61, therefore the rounding + must round up and produce (2^63 + 2^61 + 1) * 2^-61. */ + volatile long double expected = 4.0L + 1.0L + ldexpl (1.0L, 3 - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 2; + } + /* This test fails on glibc 2.11 x86,x86_64,powerpc glibc 2.7 hppa,sparc, + OSF/1 5.1, mingw. */ + { + volatile long double x = 1.0L + ldexpl (1.0L, 1 - LDBL_MANT_DIG); /* 2^0 + 2^-63 */ + volatile long double y = - x; + volatile long double z = 8.0L; /* 2^3 */ + /* x * y + z with infinite precision: 2^2 + 2^1 + 2^0 - 2^-62 - 2^-126. + Lies between (2^63 + 2^62 + 2^61 - 1) * 2^-61 and + (2^63 + 2^62 + 2^61) * 2^-61 and is closer to + (2^63 + 2^62 + 2^61 - 1) * 2^-61, therefore the rounding + must round down and produce (2^63 + 2^62 + 2^61 - 1) * 2^-61. */ + volatile long double expected = 7.0L - ldexpl (1.0L, 3 - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 2; + } + /* This test fails on glibc 2.11 powerpc. */ + { + volatile long double x = 1.25L; /* 2^0 + 2^-2 */ + volatile long double y = - 0.75L; /* - 2^0 + 2^-2 */ + volatile long double z = ldexpl (1.0L, LDBL_MANT_DIG); /* 2^64 */ + /* x * y + z with infinite precision: 2^64 - 2^0 + 2^-4. + Lies between (2^64 - 2^0) and 2^64 and is closer to (2^64 - 2^0), + therefore the rounding must round down and produce (2^64 - 2^0). */ + volatile long double expected = ldexpl (1.0L, LDBL_MANT_DIG) - 1.0L; + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 1; + } + if ((LDBL_MANT_DIG % 2) == 1) + { + /* These tests fail on glibc 2.7 hppa,sparc, OSF/1 5.1. */ + { + volatile long double x = 1.0L + ldexpl (1.0L, - (LDBL_MANT_DIG + 1) / 2); /* 2^0 + 2^-27 */ + volatile long double y = 1.0L - ldexpl (1.0L, - (LDBL_MANT_DIG + 1) / 2); /* 2^0 - 2^-27 */ + volatile long double z = - ldexpl (1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG); /* - 2^-1074 */ + /* x * y + z with infinite precision: 2^0 - 2^-54 - 2^-1074. + Lies between (2^53 - 1) * 2^-53 and 2^53 * 2^-53 and is closer to + (2^53 - 1) * 2^-53, therefore the rounding must round down and + produce (2^53 - 1) * 2^-53. */ + volatile long double expected = 1.0L - ldexpl (1.0L, - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 4; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - (LDBL_MANT_DIG + 1) / 2); /* 2^0 + 2^-57 */ + volatile long double y = x; + volatile long double z = ldexpl (1.0L, - LDBL_MANT_DIG); /* 2^-113 */ + /* x * y + z with infinite precision: 2^0 + 2^-56 + 2^-113 + 2^-114. + Lies between (2^112 + 2^56) * 2^-112 and (2^112 + 2^56 + 1) * 2^-112 + and is closer to (2^112 + 2^56 + 1) * 2^-112, therefore the rounding + must round up and produce (2^112 + 2^56 + 1) * 2^-112. */ + volatile long double expected = + 1.0L + ldexpl (1.0L, - (LDBL_MANT_DIG - 1) / 2) + ldexpl (1.0L, 1 - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 4; + } + } + else + { + /* These tests fail on glibc 2.11 x86,x86_64,powerpc, mingw. */ + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = x; + volatile long double z = ldexpl (1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG); /* 2^-16445 */ + /* x * y + z with infinite precision: 2^0 + 2^-31 + 2^-64 + 2^-16445. + Lies between (2^63 + 2^32 + 0) * 2^-63 and (2^63 + 2^32 + 1) * 2^-63 + and is closer to (2^63 + 2^32 + 1) * 2^-63, therefore the rounding + must round up and produce (2^63 + 2^32 + 1) * 2^-63. */ + volatile long double expected = + 1.0L + ldexpl (1.0L, 1 - LDBL_MANT_DIG / 2) + ldexpl (1.0L, 1 - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = x; + volatile long double z = ldexpl (1.0L, - LDBL_MANT_DIG); /* 2^-64 */ + /* x * y + z with infinite precision: 2^0 + 2^-31 + 2^-63. + Rounding must return this value unchanged. */ + volatile long double expected = 1.0L + ldexpl (1.0L, 1 - LDBL_MANT_DIG / 2) + ldexpl (1.0L, 1 - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = x; + volatile long double z = ldexpl (1.0L, 1 - LDBL_MANT_DIG); /* 2^-63 */ + /* x * y + z with infinite precision: 2^0 + 2^-31 + 2^-63 + 2^-64. + Lies between (2^63 + 2^32 + 1) * 2^-63 and (2^63 + 2^32 + 2) * 2^-63 + and is at the same distance from each. According to the round-to-even + rule, the rounding must round up and produce (2^63 + 2^32 + 2) * 2^-63. */ + volatile long double expected = 1.0L + ldexpl (1.0L, -31) + ldexpl (1.0L, -62); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = x; + volatile long double z = ldexpl (1.0L, LDBL_MANT_DIG / 2 + 1); /* 2^33 */ + /* x * y + z with infinite precision: 2^33 + 2^0 + 2^-31 + 2^-64. + Lies between (2^63 + 2^30) * 2^-30 and (2^63 + 2^30 + 1) * 2^-30 + and is closer to (2^63 + 2^30 + 1) * 2^-30, therefore the rounding + must round up and produce (2^63 + 2^30 + 1) * 2^-30. */ + volatile long double expected = z + 1.0L + ldexp (1.0L, 2 - LDBL_MANT_DIG / 2); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = x; + volatile long double z = - ldexpl (1.0, 1 - LDBL_MANT_DIG); /* - 2^-63 */ + /* x * y + z with infinite precision: 2^0 + 2^-31 - 2^-64. + Lies between (2^63 + 2^32 - 1) * 2^-63 and (2^63 + 2^32) * 2^-63 + and is at the same distance from each. According to the round-to-even + rule, the rounding must round up and produce (2^63 + 2^32) * 2^-63. */ + volatile long double expected = 1.0L + ldexpl (1.0L, 1 - LDBL_MANT_DIG / 2); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = x; + volatile long double z = - 1.0L; /* - 2^0 */ + /* x * y + z with infinite precision: 2^-31 + 2^-64. + Rounding must return this value unchanged. */ + volatile long double expected = ldexpl (1.0L, 1 - LDBL_MANT_DIG / 2) + ldexpl (1.0L, - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = - x; + volatile long double z = 2.0L; /* 2^1 */ + /* x * y + z with infinite precision: 2^0 - 2^31 - 2^-64. + Rounding must return this value unchanged. */ + volatile long double expected = 1.0L - ldexpl (1.0L, 1 - LDBL_MANT_DIG / 2) - ldexpl (1.0L, - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2); /* 2^0 + 2^-32 */ + volatile long double y = - x; + volatile long double z = ldexpl (1.0L, LDBL_MANT_DIG / 2 + 2); /* 2^34 */ + /* x * y + z with infinite precision: 2^34 - (2^0 + 2^-31 + 2^-64). + Lies between (2^64 - 2^30 - 1) * 2^-30 and (2^64 - 2^30) * 2^-30 + and is closer to (2^64 - 2^30 - 1) * 2^-30, therefore the rounding + must round down and produce (2^64 - 2^30 - 1) * 2^-30. */ + volatile long double expected = z - 1.0L - ldexpl (1.0L, 2 - LDBL_MANT_DIG / 2); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2 - 1); /* 2^0 + 2^-33 */ + volatile long double y = 1.0L - ldexpl (1.0L, - LDBL_MANT_DIG / 2 - 1); /* 2^0 - 2^-33 */ + volatile long double z = - ldexpl (1.0L, - LDBL_MANT_DIG - 1); /* 2^-65 */ + /* x * y + z with infinite precision: 2^0 - 2^-65 - 2^-66. + Lies between (2^64 - 1) * 2^-64 and 2^64 * 2^-64 and is closer to + (2^64 - 1) * 2^-64, therefore the rounding must round down and + produce (2^64 - 1) * 2^-64. */ + volatile long double expected = 1.0L - ldexpl (1.0L, - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + { + volatile long double x = 1.0L + ldexpl (1.0L, - LDBL_MANT_DIG / 2 - 1); /* 2^0 + 2^-33 */ + volatile long double y = 1.0L - ldexpl (1.0L, - LDBL_MANT_DIG / 2 - 1); /* 2^0 - 2^-33 */ + volatile long double z = - 1.0L; /* 2^0 */ + /* x * y + z with infinite precision: - 2^-66. + Rounding must return this value unchanged. */ + volatile long double expected = - ldexpl (1.0L, - LDBL_MANT_DIG - 2); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 8; + } + } + /* This test fails on glibc 2.11 x86,x86_64,powerpc, glibc 2.7 hppa,sparc, + FreeBSD 6.4 x86, mingw. */ + { + long double minus_inf = -1.0L / p0; + volatile long double x = ldexpl (1.0L, LDBL_MAX_EXP - 1); + volatile long double y = ldexpl (1.0L, LDBL_MAX_EXP - 1); + volatile long double z = minus_inf; + volatile long double result = fmal (x, y, z); + if (!(result == minus_inf)) + failed_tests |= 16; + } + /* This test fails on glibc 2.11 x86,x86_64,powerpc glibc 2.7 hppa,sparc, + MacOS X 10.5, FreeBSD 6.4 x86, OSF/1 5.1, mingw. */ + { + volatile long double x = ldexpl (1.0L, LDBL_MAX_EXP - 1); + volatile long double y = 2.0L; + volatile long double z = + - ldexpl (ldexpl (1.0L, LDBL_MAX_EXP - 1) - ldexpl (1.0L, LDBL_MAX_EXP - LDBL_MANT_DIG - 1), 1); + volatile long double expected = ldexpl (1.0L, LDBL_MAX_EXP - LDBL_MANT_DIG); + volatile long double result = fmal (x, y, z); + if (result != expected) + failed_tests |= 32; + } + return failed_tests; +}]])], + [gl_cv_func_fmal_works=yes], + [gl_cv_func_fmal_works=no], + [dnl Guess no, even on glibc systems. + gl_cv_func_fmal_works="guessing no" + ]) + ]) + LIBS="$save_LIBS" +]) + +# Prerequisites of lib/fmal.c. +AC_DEFUN([gl_PREREQ_FMAL], [:])
--- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 55 +# math_h.m4 serial 56 dnl Copyright (C) 2007-2011 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 fmodf frexpf frexpl + expf expl fabsf 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]) @@ -82,6 +82,7 @@ GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) GNULIB_FMA=0; AC_SUBST([GNULIB_FMA]) GNULIB_FMAF=0; AC_SUBST([GNULIB_FMAF]) + GNULIB_FMAL=0; AC_SUBST([GNULIB_FMAL]) GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF]) GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF]) GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) @@ -137,6 +138,7 @@ HAVE_FABSF=1; AC_SUBST([HAVE_FABSF]) HAVE_FMA=1; AC_SUBST([HAVE_FMA]) HAVE_FMAF=1; AC_SUBST([HAVE_FMAF]) + HAVE_FMAL=1; AC_SUBST([HAVE_FMAL]) HAVE_FMODF=1; AC_SUBST([HAVE_FMODF]) HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF]) HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF]) @@ -189,6 +191,7 @@ REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL]) REPLACE_FMA=0; AC_SUBST([REPLACE_FMA]) REPLACE_FMAF=0; AC_SUBST([REPLACE_FMAF]) + REPLACE_FMAL=0; AC_SUBST([REPLACE_FMAL]) REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF]) REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP]) REPLACE_FREXPL=0; AC_SUBST([REPLACE_FREXPL])
new file mode 100644 --- /dev/null +++ b/modules/fmal @@ -0,0 +1,43 @@ +Description: +fmal() function: fused multiply-add. + +Files: +lib/fmal.c +lib/fma.c +lib/float+.h +m4/fmal.m4 +m4/fegetround.m4 +m4/mathfunc.m4 + +Depends-on: +math +fma [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +float [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +stdbool [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +verify [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isfinite [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +integer_length [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +frexpl [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +ldexpl [{ test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] + +configure.ac: +gl_FUNC_FMAL +if test $HAVE_FMAL = 0 || test $REPLACE_FMAL = 1; then + AC_LIBOBJ([fmal]) + gl_PREREQ_FMAL +fi +gl_MATH_MODULE_INDICATOR([fmal]) + +Makefile.am: + +Include: +<math.h> + +Link: +$(FMAL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible
--- a/modules/math +++ b/modules/math @@ -52,6 +52,7 @@ -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \ -e 's/@''GNULIB_FMA''@/$(GNULIB_FMA)/g' \ -e 's/@''GNULIB_FMAF''@/$(GNULIB_FMAF)/g' \ + -e 's/@''GNULIB_FMAL''@/$(GNULIB_FMAL)/g' \ -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \ -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \ -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \ @@ -107,6 +108,7 @@ -e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \ -e 's|@''HAVE_FMA''@|$(HAVE_FMA)|g' \ -e 's|@''HAVE_FMAF''@|$(HAVE_FMAF)|g' \ + -e 's|@''HAVE_FMAL''@|$(HAVE_FMAL)|g' \ -e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|g' \ -e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \ -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \ @@ -160,6 +162,7 @@ -e 's|@''REPLACE_FLOORL''@|$(REPLACE_FLOORL)|g' \ -e 's|@''REPLACE_FMA''@|$(REPLACE_FMA)|g' \ -e 's|@''REPLACE_FMAF''@|$(REPLACE_FMAF)|g' \ + -e 's|@''REPLACE_FMAL''@|$(REPLACE_FMAL)|g' \ -e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \ -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \ -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \