From: Bruno Haible Date: Mon, 10 Oct 2011 22:00:31 +0000 (+0200) Subject: expl: Simplify for platforms where 'long double' == 'double'. X-Git-Tag: v0.1~1589 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=150ee3a66dce0f413327e67322e5b89ed440bd71;p=gnulib.git expl: Simplify for platforms where 'long double' == 'double'. * lib/expl.c (expl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New alternative implementation. * m4/expl.m4 (gl_FUNC_EXPL): Require gl_LONG_DOUBLE_VS_DOUBLE. Determine EXPL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE. * modules/expl (Depends-on): Add exp. Update conditions. --- diff --git a/ChangeLog b/ChangeLog index a55d7b0ff..ed76156b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2011-10-10 Bruno Haible + expl: Simplify for platforms where 'long double' == 'double'. + * lib/expl.c (expl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New alternative + implementation. + * m4/expl.m4 (gl_FUNC_EXPL): Require gl_LONG_DOUBLE_VS_DOUBLE. + Determine EXPL_LIBM according to HAVE_SAME_LONG_DOUBLE_AS_DOUBLE. + * modules/expl (Depends-on): Add exp. Update conditions. + +2011-10-10 Bruno Haible + sqrtl: Simplify for platforms where 'long double' == 'double'. * lib/sqrtl.c (sqrtl) [HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]: New alternative implementation. diff --git a/lib/expl.c b/lib/expl.c index 3f438925f..49fdefae6 100644 --- a/lib/expl.c +++ b/lib/expl.c @@ -23,16 +23,26 @@ /* Specification. */ #include -#include +#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE + +long double +expl (long double x) +{ + return exp (x); +} + +#else + +# include static const long double C[] = { /* Chebyshev polynom coeficients for (exp(x)-1)/x */ -#define P1 C[0] -#define P2 C[1] -#define P3 C[2] -#define P4 C[3] -#define P5 C[4] -#define P6 C[5] +# define P1 C[0] +# define P2 C[1] +# define P3 C[2] +# define P4 C[3] +# define P5 C[4] +# define P6 C[5] 0.5L, 1.66666666666666666666666666666666683E-01L, 4.16666666666666666666654902320001674E-02L, @@ -41,19 +51,19 @@ static const long double C[] = { 1.98412698413981650382436541785404286E-04L, /* Smallest integer x for which e^x overflows. */ -#define himark C[6] +# define himark C[6] 11356.523406294143949491931077970765L, /* Largest integer x for which e^x underflows. */ -#define lomark C[7] +# define lomark C[7] -11433.4627433362978788372438434526231L, /* very small number */ -#define TINY C[8] +# define TINY C[8] 1.0e-4900L, /* 2^16383 */ -#define TWO16383 C[9] +# define TWO16383 C[9] 5.94865747678615882542879663314003565E+4931L}; long double @@ -118,6 +128,8 @@ expl (long double x) return TWO16383*x; } +#endif + #if 0 int main (void) diff --git a/m4/expl.m4 b/m4/expl.m4 index c9c1b7b9e..af60829fa 100644 --- a/m4/expl.m4 +++ b/m4/expl.m4 @@ -1,4 +1,4 @@ -# expl.m4 serial 4 +# expl.m4 serial 5 dnl Copyright (C) 2010-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, @@ -7,6 +7,8 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_EXPL], [ AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) + dnl Persuade glibc to declare expl(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) @@ -56,8 +58,13 @@ AC_DEFUN([gl_FUNC_EXPL], HAVE_DECL_EXPL=0 HAVE_EXPL=0 dnl Find libraries needed to link lib/expl.c. - AC_REQUIRE([gl_FUNC_FLOORL]) - EXPL_LIBM="$FLOORL_LIBM" + if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then + AC_REQUIRE([gl_FUNC_EXP]) + EXPL_LIBM="$EXP_LIBM" + else + AC_REQUIRE([gl_FUNC_FLOORL]) + EXPL_LIBM="$FLOORL_LIBM" + fi fi AC_SUBST([EXPL_LIBM]) ]) diff --git a/modules/expl b/modules/expl index ed377c305..7df4fb653 100644 --- a/modules/expl +++ b/modules/expl @@ -8,8 +8,9 @@ m4/expl.m4 Depends-on: math extensions -float [test $HAVE_EXPL = 0] -floorl [test $HAVE_EXPL = 0] +exp [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +float [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +floorl [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_EXPL