public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983)
@ 2021-02-26 17:44 Paul Zimmermann
  2021-02-26 18:22 ` Joseph Myers
  2021-02-26 18:31 ` Andreas Schwab
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Zimmermann @ 2021-02-26 17:44 UTC (permalink / raw)
  To: 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 <math-underflow.h>
 #include <float.h>
 #include <libm-alias-finite.h>
+#include <mul_split.h>
 
 /* 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);
 	    }
-- 
2.30.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983)
  2021-02-26 17:44 [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983) Paul Zimmermann
@ 2021-02-26 18:22 ` Joseph Myers
  2021-02-26 18:31 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Joseph Myers @ 2021-02-26 18:22 UTC (permalink / raw)
  To: Paul Zimmermann; +Cc: libc-alpha

On Fri, 26 Feb 2021, Paul Zimmermann wrote:

> ---
>  sysdeps/ieee754/dbl-64/e_gamma_r.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)

Please include a longer commit message explaining the change made and why 
it's an appropriate fix for the issue seen.

> @@ -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;

Note that glibc uses tabs for the initial multiple-of-8-columns of 
indentation; this is inserting code using spaces instead.

I'd expect similar changes for ldbl-96 and ldbl-128 at least, in the 
absence of some reason it makes sense for the implementations to diverge.

The test input that justifies this change as being needed should also be 
added to auto-libm-test-in by the patch (or XFAILs for that test input 
removed if already present), with any corresponding libm-test-ulps updates 
also being included for at least one architecture on which the patch was 
tested.  Likewise the test input you found giving too-large ulps for 
binary128, unless the binary128 problem is still present after making a 
corresponding fix to the implementation for ldbl-128.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983)
  2021-02-26 17:44 [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983) Paul Zimmermann
  2021-02-26 18:22 ` Joseph Myers
@ 2021-02-26 18:31 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2021-02-26 18:31 UTC (permalink / raw)
  To: Paul Zimmermann; +Cc: libc-alpha

On Feb 26 2021, Paul Zimmermann wrote:

> @@ -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;

There is a mix of tab and space indentation. Please always use tab
indentation.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-26 18:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26 17:44 [PATCH] Improve the accuracy of tgamma for negative inputs (BZ 26983) Paul Zimmermann
2021-02-26 18:22 ` Joseph Myers
2021-02-26 18:31 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).