From patchwork Fri Aug 7 23:11:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 505270 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 7DD7A140216 for ; Sat, 8 Aug 2015 09:12:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=YNYEROdv; 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=jJFiHbDOTGA+4WWNTj1IDsIIyQQwW V5Ntq/ZL0KR0XDEd8Yu4JyCr4mi7ViLpV4eHu/BFHKE6+EXA6IGUbeRpPRKra+2n mHfGxt+Zr/fi08l1kVmC4v2ibOzadbOnHBJiWTtVIGoliHILdVcIv+Ha9AzaZwN2 IZgGExubXpDzF4= 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=yCOuJswyAS4zBS4kirPBG+Yjb40=; b=YNY EROdvqJ00oCqRaml44JlT6Y86khi2hFDN7FNJp0Q3XK3ZiWXLcKd4IKz9VreBT3M 7ScitYEWMW4dpxpcE8zysZa8EC7hzEy7fEwTXgtrDmOjaaseRREo1is6xS5cLoa7 M04CTOnit47CD3VhgcZReKX7n3wH7NERGlu34Tls= Received: (qmail 60431 invoked by alias); 7 Aug 2015 23:11:59 -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 60415 invoked by uid 89); 7 Aug 2015 23:11:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Fri, 7 Aug 2015 23:11:49 +0000 From: Joseph Myers To: Subject: Fix tan missing underflows (bug 16517) [committed] Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Similar to various other bugs in this area, some tan implementations do not raise the underflow exception for subnormal arguments, when the result is tiny and inexact. This patch forces the exception in a similar way to previous fixes. Tested for x86_64, x86, mips64 and powerpc. Committed. (auto-libm-test-out diffs omitted below.) 2015-08-07 Joseph Myers [BZ #16517] * sysdeps/ieee754/dbl-64/s_tan.c: Include . (tan): Force underflow exception for arguments with small absolute value. * sysdeps/ieee754/flt-32/k_tanf.c: Include . (__kernel_tanf): Force underflow exception for arguments with small absolute value. * sysdeps/ieee754/ldbl-128/k_tanl.c: Include . (__kernel_tanl): Force underflow exception for arguments with small absolute value. * sysdeps/ieee754/ldbl-128ibm/k_tanl.c: Include . (__kernel_tanl): Force underflow exception for arguments with small absolute value. * sysdeps/ieee754/ldbl-96/k_tanl.c: Include . (__kernel_tanl): Force underflow exception for arguments with small absolute value. * math/auto-libm-test-in: Add more tests of tan. * math/auto-libm-test-out: Regenerated. diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in index cc9b7fd..bb6d30e 100644 --- a/math/auto-libm-test-in +++ b/math/auto-libm-test-in @@ -2659,6 +2659,10 @@ tan 9 tan 10 tan -0x1.062a48p+0 tan -0x1.4f69cp+0 +tan min +tan -min +tan min_subnorm +tan -min_subnorm tanh 0 tanh -0 diff --git a/sysdeps/ieee754/dbl-64/s_tan.c b/sysdeps/ieee754/dbl-64/s_tan.c index dcb4aca..b4e3bd2 100644 --- a/sysdeps/ieee754/dbl-64/s_tan.c +++ b/sysdeps/ieee754/dbl-64/s_tan.c @@ -34,6 +34,7 @@ /*********************************************************************/ #include +#include #include "endian.h" #include #include "mpa.h" @@ -91,6 +92,11 @@ tan (double x) /* (I) The case abs(x) <= 1.259e-8 */ if (w <= g1.d) { + if (w < DBL_MIN) + { + double force_underflow = x * x; + math_force_eval (force_underflow); + } retval = x; goto ret; } diff --git a/sysdeps/ieee754/flt-32/k_tanf.c b/sysdeps/ieee754/flt-32/k_tanf.c index a67f36e..2f2076d 100644 --- a/sysdeps/ieee754/flt-32/k_tanf.c +++ b/sysdeps/ieee754/flt-32/k_tanf.c @@ -17,6 +17,7 @@ static char rcsid[] = "$NetBSD: k_tanf.c,v 1.4 1995/05/10 20:46:39 jtc Exp $"; #endif +#include #include #include static const float @@ -48,7 +49,17 @@ float __kernel_tanf(float x, float y, int iy) if(ix<0x39000000) /* x < 2**-13 */ {if((int)x==0) { /* generate inexact */ if((ix|(iy+1))==0) return one/fabsf(x); - else return (iy==1)? x: -one/x; + else if (iy == 1) + { + if (fabsf (x) < FLT_MIN) + { + float force_underflow = x * x; + math_force_eval (force_underflow); + } + return x; + } + else + return -one / x; } } if(ix>=0x3f2ca140) { /* |x|>=0.6744 */ diff --git a/sysdeps/ieee754/ldbl-128/k_tanl.c b/sysdeps/ieee754/ldbl-128/k_tanl.c index dfba2d9..6a6fa9f 100644 --- a/sysdeps/ieee754/ldbl-128/k_tanl.c +++ b/sysdeps/ieee754/ldbl-128/k_tanl.c @@ -56,6 +56,7 @@ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) */ +#include #include #include #include @@ -98,8 +99,17 @@ __kernel_tanl (long double x, long double y, int iy) if ((ix | u.parts32.w1 | u.parts32.w2 | u.parts32.w3 | (iy + 1)) == 0) return one / fabs (x); + else if (iy == 1) + { + if (fabsl (x) < LDBL_MIN) + { + long double force_underflow = x * x; + math_force_eval (force_underflow); + } + return x; + } else - return (iy == 1) ? x : -one / x; + return -one / x; } } if (ix >= 0x3ffe5942) /* |x| >= 0.6743316650390625 */ diff --git a/sysdeps/ieee754/ldbl-128ibm/k_tanl.c b/sysdeps/ieee754/ldbl-128ibm/k_tanl.c index 7f1caee..e50cc88 100644 --- a/sysdeps/ieee754/ldbl-128ibm/k_tanl.c +++ b/sysdeps/ieee754/ldbl-128ibm/k_tanl.c @@ -56,6 +56,7 @@ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) */ +#include #include #include #include @@ -98,8 +99,17 @@ __kernel_tanl (long double x, long double y, int iy) { if ((ix | lx | (iy + 1)) == 0) return one / fabs (x); + else if (iy == 1) + { + if (fabsl (x) < LDBL_MIN) + { + long double force_underflow = x * x; + math_force_eval (force_underflow); + } + return x; + } else - return (iy == 1) ? x : -one / x; + return -one / x; } } if (ix >= 0x3fe59420) /* |x| >= 0.6743316650390625 */ diff --git a/sysdeps/ieee754/ldbl-96/k_tanl.c b/sysdeps/ieee754/ldbl-96/k_tanl.c index 31cd236..ae6821d 100644 --- a/sysdeps/ieee754/ldbl-96/k_tanl.c +++ b/sysdeps/ieee754/ldbl-96/k_tanl.c @@ -56,6 +56,7 @@ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) */ +#include #include #include static const long double @@ -94,8 +95,17 @@ __kernel_tanl (long double x, long double y, int iy) { /* generate inexact */ if (x == 0 && iy == -1) return one / fabsl (x); + else if (iy == 1) + { + if (absx < LDBL_MIN) + { + long double force_underflow = x * x; + math_force_eval (force_underflow); + } + return x; + } else - return (iy == 1) ? x : -one / x; + return -one / x; } } if (absx >= 0.6743316650390625L)