xref: /haiku/src/system/libroot/posix/glibc/arch/generic/s_ctanhl.c (revision f504f61099b010fbfa94b1cc63d2e9072c7f7185)
1ba41c650SJérôme Duval /* Complex hyperbole tangent for long 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__ long double
__ctanhl(__complex__ long double x)29ba41c650SJérôme Duval __ctanhl (__complex__ long double x)
30ba41c650SJérôme Duval {
31ba41c650SJérôme Duval   __complex__ long 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 (__isinfl (__real__ x))
36ba41c650SJérôme Duval 	{
37*f504f610SAugustin Cavalier 	  __real__ res = copysignl (1.0, __real__ x);
38*f504f610SAugustin Cavalier 	  __imag__ res = copysignl (0.0, __imag__ x);
39ba41c650SJérôme Duval 	}
40ba41c650SJérôme Duval       else if (__imag__ 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 = nanl ("");
47*f504f610SAugustin Cavalier 	  __imag__ res = nanl ("");
48ba41c650SJérôme Duval 
49ba41c650SJérôme Duval #ifdef FE_INVALID
50ba41c650SJérôme Duval 	  if (__isinfl (__imag__ 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       long double sin2ix, cos2ix;
58ba41c650SJérôme Duval       long double den;
59ba41c650SJérôme Duval 
60*f504f610SAugustin Cavalier       sincosl (2.0 * __imag__ x, &sin2ix, &cos2ix);
61ba41c650SJérôme Duval 
62*f504f610SAugustin Cavalier       den = (coshl (2.0 * __real__ x) + cos2ix);
63ba41c650SJérôme Duval 
64*f504f610SAugustin Cavalier       __real__ res = sinhl (2.0 * __real__ x) / den;
65ba41c650SJérôme Duval       __imag__ res = sin2ix / 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 (__ctanhl, ctanhl)
71