From patchwork Fri May 9 23:26:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 871 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 AF7A2360073 for ; Fri, 9 May 2014 16:26:39 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14307373) id E6B271659429; Fri, 9 May 2014 16:26:38 -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 29743160D823 for ; Fri, 9 May 2014 16:26:38 -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=rGgKVazlSjr+QOwOs7/qleANO0GPr 1o/mTbFZCMwnubN5xd/fAnhCN+0xGOUSrwHLluMrGeuVe0iDTo6twMInaw100Y3Y +GVihR+rnMaNhdrbGT0ZaM8HTiEZq+sHZvOZ9EU6o670UQwiRTObT+IaFWxuyjcz DYLgXgFQjSrrB8= 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=ksrne2mqKuV3DRvHN2ERhF2ah6E=; b=JSt UxASgPPvkluFEvnuCP0JoR+VisO8ah7eOAHhmPN6SPX2/bBfHTOXNu+zXb+g3b7x l3FXOK+hWSXM8I0iaPyWAoOWulSAWIZg4C5OLi98ICYklAPGeuQjiRmhcK7aTjw/ /pu8JdogFYqwQJpTctcOGTIqQqXLeO1l6JJ1n7ik= Received: (qmail 30546 invoked by alias); 9 May 2014 23:26:36 -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 30535 invoked by uid 89); 9 May 2014 23:26:35 -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: Fri, 9 May 2014 23:26:27 +0000 From: "Joseph S. Myers" To: Subject: Fix cacos (+Inf + finite*i) in round-downward mode (bug 16928) Message-ID: MIME-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in According to C99/C11 Annex G, cacos applied to a value with real part +Inf and finite imaginary part should produce a result with real part +0. glibc wrongly produces a result with real part -0 in FE_DOWNWARD mode. This patch fixes this by checking for zero results in the relevant case of non-finite arguments (where there should never be a result with -0 real part), and converts the tests of cacos to ALL_RM_TEST. Tested x86_64 and x86 and ulps updated accordingly. 2014-05-09 Joseph Myers [BZ #16928] * math/s_cacos.c (__cacos): Ensure zero real part of result from non-finite arguments is +0. * math/s_cacosf.c (__cacosf): Likewise. * math/s_cacosl.c (__cacosl): Likewise. * math/libm-test.inc (cacos_test): Use ALL_RM_TEST. * 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 a4bf0b8..1cd8359 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -2617,9 +2617,7 @@ static const struct test_c_c_data cacos_test_data[] = static void cacos_test (void) { - START (cacos, 0); - RUN_TEST_LOOP_c_c (cacos, cacos_test_data, ); - END_COMPLEX; + ALL_RM_TEST (cacos, 0, cacos_test_data, RUN_TEST_LOOP_c_c, END_COMPLEX); } static const struct test_c_c_data cacosh_test_data[] = diff --git a/math/s_cacos.c b/math/s_cacos.c index d0aaba4..2c22817 100644 --- a/math/s_cacos.c +++ b/math/s_cacos.c @@ -34,6 +34,8 @@ __cacos (__complex__ double x) y = __casin (x); __real__ res = (double) M_PI_2 - __real__ y; + if (__real__ res == 0.0) + __real__ res = 0.0; __imag__ res = -__imag__ y; } else diff --git a/math/s_cacosf.c b/math/s_cacosf.c index 9eaeeec..1c9d8b9 100644 --- a/math/s_cacosf.c +++ b/math/s_cacosf.c @@ -34,6 +34,8 @@ __cacosf (__complex__ float x) y = __casinf (x); __real__ res = (float) M_PI_2 - __real__ y; + if (__real__ res == 0.0f) + __real__ res = 0.0f; __imag__ res = -__imag__ y; } else diff --git a/math/s_cacosl.c b/math/s_cacosl.c index b9d3493..8688d3c 100644 --- a/math/s_cacosl.c +++ b/math/s_cacosl.c @@ -34,6 +34,8 @@ __cacosl (__complex__ long double x) y = __casinl (x); __real__ res = M_PI_2l - __real__ y; + if (__real__ res == 0.0L) + __real__ res = 0.0L; __imag__ res = -__imag__ y; } else diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index aea6c51..199e4ff 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -161,6 +161,54 @@ ifloat: 1 ildouble: 2 ldouble: 2 +Function: Real part of "cacos_downward": +double: 2 +float: 1 +idouble: 2 +ifloat: 1 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "cacos_downward": +double: 3 +float: 3 +idouble: 3 +ifloat: 3 +ildouble: 5 +ldouble: 5 + +Function: Real part of "cacos_towardzero": +double: 2 +float: 1 +idouble: 2 +ifloat: 1 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "cacos_towardzero": +double: 3 +float: 3 +idouble: 3 +ifloat: 3 +ildouble: 5 +ldouble: 5 + +Function: Real part of "cacos_upward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "cacos_upward": +double: 4 +float: 4 +idouble: 4 +ifloat: 4 +ildouble: 5 +ldouble: 5 + Function: Real part of "cacosh": double: 1 float: 1 diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index 4ba83a4..2369a78 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -184,6 +184,54 @@ ifloat: 2 ildouble: 2 ldouble: 2 +Function: Real part of "cacos_downward": +double: 1 +float: 2 +idouble: 1 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "cacos_downward": +double: 5 +float: 3 +idouble: 5 +ifloat: 3 +ildouble: 5 +ldouble: 5 + +Function: Real part of "cacos_towardzero": +double: 1 +float: 2 +idouble: 1 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "cacos_towardzero": +double: 5 +float: 3 +idouble: 5 +ifloat: 3 +ildouble: 5 +ldouble: 5 + +Function: Real part of "cacos_upward": +double: 2 +float: 2 +idouble: 2 +ifloat: 2 +ildouble: 2 +ldouble: 2 + +Function: Imaginary part of "cacos_upward": +double: 4 +float: 4 +idouble: 4 +ifloat: 4 +ildouble: 5 +ldouble: 5 + Function: Real part of "cacosh": double: 1 float: 2