e_sinh.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* @(#)e_sinh.c 5.1 93/09/24 */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, 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. #if defined(LIBM_SCCS) && !defined(lint)
  13. static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
  14. #endif
  15. /* __ieee754_sinh(x)
  16. * Method :
  17. * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  18. * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
  19. * 2.
  20. * E + E/(E+1)
  21. * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
  22. * 2
  23. *
  24. * 22 <= x <= lnovft : sinh(x) := exp(x)/2
  25. * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
  26. * ln2ovft < x : sinh(x) := x*shuge (overflow)
  27. *
  28. * Special cases:
  29. * sinh(x) is |x| if x is +INF, -INF, or NaN.
  30. * only sinh(0)=0 is exact for finite x.
  31. */
  32. #include "math.h"
  33. #include "math_private.h"
  34. #ifdef __STDC__
  35. static const double one = 1.0, shuge = 1.0e307;
  36. #else
  37. static double one = 1.0, shuge = 1.0e307;
  38. #endif
  39. #ifdef __STDC__
  40. double __ieee754_sinh(double x)
  41. #else
  42. double __ieee754_sinh(x)
  43. double x;
  44. #endif
  45. {
  46. double t,w,h;
  47. int32_t ix,jx;
  48. u_int32_t lx;
  49. /* High word of |x|. */
  50. GET_HIGH_WORD(jx,x);
  51. ix = jx&0x7fffffff;
  52. /* x is INF or NaN */
  53. if(ix>=0x7ff00000) return x+x;
  54. h = 0.5;
  55. if (jx<0) h = -h;
  56. /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
  57. if (ix < 0x40360000) { /* |x|<22 */
  58. if (ix<0x3e300000) /* |x|<2**-28 */
  59. if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
  60. t = expm1(fabs(x));
  61. if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
  62. return h*(t+t/(t+one));
  63. }
  64. /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
  65. if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
  66. /* |x| in [log(maxdouble), overflowthresold] */
  67. GET_LOW_WORD(lx,x);
  68. if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
  69. w = __ieee754_exp(0.5*fabs(x));
  70. t = h*w;
  71. return t*w;
  72. }
  73. /* |x| > overflowthresold, sinh(x) overflow */
  74. return x*shuge;
  75. }