atanhf.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* origin: FreeBSD /usr/src/lib/msun/src/e_atanhf.c */
  2. /*
  3. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  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. #include "libm.h"
  16. static const float huge = 1e30;
  17. float atanhf(float x)
  18. {
  19. float t;
  20. int32_t hx,ix;
  21. GET_FLOAT_WORD(hx, x);
  22. ix = hx & 0x7fffffff;
  23. if (ix > 0x3f800000) /* |x| > 1 */
  24. return (x-x)/(x-x);
  25. if (ix == 0x3f800000)
  26. return x/0.0f;
  27. if (ix < 0x31800000 && huge+x > 0.0f) /* x < 2**-28 */
  28. return x;
  29. SET_FLOAT_WORD(x, ix);
  30. if (ix < 0x3f000000) { /* x < 0.5 */
  31. t = x+x;
  32. t = 0.5f*log1pf(t + t*x/(1.0f-x));
  33. } else
  34. t = 0.5f*log1pf((x+x)/(1.0f-x));
  35. if (hx >= 0)
  36. return t;
  37. return -t;
  38. }