From a820f9b3c0cb5e80cd892b0f9c1c48f48bd4413f Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 16 Feb 2015 22:38:28 +0000 Subject: Fix remquo spurious overflows (bug 17978). Various remquo implementations, when computing the last three bits of the quotient, have spurious overflows when 4 times the second argument to remquo overflows. These overflows can in turn cause bad results in rounding modes where that overflow results in a finite value. This patch adds tests to avoid the problem multiplications in cases where they would overflow, similar to those that control an earlier multiplication by 8. Tested for x86_64, x86, mips64 and powerpc. [BZ #17978] * sysdeps/ieee754/dbl-64/s_remquo.c (__remquo): Do not form products 4 * y and 2 * y where those would overflow. * sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c (__remquo): Likewise. * sysdeps/ieee754/flt-32/s_remquof.c (__remquof): Likewise. * sysdeps/ieee754/ldbl-128/s_remquol.c (__remquol): Likewise. * sysdeps/ieee754/ldbl-128ibm/s_remquol.c (__remquol): Likewise. * sysdeps/ieee754/ldbl-96/s_remquol.c (__remquol): Likewise. * math/libm-test.inc (remquo_test_data): Add more tests. --- sysdeps/ieee754/dbl-64/s_remquo.c | 4 ++-- sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'sysdeps/ieee754/dbl-64') diff --git a/sysdeps/ieee754/dbl-64/s_remquo.c b/sysdeps/ieee754/dbl-64/s_remquo.c index 2724902908..e07efa89f8 100644 --- a/sysdeps/ieee754/dbl-64/s_remquo.c +++ b/sysdeps/ieee754/dbl-64/s_remquo.c @@ -60,12 +60,12 @@ __remquo (double x, double y, int *quo) y = fabs (y); cquo = 0; - if (x >= 4 * y) + if (hy <= 0x7fcfffff && x >= 4 * y) { x -= 4 * y; cquo += 4; } - if (x >= 2 * y) + if (hy <= 0x7fdfffff && x >= 2 * y) { x -= 2 * y; cquo += 2; diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c index 5b7142576a..ab561780c8 100644 --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c +++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c @@ -59,12 +59,12 @@ __remquo (double x, double y, int *quo) INSERT_WORDS64 (y, hy); cquo = 0; - if (x >= 4 * y) + if (hy <= UINT64_C(0x7fcfffffffffffff) && x >= 4 * y) { x -= 4 * y; cquo += 4; } - if (x >= 2 * y) + if (hy <= UINT64_C(0x7fdfffffffffffff) && x >= 2 * y) { x -= 2 * y; cquo += 2; -- cgit 1.4.1