1
0

asinl.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /* 0.95 */
  25. #define THRESH ((0xe666666666666666ULL>>(64-(LDBL_MANH_SIZE-1)))|LDBL_NBIT)
  26. long double asinl(long double x)
  27. {
  28. union IEEEl2bits u;
  29. long double z,r,s;
  30. uint16_t expsign, expt;
  31. u.e = x;
  32. expsign = u.xbits.expsign;
  33. expt = expsign & 0x7fff;
  34. if (expt >= 0x3fff) { /* |x| >= 1 or nan */
  35. if (expt == 0x3fff &&
  36. ((u.bits.manh&~LDBL_NBIT)|u.bits.manl) == 0)
  37. /* asin(+-1)=+-pi/2 with inexact */
  38. return x*pio2_hi + 0x1p-120f;
  39. return 0/(x-x);
  40. }
  41. if (expt < 0x3fff - 1) { /* |x| < 0.5 */
  42. if (expt < 0x3fff - 32) { /* |x|<0x1p-32, asinl(x)=x */
  43. /* return x with inexact if x!=0 */
  44. FORCE_EVAL(x + 0x1p120f);
  45. return x;
  46. }
  47. return x + x*__invtrigl_R(x*x);
  48. }
  49. /* 1 > |x| >= 0.5 */
  50. z = (1.0 - fabsl(x))*0.5;
  51. s = sqrtl(z);
  52. r = __invtrigl_R(z);
  53. if (u.bits.manh >= THRESH) { /* if |x| is close to 1 */
  54. x = pio2_hi - (2*(s+s*r)-pio2_lo);
  55. } else {
  56. long double f, c;
  57. u.e = s;
  58. u.bits.manl = 0;
  59. f = u.e;
  60. c = (z-f*f)/(s+f);
  61. x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f));
  62. }
  63. if (expsign>>15)
  64. return -x;
  65. return x;
  66. }
  67. #endif