asinf.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 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 (ix < 0x39800000) { /* |x| < 2**-12 */
  45. FORCE_EVAL(x + 0x1p120f);
  46. return x; /* return x with inexact if x!=0 */
  47. }
  48. return x + x*R(x*x);
  49. }
  50. /* 1 > |x| >= 0.5 */
  51. z = (1 - fabsf(x))*0.5f;
  52. s = sqrt(z);
  53. x = pio2 - 2*(s+s*R(z));
  54. if (hx >> 31)
  55. return -x;
  56. return x;
  57. }