1ba41c650SJérôme Duval /* Complex tangent function for double.
2ba41c650SJérôme Duval Copyright (C) 1997 Free Software Foundation, Inc.
3ba41c650SJérôme Duval This file is part of the GNU C Library.
4ba41c650SJérôme Duval Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5ba41c650SJérôme Duval
6ba41c650SJérôme Duval The GNU C Library is free software; you can redistribute it and/or
7ba41c650SJérôme Duval modify it under the terms of the GNU Lesser General Public
8ba41c650SJérôme Duval License as published by the Free Software Foundation; either
9ba41c650SJérôme Duval version 2.1 of the License, or (at your option) any later version.
10ba41c650SJérôme Duval
11ba41c650SJérôme Duval The GNU C Library is distributed in the hope that it will be useful,
12ba41c650SJérôme Duval but WITHOUT ANY WARRANTY; without even the implied warranty of
13ba41c650SJérôme Duval MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14ba41c650SJérôme Duval Lesser General Public License for more details.
15ba41c650SJérôme Duval
16ba41c650SJérôme Duval You should have received a copy of the GNU Lesser General Public
17ba41c650SJérôme Duval License along with the GNU C Library; if not, write to the Free
18ba41c650SJérôme Duval Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19ba41c650SJérôme Duval 02111-1307 USA. */
20ba41c650SJérôme Duval
21ba41c650SJérôme Duval #include <complex.h>
22ba41c650SJérôme Duval #include <fenv.h>
23ba41c650SJérôme Duval #include <math.h>
24ba41c650SJérôme Duval
25ba41c650SJérôme Duval #include "math_private.h"
26ba41c650SJérôme Duval
27ba41c650SJérôme Duval
28ba41c650SJérôme Duval __complex__ double
__ctan(__complex__ double x)29ba41c650SJérôme Duval __ctan (__complex__ double x)
30ba41c650SJérôme Duval {
31ba41c650SJérôme Duval __complex__ double res;
32ba41c650SJérôme Duval
33ba41c650SJérôme Duval if (!isfinite (__real__ x) || !isfinite (__imag__ x))
34ba41c650SJérôme Duval {
35ba41c650SJérôme Duval if (__isinf (__imag__ x))
36ba41c650SJérôme Duval {
37*f504f610SAugustin Cavalier __real__ res = copysign (0.0, __real__ x);
38*f504f610SAugustin Cavalier __imag__ res = copysign (1.0, __imag__ x);
39ba41c650SJérôme Duval }
40ba41c650SJérôme Duval else if (__real__ x == 0.0)
41ba41c650SJérôme Duval {
42ba41c650SJérôme Duval res = x;
43ba41c650SJérôme Duval }
44ba41c650SJérôme Duval else
45ba41c650SJérôme Duval {
46*f504f610SAugustin Cavalier __real__ res = nan ("");
47*f504f610SAugustin Cavalier __imag__ res = nan ("");
48ba41c650SJérôme Duval
49ba41c650SJérôme Duval #ifdef FE_INVALID
50ba41c650SJérôme Duval if (__isinf (__real__ x))
51ba41c650SJérôme Duval feraiseexcept (FE_INVALID);
52ba41c650SJérôme Duval #endif
53ba41c650SJérôme Duval }
54ba41c650SJérôme Duval }
55ba41c650SJérôme Duval else
56ba41c650SJérôme Duval {
57ba41c650SJérôme Duval double sin2rx, cos2rx;
58ba41c650SJérôme Duval double den;
59ba41c650SJérôme Duval
60*f504f610SAugustin Cavalier sincos (2.0 * __real__ x, &sin2rx, &cos2rx);
61ba41c650SJérôme Duval
62*f504f610SAugustin Cavalier den = cos2rx + cosh (2.0 * __imag__ x);
63ba41c650SJérôme Duval
64ba41c650SJérôme Duval __real__ res = sin2rx / den;
65*f504f610SAugustin Cavalier __imag__ res = sinh (2.0 * __imag__ x) / den;
66ba41c650SJérôme Duval }
67ba41c650SJérôme Duval
68ba41c650SJérôme Duval return res;
69ba41c650SJérôme Duval }
70ba41c650SJérôme Duval weak_alias (__ctan, ctan)
71ba41c650SJérôme Duval #ifdef NO_LONG_DOUBLE
72ba41c650SJérôme Duval strong_alias (__ctan, __ctanl)
73ba41c650SJérôme Duval weak_alias (__ctan, ctanl)
74ba41c650SJérôme Duval #endif
75