15acbf1f5SJérôme Duval /* Return arc hyperbole cosine for float value.
25acbf1f5SJérôme Duval Copyright (C) 1997 Free Software Foundation, Inc.
35acbf1f5SJérôme Duval This file is part of the GNU C Library.
45acbf1f5SJérôme Duval Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
55acbf1f5SJérôme Duval
65acbf1f5SJérôme Duval The GNU C Library is free software; you can redistribute it and/or
75acbf1f5SJérôme Duval modify it under the terms of the GNU Lesser General Public
85acbf1f5SJérôme Duval License as published by the Free Software Foundation; either
95acbf1f5SJérôme Duval version 2.1 of the License, or (at your option) any later version.
105acbf1f5SJérôme Duval
115acbf1f5SJérôme Duval The GNU C Library is distributed in the hope that it will be useful,
125acbf1f5SJérôme Duval but WITHOUT ANY WARRANTY; without even the implied warranty of
135acbf1f5SJérôme Duval MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
145acbf1f5SJérôme Duval Lesser General Public License for more details.
155acbf1f5SJérôme Duval
165acbf1f5SJérôme Duval You should have received a copy of the GNU Lesser General Public
175acbf1f5SJérôme Duval License along with the GNU C Library; if not, write to the Free
185acbf1f5SJérôme Duval Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
195acbf1f5SJérôme Duval 02111-1307 USA. */
205acbf1f5SJérôme Duval
215acbf1f5SJérôme Duval #include <complex.h>
225acbf1f5SJérôme Duval #include <math.h>
235acbf1f5SJérôme Duval
245acbf1f5SJérôme Duval #include "math_private.h"
255acbf1f5SJérôme Duval
265acbf1f5SJérôme Duval __complex__ float
__cacoshf(__complex__ float x)275acbf1f5SJérôme Duval __cacoshf (__complex__ float x)
285acbf1f5SJérôme Duval {
295acbf1f5SJérôme Duval __complex__ float res;
305acbf1f5SJérôme Duval int rcls = fpclassify (__real__ x);
315acbf1f5SJérôme Duval int icls = fpclassify (__imag__ x);
325acbf1f5SJérôme Duval
335acbf1f5SJérôme Duval if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
345acbf1f5SJérôme Duval {
355acbf1f5SJérôme Duval if (icls == FP_INFINITE)
365acbf1f5SJérôme Duval {
375acbf1f5SJérôme Duval __real__ res = HUGE_VALF;
385acbf1f5SJérôme Duval
395acbf1f5SJérôme Duval if (rcls == FP_NAN)
40*f504f610SAugustin Cavalier __imag__ res = nanf ("");
415acbf1f5SJérôme Duval else
42*f504f610SAugustin Cavalier __imag__ res = copysignf ((rcls == FP_INFINITE
435acbf1f5SJérôme Duval ? (__real__ x < 0.0
445acbf1f5SJérôme Duval ? M_PI - M_PI_4 : M_PI_4)
455acbf1f5SJérôme Duval : M_PI_2), __imag__ x);
465acbf1f5SJérôme Duval }
475acbf1f5SJérôme Duval else if (rcls == FP_INFINITE)
485acbf1f5SJérôme Duval {
495acbf1f5SJérôme Duval __real__ res = HUGE_VALF;
505acbf1f5SJérôme Duval
515acbf1f5SJérôme Duval if (icls >= FP_ZERO)
52*f504f610SAugustin Cavalier __imag__ res = copysignf (signbit (__real__ x) ? M_PI : 0.0,
535acbf1f5SJérôme Duval __imag__ x);
545acbf1f5SJérôme Duval else
55*f504f610SAugustin Cavalier __imag__ res = nanf ("");
565acbf1f5SJérôme Duval }
575acbf1f5SJérôme Duval else
585acbf1f5SJérôme Duval {
59*f504f610SAugustin Cavalier __real__ res = nanf ("");
60*f504f610SAugustin Cavalier __imag__ res = nanf ("");
615acbf1f5SJérôme Duval }
625acbf1f5SJérôme Duval }
635acbf1f5SJérôme Duval else if (rcls == FP_ZERO && icls == FP_ZERO)
645acbf1f5SJérôme Duval {
655acbf1f5SJérôme Duval __real__ res = 0.0;
66*f504f610SAugustin Cavalier __imag__ res = copysignf (M_PI_2, __imag__ x);
675acbf1f5SJérôme Duval }
685acbf1f5SJérôme Duval else
695acbf1f5SJérôme Duval {
705acbf1f5SJérôme Duval #if 1
715acbf1f5SJérôme Duval __complex__ float y;
725acbf1f5SJérôme Duval
735acbf1f5SJérôme Duval __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) - 1.0;
745acbf1f5SJérôme Duval __imag__ y = 2.0 * __real__ x * __imag__ x;
755acbf1f5SJérôme Duval
765acbf1f5SJérôme Duval y = __csqrtf (y);
775acbf1f5SJérôme Duval
785acbf1f5SJérôme Duval __real__ y += __real__ x;
795acbf1f5SJérôme Duval __imag__ y += __imag__ x;
805acbf1f5SJérôme Duval
815acbf1f5SJérôme Duval res = __clogf (y);
825acbf1f5SJérôme Duval #else
835acbf1f5SJérôme Duval float re2 = __real__ x * __real__ x;
845acbf1f5SJérôme Duval float im2 = __imag__ x * __imag__ x;
855acbf1f5SJérôme Duval float sq = re2 - im2 - 1.0;
86*f504f610SAugustin Cavalier float ro = sqrtf (sq * sq + 4 * re2 * im2);
87*f504f610SAugustin Cavalier float a = sqrtf ((sq + ro) / 2.0);
88*f504f610SAugustin Cavalier float b = sqrtf ((-sq + ro) / 2.0);
895acbf1f5SJérôme Duval
90*f504f610SAugustin Cavalier __real__ res = 0.5 * logf (re2 + __real__ x * 2 * a
915acbf1f5SJérôme Duval + im2 + __imag__ x * 2 * b
925acbf1f5SJérôme Duval + ro);
93*f504f610SAugustin Cavalier __imag__ res = atan2f (__imag__ x + b, __real__ x + a);
945acbf1f5SJérôme Duval #endif
955acbf1f5SJérôme Duval }
965acbf1f5SJérôme Duval
975acbf1f5SJérôme Duval return res;
985acbf1f5SJérôme Duval }
995acbf1f5SJérôme Duval #ifndef __cacoshf
1005acbf1f5SJérôme Duval weak_alias (__cacoshf, cacoshf)
1015acbf1f5SJérôme Duval #endif
102