/math/s_ccoshf.c

https://gitlab.com/Namal/glibc · C · 147 lines · 111 code · 11 blank · 25 comment · 21 complexity · 51b2d916908d0d092efd54afe0afd5b1 MD5 · raw file

  1. /* Complex cosine hyperbole function for float.
  2. Copyright (C) 1997-2016 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 <float.h>
  21. __complex__ float
  22. __ccoshf (__complex__ float x)
  23. {
  24. __complex__ float retval;
  25. int rcls = fpclassify (__real__ x);
  26. int icls = fpclassify (__imag__ x);
  27. if (__glibc_likely (rcls >= FP_ZERO))
  28. {
  29. /* Real part is finite. */
  30. if (__glibc_likely (icls >= FP_ZERO))
  31. {
  32. /* Imaginary part is finite. */
  33. const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2);
  34. float sinix, cosix;
  35. if (__glibc_likely (fabsf (__imag__ x) > FLT_MIN))
  36. {
  37. __sincosf (__imag__ x, &sinix, &cosix);
  38. }
  39. else
  40. {
  41. sinix = __imag__ x;
  42. cosix = 1.0f;
  43. }
  44. if (fabsf (__real__ x) > t)
  45. {
  46. float exp_t = __ieee754_expf (t);
  47. float rx = fabsf (__real__ x);
  48. if (signbit (__real__ x))
  49. sinix = -sinix;
  50. rx -= t;
  51. sinix *= exp_t / 2.0f;
  52. cosix *= exp_t / 2.0f;
  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 = FLT_MAX * cosix;
  63. __imag__ retval = FLT_MAX * sinix;
  64. }
  65. else
  66. {
  67. float exp_val = __ieee754_expf (rx);
  68. __real__ retval = exp_val * cosix;
  69. __imag__ retval = exp_val * sinix;
  70. }
  71. }
  72. else
  73. {
  74. __real__ retval = __ieee754_coshf (__real__ x) * cosix;
  75. __imag__ retval = __ieee754_sinhf (__real__ x) * sinix;
  76. }
  77. math_check_force_underflow_complex (retval);
  78. }
  79. else
  80. {
  81. __imag__ retval = __real__ x == 0.0 ? 0.0 : __nanf ("");
  82. __real__ retval = __nanf ("");
  83. if (icls == FP_INFINITE)
  84. feraiseexcept (FE_INVALID);
  85. }
  86. }
  87. else if (__glibc_likely (rcls == FP_INFINITE))
  88. {
  89. /* Real part is infinite. */
  90. if (__glibc_likely (icls > FP_ZERO))
  91. {
  92. /* Imaginary part is finite. */
  93. float sinix, cosix;
  94. if (__glibc_likely (fabsf (__imag__ x) > FLT_MIN))
  95. {
  96. __sincosf (__imag__ x, &sinix, &cosix);
  97. }
  98. else
  99. {
  100. sinix = __imag__ x;
  101. cosix = 1.0f;
  102. }
  103. __real__ retval = __copysignf (HUGE_VALF, cosix);
  104. __imag__ retval = (__copysignf (HUGE_VALF, sinix)
  105. * __copysignf (1.0, __real__ x));
  106. }
  107. else if (icls == FP_ZERO)
  108. {
  109. /* Imaginary part is 0.0. */
  110. __real__ retval = HUGE_VALF;
  111. __imag__ retval = __imag__ x * __copysignf (1.0, __real__ x);
  112. }
  113. else
  114. {
  115. /* The addition raises the invalid exception. */
  116. __real__ retval = HUGE_VALF;
  117. __imag__ retval = __nanf ("") + __nanf ("");
  118. #ifdef FE_INVALID
  119. if (icls == FP_INFINITE)
  120. feraiseexcept (FE_INVALID);
  121. #endif
  122. }
  123. }
  124. else
  125. {
  126. __real__ retval = __nanf ("");
  127. __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nanf ("");
  128. }
  129. return retval;
  130. }
  131. #ifndef __ccoshf
  132. weak_alias (__ccoshf, ccoshf)
  133. #endif