From patchwork Fri Feb 26 17:44:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Zimmermann X-Patchwork-Id: 42151 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE5B4398B17E; Fri, 26 Feb 2021 17:44:24 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sourceware.org (Postfix) with ESMTPS id 68FC4384B011 for ; Fri, 26 Feb 2021 17:44:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 68FC4384B011 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Paul.Zimmermann@loria.fr X-IronPort-AV: E=Sophos;i="5.81,209,1610406000"; d="scan'208";a="495135060" Received: from tomate.loria.fr ([152.81.10.51]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2021 18:44:21 +0100 Received: from zimmerma by tomate.loria.fr with local (Exim 4.94) (envelope-from ) id 1lFhA5-001Qak-3n; Fri, 26 Feb 2021 18:44:21 +0100 From: Paul Zimmermann To: libc-alpha@sourceware.org Subject: [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983) Date: Fri, 26 Feb 2021 18:44:19 +0100 Message-Id: <20210226174419.340501-1-Paul.Zimmermann@inria.fr> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- sysdeps/ieee754/dbl-64/e_gamma_r.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sysdeps/ieee754/dbl-64/e_gamma_r.c b/sysdeps/ieee754/dbl-64/e_gamma_r.c index fe69920c76..37e15e1428 100644 --- a/sysdeps/ieee754/dbl-64/e_gamma_r.c +++ b/sysdeps/ieee754/dbl-64/e_gamma_r.c @@ -24,6 +24,7 @@ #include #include #include +#include /* Coefficients B_2k / 2k(2k-1) of x^-(2k-1) inside exp in Stirling's approximation to gamma function. */ @@ -188,8 +189,15 @@ __ieee754_gamma_r (double x, int *signgamp) ? __sin (M_PI * frac) : __cos (M_PI * (0.5 - frac))); int exp2_adj; - double tret = M_PI / (-x * sinpix - * gamma_positive (-x, &exp2_adj)); + double h1, l1, h2, l2; + mul_split (&h1, &l1, sinpix, gamma_positive (-x, &exp2_adj)); + /* sinpix*gamma_positive(.) = h1 + l1 */ + mul_split (&h2, &l2, h1, x); + /* h1*x = h2 + l2 */ + /* (h1 + l1) * x = h1*x + l1*x = h2 + l2 + l1*x */ + l2 += l1 * x; + h2 += l2; + double tret = M_PI / -h2; ret = __scalbn (tret, -exp2_adj); math_check_force_underflow_nonneg (ret); }