e_atanh.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 __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. }