comparison libquadmath/math/catanq.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 561a7518be6b
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Return arc tangent of complex __float128 value. 1 /* Return arc tangent of complex float type.
2 Copyright (C) 1997, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1997-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. 4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5 5
6 The GNU C Library is free software; you can redistribute it and/or 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 7 modify it under the terms of the GNU Lesser General Public
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU Lesser General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free 17 License along with the GNU C Library; if not, see
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 <http://www.gnu.org/licenses/>. */
19 02111-1307 USA. */
20 19
21 #include "quadmath-imp.h" 20 #include "quadmath-imp.h"
22
23 21
24 __complex128 22 __complex128
25 catanq (__complex128 x) 23 catanq (__complex128 x)
26 { 24 {
27 __complex128 res; 25 __complex128 res;
28 int rcls = fpclassifyq (__real__ x); 26 int rcls = fpclassifyq (__real__ x);
29 int icls = fpclassifyq (__imag__ x); 27 int icls = fpclassifyq (__imag__ x);
30 28
31 if (rcls <= QUADFP_INFINITE || icls <= QUADFP_INFINITE) 29 if (__glibc_unlikely (rcls <= QUADFP_INFINITE || icls <= QUADFP_INFINITE))
32 { 30 {
33 if (rcls == QUADFP_INFINITE) 31 if (rcls == QUADFP_INFINITE)
34 { 32 {
35 __real__ res = copysignq (M_PI_2q, __real__ x); 33 __real__ res = copysignq (M_PI_2q, __real__ x);
36 __imag__ res = copysignq (0.0, __imag__ x); 34 __imag__ res = copysignq (0, __imag__ x);
37 } 35 }
38 else if (icls == QUADFP_INFINITE) 36 else if (icls == QUADFP_INFINITE)
39 { 37 {
40 if (rcls >= QUADFP_ZERO) 38 if (rcls >= QUADFP_ZERO)
41 __real__ res = copysignq (M_PI_2q, __real__ x); 39 __real__ res = copysignq (M_PI_2q, __real__ x);
42 else 40 else
43 __real__ res = nanq (""); 41 __real__ res = nanq ("");
44 __imag__ res = copysignq (0.0, __imag__ x); 42 __imag__ res = copysignq (0, __imag__ x);
45 } 43 }
46 else if (icls == QUADFP_ZERO || icls == QUADFP_INFINITE) 44 else if (icls == QUADFP_ZERO || icls == QUADFP_INFINITE)
47 { 45 {
48 __real__ res = nanq (""); 46 __real__ res = nanq ("");
49 __imag__ res = copysignq (0.0, __imag__ x); 47 __imag__ res = copysignq (0, __imag__ x);
50 } 48 }
51 else 49 else
52 { 50 {
53 __real__ res = nanq (""); 51 __real__ res = nanq ("");
54 __imag__ res = nanq (""); 52 __imag__ res = nanq ("");
55 } 53 }
56 } 54 }
57 else if (rcls == QUADFP_ZERO && icls == QUADFP_ZERO) 55 else if (__glibc_unlikely (rcls == QUADFP_ZERO && icls == QUADFP_ZERO))
58 { 56 {
59 res = x; 57 res = x;
60 } 58 }
61 else 59 else
62 { 60 {
63 __float128 r2, num, den; 61 if (fabsq (__real__ x) >= 16 / FLT128_EPSILON
62 || fabsq (__imag__ x) >= 16 / FLT128_EPSILON)
63 {
64 __real__ res = copysignq (M_PI_2q, __real__ x);
65 if (fabsq (__real__ x) <= 1)
66 __imag__ res = 1 / __imag__ x;
67 else if (fabsq (__imag__ x) <= 1)
68 __imag__ res = __imag__ x / __real__ x / __real__ x;
69 else
70 {
71 __float128 h = hypotq (__real__ x / 2, __imag__ x / 2);
72 __imag__ res = __imag__ x / h / h / 4;
73 }
74 }
75 else
76 {
77 __float128 den, absx, absy;
64 78
65 r2 = __real__ x * __real__ x; 79 absx = fabsq (__real__ x);
80 absy = fabsq (__imag__ x);
81 if (absx < absy)
82 {
83 __float128 t = absx;
84 absx = absy;
85 absy = t;
86 }
66 87
67 den = 1 - r2 - __imag__ x * __imag__ x; 88 if (absy < FLT128_EPSILON / 2)
89 {
90 den = (1 - absx) * (1 + absx);
91 if (den == 0)
92 den = 0;
93 }
94 else if (absx >= 1)
95 den = (1 - absx) * (1 + absx) - absy * absy;
96 else if (absx >= 0.75Q || absy >= 0.5Q)
97 den = -__quadmath_x2y2m1q (absx, absy);
98 else
99 den = (1 - absx) * (1 + absx) - absy * absy;
68 100
69 __real__ res = 0.5 * atan2q (2.0 * __real__ x, den); 101 __real__ res = 0.5Q * atan2q (2 * __real__ x, den);
70 102
71 num = __imag__ x + 1.0; 103 if (fabsq (__imag__ x) == 1
72 num = r2 + num * num; 104 && fabsq (__real__ x) < FLT128_EPSILON * FLT128_EPSILON)
105 __imag__ res = (copysignq (0.5Q, __imag__ x)
106 * ((__float128) M_LN2q
107 - logq (fabsq (__real__ x))));
108 else
109 {
110 __float128 r2 = 0, num, f;
73 111
74 den = __imag__ x - 1.0; 112 if (fabsq (__real__ x) >= FLT128_EPSILON * FLT128_EPSILON)
75 den = r2 + den * den; 113 r2 = __real__ x * __real__ x;
76 114
77 __imag__ res = 0.25 * logq (num / den); 115 num = __imag__ x + 1;
116 num = r2 + num * num;
117
118 den = __imag__ x - 1;
119 den = r2 + den * den;
120
121 f = num / den;
122 if (f < 0.5Q)
123 __imag__ res = 0.25Q * logq (f);
124 else
125 {
126 num = 4 * __imag__ x;
127 __imag__ res = 0.25Q * log1pq (num / den);
128 }
129 }
130 }
131
132 math_check_force_underflow_complex (res);
78 } 133 }
79 134
80 return res; 135 return res;
81 } 136 }