sinhq.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* e_sinhl.c -- long double version of e_sinh.c.
  2. * Conversion to long double by Ulrich Drepper,
  3. * Cygnus Support, drepper@cygnus.com.
  4. */
  5. /*
  6. * ====================================================
  7. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  8. *
  9. * Developed at SunPro, a Sun Microsystems, Inc. business.
  10. * Permission to use, copy, modify, and distribute this
  11. * software is freely granted, provided that this notice
  12. * is preserved.
  13. * ====================================================
  14. */
  15. /* Changes for 128-bit long double are
  16. Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov>
  17. and are incorporated herein by permission of the author. The author
  18. reserves the right to distribute this material elsewhere under different
  19. copying permissions. These modifications are distributed here under
  20. the following terms:
  21. This library is free software; you can redistribute it and/or
  22. modify it under the terms of the GNU Lesser General Public
  23. License as published by the Free Software Foundation; either
  24. version 2.1 of the License, or (at your option) any later version.
  25. This library is distributed in the hope that it will be useful,
  26. but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  28. Lesser General Public License for more details.
  29. You should have received a copy of the GNU Lesser General Public
  30. License along with this library; if not, see
  31. <http://www.gnu.org/licenses/>. */
  32. /* sinhq(x)
  33. * Method :
  34. * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
  35. * 1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
  36. * 2.
  37. * E + E/(E+1)
  38. * 0 <= x <= 25 : sinhl(x) := --------------, E=expm1q(x)
  39. * 2
  40. *
  41. * 25 <= x <= lnovft : sinhl(x) := expq(x)/2
  42. * lnovft <= x <= ln2ovft: sinhl(x) := expq(x/2)/2 * expq(x/2)
  43. * ln2ovft < x : sinhl(x) := x*shuge (overflow)
  44. *
  45. * Special cases:
  46. * sinhl(x) is |x| if x is +INF, -INF, or NaN.
  47. * only sinhl(0)=0 is exact for finite x.
  48. */
  49. #include "quadmath-imp.h"
  50. static const __float128 one = 1.0, shuge = 1.0e4931Q,
  51. ovf_thresh = 1.1357216553474703894801348310092223067821E4Q;
  52. __float128
  53. sinhq (__float128 x)
  54. {
  55. __float128 t, w, h;
  56. uint32_t jx, ix;
  57. ieee854_float128 u;
  58. /* Words of |x|. */
  59. u.value = x;
  60. jx = u.words32.w0;
  61. ix = jx & 0x7fffffff;
  62. /* x is INF or NaN */
  63. if (ix >= 0x7fff0000)
  64. return x + x;
  65. h = 0.5;
  66. if (jx & 0x80000000)
  67. h = -h;
  68. /* Absolute value of x. */
  69. u.words32.w0 = ix;
  70. /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
  71. if (ix <= 0x40044000)
  72. {
  73. if (ix < 0x3fc60000) /* |x| < 2^-57 */
  74. {
  75. math_check_force_underflow (x);
  76. if (shuge + x > one)
  77. return x; /* sinh(tiny) = tiny with inexact */
  78. }
  79. t = expm1q (u.value);
  80. if (ix < 0x3fff0000)
  81. return h * (2.0 * t - t * t / (t + one));
  82. return h * (t + t / (t + one));
  83. }
  84. /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
  85. if (ix <= 0x400c62e3) /* 11356.375 */
  86. return h * expq (u.value);
  87. /* |x| in [log(maxdouble), overflowthreshold]
  88. Overflow threshold is log(2 * maxdouble). */
  89. if (u.value <= ovf_thresh)
  90. {
  91. w = expq (0.5 * u.value);
  92. t = h * w;
  93. return t * w;
  94. }
  95. /* |x| > overflowthreshold, sinhl(x) overflow */
  96. return x * shuge;
  97. }