]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/s_catanhl.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / math / s_catanhl.c
CommitLineData
63551311 1/* Return arc hyperbole tangent for long double value.
d4697bc9 2 Copyright (C) 1997-2014 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
77425c63 39 if (__builtin_expect (rcls <= FP_INFINITE || icls <= FP_INFINITE, 0))
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 }
77425c63 60 else if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0))
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)
caf84319 121 den = (1.0L - absx) * (1.0L + absx);
10de07f5
JM
122 else if (absx >= 1.0L)
123 den = (1.0L - absx) * (1.0L + absx) - absy * absy;
caf84319
JM
124 else if (absx >= 0.75L || absy >= 0.5L)
125 den = -__x2y2m1l (absx, absy);
126 else
127 den = (1.0L - absx) * (1.0L + absx) - absy * absy;
63551311 128
5b4217d7
JM
129 __imag__ res = 0.5L * __ieee754_atan2l (2.0L * __imag__ x, den);
130 }
9457fd95
JM
131
132 if (fabsl (__real__ res) < LDBL_MIN)
133 {
134 volatile long double force_underflow = __real__ res * __real__ res;
135 (void) force_underflow;
136 }
137 if (fabsl (__imag__ res) < LDBL_MIN)
138 {
139 volatile long double force_underflow = __imag__ res * __imag__ res;
140 (void) force_underflow;
141 }
63551311
UD
142 }
143
144 return res;
145}
146weak_alias (__catanhl, catanhl)