1 /* Compute complex base 10 logarithm.
2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
22 #include <math_private.h>
26 #define LOG10_2 M_LIT (0.3010299956639811952137388947244930267682)
29 #define PI_LOG10E M_LIT (1.364376353841841347485783625431355770210)
32 M_DECL_FUNC (__clog10
) (CFLOAT x
)
35 int rcls
= fpclassify (__real__ x
);
36 int icls
= fpclassify (__imag__ x
);
38 if (__glibc_unlikely (rcls
== FP_ZERO
&& icls
== FP_ZERO
))
40 /* Real and imaginary part are 0.0. */
41 __imag__ result
= signbit (__real__ x
) ? PI_LOG10E
: 0;
42 __imag__ result
= M_COPYSIGN (__imag__ result
, __imag__ x
);
43 /* Yes, the following line raises an exception. */
44 __real__ result
= -1 / M_FABS (__real__ x
);
46 else if (__glibc_likely (rcls
!= FP_NAN
&& icls
!= FP_NAN
))
48 /* Neither real nor imaginary part is NaN. */
49 FLOAT absx
= M_FABS (__real__ x
), absy
= M_FABS (__imag__ x
);
62 absx
= M_SCALBN (absx
, scale
);
63 absy
= (absy
>= M_MIN
* 2 ? M_SCALBN (absy
, scale
) : 0);
65 else if (absx
< M_MIN
&& absy
< M_MIN
)
68 absx
= M_SCALBN (absx
, scale
);
69 absy
= M_SCALBN (absy
, scale
);
72 if (absx
== 1 && scale
== 0)
74 __real__ result
= (M_LOG1P (absy
* absy
)
75 * ((FLOAT
) M_MLIT (M_LOG10E
) / 2));
76 math_check_force_underflow_nonneg (__real__ result
);
78 else if (absx
> 1 && absx
< 2 && absy
< 1 && scale
== 0)
80 FLOAT d2m1
= (absx
- 1) * (absx
+ 1);
81 if (absy
>= M_EPSILON
)
83 __real__ result
= M_LOG1P (d2m1
) * ((FLOAT
) M_MLIT (M_LOG10E
) / 2);
86 && absx
>= M_LIT (0.5)
87 && absy
< M_EPSILON
/ 2
90 FLOAT d2m1
= (absx
- 1) * (absx
+ 1);
91 __real__ result
= M_LOG1P (d2m1
) * ((FLOAT
) M_MLIT (M_LOG10E
) / 2);
94 && absx
>= M_LIT (0.5)
96 && absx
* absx
+ absy
* absy
>= M_LIT (0.5))
98 FLOAT d2m1
= M_SUF (__x2y2m1
) (absx
, absy
);
99 __real__ result
= M_LOG1P (d2m1
) * ((FLOAT
) M_MLIT (M_LOG10E
) / 2);
103 FLOAT d
= M_HYPOT (absx
, absy
);
104 __real__ result
= M_SUF (__ieee754_log10
) (d
) - scale
* LOG10_2
;
107 __imag__ result
= M_MLIT (M_LOG10E
) * M_ATAN2 (__imag__ x
, __real__ x
);
111 __imag__ result
= M_NAN
;
112 if (rcls
== FP_INFINITE
|| icls
== FP_INFINITE
)
113 /* Real or imaginary part is infinite. */
114 __real__ result
= M_HUGE_VAL
;
116 __real__ result
= M_NAN
;
122 declare_mgen_alias (__clog10
, clog10
)