csinhq.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Complex sine hyperbole function for float types.
  2. Copyright (C) 1997-2018 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "quadmath-imp.h"
  17. __complex128
  18. csinhq (__complex128 x)
  19. {
  20. __complex128 retval;
  21. int negate = signbitq (__real__ x);
  22. int rcls = fpclassifyq (__real__ x);
  23. int icls = fpclassifyq (__imag__ x);
  24. __real__ x = fabsq (__real__ x);
  25. if (__glibc_likely (rcls >= QUADFP_ZERO))
  26. {
  27. /* Real part is finite. */
  28. if (__glibc_likely (icls >= QUADFP_ZERO))
  29. {
  30. /* Imaginary part is finite. */
  31. const int t = (int) ((FLT128_MAX_EXP - 1) * M_LN2q);
  32. __float128 sinix, cosix;
  33. if (__glibc_likely (fabsq (__imag__ x) > FLT128_MIN))
  34. {
  35. sincosq (__imag__ x, &sinix, &cosix);
  36. }
  37. else
  38. {
  39. sinix = __imag__ x;
  40. cosix = 1;
  41. }
  42. if (negate)
  43. cosix = -cosix;
  44. if (fabsq (__real__ x) > t)
  45. {
  46. __float128 exp_t = expq (t);
  47. __float128 rx = fabsq (__real__ x);
  48. if (signbitq (__real__ x))
  49. cosix = -cosix;
  50. rx -= t;
  51. sinix *= exp_t / 2;
  52. cosix *= exp_t / 2;
  53. if (rx > t)
  54. {
  55. rx -= t;
  56. sinix *= exp_t;
  57. cosix *= exp_t;
  58. }
  59. if (rx > t)
  60. {
  61. /* Overflow (original real part of x > 3t). */
  62. __real__ retval = FLT128_MAX * cosix;
  63. __imag__ retval = FLT128_MAX * sinix;
  64. }
  65. else
  66. {
  67. __float128 exp_val = expq (rx);
  68. __real__ retval = exp_val * cosix;
  69. __imag__ retval = exp_val * sinix;
  70. }
  71. }
  72. else
  73. {
  74. __real__ retval = sinhq (__real__ x) * cosix;
  75. __imag__ retval = coshq (__real__ x) * sinix;
  76. }
  77. math_check_force_underflow_complex (retval);
  78. }
  79. else
  80. {
  81. if (rcls == QUADFP_ZERO)
  82. {
  83. /* Real part is 0.0. */
  84. __real__ retval = copysignq (0, negate ? -1 : 1);
  85. __imag__ retval = __imag__ x - __imag__ x;
  86. }
  87. else
  88. {
  89. __real__ retval = nanq ("");
  90. __imag__ retval = nanq ("");
  91. feraiseexcept (FE_INVALID);
  92. }
  93. }
  94. }
  95. else if (rcls == QUADFP_INFINITE)
  96. {
  97. /* Real part is infinite. */
  98. if (__glibc_likely (icls > QUADFP_ZERO))
  99. {
  100. /* Imaginary part is finite. */
  101. __float128 sinix, cosix;
  102. if (__glibc_likely (fabsq (__imag__ x) > FLT128_MIN))
  103. {
  104. sincosq (__imag__ x, &sinix, &cosix);
  105. }
  106. else
  107. {
  108. sinix = __imag__ x;
  109. cosix = 1;
  110. }
  111. __real__ retval = copysignq (HUGE_VALQ, cosix);
  112. __imag__ retval = copysignq (HUGE_VALQ, sinix);
  113. if (negate)
  114. __real__ retval = -__real__ retval;
  115. }
  116. else if (icls == QUADFP_ZERO)
  117. {
  118. /* Imaginary part is 0.0. */
  119. __real__ retval = negate ? -HUGE_VALQ : HUGE_VALQ;
  120. __imag__ retval = __imag__ x;
  121. }
  122. else
  123. {
  124. __real__ retval = HUGE_VALQ;
  125. __imag__ retval = __imag__ x - __imag__ x;
  126. }
  127. }
  128. else
  129. {
  130. __real__ retval = nanq ("");
  131. __imag__ retval = __imag__ x == 0 ? __imag__ x : nanq ("");
  132. }
  133. return retval;
  134. }