asinhq.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* s_asinhl.c -- long double 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. #if defined(LIBM_SCCS) && !defined(lint)
  16. static char rcsid[] = "$NetBSD: $";
  17. #endif
  18. /* asinhq(x)
  19. * Method :
  20. * Based on
  21. * asinhq(x) = signl(x) * logq [ |x| + sqrtq(x*x+1) ]
  22. * we have
  23. * asinhq(x) := x if 1+x*x=1,
  24. * := signl(x)*(logq(x)+ln2)) for large |x|, else
  25. * := signl(x)*logq(2|x|+1/(|x|+sqrtq(x*x+1))) if|x|>2, else
  26. * := signl(x)*log1pq(|x| + x^2/(1 + sqrtq(1+x^2)))
  27. */
  28. #include "quadmath-imp.h"
  29. static const __float128
  30. one = 1,
  31. ln2 = 6.931471805599453094172321214581765681e-1Q,
  32. huge = 1.0e+4900Q;
  33. __float128
  34. asinhq (__float128 x)
  35. {
  36. __float128 t, w;
  37. int32_t ix, sign;
  38. ieee854_float128 u;
  39. u.value = x;
  40. sign = u.words32.w0;
  41. ix = sign & 0x7fffffff;
  42. if (ix == 0x7fff0000)
  43. return x + x; /* x is inf or NaN */
  44. if (ix < 0x3fc70000)
  45. { /* |x| < 2^ -56 */
  46. math_check_force_underflow (x);
  47. if (huge + x > one)
  48. return x; /* return x inexact except 0 */
  49. }
  50. u.words32.w0 = ix;
  51. if (ix > 0x40350000)
  52. { /* |x| > 2 ^ 54 */
  53. w = logq (u.value) + ln2;
  54. }
  55. else if (ix >0x40000000)
  56. { /* 2^ 54 > |x| > 2.0 */
  57. t = u.value;
  58. w = logq (2.0 * t + one / (sqrtq (x * x + one) + t));
  59. }
  60. else
  61. { /* 2.0 > |x| > 2 ^ -56 */
  62. t = x * x;
  63. w = log1pq (u.value + t / (one + sqrtq (one + t)));
  64. }
  65. if (sign & 0x80000000)
  66. return -w;
  67. else
  68. return w;
  69. }