e_sinh.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /* __ieee754_sinh(x)
  13. * Method :
  14. * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  15. * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
  16. * 2.
  17. * E + E/(E+1)
  18. * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
  19. * 2
  20. *
  21. * 22 <= x <= lnovft : sinh(x) := exp(x)/2
  22. * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
  23. * ln2ovft < x : sinh(x) := x*shuge (overflow)
  24. *
  25. * Special cases:
  26. * sinh(x) is |x| if x is +INF, -INF, or NaN.
  27. * only sinh(0)=0 is exact for finite x.
  28. */
  29. #include "fdlibm.h"
  30. #ifndef _DOUBLE_IS_32BITS
  31. #ifdef __STDC__
  32. static const double one = 1.0, shuge = 1.0e307;
  33. #else
  34. static double one = 1.0, shuge = 1.0e307;
  35. #endif
  36. #ifdef __STDC__
  37. double __ieee754_sinh(double x)
  38. #else
  39. double __ieee754_sinh(x)
  40. double x;
  41. #endif
  42. {
  43. double t,w,h;
  44. int32_t ix,jx;
  45. uint32_t lx;
  46. /* High word of |x|. */
  47. GET_HIGH_WORD(jx,x);
  48. ix = jx&0x7fffffff;
  49. /* x is INF or NaN */
  50. if(ix>=0x7ff00000) return x+x;
  51. h = 0.5;
  52. if (jx<0) h = -h;
  53. /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
  54. if (ix < 0x40360000) { /* |x|<22 */
  55. if (ix<0x3e300000) /* |x|<2**-28 */
  56. if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
  57. t = expm1(fabs(x));
  58. if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
  59. return h*(t+t/(t+one));
  60. }
  61. /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
  62. if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
  63. /* |x| in [log(maxdouble), overflowthresold] */
  64. lx = *( (((*(uint32_t*)&one)>>29)) + (uint32_t*)&x);
  65. if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d)) {
  66. w = __ieee754_exp(0.5*fabs(x));
  67. t = h*w;
  68. return t*w;
  69. }
  70. /* |x| > overflowthresold, sinh(x) overflow */
  71. return x*shuge;
  72. }
  73. #endif /* defined(_DOUBLE_IS_32BITS) */