asinhq.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* asinhq.c -- __float128 version of s_asinh.c.
  2. * Conversion to long double by Ulrich Drepper,
  3. * Cygnus Support, drepper@cygnus.com.
  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. /* asinhl(x)
  16. * Method :
  17. * Based on
  18. * asinhl(x) = signl(x) * logl [ |x| + sqrtl(x*x+1) ]
  19. * we have
  20. * asinhl(x) := x if 1+x*x=1,
  21. * := signl(x)*(logl(x)+ln2)) for large |x|, else
  22. * := signl(x)*logl(2|x|+1/(|x|+sqrtl(x*x+1))) if|x|>2, else
  23. * := signl(x)*log1pl(|x| + x^2/(1 + sqrtl(1+x^2)))
  24. */
  25. #include "quadmath-imp.h"
  26. static const __float128
  27. one = 1.0Q,
  28. ln2 = 6.931471805599453094172321214581765681e-1Q,
  29. huge = 1.0e+4900Q;
  30. __float128
  31. asinhq (__float128 x)
  32. {
  33. __float128 t, w;
  34. int32_t ix, sign;
  35. ieee854_float128 u;
  36. u.value = x;
  37. sign = u.words32.w0;
  38. ix = sign & 0x7fffffff;
  39. if (ix == 0x7fff0000)
  40. return x + x; /* x is inf or NaN */
  41. if (ix < 0x3fc70000)
  42. { /* |x| < 2^ -56 */
  43. if (huge + x > one)
  44. return x; /* return x inexact except 0 */
  45. }
  46. u.words32.w0 = ix;
  47. if (ix > 0x40350000)
  48. { /* |x| > 2 ^ 54 */
  49. w = logq (u.value) + ln2;
  50. }
  51. else if (ix >0x40000000)
  52. { /* 2^ 54 > |x| > 2.0 */
  53. t = u.value;
  54. w = logq (2.0 * t + one / (sqrtq (x * x + one) + t));
  55. }
  56. else
  57. { /* 2.0 > |x| > 2 ^ -56 */
  58. t = x * x;
  59. w = log1pq (u.value + t / (one + sqrtq (one + t)));
  60. }
  61. if (sign & 0x80000000)
  62. return -w;
  63. else
  64. return w;
  65. }