e_sinh.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* @(#)e_sinh.c 1.3 95/01/18 */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunSoft, 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. #include "cdefs-compat.h"
  13. //__FBSDID("$FreeBSD: src/lib/msun/src/e_sinh.c,v 1.11 2011/10/21 06:28:47 das Exp $");
  14. /* __ieee754_sinh(x)
  15. * Method :
  16. * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  17. * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
  18. * 2.
  19. * E + E/(E+1)
  20. * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
  21. * 2
  22. *
  23. * 22 <= x <= lnovft : sinh(x) := exp(x)/2
  24. * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
  25. * ln2ovft < x : sinh(x) := x*shuge (overflow)
  26. *
  27. * Special cases:
  28. * sinh(x) is |x| if x is +INF, -INF, or NaN.
  29. * only sinh(0)=0 is exact for finite x.
  30. */
  31. #include <openlibm.h>
  32. #include "math_private.h"
  33. static const double one = 1.0, shuge = 1.0e307;
  34. DLLEXPORT double
  35. __ieee754_sinh(double x)
  36. {
  37. double t,h;
  38. int32_t ix,jx;
  39. /* High word of |x|. */
  40. GET_HIGH_WORD(jx,x);
  41. ix = jx&0x7fffffff;
  42. /* x is INF or NaN */
  43. if(ix>=0x7ff00000) return x+x;
  44. h = 0.5;
  45. if (jx<0) h = -h;
  46. /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
  47. if (ix < 0x40360000) { /* |x|<22 */
  48. if (ix<0x3e300000) /* |x|<2**-28 */
  49. if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
  50. t = expm1(fabs(x));
  51. if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
  52. return h*(t+t/(t+one));
  53. }
  54. /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
  55. if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
  56. /* |x| in [log(maxdouble), overflowthresold] */
  57. if (ix<=0x408633CE)
  58. return h*2.0*__ldexp_exp(fabs(x), -1);
  59. /* |x| > overflowthresold, sinh(x) overflow */
  60. return x*shuge;
  61. }