1 /* Compute complex base 10 logarithm for complex __float128.
2 Copyright (C) 1997-2012 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/>. */
20 #include "quadmath-imp.h"
24 #define M_LOG10_2q 0.3010299956639811952137388947244930267682Q
28 clog10q (__complex128 x
)
31 int rcls
= fpclassifyq (__real__ x
);
32 int icls
= fpclassifyq (__imag__ x
);
34 if (__builtin_expect (rcls
== QUADFP_ZERO
&& icls
== QUADFP_ZERO
, 0))
36 /* Real and imaginary part are 0.0. */
37 __imag__ result
= signbitq (__real__ x
) ? M_PIq
: 0.0Q
;
38 __imag__ result
= copysignq (__imag__ result
, __imag__ x
);
39 /* Yes, the following line raises an exception. */
40 __real__ result
= -1.0Q
/ fabsq (__real__ x
);
42 else if (__builtin_expect (rcls
!= QUADFP_NAN
&& icls
!= QUADFP_NAN
, 1))
44 /* Neither real nor imaginary part is NaN. */
45 __float128 absx
= fabsq (__real__ x
), absy
= fabsq (__imag__ x
);
55 if (absx
> FLT128_MAX
/ 2.0Q
)
58 absx
= scalbnq (absx
, scale
);
59 absy
= (absy
>= FLT128_MIN
* 2.0Q
? scalbnq (absy
, scale
) : 0.0Q
);
61 else if (absx
< FLT128_MIN
&& absy
< FLT128_MIN
)
63 scale
= FLT128_MANT_DIG
;
64 absx
= scalbnq (absx
, scale
);
65 absy
= scalbnq (absy
, scale
);
68 if (absx
== 1.0Q
&& scale
== 0)
70 __float128 absy2
= absy
* absy
;
71 if (absy2
<= FLT128_MIN
* 2.0Q
* M_LN10q
)
73 = (absy2
/ 2.0Q
- absy2
* absy2
/ 4.0Q
) * M_LOG10Eq
;
75 __real__ result
= log1pq (absy2
) * (M_LOG10Eq
/ 2.0Q
);
77 else if (absx
> 1.0Q
&& absx
< 2.0Q
&& absy
< 1.0Q
&& scale
== 0)
79 __float128 d2m1
= (absx
- 1.0Q
) * (absx
+ 1.0Q
);
80 if (absy
>= FLT128_EPSILON
)
82 __real__ result
= log1pq (d2m1
) * (M_LOG10Eq
/ 2.0Q
);
86 && absy
< FLT128_EPSILON
/ 2.0Q
89 __float128 d2m1
= (absx
- 1.0Q
) * (absx
+ 1.0Q
);
90 __real__ result
= log1pq (d2m1
) * (M_LOG10Eq
/ 2.0Q
);
92 else if (absx
< 1.0Q
&& (absx
>= 0.75Q
|| absy
>= 0.5Q
) && scale
== 0)
94 __float128 d2m1
= __quadmath_x2y2m1q (absx
, absy
);
95 __real__ result
= log1pq (d2m1
) * (M_LOG10Eq
/ 2.0Q
);
99 __float128 d
= hypotq (absx
, absy
);
100 __real__ result
= log10q (d
) - scale
* M_LOG10_2q
;
103 __imag__ result
= M_LOG10Eq
* atan2q (__imag__ x
, __real__ x
);
107 __imag__ result
= nanq ("");
108 if (rcls
== QUADFP_INFINITE
|| icls
== QUADFP_INFINITE
)
109 /* Real or imaginary part is infinite. */
110 __real__ result
= HUGE_VALQ
;
112 __real__ result
= nanq ("");