e_atanh.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /* __ieee754_atanh(x)
  12. * Method :
  13. * 1.Reduced x to positive by atanh(-x) = -atanh(x)
  14. * 2.For x>=0.5
  15. * 1 2x x
  16. * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
  17. * 2 1 - x 1 - x
  18. *
  19. * For x<0.5
  20. * atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
  21. *
  22. * Special cases:
  23. * atanh(x) is NaN if |x| > 1 with signal;
  24. * atanh(NaN) is that NaN with no signal;
  25. * atanh(+-1) is +-INF with signal.
  26. *
  27. */
  28. #include "math.h"
  29. #include "math_private.h"
  30. static const double one = 1.0, huge = 1e300;
  31. static const double zero = 0.0;
  32. double attribute_hidden __ieee754_atanh(double x)
  33. {
  34. double t;
  35. int32_t hx,ix;
  36. u_int32_t lx;
  37. EXTRACT_WORDS(hx,lx,x);
  38. ix = hx&0x7fffffff;
  39. if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
  40. return (x-x)/(x-x);
  41. if(ix==0x3ff00000)
  42. return x/zero;
  43. if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */
  44. SET_HIGH_WORD(x,ix);
  45. if(ix<0x3fe00000) { /* x < 0.5 */
  46. t = x+x;
  47. t = 0.5*log1p(t+t*x/(one-x));
  48. } else
  49. t = 0.5*log1p((x+x)/(one-x));
  50. if(hx>=0) return t; else return -t;
  51. }
  52. /*
  53. * wrapper atanh(x)
  54. */
  55. #ifndef _IEEE_LIBM
  56. double atanh(double x)
  57. {
  58. double z, y;
  59. z = __ieee754_atanh(x);
  60. if (_LIB_VERSION == _IEEE_ || isnan(x))
  61. return z;
  62. y = fabs(x);
  63. if (y >= 1.0) {
  64. if (y > 1.0)
  65. return __kernel_standard(x, x, 30); /* atanh(|x|>1) */
  66. return __kernel_standard(x, x, 31); /* atanh(|x|==1) */
  67. }
  68. return z;
  69. }
  70. #else
  71. strong_alias(__ieee754_atanh, atanh)
  72. #endif
  73. libm_hidden_def(atanh)