w_gamma.c 919 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /* double gamma(double x)
  12. * Return the logarithm of the Gamma function of x.
  13. *
  14. * Method: call gamma_r
  15. */
  16. #include <math.h>
  17. #include "math_private.h"
  18. double gamma(double x)
  19. {
  20. #ifdef _IEEE_LIBM
  21. return __ieee754_lgamma_r(x, &signgam);
  22. #else
  23. double y = __ieee754_lgamma_r(x, &signgam);
  24. if (_LIB_VERSION == _IEEE_)
  25. return y;
  26. if (!isfinite(y) && isfinite(x)) {
  27. if (floor(x) == x && x <= 0.0)
  28. return __kernel_standard(x, x, 41); /* gamma pole */
  29. return __kernel_standard(x, x, 40); /* gamma overflow */
  30. }
  31. return y;
  32. #endif
  33. }