From 2786c7d21611b9fa3b2fe356542cf213e7dd0ba4 Mon Sep 17 00:00:00 2001 From: nsz Date: Mon, 19 Mar 2012 22:57:58 +0100 Subject: use scalbn or *2.0 instead of ldexp, fix fmal Some code assumed ldexp(x, 1) is faster than 2.0*x, but ldexp is a wrapper around scalbn which uses multiplications inside, so this optimization is wrong. This commit also fixes fmal which accidentally used ldexp instead of ldexpl loosing precision. There are various additional changes from the work-in-progress const cleanups. --- src/math/expl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/math/expl.c') diff --git a/src/math/expl.c b/src/math/expl.c index 9507fd2e..b289ffec 100644 --- a/src/math/expl.c +++ b/src/math/expl.c @@ -102,13 +102,13 @@ long double expl(long double x) if (x > MAXLOGL) return INFINITY; if (x < MINLOGL) - return 0.0L; + return 0.0; /* Express e**x = e**g 2**n * = e**g e**(n loge(2)) * = e**(g + n loge(2)) */ - px = floorl(LOG2EL * x + 0.5L); /* floor() truncates toward -infinity. */ + px = floorl(LOG2EL * x + 0.5); /* floor() truncates toward -infinity. */ n = px; x -= px * C1; x -= px * C2; @@ -120,8 +120,8 @@ long double expl(long double x) xx = x * x; px = x * __polevll(xx, P, 2); x = px/(__polevll(xx, Q, 3) - px); - x = 1.0L + ldexpl(x, 1); - x = ldexpl(x, n); + x = 1.0 + 2.0 * x; + x = scalbnl(x, n); return x; } #endif -- cgit v1.2.1