From patchwork Wed Aug 19 22:42:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 508855 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 CDE05140771 for ; Thu, 20 Aug 2015 08:43:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=uSq3rRhv; 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=XLsZv0LLKk3EvrAcRzHiJSFlq0+/a hET5N+EvOhc2D5oHpgEnpSttHipG7oOx1hnfrWcAmcKXKv/rnGDAohK0NqhYsRHc 4d9EGH+ZHkRachXRjIYO9X1wi3i97gPz0+go1FcXxrWhEqV/txfWozrp9HJ5KvSC SKOnYcwd1RVdic= 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=/cF2E4GFeBmFETcBWkk5HuYOgdM=; b=uSq 3rRhvFxIXxRuKx/6g2V2K1tGB+yz5NqjWcAqg5yXLdKvklC5DcoAovwh3GX6qePj rjdPdI1dh9VwFyChIu0IFsXO1lsAgR7Adbsqo9+d74ancAC5UU+zjM1E6kOpYXhg QaxcyqKrFLLpG8hQ5nrjoj2k6nbSbdJntkhCIVVo= Received: (qmail 89788 invoked by alias); 19 Aug 2015 22:42:46 -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 89721 invoked by uid 89); 19 Aug 2015 22:42:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Wed, 19 Aug 2015 22:42:34 +0000 From: Joseph Myers To: Subject: Fix csqrt missing underflows (bug 18370) [committed] Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 The csqrt implementations in glibc can miss underflow exceptions when the real or imaginary part of the result becomes tiny in the course of scaling down (in particular, multiplication by 0.5) and that scaling is exact although the relevant part of the mathematical result isn't. This patch forces the exception in a similar way to previous fixes. Tested for x86_64 and x86. Committed. (auto-libm-test-out diffs omitted below.) 2015-08-19 Joseph Myers [BZ #18370] * math/s_csqrt.c (__csqrt): Force underflow exception for results whose real or imaginary part has small absolute value. * math/s_csqrtf.c (__csqrtf): Likewise. * math/s_csqrtl.c (__csqrtl): Likewise. * math/auto-libm-test-in: Add more tests of csqrt. * math/auto-libm-test-out: Regenerated. * sysdeps/i386/fpu/libm-test-ulps: Update. diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in index 015041a..49f1c55 100644 --- a/math/auto-libm-test-in +++ b/math/auto-libm-test-in @@ -1171,6 +1171,11 @@ csqrt 0x1p-16445 0x1.0000000000000004p-16382 csqrt 0x1p-16494 0x1.0000000000000000000000000001p-16382 csqrt 0x1p-16494 0x1.0000000000000000000000000002p-16382 +csqrt 1 min +csqrt 1 -min +csqrt -1 min +csqrt -1 -min + ctan 0 0 ctan 0 -0 ctan -0 0 diff --git a/math/s_csqrt.c b/math/s_csqrt.c index 068534c..b86f533 100644 --- a/math/s_csqrt.c +++ b/math/s_csqrt.c @@ -148,6 +148,17 @@ __csqrt (__complex__ double x) s = __scalbn (s, scale); } + if (fabs (r) < DBL_MIN) + { + double force_underflow = r * r; + math_force_eval (force_underflow); + } + if (fabs (s) < DBL_MIN) + { + double force_underflow = s * s; + math_force_eval (force_underflow); + } + __real__ res = r; __imag__ res = __copysign (s, __imag__ x); } diff --git a/math/s_csqrtf.c b/math/s_csqrtf.c index f7dc3b1..e433f47 100644 --- a/math/s_csqrtf.c +++ b/math/s_csqrtf.c @@ -148,6 +148,17 @@ __csqrtf (__complex__ float x) s = __scalbnf (s, scale); } + if (fabsf (r) < FLT_MIN) + { + float force_underflow = r * r; + math_force_eval (force_underflow); + } + if (fabsf (s) < FLT_MIN) + { + float force_underflow = s * s; + math_force_eval (force_underflow); + } + __real__ res = r; __imag__ res = __copysignf (s, __imag__ x); } diff --git a/math/s_csqrtl.c b/math/s_csqrtl.c index a0252e6..003d614 100644 --- a/math/s_csqrtl.c +++ b/math/s_csqrtl.c @@ -148,6 +148,17 @@ __csqrtl (__complex__ long double x) s = __scalbnl (s, scale); } + if (fabsl (r) < LDBL_MIN) + { + long double force_underflow = r * r; + math_force_eval (force_underflow); + } + if (fabsl (s) < LDBL_MIN) + { + long double force_underflow = s * s; + math_force_eval (force_underflow); + } + __real__ res = r; __imag__ res = __copysignl (s, __imag__ x); } diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index 8263717..1cbf0db 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -1213,7 +1213,9 @@ ldouble: 2 Function: Real part of "csqrt_downward": double: 1 +float: 1 idouble: 1 +ifloat: 1 ildouble: 4 ldouble: 4 @@ -1227,7 +1229,9 @@ ldouble: 4 Function: Real part of "csqrt_towardzero": double: 1 +float: 1 idouble: 1 +ifloat: 1 ildouble: 4 ldouble: 4