w_tgammaf.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* w_gammaf.c -- float version of w_gamma.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  3. */
  4. /*
  5. * ====================================================
  6. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7. *
  8. * Developed at SunPro, a Sun Microsystems, Inc. business.
  9. * Permission to use, copy, modify, and distribute this
  10. * software is freely granted, provided that this notice
  11. * is preserved.
  12. * ====================================================
  13. */
  14. #include <math.h>
  15. #include "math_private.h"
  16. #if __UCLIBC_HAS_FENV__
  17. #include <errno.h>
  18. #endif
  19. float
  20. tgammaf(float x)
  21. {
  22. #if __UCLIBC_HAS_FENV__
  23. float y = (float) __ieee754_tgamma((double)x);
  24. if(__builtin_expect (!isfinite (y) || y == 0, 0)
  25. && (isfinite (x) || (isinf (x) && x < 0.0))
  26. && _LIB_VERSION != _IEEE_) {
  27. if (x == (float)0.0)
  28. /* tgammaf pole */
  29. return __kernel_standard_f(x, x, 150);
  30. else if(floorf(x)==x&&x<0.0f)
  31. /* tgammaf domain */
  32. return __kernel_standard_f(x, x, 141);
  33. else if (y == 0)
  34. /* tgammaf underflow */
  35. __set_errno (ERANGE);
  36. else
  37. /* tgammaf overflow */
  38. return __kernel_standard_f(x, x, 140);
  39. }
  40. return y;
  41. #else
  42. return (float) __ieee754_tgamma((double)x);
  43. #endif /* __UCLIBC_HAS_FENV__ */
  44. }