From owner-freebsd-numerics@FreeBSD.ORG Thu Dec 5 17:37:06 2013 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A23E648A for ; Thu, 5 Dec 2013 17:37:06 +0000 (UTC) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 825A91E69 for ; Thu, 5 Dec 2013 17:37:06 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.7/8.14.7) with ESMTP id rB5Hb02c064655 for ; Thu, 5 Dec 2013 09:37:00 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.7/8.14.7/Submit) id rB5Hb0xQ064654 for freebsd-numerics@freebsd.org; Thu, 5 Dec 2013 09:37:00 -0800 (PST) (envelope-from sgk) Date: Thu, 5 Dec 2013 09:37:00 -0800 From: Steve Kargl To: freebsd-numerics@freebsd.org Subject: dead code in lgamma_r[f]? Message-ID: <20131205173700.GA64575@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Dec 2013 17:37:06 -0000 In reviewing the implementation details for lgamma_r[f], I noticed that in src/e_lgamma.c (and similar code in e_lgammaf.c): static double sin_pi(double x) { ... } else { if(ix>=0x43400000) { y = zero; n = 0; /* y must be even */ } else { if(ix<0x43300000) z = y+two52; /* exact */ ... } double __ieee754_lgamma_r(double x, int *signgamp) { ... if(hx<0) { if(ix>=0x43300000) /* |x|>=2**52, must be -integer */ return one/zero; t = sin_pi(x); ... } sin_pi is only called as shown above. It is appears that the 'if(ix>=0x43400000)' block is dead code. It also appears that (if I'm reading the code correctly) the 'if(ix<0x43300000)' is always true. Thus, if seems that following patch (note cut-n-paste whitespace munging) should be appropriate: Index: src/e_lgamma_r.c =================================================================== --- src/e_lgamma_r.c (revision 1427) +++ src/e_lgamma_r.c (working copy) @@ -177,15 +177,11 @@ y = 2.0*(y - floor(y)); /* y = |x| mod 2.0 */ n = (int) (y*4.0); } else { - if(ix>=0x43400000) { - y = zero; n = 0; /* y must be even */ - } else { - if(ix<0x43300000) z = y+two52; /* exact */ - GET_LOW_WORD(n,z); - n &= 1; - y = n; - n<<= 2; - } + z = y+two52; /* exact */ + GET_LOW_WORD(n,z); + n &= 1; + y = n; + n<<= 2; } switch (n) { case 0: y = __kernel_sin(pi*y,zero,0); break; Am I mssing something here? -- Steve