From patchwork Tue Apr 1 15:46:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 373 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id EFDDC3600E7 for ; Tue, 1 Apr 2014 08:46:40 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14307373) id 85E2BFABC11; Tue, 1 Apr 2014 08:46:40 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 51C5FFABC0C for ; Tue, 1 Apr 2014 08:46:40 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=cFWvKM2uGN3vbmq8Gdt1IsI6bfch2 ft4aBAolO0Ev/v7DXEMF93fCmuAkU7kzlwP+FJDWk3q9rgU3rm6golNHswm7yMT3 wvfwq24pW02RUbLzW9xiq/2nlB2aO23hDsLb21BDjttxLYNPJRx+peFo3fGiY1qy WiBjKNruHxPXvg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=dSBP396ziIsXu6rCezWUCeG5PDk=; b=f+Q tsaMeEKQcpEdyJRLi5bXtNbD3H1RzRy87TQ8slMeRMvzAVrWqvbhzkC2m22Virk0 nZ6dEOzjMPJANxXkpKAl+ejcZDh+gez3KJRpdxja/LAXonFt1WGE9t7uG6Qu16ny wyYyj3bNmvrBP0pW3MKNxxTM7QnzDNnvICOsQy2Q= Received: (qmail 7448 invoked by alias); 1 Apr 2014 15:46:38 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 7436 invoked by uid 89); 1 Apr 2014 15:46:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Tue, 1 Apr 2014 15:46:28 +0000 From: "Joseph S. Myers" To: Subject: Fix clog / clog10 sign of zero result in round-downward mode (bug 16789) Message-ID: MIME-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in This patch fixes bug 16789, incorrect sign of (real part) zero result from clog and clog10 in round-downward mode, arising from that real part being computed as 0 - 0. To ensure that an underflow exception occurred, the code used an underflowing value (the next term in the series for log1p) in arithmetic computing the real part of the result, yielding the problematic 0 - 0 computation in some cases even when the mathematical result would be small but positive. The patch changes this code to use the math_force_eval approach to ensuring that an underflowing computation actually occurs. Tests of clog and clog10 are enabled in all rounding modes. Tested x86_64 and x86 and ulps updated accordingly. 2014-04-01 Joseph Myers [BZ #16789] * math/s_clog.c (__clog): Use math_force_eval to ensure underflow instead of using underflowing value in computing result. * math/s_clog10.c (__clog10): Likewise. * math/s_clog10f.c (__clog10f): Likewise. * math/s_clog10l.c (__clog10l): Likewise. * math/s_clogf.c (__clogf): Likewise. * math/s_clogl.c (__clogl): Likewise. * math/libm-test.inc (clog_test): Use ALL_RM_TEST. (clog10_test): Likewise. * sysdeps/i386/fpu/libm-test-ulps: Update. * sysdeps/x86_64/fpu/libm-test-ulps: Likewise. diff --git a/math/libm-test.inc b/math/libm-test.inc index 19194f6..fe43185 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -6122,9 +6122,7 @@ static const struct test_c_c_data clog_test_data[] = static void clog_test (void) { - START (clog, 0); - RUN_TEST_LOOP_c_c (clog, clog_test_data, ); - END_COMPLEX; + ALL_RM_TEST (clog, 0, clog_test_data, RUN_TEST_LOOP_c_c, END_COMPLEX); } @@ -6184,9 +6182,7 @@ static const struct test_c_c_data clog10_test_data[] = static void clog10_test (void) { - START (clog10, 0); - RUN_TEST_LOOP_c_c (clog10, clog10_test_data, ); - END_COMPLEX; + ALL_RM_TEST (clog10, 0, clog10_test_data, RUN_TEST_LOOP_c_c, END_COMPLEX); } diff --git a/math/s_clog.c b/math/s_clog.c index 8639868..077f8f2 100644 --- a/math/s_clog.c +++ b/math/s_clog.c @@ -68,12 +68,9 @@ __clog (__complex__ double x) double absy2 = absy * absy; if (absy2 <= DBL_MIN * 2.0) { -#if __FLT_EVAL_METHOD__ == 0 - __real__ result = absy2 / 2.0 - absy2 * absy2 / 4.0; -#else - volatile double force_underflow = absy2 * absy2 / 4.0; - __real__ result = absy2 / 2.0 - force_underflow; -#endif + double force_underflow = absy2 * absy2; + __real__ result = absy2 / 2.0; + math_force_eval (force_underflow); } else __real__ result = __log1p (absy2) / 2.0; diff --git a/math/s_clog10.c b/math/s_clog10.c index e757879..aa0537c 100644 --- a/math/s_clog10.c +++ b/math/s_clog10.c @@ -74,12 +74,9 @@ __clog10 (__complex__ double x) double absy2 = absy * absy; if (absy2 <= DBL_MIN * 2.0 * M_LN10) { -#if __FLT_EVAL_METHOD__ == 0 - __real__ result = (absy2 / 2.0 - absy2 * absy2 / 4.0) * M_LOG10E; -#else - volatile double force_underflow = absy2 * absy2 / 4.0; - __real__ result = (absy2 / 2.0 - force_underflow) * M_LOG10E; -#endif + double force_underflow = absy2 * absy2; + __real__ result = absy2 * (M_LOG10E / 2.0); + math_force_eval (force_underflow); } else __real__ result = __log1p (absy2) * (M_LOG10E / 2.0); diff --git a/math/s_clog10f.c b/math/s_clog10f.c index ca2cdf4..3403b6c 100644 --- a/math/s_clog10f.c +++ b/math/s_clog10f.c @@ -74,14 +74,9 @@ __clog10f (__complex__ float x) float absy2 = absy * absy; if (absy2 <= FLT_MIN * 2.0f * (float) M_LN10) { -#if __FLT_EVAL_METHOD__ == 0 - __real__ result - = (absy2 / 2.0f - absy2 * absy2 / 4.0f) * (float) M_LOG10E; -#else - volatile float force_underflow = absy2 * absy2 / 4.0f; - __real__ result - = (absy2 / 2.0f - force_underflow) * (float) M_LOG10E; -#endif + float force_underflow = absy2 * absy2; + __real__ result = absy2 * ((float) M_LOG10E / 2.0f); + math_force_eval (force_underflow); } else __real__ result = __log1pf (absy2) * ((float) M_LOG10E / 2.0f); diff --git a/math/s_clog10l.c b/math/s_clog10l.c index cdb5d61..fd86ecb 100644 --- a/math/s_clog10l.c +++ b/math/s_clog10l.c @@ -80,8 +80,11 @@ __clog10l (__complex__ long double x) { long double absy2 = absy * absy; if (absy2 <= LDBL_MIN * 2.0L * M_LN10l) - __real__ result - = (absy2 / 2.0L - absy2 * absy2 / 4.0L) * M_LOG10El; + { + long double force_underflow = absy2 * absy2; + __real__ result = absy2 * (M_LOG10El / 2.0); + math_force_eval (force_underflow); + } else __real__ result = __log1pl (absy2) * (M_LOG10El / 2.0L); } diff --git a/math/s_clogf.c b/math/s_clogf.c index 79117df..b487334 100644 --- a/math/s_clogf.c +++ b/math/s_clogf.c @@ -68,12 +68,9 @@ __clogf (__complex__ float x) float absy2 = absy * absy; if (absy2 <= FLT_MIN * 2.0f) { -#if __FLT_EVAL_METHOD__ == 0 - __real__ result = absy2 / 2.0f - absy2 * absy2 / 4.0f; -#else - volatile float force_underflow = absy2 * absy2 / 4.0f; - __real__ result = absy2 / 2.0f - force_underflow; -#endif + float force_underflow = absy2 * absy2; + __real__ result = absy2 / 2.0f; + math_force_eval (force_underflow); } else __real__ result = __log1pf (absy2) / 2.0f; diff --git a/math/s_clogl.c b/math/s_clogl.c index bdf82c1..1b4a304 100644 --- a/math/s_clogl.c +++ b/math/s_clogl.c @@ -74,7 +74,11 @@ __clogl (__complex__ long double x) { long double absy2 = absy * absy; if (absy2 <= LDBL_MIN * 2.0L) - __real__ result = absy2 / 2.0L - absy2 * absy2 / 4.0L; + { + long double force_underflow = absy2 * absy2; + __real__ result = absy2 / 2.0L; + math_force_eval (force_underflow); + } else __real__ result = __log1pl (absy2) / 2.0L; } diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index a82de19..0252d5b 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -593,6 +593,102 @@ ifloat: 1 ildouble: 2 ldouble: 2 +Function: Real part of "clog10_downward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 4 +ldouble: 4 + +Function: Imaginary part of "clog10_downward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Real part of "clog10_towardzero": +double: 2 +float: 1 +idouble: 2 +ifloat: 1 +ildouble: 4 +ldouble: 4 + +Function: Imaginary part of "clog10_towardzero": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Real part of "clog10_upward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 4 +ldouble: 4 + +Function: Imaginary part of "clog10_upward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Real part of "clog_downward": +double: 2 +float: 1 +idouble: 2 +ifloat: 1 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "clog_downward": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +ildouble: 1 +ldouble: 1 + +Function: Real part of "clog_towardzero": +double: 2 +float: 1 +idouble: 2 +ifloat: 1 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "clog_towardzero": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +ildouble: 1 +ldouble: 1 + +Function: Real part of "clog_upward": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "clog_upward": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +ildouble: 1 +ldouble: 1 + Function: "cos": ildouble: 1 ldouble: 1 diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index e2fa9b2..1b6ebe2 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -624,6 +624,102 @@ ifloat: 1 ildouble: 2 ldouble: 2 +Function: Real part of "clog10_downward": +double: 3 +float: 3 +idouble: 3 +ifloat: 3 +ildouble: 4 +ldouble: 4 + +Function: Imaginary part of "clog10_downward": +double: 3 +float: 2 +idouble: 3 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Real part of "clog10_towardzero": +double: 3 +float: 2 +idouble: 3 +ifloat: 2 +ildouble: 4 +ldouble: 4 + +Function: Imaginary part of "clog10_towardzero": +double: 3 +float: 2 +idouble: 3 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Real part of "clog10_upward": +double: 4 +float: 3 +idouble: 4 +ifloat: 3 +ildouble: 4 +ldouble: 4 + +Function: Imaginary part of "clog10_upward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Real part of "clog_downward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "clog_downward": +double: 1 +float: 2 +idouble: 1 +ifloat: 2 +ildouble: 1 +ldouble: 1 + +Function: Real part of "clog_towardzero": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "clog_towardzero": +double: 1 +float: 2 +idouble: 1 +ifloat: 2 +ildouble: 1 +ldouble: 1 + +Function: Real part of "clog_upward": +double: 2 +float: 1 +idouble: 2 +ifloat: 1 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "clog_upward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 1 +ldouble: 1 + Function: "cos": ildouble: 1 ldouble: 1