powerpc: Fix memchr for powerpc32.
[glibc.git] / math / s_catanhl.c
bloba0b760082e3275b147137687486cd81fbfed6a71
1 /* Return arc hyperbole tangent for long double value.
2 Copyright (C) 1997-2015 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 /* 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
32 __complex__ long double
33 __catanhl (__complex__ long double x)
35 __complex__ long double res;
36 int rcls = fpclassify (__real__ x);
37 int icls = fpclassify (__imag__ x);
39 if (__glibc_unlikely (rcls <= FP_INFINITE || icls <= FP_INFINITE))
41 if (icls == FP_INFINITE)
43 __real__ res = __copysignl (0.0, __real__ x);
44 __imag__ res = __copysignl (M_PI_2l, __imag__ x);
46 else if (rcls == FP_INFINITE || rcls == FP_ZERO)
48 __real__ res = __copysignl (0.0, __real__ x);
49 if (icls >= FP_ZERO)
50 __imag__ res = __copysignl (M_PI_2l, __imag__ x);
51 else
52 __imag__ res = __nanl ("");
54 else
56 __real__ res = __nanl ("");
57 __imag__ res = __nanl ("");
60 else if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO))
62 res = x;
64 else
66 if (fabsl (__real__ x) >= 16.0L / LDBL_EPSILON
67 || fabsl (__imag__ x) >= 16.0L / LDBL_EPSILON)
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
76 long double h = __ieee754_hypotl (__real__ x / 2.0L,
77 __imag__ x / 2.0L);
78 __real__ res = __real__ x / h / h / 4.0L;
81 else
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))));
87 else
89 long double i2 = 0.0;
90 if (fabsl (__imag__ x) >= LDBL_EPSILON * LDBL_EPSILON)
91 i2 = __imag__ x * __imag__ x;
93 long double num = 1.0L + __real__ x;
94 num = i2 + num * num;
96 long double den = 1.0L - __real__ x;
97 den = i2 + den * den;
99 long double f = num / den;
100 if (f < 0.5L)
101 __real__ res = 0.25L * __ieee754_logl (f);
102 else
104 num = 4.0L * __real__ x;
105 __real__ res = 0.25L * __log1pl (num / den);
109 long double absx, absy, den;
111 absx = fabsl (__real__ x);
112 absy = fabsl (__imag__ x);
113 if (absx < absy)
115 long double t = absx;
116 absx = absy;
117 absy = t;
120 if (absy < LDBL_EPSILON / 2.0L)
122 den = (1.0L - absx) * (1.0L + absx);
123 if (den == -0.0L)
124 den = 0.0L;
126 else if (absx >= 1.0L)
127 den = (1.0L - absx) * (1.0L + absx) - absy * absy;
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;
133 __imag__ res = 0.5L * __ieee754_atan2l (2.0L * __imag__ x, den);
136 if (fabsl (__real__ res) < LDBL_MIN)
138 volatile long double force_underflow = __real__ res * __real__ res;
139 (void) force_underflow;
141 if (fabsl (__imag__ res) < LDBL_MIN)
143 volatile long double force_underflow = __imag__ res * __imag__ res;
144 (void) force_underflow;
148 return res;
150 weak_alias (__catanhl, catanhl)