]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/s_catanhl.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / math / s_catanhl.c
CommitLineData
63551311 1/* Return arc hyperbole tangent for long double value.
b168057a 2 Copyright (C) 1997-2015 Free Software Foundation, Inc.
63551311
UD
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
63551311
UD
10
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
41bdb6e2 14 Lesser General Public License for more details.
63551311 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
63551311
UD
19
20#include <complex.h>
21#include <math.h>
9277c064 22#include <math_private.h>
9457fd95 23#include <float.h>
63551311 24
5b4217d7
JM
25/* To avoid spurious overflows, 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
31
63551311
UD
32__complex__ long double
33__catanhl (__complex__ long double x)
34{
35 __complex__ long double res;
36 int rcls = fpclassify (__real__ x);
37 int icls = fpclassify (__imag__ x);
38
a1ffb40e 39 if (__glibc_unlikely (rcls <= FP_INFINITE || icls <= FP_INFINITE))
63551311
UD
40 {
41 if (icls == FP_INFINITE)
42 {
43 __real__ res = __copysignl (0.0, __real__ x);
0a614877 44 __imag__ res = __copysignl (M_PI_2l, __imag__ x);
63551311
UD
45 }
46 else if (rcls == FP_INFINITE || rcls == FP_ZERO)
47 {
48 __real__ res = __copysignl (0.0, __real__ x);
49 if (icls >= FP_ZERO)
0a614877 50 __imag__ res = __copysignl (M_PI_2l, __imag__ x);
63551311
UD
51 else
52 __imag__ res = __nanl ("");
53 }
54 else
55 {
56 __real__ res = __nanl ("");
57 __imag__ res = __nanl ("");
58 }
59 }
a1ffb40e 60 else if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO))
63551311
UD
61 {
62 res = x;
63 }
64 else
65 {
5b4217d7
JM
66 if (fabsl (__real__ x) >= 16.0L / LDBL_EPSILON
67 || fabsl (__imag__ x) >= 16.0L / LDBL_EPSILON)
68 {
69 __imag__ res = __copysignl (M_PI_2l, __imag__ x);
70 if (fabsl (__imag__ x) <= 1.0L)
71 __real__ res = 1.0L / __real__ x;
72 else if (fabsl (__real__ x) <= 1.0L)
73 __real__ res = __real__ x / __imag__ x / __imag__ x;
74 else
75 {
76 long double h = __ieee754_hypotl (__real__ x / 2.0L,
77 __imag__ x / 2.0L);
78 __real__ res = __real__ x / h / h / 4.0L;
79 }
80 }
81 else
82 {
10de07f5
JM
83 if (fabsl (__real__ x) == 1.0L
84 && fabsl (__imag__ x) < LDBL_EPSILON * LDBL_EPSILON)
85 __real__ res = (__copysignl (0.5L, __real__ x)
86 * (M_LN2l - __ieee754_logl (fabsl (__imag__ x))));
5b4217d7
JM
87 else
88 {
10de07f5
JM
89 long double i2 = 0.0;
90 if (fabsl (__imag__ x) >= LDBL_EPSILON * LDBL_EPSILON)
91 i2 = __imag__ x * __imag__ x;
92
93 long double num = 1.0L + __real__ x;
94 num = i2 + num * num;
95
96 long double den = 1.0L - __real__ x;
97 den = i2 + den * den;
98
99 long double f = num / den;
100 if (f < 0.5L)
101 __real__ res = 0.25L * __ieee754_logl (f);
102 else
103 {
104 num = 4.0L * __real__ x;
105 __real__ res = 0.25L * __log1pl (num / den);
106 }
5b4217d7 107 }
63551311 108
10de07f5 109 long double absx, absy, den;
caf84319
JM
110
111 absx = fabsl (__real__ x);
112 absy = fabsl (__imag__ x);
113 if (absx < absy)
114 {
115 long double t = absx;
116 absx = absy;
117 absy = t;
118 }
119
10de07f5 120 if (absy < LDBL_EPSILON / 2.0L)
a84e78c8
JM
121 {
122 den = (1.0L - absx) * (1.0L + absx);
123 if (den == -0.0L)
124 den = 0.0L;
125 }
10de07f5
JM
126 else if (absx >= 1.0L)
127 den = (1.0L - absx) * (1.0L + absx) - absy * absy;
caf84319
JM
128 else if (absx >= 0.75L || absy >= 0.5L)
129 den = -__x2y2m1l (absx, absy);
130 else
131 den = (1.0L - absx) * (1.0L + absx) - absy * absy;
63551311 132
5b4217d7
JM
133 __imag__ res = 0.5L * __ieee754_atan2l (2.0L * __imag__ x, den);
134 }
9457fd95
JM
135
136 if (fabsl (__real__ res) < LDBL_MIN)
137 {
138 volatile long double force_underflow = __real__ res * __real__ res;
139 (void) force_underflow;
140 }
141 if (fabsl (__imag__ res) < LDBL_MIN)
142 {
143 volatile long double force_underflow = __imag__ res * __imag__ res;
144 (void) force_underflow;
145 }
63551311
UD
146 }
147
148 return res;
149}
150weak_alias (__catanhl, catanhl)