145
|
1 /* Return arc hyperbolic tangent for a complex float type.
|
|
2 Copyright (C) 1997-2018 Free Software Foundation, Inc.
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 This file is part of the GNU C Library.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 The GNU C Library is free software; you can redistribute it and/or
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 modify it under the terms of the GNU Lesser General Public
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 License as published by the Free Software Foundation; either
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 version 2.1 of the License, or (at your option) any later version.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 The GNU C Library is distributed in the hope that it will be useful,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 Lesser General Public License for more details.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 You should have received a copy of the GNU Lesser General Public
|
145
|
17 License along with the GNU C Library; if not, see
|
|
18 <http://www.gnu.org/licenses/>. */
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 #include "quadmath-imp.h"
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 __complex128
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 catanhq (__complex128 x)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 __complex128 res;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 int rcls = fpclassifyq (__real__ x);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 int icls = fpclassifyq (__imag__ x);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28
|
145
|
29 if (__glibc_unlikely (rcls <= QUADFP_INFINITE || icls <= QUADFP_INFINITE))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 if (icls == QUADFP_INFINITE)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 {
|
145
|
33 __real__ res = copysignq (0, __real__ x);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 __imag__ res = copysignq (M_PI_2q, __imag__ x);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 else if (rcls == QUADFP_INFINITE || rcls == QUADFP_ZERO)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 {
|
145
|
38 __real__ res = copysignq (0, __real__ x);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 if (icls >= QUADFP_ZERO)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 __imag__ res = copysignq (M_PI_2q, __imag__ x);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 __imag__ res = nanq ("");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 __real__ res = nanq ("");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 __imag__ res = nanq ("");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 }
|
145
|
50 else if (__glibc_unlikely (rcls == QUADFP_ZERO && icls == QUADFP_ZERO))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 res = x;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 {
|
145
|
56 if (fabsq (__real__ x) >= 16 / FLT128_EPSILON
|
|
57 || fabsq (__imag__ x) >= 16 / FLT128_EPSILON)
|
|
58 {
|
|
59 __imag__ res = copysignq (M_PI_2q, __imag__ x);
|
|
60 if (fabsq (__imag__ x) <= 1)
|
|
61 __real__ res = 1 / __real__ x;
|
|
62 else if (fabsq (__real__ x) <= 1)
|
|
63 __real__ res = __real__ x / __imag__ x / __imag__ x;
|
|
64 else
|
|
65 {
|
|
66 __float128 h = hypotq (__real__ x / 2, __imag__ x / 2);
|
|
67 __real__ res = __real__ x / h / h / 4;
|
|
68 }
|
|
69 }
|
|
70 else
|
|
71 {
|
|
72 if (fabsq (__real__ x) == 1
|
|
73 && fabsq (__imag__ x) < FLT128_EPSILON * FLT128_EPSILON)
|
|
74 __real__ res = (copysignq (0.5Q, __real__ x)
|
|
75 * ((__float128) M_LN2q
|
|
76 - logq (fabsq (__imag__ x))));
|
|
77 else
|
|
78 {
|
|
79 __float128 i2 = 0;
|
|
80 if (fabsq (__imag__ x) >= FLT128_EPSILON * FLT128_EPSILON)
|
|
81 i2 = __imag__ x * __imag__ x;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82
|
145
|
83 __float128 num = 1 + __real__ x;
|
|
84 num = i2 + num * num;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85
|
145
|
86 __float128 den = 1 - __real__ x;
|
|
87 den = i2 + den * den;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88
|
145
|
89 __float128 f = num / den;
|
|
90 if (f < 0.5Q)
|
|
91 __real__ res = 0.25Q * logq (f);
|
|
92 else
|
|
93 {
|
|
94 num = 4 * __real__ x;
|
|
95 __real__ res = 0.25Q * log1pq (num / den);
|
|
96 }
|
|
97 }
|
|
98
|
|
99 __float128 absx, absy, den;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100
|
145
|
101 absx = fabsq (__real__ x);
|
|
102 absy = fabsq (__imag__ x);
|
|
103 if (absx < absy)
|
|
104 {
|
|
105 __float128 t = absx;
|
|
106 absx = absy;
|
|
107 absy = t;
|
|
108 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109
|
145
|
110 if (absy < FLT128_EPSILON / 2)
|
|
111 {
|
|
112 den = (1 - absx) * (1 + absx);
|
|
113 if (den == 0)
|
|
114 den = 0;
|
|
115 }
|
|
116 else if (absx >= 1)
|
|
117 den = (1 - absx) * (1 + absx) - absy * absy;
|
|
118 else if (absx >= 0.75Q || absy >= 0.5Q)
|
|
119 den = -__quadmath_x2y2m1q (absx, absy);
|
|
120 else
|
|
121 den = (1 - absx) * (1 + absx) - absy * absy;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122
|
145
|
123 __imag__ res = 0.5Q * atan2q (2 * __imag__ x, den);
|
|
124 }
|
|
125
|
|
126 math_check_force_underflow_complex (res);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 return res;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 }
|