s_cacosh_template.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Return arc hyperbolic cosine for a complex type.
  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 <math.h>
  18. CFLOAT
  19. M_DECL_FUNC (__cacosh) (CFLOAT x)
  20. {
  21. CFLOAT res;
  22. int rcls = fpclassify (__real__ x);
  23. int icls = fpclassify (__imag__ x);
  24. if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
  25. {
  26. if (icls == FP_INFINITE)
  27. {
  28. __real__ res = M_HUGE_VAL;
  29. if (rcls == FP_NAN)
  30. __imag__ res = M_NAN;
  31. else
  32. __imag__ res = M_COPYSIGN ((rcls == FP_INFINITE
  33. ? (__real__ x < 0
  34. ? M_MLIT (M_PI) - M_MLIT (M_PI_4)
  35. : M_MLIT (M_PI_4))
  36. : M_MLIT (M_PI_2)), __imag__ x);
  37. }
  38. else if (rcls == FP_INFINITE)
  39. {
  40. __real__ res = M_HUGE_VAL;
  41. if (icls >= FP_ZERO)
  42. __imag__ res = M_COPYSIGN (signbit (__real__ x)
  43. ? M_MLIT (M_PI) : 0, __imag__ x);
  44. else
  45. __imag__ res = M_NAN;
  46. }
  47. else
  48. {
  49. __real__ res = M_NAN;
  50. if (rcls == FP_ZERO)
  51. __imag__ res = M_MLIT (M_PI_2);
  52. else
  53. __imag__ res = M_NAN;
  54. }
  55. }
  56. else if (rcls == FP_ZERO && icls == FP_ZERO)
  57. {
  58. __real__ res = 0;
  59. __imag__ res = M_COPYSIGN (M_MLIT (M_PI_2), __imag__ x);
  60. }
  61. else
  62. {
  63. CFLOAT y;
  64. __real__ y = -__imag__ x;
  65. __imag__ y = __real__ x;
  66. y = M_SUF (__kernel_casinh) (y, 1);
  67. if (signbit (__imag__ x))
  68. {
  69. __real__ res = __real__ y;
  70. __imag__ res = -__imag__ y;
  71. }
  72. else
  73. {
  74. __real__ res = -__real__ y;
  75. __imag__ res = __imag__ y;
  76. }
  77. }
  78. return res;
  79. }
  80. declare_mgen_alias (__cacosh, cacosh)