xref: /haiku/src/system/libroot/posix/glibc/arch/generic/s_ccoshf.c (revision f504f61099b010fbfa94b1cc63d2e9072c7f7185)
1ba41c650SJérôme Duval /* Complex cosine hyperbole function for float.
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__ float
__ccoshf(__complex__ float x)29ba41c650SJérôme Duval __ccoshf (__complex__ float x)
30ba41c650SJérôme Duval {
31ba41c650SJérôme Duval   __complex__ float retval;
32ba41c650SJérôme Duval   int rcls = fpclassify (__real__ x);
33ba41c650SJérôme Duval   int icls = fpclassify (__imag__ x);
34ba41c650SJérôme Duval 
35ba41c650SJérôme Duval   if (rcls >= FP_ZERO)
36ba41c650SJérôme Duval     {
37ba41c650SJérôme Duval       /* Real part is finite.  */
38ba41c650SJérôme Duval       if (icls >= FP_ZERO)
39ba41c650SJérôme Duval 	{
40ba41c650SJérôme Duval 	  /* Imaginary part is finite.  */
41*f504f610SAugustin Cavalier 	  float sinh_val = sinhf (__real__ x);
42*f504f610SAugustin Cavalier 	  float cosh_val = coshf (__real__ x);
43ba41c650SJérôme Duval 	  float sinix, cosix;
44ba41c650SJérôme Duval 
45*f504f610SAugustin Cavalier 	  sincosf (__imag__ x, &sinix, &cosix);
46ba41c650SJérôme Duval 
47ba41c650SJérôme Duval 	  __real__ retval = cosh_val * cosix;
48ba41c650SJérôme Duval 	  __imag__ retval = sinh_val * sinix;
49ba41c650SJérôme Duval 	}
50ba41c650SJérôme Duval       else
51ba41c650SJérôme Duval 	{
52*f504f610SAugustin Cavalier 	  __imag__ retval = __real__ x == 0.0 ? 0.0 : nanf ("");
53*f504f610SAugustin Cavalier 	  __real__ retval = nanf ("");
54ba41c650SJérôme Duval 
55ba41c650SJérôme Duval #ifdef FE_INVALID
56ba41c650SJérôme Duval 	  if (icls == FP_INFINITE)
57ba41c650SJérôme Duval 	    feraiseexcept (FE_INVALID);
58ba41c650SJérôme Duval #endif
59ba41c650SJérôme Duval 	}
60ba41c650SJérôme Duval     }
61ba41c650SJérôme Duval   else if (rcls == FP_INFINITE)
62ba41c650SJérôme Duval     {
63ba41c650SJérôme Duval       /* Real part is infinite.  */
64ba41c650SJérôme Duval       if (icls == FP_ZERO)
65ba41c650SJérôme Duval 	{
66ba41c650SJérôme Duval 	  /* Imaginary part is 0.0.  */
67ba41c650SJérôme Duval 	  __real__ retval = HUGE_VALF;
68*f504f610SAugustin Cavalier 	  __imag__ retval = __imag__ x * copysignf (1.0, __real__ x);
69ba41c650SJérôme Duval 	}
70ba41c650SJérôme Duval       else if (icls > FP_ZERO)
71ba41c650SJérôme Duval 	{
72ba41c650SJérôme Duval 	  /* Imaginary part is finite.  */
73ba41c650SJérôme Duval 	  float sinix, cosix;
74ba41c650SJérôme Duval 
75*f504f610SAugustin Cavalier 	  sincosf (__imag__ x, &sinix, &cosix);
76ba41c650SJérôme Duval 
77*f504f610SAugustin Cavalier 	  __real__ retval = copysignf (HUGE_VALF, cosix);
78*f504f610SAugustin Cavalier 	  __imag__ retval = (copysignf (HUGE_VALF, sinix)
79*f504f610SAugustin Cavalier 			     * copysignf (1.0, __real__ x));
80ba41c650SJérôme Duval 	}
81ba41c650SJérôme Duval       else
82ba41c650SJérôme Duval 	{
83ba41c650SJérôme Duval 	  /* The addition raises the invalid exception.  */
84ba41c650SJérôme Duval 	  __real__ retval = HUGE_VALF;
85*f504f610SAugustin Cavalier 	  __imag__ retval = nanf ("") + nanf ("");
86ba41c650SJérôme Duval 
87ba41c650SJérôme Duval #ifdef FE_INVALID
88ba41c650SJérôme Duval 	  if (icls == FP_INFINITE)
89ba41c650SJérôme Duval 	    feraiseexcept (FE_INVALID);
90ba41c650SJérôme Duval #endif
91ba41c650SJérôme Duval 	}
92ba41c650SJérôme Duval     }
93ba41c650SJérôme Duval   else
94ba41c650SJérôme Duval     {
95*f504f610SAugustin Cavalier       __real__ retval = nanf ("");
96*f504f610SAugustin Cavalier       __imag__ retval = __imag__ x == 0.0 ? __imag__ x : nanf ("");
97ba41c650SJérôme Duval     }
98ba41c650SJérôme Duval 
99ba41c650SJérôme Duval   return retval;
100ba41c650SJérôme Duval }
101ba41c650SJérôme Duval #ifndef __ccoshf
102ba41c650SJérôme Duval weak_alias (__ccoshf, ccoshf)
103ba41c650SJérôme Duval #endif
104