Fix warnings in fwscanf / rewind tests.
[glibc.git] / math / s_clog10l.c
blobfd86ecb47d18fd089fb8a1a1793a7fa3efa92615
1 /* Compute complex base 10 logarithm.
2 Copyright (C) 1997-2014 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 <complex.h>
21 #include <math.h>
22 #include <math_private.h>
23 #include <float.h>
25 /* To avoid spurious underflows, use this definition to treat IBM long
26 double as approximating an IEEE-style format. */
27 #if LDBL_MANT_DIG == 106
28 # undef LDBL_EPSILON
29 # define LDBL_EPSILON 0x1p-106L
30 #endif
32 /* log_10 (2). */
33 #define M_LOG10_2l 0.3010299956639811952137388947244930267682L
35 /* pi * log10 (e). */
36 #define M_PI_LOG10El 1.364376353841841347485783625431355770210L
38 __complex__ long double
39 __clog10l (__complex__ long double x)
41 __complex__ long double result;
42 int rcls = fpclassify (__real__ x);
43 int icls = fpclassify (__imag__ x);
45 if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO))
47 /* Real and imaginary part are 0.0. */
48 __imag__ result = signbit (__real__ x) ? M_PI_LOG10El : 0.0;
49 __imag__ result = __copysignl (__imag__ result, __imag__ x);
50 /* Yes, the following line raises an exception. */
51 __real__ result = -1.0 / fabsl (__real__ x);
53 else if (__glibc_likely (rcls != FP_NAN && icls != FP_NAN))
55 /* Neither real nor imaginary part is NaN. */
56 long double absx = fabsl (__real__ x), absy = fabsl (__imag__ x);
57 int scale = 0;
59 if (absx < absy)
61 long double t = absx;
62 absx = absy;
63 absy = t;
66 if (absx > LDBL_MAX / 2.0L)
68 scale = -1;
69 absx = __scalbnl (absx, scale);
70 absy = (absy >= LDBL_MIN * 2.0L ? __scalbnl (absy, scale) : 0.0L);
72 else if (absx < LDBL_MIN && absy < LDBL_MIN)
74 scale = LDBL_MANT_DIG;
75 absx = __scalbnl (absx, scale);
76 absy = __scalbnl (absy, scale);
79 if (absx == 1.0L && scale == 0)
81 long double absy2 = absy * absy;
82 if (absy2 <= LDBL_MIN * 2.0L * M_LN10l)
84 long double force_underflow = absy2 * absy2;
85 __real__ result = absy2 * (M_LOG10El / 2.0);
86 math_force_eval (force_underflow);
88 else
89 __real__ result = __log1pl (absy2) * (M_LOG10El / 2.0L);
91 else if (absx > 1.0L && absx < 2.0L && absy < 1.0L && scale == 0)
93 long double d2m1 = (absx - 1.0L) * (absx + 1.0L);
94 if (absy >= LDBL_EPSILON)
95 d2m1 += absy * absy;
96 __real__ result = __log1pl (d2m1) * (M_LOG10El / 2.0L);
98 else if (absx < 1.0L
99 && absx >= 0.75L
100 && absy < LDBL_EPSILON / 2.0L
101 && scale == 0)
103 long double d2m1 = (absx - 1.0L) * (absx + 1.0L);
104 __real__ result = __log1pl (d2m1) * (M_LOG10El / 2.0L);
106 else if (absx < 1.0L && (absx >= 0.75L || absy >= 0.5L) && scale == 0)
108 long double d2m1 = __x2y2m1l (absx, absy);
109 __real__ result = __log1pl (d2m1) * (M_LOG10El / 2.0L);
111 else
113 long double d = __ieee754_hypotl (absx, absy);
114 __real__ result = __ieee754_log10l (d) - scale * M_LOG10_2l;
117 __imag__ result = M_LOG10El * __ieee754_atan2l (__imag__ x, __real__ x);
119 else
121 __imag__ result = __nanl ("");
122 if (rcls == FP_INFINITE || icls == FP_INFINITE)
123 /* Real or imaginary part is infinite. */
124 __real__ result = HUGE_VALL;
125 else
126 __real__ result = __nanl ("");
129 return result;
131 weak_alias (__clog10l, clog10l)