e_acoshf.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* e_acoshf.c -- float version of e_acosh.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  3. */
  4. /*
  5. * ====================================================
  6. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7. *
  8. * Developed at SunPro, a Sun Microsystems, Inc. business.
  9. * Permission to use, copy, modify, and distribute this
  10. * software is freely granted, provided that this notice
  11. * is preserved.
  12. * ====================================================
  13. */
  14. #include <sys/cdefs.h>
  15. //__FBSDID("$FreeBSD: src/lib/msun/src/e_acoshf.c,v 1.8 2008/02/22 02:30:34 das Exp $");
  16. #include "openlibm.h"
  17. #include "math_private.h"
  18. static const float
  19. one = 1.0,
  20. ln2 = 6.9314718246e-01; /* 0x3f317218 */
  21. float
  22. __ieee754_acoshf(float x)
  23. {
  24. float t;
  25. int32_t hx;
  26. GET_FLOAT_WORD(hx,x);
  27. if(hx<0x3f800000) { /* x < 1 */
  28. return (x-x)/(x-x);
  29. } else if(hx >=0x4d800000) { /* x > 2**28 */
  30. if(hx >=0x7f800000) { /* x is inf of NaN */
  31. return x+x;
  32. } else
  33. return __ieee754_logf(x)+ln2; /* acosh(huge)=log(2x) */
  34. } else if (hx==0x3f800000) {
  35. return 0.0; /* acosh(1) = 0 */
  36. } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
  37. t=x*x;
  38. return __ieee754_logf((float)2.0*x-one/(x+__ieee754_sqrtf(t-one)));
  39. } else { /* 1<x<2 */
  40. t = x-one;
  41. return log1pf(t+__ieee754_sqrtf((float)2.0*t+t*t));
  42. }
  43. }