e_atanhl.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* @(#)e_atanh.c 5.1 93/09/24 */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, 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. /* atanhl(x)
  13. * Method :
  14. * 1.Reduced x to positive by atanh(-x) = -atanh(x)
  15. * 2.For x>=0.5
  16. * 1 2x x
  17. * atanhl(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
  18. * 2 1 - x 1 - x
  19. *
  20. * For x<0.5
  21. * atanhl(x) = 0.5*log1pl(2x+2x*x/(1-x))
  22. *
  23. * Special cases:
  24. * atanhl(x) is NaN if |x| > 1 with signal;
  25. * atanhl(NaN) is that NaN with no signal;
  26. * atanhl(+-1) is +-INF with signal.
  27. *
  28. */
  29. #include <openlibm_math.h>
  30. #include "math_private.h"
  31. #include "math_private_openbsd.h"
  32. static const long double one = 1.0, huge = 1e4900L;
  33. static const long double zero = 0.0;
  34. long double
  35. atanhl(long double x)
  36. {
  37. long double t;
  38. int32_t ix;
  39. u_int32_t se,i0,i1;
  40. GET_LDOUBLE_WORDS(se,i0,i1,x);
  41. ix = se&0x7fff;
  42. if ((ix+((((i0&0x7fffffff)|i1)|(-((i0&0x7fffffff)|i1)))>>31))>0x3fff)
  43. /* |x|>1 */
  44. return (x-x)/(x-x);
  45. if(ix==0x3fff)
  46. return x/zero;
  47. if(ix<0x3fe3&&(huge+x)>zero) return x; /* x<2**-28 */
  48. SET_LDOUBLE_EXP(x,ix);
  49. if(ix<0x3ffe) { /* x < 0.5 */
  50. t = x+x;
  51. t = 0.5*log1pl(t+t*x/(one-x));
  52. } else
  53. t = 0.5*log1pl((x+x)/(one-x));
  54. if(se<=0x7fff) return t; else return -t;
  55. }