wf_tgamma.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * These math functions are taken from newlib-nano-2, the newlib/libm/math
  5. * directory, available from https://github.com/32bitmicro/newlib-nano-2.
  6. *
  7. * Appropriate copyright headers are reproduced below.
  8. */
  9. /* w_gammaf.c -- float version of w_gamma.c.
  10. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  11. */
  12. /*
  13. * ====================================================
  14. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  15. *
  16. * Developed at SunPro, a Sun Microsystems, Inc. business.
  17. * Permission to use, copy, modify, and distribute this
  18. * software is freely granted, provided that this notice
  19. * is preserved.
  20. * ====================================================
  21. */
  22. #include "math.h"
  23. #include "fdlibm.h"
  24. #define _IEEE_LIBM 1
  25. #ifdef __STDC__
  26. float tgammaf(float x)
  27. #else
  28. float tgammaf(x)
  29. float x;
  30. #endif
  31. {
  32. float y;
  33. int local_signgam;
  34. y = expf(__ieee754_lgammaf_r(x,&local_signgam));
  35. if (local_signgam < 0) y = -y;
  36. #ifdef _IEEE_LIBM
  37. return y;
  38. #else
  39. if(_LIB_VERSION == _IEEE_) return y;
  40. if(!finitef(y)&&finitef(x)) {
  41. if(floorf(x)==x&&x<=(float)0.0)
  42. /* tgammaf pole */
  43. return (float)__kernel_standard((double)x,(double)x,141);
  44. else
  45. /* tgammaf overflow */
  46. return (float)__kernel_standard((double)x,(double)x,140);
  47. }
  48. return y;
  49. #endif
  50. }
  51. #ifdef _DOUBLE_IS_32BITS
  52. #ifdef __STDC__
  53. double tgamma(double x)
  54. #else
  55. double tgamma(x)
  56. double x;
  57. #endif
  58. {
  59. return (double) tgammaf((float) x);
  60. }
  61. #endif /* defined(_DOUBLE_IS_32BITS) */