asinf.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.c */
  2. /*
  3. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  4. */
  5. /*
  6. * ====================================================
  7. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  8. *
  9. * Developed at SunPro, a Sun Microsystems, Inc. business.
  10. * Permission to use, copy, modify, and distribute this
  11. * software is freely granted, provided that this notice
  12. * is preserved.
  13. * ====================================================
  14. */
  15. #include "libm.h"
  16. static const double
  17. pio2 = 1.570796326794896558e+00;
  18. static const float
  19. /* coefficients for R(x^2) */
  20. pS0 = 1.6666586697e-01,
  21. pS1 = -4.2743422091e-02,
  22. pS2 = -8.6563630030e-03,
  23. qS1 = -7.0662963390e-01;
  24. static float R(float z)
  25. {
  26. float_t p, q;
  27. p = z*(pS0+z*(pS1+z*pS2));
  28. q = 1.0f+z*qS1;
  29. return p/q;
  30. }
  31. float asinf(float x)
  32. {
  33. double s;
  34. float z;
  35. uint32_t hx,ix;
  36. GET_FLOAT_WORD(hx, x);
  37. ix = hx & 0x7fffffff;
  38. if (ix >= 0x3f800000) { /* |x| >= 1 */
  39. if (ix == 0x3f800000) /* |x| == 1 */
  40. return x*pio2 + 0x1p-120f; /* asin(+-1) = +-pi/2 with inexact */
  41. return 0/(x-x); /* asin(|x|>1) is NaN */
  42. }
  43. if (ix < 0x3f000000) { /* |x| < 0.5 */
  44. /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
  45. if (ix < 0x39800000 && ix >= 0x00800000)
  46. return x;
  47. return x + x*R(x*x);
  48. }
  49. /* 1 > |x| >= 0.5 */
  50. z = (1 - fabsf(x))*0.5f;
  51. s = sqrt(z);
  52. x = pio2 - 2*(s+s*R(z));
  53. if (hx >> 31)
  54. return -x;
  55. return x;
  56. }