From 9655379852fdbf3a0797035fc30a4060a2b191cf Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 4 Mar 2012 23:01:33 +0100 Subject: remainder, remainderf, remainderl: Fix computation for large quotients. * lib/remainder.c: Completely rewritten. * lib/remainderf.c (remainderf): Use implementation of remainder.c with USE_FLOAT. * lib/remainderl.c (remainderl): Use implementation of remainder.c with USE_LONG_DOUBLE. * modules/remainder (Depends-on): Add isfinite, signbit, fabs, fmod, isnand, isinf. Remove round, fma. * modules/remainderf (Files): Add lib/remainder.c. (Depends-on): Add isfinite, signbit, fabsf, fmodf, isnanf, isinf. Remove roundf, fmaf. * modules/remainderl (Files): Add lib/remainder.c. (Depends-on): Add float, isfinite, signbit, fabsl, fmodl, isnanl, isinf. Remove roundl, fmal. * m4/remainder.m4 (gl_FUNC_REMAINDER): Update computation of REMAINDER_LIBM. * m4/remainderf.m4 (gl_FUNC_REMAINDERF): Update computation of REMAINDERF_LIBM. * m4/remainderl.m4 (gl_FUNC_REMAINDERL): Update computation of REMAINDERL_LIBM. --- lib/remainderl.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'lib/remainderl.c') diff --git a/lib/remainderl.c b/lib/remainderl.c index 3476f948e2..474ebe217c 100644 --- a/lib/remainderl.c +++ b/lib/remainderl.c @@ -29,30 +29,7 @@ remainderl (long double x, long double y) #else -long double -remainderl (long double x, long double y) -{ - long double q = - roundl (x / y); - long double r = fmal (q, y, x); /* = x + q * y, computed in one step */ - /* Correct possible rounding errors in the quotient x / y. */ - long double half_y = 0.5L * y; - if (y >= 0) - { - /* Expect -y/2 <= r <= y/2. */ - if (r > half_y) - q -= 1, r = fmal (q, y, x); - else if (r < - half_y) - q += 1, r = fmal (q, y, x); - } - else - { - /* Expect y/2 <= r <= -y/2. */ - if (r > - half_y) - q += 1, r = fmal (q, y, x); - else if (r < half_y) - q -= 1, r = fmal (q, y, x); - } - return r; -} +# define USE_LONG_DOUBLE +# include "remainder.c" #endif -- cgit v1.2.1