xref: /netbsd-src/external/gpl3/gcc/dist/libquadmath/math/cacoshq.c (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1*181254a7Smrg /* Return arc hyperbolic cosine for a complex type.
2*181254a7Smrg    Copyright (C) 1997-2018 Free Software Foundation, Inc.
3*181254a7Smrg    This file is part of the GNU C Library.
4*181254a7Smrg    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5*181254a7Smrg 
6*181254a7Smrg    The GNU C Library is free software; you can redistribute it and/or
7*181254a7Smrg    modify it under the terms of the GNU Lesser General Public
8*181254a7Smrg    License as published by the Free Software Foundation; either
9*181254a7Smrg    version 2.1 of the License, or (at your option) any later version.
10*181254a7Smrg 
11*181254a7Smrg    The GNU C Library is distributed in the hope that it will be useful,
12*181254a7Smrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*181254a7Smrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*181254a7Smrg    Lesser General Public License for more details.
15*181254a7Smrg 
16*181254a7Smrg    You should have received a copy of the GNU Lesser General Public
17*181254a7Smrg    License along with the GNU C Library; if not, see
18*181254a7Smrg    <http://www.gnu.org/licenses/>.  */
19*181254a7Smrg 
20*181254a7Smrg #include "quadmath-imp.h"
21*181254a7Smrg 
22*181254a7Smrg __complex128
cacoshq(__complex128 x)23*181254a7Smrg cacoshq (__complex128 x)
24*181254a7Smrg {
25*181254a7Smrg   __complex128 res;
26*181254a7Smrg   int rcls = fpclassifyq (__real__ x);
27*181254a7Smrg   int icls = fpclassifyq (__imag__ x);
28*181254a7Smrg 
29*181254a7Smrg   if (rcls <= QUADFP_INFINITE || icls <= QUADFP_INFINITE)
30*181254a7Smrg     {
31*181254a7Smrg       if (icls == QUADFP_INFINITE)
32*181254a7Smrg 	{
33*181254a7Smrg 	  __real__ res = HUGE_VALQ;
34*181254a7Smrg 
35*181254a7Smrg 	  if (rcls == QUADFP_NAN)
36*181254a7Smrg 	    __imag__ res = nanq ("");
37*181254a7Smrg 	  else
38*181254a7Smrg 	    __imag__ res = copysignq ((rcls == QUADFP_INFINITE
39*181254a7Smrg 					? (__real__ x < 0
40*181254a7Smrg 					   ? M_PIq - M_PI_4q
41*181254a7Smrg 					   : M_PI_4q)
42*181254a7Smrg 					: M_PI_2q), __imag__ x);
43*181254a7Smrg 	}
44*181254a7Smrg       else if (rcls == QUADFP_INFINITE)
45*181254a7Smrg 	{
46*181254a7Smrg 	  __real__ res = HUGE_VALQ;
47*181254a7Smrg 
48*181254a7Smrg 	  if (icls >= QUADFP_ZERO)
49*181254a7Smrg 	    __imag__ res = copysignq (signbitq (__real__ x)
50*181254a7Smrg 				       ? M_PIq : 0, __imag__ x);
51*181254a7Smrg 	  else
52*181254a7Smrg 	    __imag__ res = nanq ("");
53*181254a7Smrg 	}
54*181254a7Smrg       else
55*181254a7Smrg 	{
56*181254a7Smrg 	  __real__ res = nanq ("");
57*181254a7Smrg 	  if (rcls == QUADFP_ZERO)
58*181254a7Smrg 	    __imag__ res = M_PI_2q;
59*181254a7Smrg 	  else
60*181254a7Smrg 	    __imag__ res = nanq ("");
61*181254a7Smrg 	}
62*181254a7Smrg     }
63*181254a7Smrg   else if (rcls == QUADFP_ZERO && icls == QUADFP_ZERO)
64*181254a7Smrg     {
65*181254a7Smrg       __real__ res = 0;
66*181254a7Smrg       __imag__ res = copysignq (M_PI_2q, __imag__ x);
67*181254a7Smrg     }
68*181254a7Smrg   else
69*181254a7Smrg     {
70*181254a7Smrg       __complex128 y;
71*181254a7Smrg 
72*181254a7Smrg       __real__ y = -__imag__ x;
73*181254a7Smrg       __imag__ y = __real__ x;
74*181254a7Smrg 
75*181254a7Smrg       y = __quadmath_kernel_casinhq (y, 1);
76*181254a7Smrg 
77*181254a7Smrg       if (signbitq (__imag__ x))
78*181254a7Smrg 	{
79*181254a7Smrg 	  __real__ res = __real__ y;
80*181254a7Smrg 	  __imag__ res = -__imag__ y;
81*181254a7Smrg 	}
82*181254a7Smrg       else
83*181254a7Smrg 	{
84*181254a7Smrg 	  __real__ res = -__real__ y;
85*181254a7Smrg 	  __imag__ res = __imag__ y;
86*181254a7Smrg 	}
87*181254a7Smrg     }
88*181254a7Smrg 
89*181254a7Smrg   return res;
90*181254a7Smrg }
91