asinl.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.c */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunSoft, a Sun Microsystems, Inc. business.
  7. * Permission to use, copy, modify, and distribute this
  8. * software is freely granted, provided that this notice
  9. * is preserved.
  10. * ====================================================
  11. */
  12. /*
  13. * See comments in asin.c.
  14. * Converted to long double by David Schultz <[email protected]>.
  15. */
  16. #include "libm.h"
  17. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  18. long double asinl(long double x)
  19. {
  20. return asin(x);
  21. }
  22. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  23. #include "__invtrigl.h"
  24. static const long double huge = 1.000e+300;
  25. long double asinl(long double x)
  26. {
  27. union IEEEl2bits u;
  28. long double t=0.0,w,p,q,c,r,s;
  29. int16_t expsign, expt;
  30. u.e = x;
  31. expsign = u.xbits.expsign;
  32. expt = expsign & 0x7fff;
  33. if (expt >= BIAS) { /* |x|>= 1 */
  34. if (expt == BIAS &&
  35. ((u.bits.manh&~LDBL_NBIT)|u.bits.manl) == 0)
  36. /* asin(1)=+-pi/2 with inexact */
  37. return x*pio2_hi + x*pio2_lo;
  38. return (x-x)/(x-x); /* asin(|x|>1) is NaN */
  39. } else if (expt < BIAS-1) { /* |x|<0.5 */
  40. if (expt < ASIN_LINEAR) { /* if |x| is small, asinl(x)=x */
  41. /* return x with inexact if x!=0 */
  42. if (huge+x > 1.0)
  43. return x;
  44. }
  45. t = x*x;
  46. p = P(t);
  47. q = Q(t);
  48. w = p/q;
  49. return x + x*w;
  50. }
  51. /* 1 > |x| >= 0.5 */
  52. w = 1.0 - fabsl(x);
  53. t = w*0.5;
  54. p = P(t);
  55. q = Q(t);
  56. s = sqrtl(t);
  57. if (u.bits.manh >= THRESH) { /* if |x| is close to 1 */
  58. w = p/q;
  59. t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
  60. } else {
  61. u.e = s;
  62. u.bits.manl = 0;
  63. w = u.e;
  64. c = (t-w*w)/(s+w);
  65. r = p/q;
  66. p = 2.0*s*r-(pio2_lo-2.0*c);
  67. q = pio4_hi-2.0*w;
  68. t = pio4_hi-(p-q);
  69. }
  70. if (expsign > 0)
  71. return t;
  72. return -t;
  73. }
  74. #endif