e_asinf.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* e_asinf.c -- float version of e_asin.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 "cdefs-compat.h"
  15. //__FBSDID("$FreeBSD: src/lib/msun/src/e_asinf.c,v 1.13 2008/08/08 00:21:27 das Exp $");
  16. #include <openlibm_math.h>
  17. #include "math_private.h"
  18. static const float
  19. one = 1.0000000000e+00, /* 0x3F800000 */
  20. huge = 1.000e+30,
  21. /* coefficient for R(x^2) */
  22. pS0 = 1.6666586697e-01,
  23. pS1 = -4.2743422091e-02,
  24. pS2 = -8.6563630030e-03,
  25. qS1 = -7.0662963390e-01;
  26. static const double
  27. pio2 = 1.570796326794896558e+00;
  28. DLLEXPORT float
  29. __ieee754_asinf(float x)
  30. {
  31. double s;
  32. float t,w,p,q;
  33. int32_t hx,ix;
  34. GET_FLOAT_WORD(hx,x);
  35. ix = hx&0x7fffffff;
  36. if(ix>=0x3f800000) { /* |x| >= 1 */
  37. if(ix==0x3f800000) /* |x| == 1 */
  38. return x*pio2; /* asin(+-1) = +-pi/2 with inexact */
  39. return (x-x)/(x-x); /* asin(|x|>1) is NaN */
  40. } else if (ix<0x3f000000) { /* |x|<0.5 */
  41. if(ix<0x39800000) { /* |x| < 2**-12 */
  42. if(huge+x>one) return x;/* return x with inexact if x!=0*/
  43. }
  44. t = x*x;
  45. p = t*(pS0+t*(pS1+t*pS2));
  46. q = one+t*qS1;
  47. w = p/q;
  48. return x+x*w;
  49. }
  50. /* 1> |x|>= 0.5 */
  51. w = one-fabsf(x);
  52. t = w*(float)0.5;
  53. p = t*(pS0+t*(pS1+t*pS2));
  54. q = one+t*qS1;
  55. s = sqrt(t);
  56. w = p/q;
  57. t = pio2-2.0*(s+s*w);
  58. if(hx>0) return t; else return -t;
  59. }