w_tgamma.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /* double gamma(double x)
  13. * Return the logarithm of the Gamma function of x or the Gamma function of x,
  14. * depending on the library mode.
  15. */
  16. #include <math.h>
  17. #include "math_private.h"
  18. #if defined(__UCLIBC_HAS_FENV__)
  19. #include <errno.h>
  20. #endif
  21. double
  22. tgamma(double x)
  23. {
  24. #if defined(__UCLIBC_HAS_FENV__)
  25. double y = __ieee754_tgamma(x);
  26. if(__builtin_expect (!isfinite (y) || y == 0, 0)
  27. && (isfinite (x) || (isinf (x) && x < 0.0))
  28. && _LIB_VERSION != _IEEE_) {
  29. if (x == 0.0)
  30. return __kernel_standard(x,x,50); /* tgamma pole */
  31. else if(floor(x)==x&&x<0.0)
  32. return __kernel_standard(x,x,41); /* tgamma domain */
  33. else if (y == 0)
  34. __set_errno (ERANGE); /* tgamma underflow */
  35. else
  36. return __kernel_standard(x,x,40); /* tgamma overflow */
  37. }
  38. return y;
  39. #else
  40. return __ieee754_tgamma(x);
  41. #endif
  42. }
  43. libm_hidden_def(tgamma);