posix: Correctly enable/disable cancellation on Linux posix_spawn
[glibc.git] / math / s_clog10_template.c
blob82624e38be8abef45bc0c54ee963432519258900
1 /* Compute complex base 10 logarithm.
2 Copyright (C) 1997-2016 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 /* log_10 (2). */
26 #define LOG10_2 M_LIT (0.3010299956639811952137388947244930267682)
28 /* pi * log10 (e). */
29 #define PI_LOG10E M_LIT (1.364376353841841347485783625431355770210)
31 CFLOAT
32 M_DECL_FUNC (__clog10) (CFLOAT x)
34 CFLOAT result;
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);
50 int scale = 0;
52 if (absx < absy)
54 FLOAT t = absx;
55 absx = absy;
56 absy = t;
59 if (absx > M_MAX / 2)
61 scale = -1;
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)
67 scale = M_MANT_DIG;
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)
82 d2m1 += absy * absy;
83 __real__ result = M_LOG1P (d2m1) * ((FLOAT) M_MLIT (M_LOG10E) / 2);
85 else if (absx < 1
86 && absx >= M_LIT (0.5)
87 && absy < M_EPSILON / 2
88 && scale == 0)
90 FLOAT d2m1 = (absx - 1) * (absx + 1);
91 __real__ result = M_LOG1P (d2m1) * ((FLOAT) M_MLIT (M_LOG10E) / 2);
93 else if (absx < 1
94 && absx >= M_LIT (0.5)
95 && scale == 0
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);
101 else
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);
109 else
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;
115 else
116 __real__ result = M_NAN;
119 return result;
122 declare_mgen_alias (__clog10, clog10)
124 #if M_LIBM_NEED_COMPAT (clog10)
125 /* __clog10 is also a public symbol. */
126 declare_mgen_libm_compat (__clog10, __clog10)
127 declare_mgen_libm_compat (clog10, clog10)
128 #endif