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