1 /* @(#)w_gamma.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 
13 /* double gamma(double x)
14  * Return  the logarithm of the Gamma function of x or the Gamma function of x,
15  * depending on the library mode.
16  */
17 
18 #include <math.h>
19 #include "math_private.h"
20 #if defined(__UCLIBC_HAS_FENV__)
21 #include <errno.h>
22 #endif
23 
24 double
tgamma(double x)25 tgamma(double x)
26 {
27 #if defined(__UCLIBC_HAS_FENV__)
28 	double y = __ieee754_tgamma(x);
29 
30 	if(__builtin_expect (!isfinite (y) || y == 0, 0)
31 	   && (isfinite (x) || (isinf (x) && x < 0.0))
32 	   && _LIB_VERSION != _IEEE_) {
33 	  if (x == 0.0)
34 	    return __kernel_standard(x,x,50); /* tgamma pole */
35 	  else if(floor(x)==x&&x<0.0)
36 	    return __kernel_standard(x,x,41); /* tgamma domain */
37 	  else if (y == 0)
38 	    __set_errno (ERANGE); /* tgamma underflow */
39 	  else
40 	    return __kernel_standard(x,x,40); /* tgamma overflow */
41 	}
42 	return y;
43 #else
44 	return __ieee754_tgamma(x);
45 #endif
46 }
47 libm_hidden_def(tgamma);
48