sf_tan.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /* sf_tan.c -- float version of s_tan.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 "fdlibm.h"
  23. #ifdef __STDC__
  24. float tanf(float x)
  25. #else
  26. float tanf(x)
  27. float x;
  28. #endif
  29. {
  30. float y[2],z=0.0;
  31. __int32_t n,ix;
  32. GET_FLOAT_WORD(ix,x);
  33. /* |x| ~< pi/4 */
  34. ix &= 0x7fffffff;
  35. if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1);
  36. /* tan(Inf or NaN) is NaN */
  37. else if (!FLT_UWORD_IS_FINITE(ix)) return x-x; /* NaN */
  38. /* argument reduction needed */
  39. else {
  40. n = __ieee754_rem_pio2f(x,y);
  41. return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
  42. -1 -- n odd */
  43. }
  44. }
  45. #ifdef _DOUBLE_IS_32BITS
  46. #ifdef __STDC__
  47. double tan(double x)
  48. #else
  49. double tan(x)
  50. double x;
  51. #endif
  52. {
  53. return (double) tanf((float) x);
  54. }
  55. #endif /* defined(_DOUBLE_IS_32BITS) */