From patchwork Wed Mar 15 22:01:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 739453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3vk5Dk4NWPz9ryr for ; Thu, 16 Mar 2017 09:02:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="vXLNt1N6"; dkim-atps=neutral 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=wYlsUP3BFeQSkPHyFM7RD32fPKFfa NDLNUubOxqHcMqW896txNfa5zfq5QtVwJROidXYyOI+ch1XmfqB8fHhwX0mq0AVu ZZVgT2qPnTcuVbJKYbrtnG+PBGCAg0vaVv1itU9Xhx3ed/SP3f4JGGAwDSr3edwx 2jIXAMb4o1ra5g= 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=MwQfmrkM0Lnu07ns7TxNGMmrOYs=; b=vXL Nt1N69LBguq/mCc9AzMQiFYr6/CkHs01ekYfm4KqI1Yhg4XJb8bN69VFNDae1f6s xmk/d0jkmhIO9zRiE64pkhEg6sBoSuh5WUek3NI58i5E+YRNQ5IqJJm0nuxMY9mB saldY1XQaPklmEgZ8u/Bi2WKgvkYXvy50CkLlQeA= Received: (qmail 40249 invoked by alias); 15 Mar 2017 22:02:07 -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 40235 invoked by uid 89); 15 Mar 2017 22:02:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Date: Wed, 15 Mar 2017 22:01:53 +0000 From: Joseph Myers To: Subject: Improve float range reduction accuracy near pi/2 (bug 21094) [committed] Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) Bug 21094 reports 3ulp errors of cosf and tanf for certain arguments near pi/2 arising from the use of an insufficiently accurate range reduction. (To be clear, this is a quality-of-implementation issue relating to the apparent intent of those particular cosf and tanf implementations; 3ulp is within the general glibc accuracy goals, so not inherently a bug.) This patch fixes that error by making a wider range of cases use the existing more accurate range reduction for arguments close to pi/2. The wider range of values is still narrow enough for the "z -= pio2_2;" in the more accurate case to be exact, as the code expects. Tested for x86_64, x86 and mips64; no ulps updates needed (but at least on mips64, the larger ulps were seen if the tests were added without the substantive fix). Committed. (auto-libm-test-out-* diffs omitted below.) 2017-03-15 Joseph Myers [BZ #21094] * sysdeps/ieee754/flt-32/e_rem_pio2f.c (__ieee754_rem_pio2f): Use 24+24+24-bit pi for wider range of values around pi/2. * math/auto-libm-test-in: Add more tests of cos and tan. * math/auto-libm-test-out-cos: Regenerated. * math/auto-libm-test-out-tan: Likewise. diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in index c8267aa..6a47044 100644 --- a/math/auto-libm-test-in +++ b/math/auto-libm-test-in @@ -4324,6 +4324,8 @@ cos -0x1.02e34cp+0 cos 0xf.f0274p+4 cos 0x3.042d88p+0 cos 0x1.8475e5afd4481p+0 +cos 1.57079697 +cos -1.57079697 cosh 0 cosh -0 @@ -7236,6 +7238,8 @@ tan 0x2.091d68p+0 tan -0x5.302ab9b18593264p+0 tan 0x1.1ad374p+0 tan -0x1.0d55b8p+0 +tan 1.57079697 +tan -1.57079697 tan 0x1p-5 tan 0x1p-10 tan 0x1p-15 diff --git a/sysdeps/ieee754/flt-32/e_rem_pio2f.c b/sysdeps/ieee754/flt-32/e_rem_pio2f.c index 0928373..c4d28c8 100644 --- a/sysdeps/ieee754/flt-32/e_rem_pio2f.c +++ b/sysdeps/ieee754/flt-32/e_rem_pio2f.c @@ -100,7 +100,7 @@ int32_t __ieee754_rem_pio2f(float x, float *y) if(ix<0x4016cbe4) { /* |x| < 3pi/4, special case with n=+-1 */ if(hx>0) { z = x - pio2_1; - if((ix&0xfffffff0)!=0x3fc90fd0) { /* 24+24 bit pi OK */ + if((ix&0xffffffc0)!=0x3fc90fc0) { /* 24+24 bit pi OK */ y[0] = z - pio2_1t; y[1] = (z-y[0])-pio2_1t; } else { /* near pi/2, use 24+24+24 bit pi */ @@ -111,7 +111,7 @@ int32_t __ieee754_rem_pio2f(float x, float *y) return 1; } else { /* negative x */ z = x + pio2_1; - if((ix&0xfffffff0)!=0x3fc90fd0) { /* 24+24 bit pi OK */ + if((ix&0xffffffc0)!=0x3fc90fc0) { /* 24+24 bit pi OK */ y[0] = z + pio2_1t; y[1] = (z-y[0])+pio2_1t; } else { /* near pi/2, use 24+24+24 bit pi */