w_gamma.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. libm_hidden_proto(signgam)
  19. double gamma(double x)
  20. {
  21. #ifdef _IEEE_LIBM
  22. return __ieee754_lgamma_r(x,&signgam);
  23. #else
  24. double y;
  25. y = __ieee754_lgamma_r(x,&signgam);
  26. if(_LIB_VERSION == _IEEE_) return y;
  27. if(!isfinite(y)&&isfinite(x)) {
  28. if(floor(x)==x&&x<=0.0)
  29. return __kernel_standard(x,x,41); /* gamma pole */
  30. else
  31. return __kernel_standard(x,x,40); /* gamma overflow */
  32. } else
  33. return y;
  34. #endif
  35. }