From ce8fc784e619ada624dc41ed7603211131e66573 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 17 Feb 2015 00:41:50 +0000 Subject: Fix sign of remquo zero remainder in round-downward mode (bug 17987). Various remquo implementations produce a zero remainder with the wrong sign (a zero remainder should always have the sign of the first argument, as specified in IEEE 754) in round-downward mode, resulting from the sign of 0 - 0. This patch checks for zero results and fixes their sign accordingly. Tested for x86_64, x86, mips64 and powerpc. [BZ #17987] * sysdeps/ieee754/dbl-64/s_remquo.c (__remquo): Ensure sign of zero result does not depend on the sign resulting from subtraction. * 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/flt-32/s_remquof.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sysdeps/ieee754/flt-32') diff --git a/sysdeps/ieee754/flt-32/s_remquof.c b/sysdeps/ieee754/flt-32/s_remquof.c index 04944fd..36cf359 100644 --- a/sysdeps/ieee754/flt-32/s_remquof.c +++ b/sysdeps/ieee754/flt-32/s_remquof.c @@ -100,6 +100,9 @@ __remquof (float x, float y, int *quo) *quo = qs ? -cquo : cquo; + /* Ensure correct sign of zero result in round-downward mode. */ + if (x == 0.0f) + x = 0.0f; if (sx) x = -x; return x; -- cgit v1.1