e_sinh.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /* __ieee754_sinh(x)
  12. * Method :
  13. * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  14. * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
  15. * 2.
  16. * E + E/(E+1)
  17. * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
  18. * 2
  19. *
  20. * 22 <= x <= lnovft : sinh(x) := exp(x)/2
  21. * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
  22. * ln2ovft < x : sinh(x) := x*shuge (overflow)
  23. *
  24. * Special cases:
  25. * sinh(x) is |x| if x is +INF, -INF, or NaN.
  26. * only sinh(0)=0 is exact for finite x.
  27. */
  28. #include "math.h"
  29. #include "math_private.h"
  30. static const double one = 1.0, shuge = 1.0e307;
  31. double attribute_hidden __ieee754_sinh(double x)
  32. {
  33. double t,w,h;
  34. int32_t ix,jx;
  35. u_int32_t lx;
  36. /* High word of |x|. */
  37. GET_HIGH_WORD(jx,x);
  38. ix = jx&0x7fffffff;
  39. /* x is INF or NaN */
  40. if(ix>=0x7ff00000) return x+x;
  41. h = 0.5;
  42. if (jx<0) h = -h;
  43. /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
  44. if (ix < 0x40360000) { /* |x|<22 */
  45. if (ix<0x3e300000) /* |x|<2**-28 */
  46. if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
  47. t = expm1(fabs(x));
  48. if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
  49. return h*(t+t/(t+one));
  50. }
  51. /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
  52. if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
  53. /* |x| in [log(maxdouble), overflowthresold] */
  54. GET_LOW_WORD(lx,x);
  55. if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
  56. w = __ieee754_exp(0.5*fabs(x));
  57. t = h*w;
  58. return t*w;
  59. }
  60. /* |x| > overflowthresold, sinh(x) overflow */
  61. return x*shuge;
  62. }