1ba41c650SJérôme Duval /* Compute complex base 10 logarithm.
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 <math.h>
23ba41c650SJérôme Duval
24ba41c650SJérôme Duval #include "math_private.h"
25ba41c650SJérôme Duval
26ba41c650SJérôme Duval
27ba41c650SJérôme Duval __complex__ float
__clog10f(__complex__ float x)28ba41c650SJérôme Duval __clog10f (__complex__ float x)
29ba41c650SJérôme Duval {
30ba41c650SJérôme Duval __complex__ float result;
31ba41c650SJérôme Duval int rcls = fpclassify (__real__ x);
32ba41c650SJérôme Duval int icls = fpclassify (__imag__ x);
33ba41c650SJérôme Duval
34ba41c650SJérôme Duval if (rcls == FP_ZERO && icls == FP_ZERO)
35ba41c650SJérôme Duval {
36ba41c650SJérôme Duval /* Real and imaginary part are 0.0. */
37ba41c650SJérôme Duval __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
38*f504f610SAugustin Cavalier __imag__ result = copysignf (__imag__ result, __imag__ x);
39ba41c650SJérôme Duval /* Yes, the following line raises an exception. */
40ba41c650SJérôme Duval __real__ result = -1.0 / fabsf (__real__ x);
41ba41c650SJérôme Duval }
42ba41c650SJérôme Duval else if (rcls != FP_NAN && icls != FP_NAN)
43ba41c650SJérôme Duval {
44ba41c650SJérôme Duval /* Neither real nor imaginary part is NaN. */
45*f504f610SAugustin Cavalier __real__ result = log10f (hypotf (__real__ x,
46ba41c650SJérôme Duval __imag__ x));
47*f504f610SAugustin Cavalier __imag__ result = M_LOG10E * atan2f (__imag__ x, __real__ x);
48ba41c650SJérôme Duval }
49ba41c650SJérôme Duval else
50ba41c650SJérôme Duval {
51*f504f610SAugustin Cavalier __imag__ result = nanf ("");
52ba41c650SJérôme Duval if (rcls == FP_INFINITE || icls == FP_INFINITE)
53ba41c650SJérôme Duval /* Real or imaginary part is infinite. */
54ba41c650SJérôme Duval __real__ result = HUGE_VALF;
55ba41c650SJérôme Duval else
56*f504f610SAugustin Cavalier __real__ result = nanf ("");
57ba41c650SJérôme Duval }
58ba41c650SJérôme Duval
59ba41c650SJérôme Duval return result;
60ba41c650SJérôme Duval }
61ba41c650SJérôme Duval #ifndef __clog10f
62ba41c650SJérôme Duval weak_alias (__clog10f, clog10f)
63ba41c650SJérôme Duval #endif
64