e_asinl.c 1.9 KB

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