e_coshf.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* e_coshf.c -- float version of e_cosh.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  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 "cdefs-compat.h"
  15. //__FBSDID("$FreeBSD: src/lib/msun/src/e_coshf.c,v 1.9 2011/10/21 06:28:47 das Exp $");
  16. #include <openlibm_math.h>
  17. #include "math_private.h"
  18. static const float one = 1.0, half=0.5, huge = 1.0e30;
  19. DLLEXPORT float
  20. __ieee754_coshf(float x)
  21. {
  22. float t,w;
  23. int32_t ix;
  24. GET_FLOAT_WORD(ix,x);
  25. ix &= 0x7fffffff;
  26. /* x is INF or NaN */
  27. if(ix>=0x7f800000) return x*x;
  28. /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
  29. if(ix<0x3eb17218) {
  30. t = expm1f(fabsf(x));
  31. w = one+t;
  32. if (ix<0x39800000) return one; /* cosh(tiny) = 1 */
  33. return one+(t*t)/(w+w);
  34. }
  35. /* |x| in [0.5*ln2,9], return (exp(|x|)+1/exp(|x|))/2; */
  36. if (ix < 0x41100000) {
  37. t = __ieee754_expf(fabsf(x));
  38. return half*t+half/t;
  39. }
  40. /* |x| in [9, log(maxfloat)] return half*exp(|x|) */
  41. if (ix < 0x42b17217) return half*__ieee754_expf(fabsf(x));
  42. /* |x| in [log(maxfloat), overflowthresold] */
  43. if (ix<=0x42b2d4fc)
  44. return __ldexp_expf(fabsf(x), -1);
  45. /* |x| > overflowthresold, cosh(x) overflow */
  46. return huge*huge;
  47. }