sinhf.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* origin: FreeBSD /usr/src/lib/msun/src/e_sinhf.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 = 1.0e37;
  17. float sinhf(float x)
  18. {
  19. float t, h;
  20. int32_t ix, jx;
  21. GET_FLOAT_WORD(jx, x);
  22. ix = jx & 0x7fffffff;
  23. /* x is INF or NaN */
  24. if (ix >= 0x7f800000)
  25. return x + x;
  26. h = 0.5;
  27. if (jx < 0)
  28. h = -h;
  29. /* |x| in [0,9], return sign(x)*0.5*(E+E/(E+1))) */
  30. if (ix < 0x41100000) { /* |x|<9 */
  31. if (ix < 0x39800000) /* |x|<2**-12 */
  32. /* raise inexact, return x */
  33. if (huge+x > 1.0f)
  34. return x;
  35. t = expm1f(fabsf(x));
  36. if (ix < 0x3f800000)
  37. return h*(2.0f*t - t*t/(t+1.0f));
  38. return h*(t + t/(t+1.0f));
  39. }
  40. /* |x| in [9, logf(maxfloat)] return 0.5*exp(|x|) */
  41. if (ix < 0x42b17217)
  42. return h*expf(fabsf(x));
  43. /* |x| in [logf(maxfloat), overflowthresold] */
  44. if (ix <= 0x42b2d4fc)
  45. return h * 2.0f * __expo2f(fabsf(x)); /* h is for sign only */
  46. /* |x| > overflowthresold, sinh(x) overflow */
  47. return x*huge;
  48. }