This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: BZ 552: Wrong return values for tgamma (0) and tgamma (-0)


This patch makes tgamma (0) and tgamma (-0) to conform F.9.5.4 in C99.
It seems that tgamma and gamma aren't the same. gamma (0) raises
the invalid exception while tgamma (0) raises the divide-by-zero
exception. The internal __ieee754_gamma_r, which is used to implement
both tgamma and gamma, always raises the invalid exception on 0. I
have to clear FE_INVALID for tgamma.


H.J.
----
2004-11-16  H.J. Lu  <hongjiu.lu@intel.com>

	[BZ #552]
	* math/libm-test.inc (tgamma_test): Update tgamma (0) and
	tgamma (-0).

	* sysdeps/generic/w_tgamma.c (__tgamma): Properly handle
	|x| == 0.
	* sysdeps/generic/w_tgammaf.c (__tgammaf): Likewise.
	* sysdeps/generic/w_tgammal.c (__tgammal): Likewise.

	* sysdeps/ieee754/k_standard.c (__kernel_standard): Handle
	tgamma (0) and tgamma (-0).

--- libc/math/libm-test.inc.tgamma	2004-09-27 11:54:13.000000000 -0700
+++ libc/math/libm-test.inc	2004-11-16 16:16:56.497767214 -0800
@@ -4132,8 +4132,8 @@ tgamma_test (void)
   START (tgamma);
 
   TEST_f_f (tgamma, plus_infty, plus_infty);
-  TEST_f_f (tgamma, 0, nan_value, INVALID_EXCEPTION);
-  TEST_f_f (tgamma, minus_zero, nan_value, INVALID_EXCEPTION);
+  TEST_f_f (tgamma, 0, plus_infty, DIVIDE_BY_ZERO_EXCEPTION);
+  TEST_f_f (tgamma, minus_zero, minus_infty, DIVIDE_BY_ZERO_EXCEPTION);
   /* tgamma (x) == NaN plus invalid exception for integer x <= 0.  */
   TEST_f_f (tgamma, -2, nan_value, INVALID_EXCEPTION);
   TEST_f_f (tgamma, minus_infty, nan_value, INVALID_EXCEPTION);
--- libc/sysdeps/generic/w_tgamma.c.tgamma	2001-02-16 17:45:34.000000000 -0800
+++ libc/sysdeps/generic/w_tgamma.c	2004-11-16 16:59:47.447835314 -0800
@@ -39,8 +39,10 @@ static char rcsid[] = "$NetBSD: w_gamma.
 	if(_LIB_VERSION == _IEEE_) return y;
 
 	if(!__finite(y)&&__finite(x)) {
-	  if(__floor(x)==x&&x<=0.0)
-	    return __kernel_standard(x,x,41); /* tgamma pole */
+	  if (x == 0.0)
+	    return __kernel_standard(x,x,50); /* tgamma pole */
+	  else if(__floor(x)==x&&x<0.0)
+	    return __kernel_standard(x,x,41); /* tgamma domain */
 	  else
 	    return __kernel_standard(x,x,40); /* tgamma overflow */
 	}
--- libc/sysdeps/generic/w_tgammaf.c.tgamma	2001-02-16 17:45:39.000000000 -0800
+++ libc/sysdeps/generic/w_tgammaf.c	2004-11-16 17:13:40.091060684 -0800
@@ -37,8 +37,11 @@ static char rcsid[] = "$NetBSD: w_gammaf
 	if(_LIB_VERSION == _IEEE_) return y;
 
 	if(!__finitef(y)&&__finitef(x)) {
-	  if(__floorf(x)==x&&x<=(float)0.0)
+	  if (x == (float)0.0)
 	    /* tgammaf pole */
+	    return (float)__kernel_standard((double)x,(double)x,150);
+	  else if(__floorf(x)==x&&x<(float)0.0)
+	    /* tgammaf domain */
 	    return (float)__kernel_standard((double)x,(double)x,141);
 	  else
 	    /* tgammaf overflow */
--- libc/sysdeps/generic/w_tgammal.c.tgamma	2001-02-16 17:45:44.000000000 -0800
+++ libc/sysdeps/generic/w_tgammal.c	2004-11-16 17:13:30.545290296 -0800
@@ -42,8 +42,10 @@ static char rcsid[] = "$NetBSD: $";
 	if(_LIB_VERSION == _IEEE_) return y;
 
 	if(!__finitel(y)&&__finitel(x)) {
-	  if(__floorl(x)==x&&x<=0.0)
-	    return __kernel_standard(x,x,241); /* tgamma pole */
+	  if(x==0.0)
+	    return __kernel_standard(x,x,250); /* tgamma pole */
+	  else if(__floorl(x)==x&&x<0.0)
+	    return __kernel_standard(x,x,241); /* tgamma domain */
 	  else
 	    return __kernel_standard(x,x,240); /* tgamma overflow */
 	}
--- libc/sysdeps/ieee754/k_standard.c.tgamma	2001-06-06 05:46:35.000000000 -0700
+++ libc/sysdeps/ieee754/k_standard.c	2004-11-16 17:11:41.330358516 -0800
@@ -17,6 +17,7 @@ static char rcsid[] = "$NetBSD: k_standa
 #include "math.h"
 #include "math_private.h"
 #include <errno.h>
+#include <fenv.h>
 
 #include <assert.h>
 
@@ -832,7 +833,7 @@ static double zero = 0.0;	/* used as con
 	    case 40:
 	    case 140:
 	    case 240:
-		/* gamma(finite) overflow */
+		/* tgamma(finite) overflow */
 		exc.type = OVERFLOW;
 		exc.name = type < 100 ? "tgamma" : (type < 200
 						   ? "tgammaf" : "tgammal");
@@ -846,7 +847,7 @@ static double zero = 0.0;	/* used as con
 	    case 41:
 	    case 141:
 	    case 241:
-		/* gamma(-integer) or gamma(0) */
+		/* tgamma(-integer) */
 		exc.type = SING;
 		exc.name = type < 100 ? "tgamma" : (type < 200
 						   ? "tgammaf" : "tgammal");
@@ -973,8 +974,29 @@ static double zero = 0.0;	/* used as con
 		  __set_errno (EDOM);
 		}
 		break;
+	    case 50:
+	    case 150:
+	    case 250:
+		/* tgamma(|x|==0) */
+#ifdef FE_INVALID
+		feclearexcept (FE_INVALID);
+#endif
+		exc.type = SING;
+		exc.name = type < 100 ? "tgamma" : (type < 200
+						   ? "tgammaf" : "tgammal");
+		exc.retval = 1.0/x;
+		if (_LIB_VERSION == _POSIX_)
+		  __set_errno (ERANGE);
+		else if (!matherr(&exc)) {
+		  if (_LIB_VERSION == _SVID_) {
+			(void) WRITE2("tgamma: SING error\n", 18);
+			exc.retval = 1.0/x;
+		      }
+		  __set_errno (ERANGE);
+		}
+		break;
 		
-		/* #### Last used is 49/149/249 ### */
+		/* #### Last used is 50/150/250 ### */
 	}
 	return exc.retval;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]