From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111354 invoked by alias); 4 Nov 2018 16:08:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 111340 invoked by uid 89); 4 Nov 2018 16:08:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL autolearn=no version=3.3.2 spammy=pictures, formula, cooler, UD:The X-HELO: sonic309-14.consmr.mail.bf2.yahoo.com Received: from sonic309-14.consmr.mail.bf2.yahoo.com (HELO sonic309-14.consmr.mail.bf2.yahoo.com) (74.6.129.124) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 04 Nov 2018 16:08:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1541347730; bh=swtNxW1Tehqr0gcXkZLeCqugUnHQVm7efgcW2qSbmbA=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=Pe24AkPPtPHu6PoJdEL9PH6Sle33So0vF2i2Wmi3FOY4f/VvXWjUb09lwEK4b4feQIvqj9SvOSnd1WDMuyWiySMEcEjp0M6aSS34Ciy4V/FhtybyU/JU5RhL4COsiYiDVYoNZxf1Yq7wH79kqG5V+r0iKzle9+VELQC/2kDuva2DBHYsj6CXZwRqQSf00DQMOXLww7cmVVw40L6aqQ5HYepbvJ1pea40+WFR43xrUomyVlFT5W3r5pkuwc0CF3pXMTQ+fdf9pdyQayd0PiCktJ4vho8Gvtq3YmZRkFP2aOC8AlINCZfPESgxRODWDWIfWotcAQ+LBUiQ99WPK8EpUw== Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.bf2.yahoo.com with HTTP; Sun, 4 Nov 2018 16:08:50 +0000 Received: from pool-173-64-127-97.bltmmd.fios.verizon.net (EHLO [192.168.1.3]) ([173.64.127.97]) by smtp429.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 78230f67ed0129a08d4dd0e23f1c4e4d; Sun, 04 Nov 2018 16:08:49 +0000 (UTC) Subject: Re: [PATCH libquadmath/PR68686] To: Jeff Law , gcc-patches , burnus@net-b.de, jakub@redhat.com References: <9c17f945-539e-01b9-34b8-656ea184b5c1@redhat.com> From: Ed Smith-Rowland <3dw4rd@verizon.net> Message-ID: <681bf291-7e3f-ac95-2c93-d970740aeea9@verizon.net> Date: Sun, 04 Nov 2018 16:08:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <9c17f945-539e-01b9-34b8-656ea184b5c1@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-SW-Source: 2018-11/txt/msg00168.txt.bz2 On 11/3/18 10:09 PM, Jeff Law wrote: > On 10/23/18 7:45 PM, Ed Smith-Rowland wrote: >> Greetings, >> >> This is an almost trivial patch to get the correct sign for tgammaq. >> >> I don't have a testcase as I don't know where to put one. >> >> OK? >> >> Ed Smith-Rowland >> >> >> >> tgammaq.CL >> >> 2018-10-24 Edward Smith-Rowland <3dw4rd@verizon.net> >> >> PR libquadmath/68686 >> * math/tgammaq.c: Correct sign for negative argument. > I don't have the relevant background to evaluate this for correctness. > Can you refer back to any kind of documentation which indicates what the > sign of the return value ought to be? > > Alternately, if you can point to the relevant code in glibc that handles > the resultant sign, that'd be useful too. > > Note that Joseph's follow-up doesn't touch on the gamma problem AFAICT, > but instead touches on the larger issues around trying to keep the > quadmath implementations between glibc and gcc more in sync. > > Jeff > Thank you for (re)considering this.The maths here can be read from a very good NIST website: For the functional formulas referred to below - https://dlmf.nist.gov/5.5 For cool pictures - https://dlmf.nist.gov/5.3#i (Aside: the reciprocal gamma function is entire - possessing no poles or other analytic complications anywhere in the complex plane.  A rgamma function might be a nice addition to the C family and to TS 18661-1 for that matter.) For a table of extrema (Table 5.4.1) - https://dlmf.nist.gov/5.4#iii These would be nice tests for accuracy as well as sign. TL;DR: ====== Either follow the factorial-like recursion Gamma(x+1) = x Gamma(x) [DLMF 5.5.1] backwards:     Gamma(x-1) = Gamma(x) / (x-1) Given that Gamma(x) is positive for x > 0 this will give alternating negative signs if you start with, say, x=1/2 and keep going. A cooler formula is [DLMF 5.5.3]:     Gamma(x) Gamma(1-x) = pi / sin(pi x) Start with x = 3/2 and continue with higher odd half integers to see the sign alternation. GLibC ===== I looked in glibc.  Unfortunately, I see how they have the same mistake: glibc/math/w_tgammal_compat.c:     long double     __tgammal(long double x)     {         int local_signgam;         long double y = __ieee754_gammal_r(x,&local_signgam);         ...         return local_signgam < 0 ? - y : y;     } I'm very sure this is where tgammaq came from. Ditto for glibc/math/w_tgamma_compat.c and glibc/math/w_tgammaf_compat.c. This fix will need to be done upstream. Ed