e_sinhl.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /*
  13. * Copyright (c) 2008 Stephen L. Moshier <[email protected]>
  14. *
  15. * Permission to use, copy, modify, and distribute this software for any
  16. * purpose with or without fee is hereby granted, provided that the above
  17. * copyright notice and this permission notice appear in all copies.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  20. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  22. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  24. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  25. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26. */
  27. /* sinhl(x)
  28. * Method :
  29. * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  30. * 1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
  31. * 2.
  32. * E + E/(E+1)
  33. * 0 <= x <= 25 : sinhl(x) := --------------, E=expm1l(x)
  34. * 2
  35. *
  36. * 25 <= x <= lnovft : sinhl(x) := expl(x)/2
  37. * lnovft <= x <= ln2ovft: sinhl(x) := expl(x/2)/2 * expl(x/2)
  38. * ln2ovft < x : sinhl(x) := x*shuge (overflow)
  39. *
  40. * Special cases:
  41. * sinhl(x) is |x| if x is +INF, -INF, or NaN.
  42. * only sinhl(0)=0 is exact for finite x.
  43. */
  44. #include <openlibm_math.h>
  45. #include "math_private.h"
  46. static const long double one = 1.0, shuge = 1.0e4931L,
  47. ovf_thresh = 1.1357216553474703894801348310092223067821E4L;
  48. long double
  49. sinhl(long double x)
  50. {
  51. long double t, w, h;
  52. u_int32_t jx, ix;
  53. ieee_quad_shape_type u;
  54. /* Words of |x|. */
  55. u.value = x;
  56. jx = u.parts32.mswhi;
  57. ix = jx & 0x7fffffff;
  58. /* x is INF or NaN */
  59. if (ix >= 0x7fff0000)
  60. return x + x;
  61. h = 0.5;
  62. if (jx & 0x80000000)
  63. h = -h;
  64. /* Absolute value of x. */
  65. u.parts32.mswhi = ix;
  66. /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
  67. if (ix <= 0x40044000)
  68. {
  69. if (ix < 0x3fc60000) /* |x| < 2^-57 */
  70. if (shuge + x > one)
  71. return x; /* sinh(tiny) = tiny with inexact */
  72. t = expm1l (u.value);
  73. if (ix < 0x3fff0000)
  74. return h * (2.0 * t - t * t / (t + one));
  75. return h * (t + t / (t + one));
  76. }
  77. /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
  78. if (ix <= 0x400c62e3) /* 11356.375 */
  79. return h * expl (u.value);
  80. /* |x| in [log(maxdouble), overflowthreshold]
  81. Overflow threshold is log(2 * maxdouble). */
  82. if (u.value <= ovf_thresh)
  83. {
  84. w = expl (0.5 * u.value);
  85. t = h * w;
  86. return t * w;
  87. }
  88. /* |x| > overflowthreshold, sinhl(x) overflow */
  89. return x * shuge;
  90. }