1 /* Return cosine of a complex type.
2    Copyright (C) 1997-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
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 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <complex.h>
20 #include <math.h>
21 
22 CFLOAT
M_DECL_FUNC(__cacos)23 M_DECL_FUNC (__cacos) (CFLOAT x)
24 {
25   CFLOAT y;
26   CFLOAT res;
27   int rcls = fpclassify (__real__ x);
28   int icls = fpclassify (__imag__ x);
29 
30   if (rcls <= FP_INFINITE || icls <= FP_INFINITE
31       || (rcls == FP_ZERO && icls == FP_ZERO))
32     {
33       y = M_SUF (__casin) (x);
34 
35       __real__ res = M_MLIT (M_PI_2) - __real__ y;
36       if (__real__ res == 0)
37 	__real__ res = 0;
38       __imag__ res = -__imag__ y;
39     }
40   else
41     {
42       __real__ y = -__imag__ x;
43       __imag__ y = __real__ x;
44 
45       y = M_SUF (__kernel_casinh) (y, 1);
46 
47       __real__ res = __imag__ y;
48       __imag__ res = __real__ y;
49     }
50 
51   return res;
52 }
53 
54 declare_mgen_alias (__cacos, cacos);
55