s_csinh_template.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* Complex sine hyperbole function for float types.
  2. Copyright (C) 1997-2019 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 <complex.h>
  17. #include <fenv.h>
  18. #include <math.h>
  19. #include <math_private.h>
  20. #include <math-underflow.h>
  21. #include <float.h>
  22. CFLOAT
  23. M_DECL_FUNC (__csinh) (CFLOAT x)
  24. {
  25. CFLOAT retval;
  26. int negate = signbit (__real__ x);
  27. int rcls = fpclassify (__real__ x);
  28. int icls = fpclassify (__imag__ x);
  29. __real__ x = M_FABS (__real__ x);
  30. if (__glibc_likely (rcls >= FP_ZERO))
  31. {
  32. /* Real part is finite. */
  33. if (__glibc_likely (icls >= FP_ZERO))
  34. {
  35. /* Imaginary part is finite. */
  36. const int t = (int) ((M_MAX_EXP - 1) * M_MLIT (M_LN2));
  37. FLOAT sinix, cosix;
  38. if (__glibc_likely (M_FABS (__imag__ x) > M_MIN))
  39. {
  40. M_SINCOS (__imag__ x, &sinix, &cosix);
  41. }
  42. else
  43. {
  44. sinix = __imag__ x;
  45. cosix = 1;
  46. }
  47. if (negate)
  48. cosix = -cosix;
  49. if (M_FABS (__real__ x) > t)
  50. {
  51. FLOAT exp_t = M_EXP (t);
  52. FLOAT rx = M_FABS (__real__ x);
  53. if (signbit (__real__ x))
  54. cosix = -cosix;
  55. rx -= t;
  56. sinix *= exp_t / 2;
  57. cosix *= exp_t / 2;
  58. if (rx > t)
  59. {
  60. rx -= t;
  61. sinix *= exp_t;
  62. cosix *= exp_t;
  63. }
  64. if (rx > t)
  65. {
  66. /* Overflow (original real part of x > 3t). */
  67. __real__ retval = M_MAX * cosix;
  68. __imag__ retval = M_MAX * sinix;
  69. }
  70. else
  71. {
  72. FLOAT exp_val = M_EXP (rx);
  73. __real__ retval = exp_val * cosix;
  74. __imag__ retval = exp_val * sinix;
  75. }
  76. }
  77. else
  78. {
  79. __real__ retval = M_SINH (__real__ x) * cosix;
  80. __imag__ retval = M_COSH (__real__ x) * sinix;
  81. }
  82. math_check_force_underflow_complex (retval);
  83. }
  84. else
  85. {
  86. if (rcls == FP_ZERO)
  87. {
  88. /* Real part is 0.0. */
  89. __real__ retval = M_COPYSIGN (0, negate ? -1 : 1);
  90. __imag__ retval = __imag__ x - __imag__ x;
  91. }
  92. else
  93. {
  94. __real__ retval = M_NAN;
  95. __imag__ retval = M_NAN;
  96. feraiseexcept (FE_INVALID);
  97. }
  98. }
  99. }
  100. else if (rcls == FP_INFINITE)
  101. {
  102. /* Real part is infinite. */
  103. if (__glibc_likely (icls > FP_ZERO))
  104. {
  105. /* Imaginary part is finite. */
  106. FLOAT sinix, cosix;
  107. if (__glibc_likely (M_FABS (__imag__ x) > M_MIN))
  108. {
  109. M_SINCOS (__imag__ x, &sinix, &cosix);
  110. }
  111. else
  112. {
  113. sinix = __imag__ x;
  114. cosix = 1;
  115. }
  116. __real__ retval = M_COPYSIGN (M_HUGE_VAL, cosix);
  117. __imag__ retval = M_COPYSIGN (M_HUGE_VAL, sinix);
  118. if (negate)
  119. __real__ retval = -__real__ retval;
  120. }
  121. else if (icls == FP_ZERO)
  122. {
  123. /* Imaginary part is 0.0. */
  124. __real__ retval = negate ? -M_HUGE_VAL : M_HUGE_VAL;
  125. __imag__ retval = __imag__ x;
  126. }
  127. else
  128. {
  129. __real__ retval = M_HUGE_VAL;
  130. __imag__ retval = __imag__ x - __imag__ x;
  131. }
  132. }
  133. else
  134. {
  135. __real__ retval = M_NAN;
  136. __imag__ retval = __imag__ x == 0 ? __imag__ x : M_NAN;
  137. }
  138. return retval;
  139. }
  140. declare_mgen_alias (__csinh, csinh)