xref: /netbsd-src/external/gpl3/gcc/dist/libquadmath/math/atanhq.c (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1*181254a7Smrg /* s_atanhl.c -- long double version of s_atan.c.
2*181254a7Smrg  * Conversion to long double by Ulrich Drepper,
3*181254a7Smrg  * Cygnus Support, drepper@cygnus.com.
4*181254a7Smrg  */
5*181254a7Smrg 
6*181254a7Smrg /*
7*181254a7Smrg  * ====================================================
8*181254a7Smrg  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9*181254a7Smrg  *
10*181254a7Smrg  * Developed at SunPro, a Sun Microsystems, Inc. business.
11*181254a7Smrg  * Permission to use, copy, modify, and distribute this
12*181254a7Smrg  * software is freely granted, provided that this notice
13*181254a7Smrg  * is preserved.
14*181254a7Smrg  * ====================================================
15*181254a7Smrg  */
16*181254a7Smrg 
17*181254a7Smrg /* atanhq(x)
18*181254a7Smrg  * Method :
19*181254a7Smrg  *    1.Reduced x to positive by atanh(-x) = -atanh(x)
20*181254a7Smrg  *    2.For x>=0.5
21*181254a7Smrg  *                   1              2x                          x
22*181254a7Smrg  *	atanhl(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
23*181254a7Smrg  *                   2             1 - x                      1 - x
24*181254a7Smrg  *
25*181254a7Smrg  *	For x<0.5
26*181254a7Smrg  *	atanhl(x) = 0.5*log1pq(2x+2x*x/(1-x))
27*181254a7Smrg  *
28*181254a7Smrg  * Special cases:
29*181254a7Smrg  *	atanhl(x) is NaN if |x| > 1 with signal;
30*181254a7Smrg  *	atanhl(NaN) is that NaN with no signal;
31*181254a7Smrg  *	atanhl(+-1) is +-INF with signal.
32*181254a7Smrg  *
33*181254a7Smrg  */
34*181254a7Smrg 
35*181254a7Smrg #include "quadmath-imp.h"
36*181254a7Smrg 
37*181254a7Smrg static const __float128 one = 1, huge = 1e4900Q;
38*181254a7Smrg 
39*181254a7Smrg static const __float128 zero = 0;
40*181254a7Smrg 
41*181254a7Smrg __float128
atanhq(__float128 x)42*181254a7Smrg atanhq(__float128 x)
43*181254a7Smrg {
44*181254a7Smrg 	__float128 t;
45*181254a7Smrg 	uint32_t jx, ix;
46*181254a7Smrg 	ieee854_float128 u;
47*181254a7Smrg 
48*181254a7Smrg 	u.value = x;
49*181254a7Smrg 	jx = u.words32.w0;
50*181254a7Smrg 	ix = jx & 0x7fffffff;
51*181254a7Smrg 	u.words32.w0 = ix;
52*181254a7Smrg 	if (ix >= 0x3fff0000) /* |x| >= 1.0 or infinity or NaN */
53*181254a7Smrg 	  {
54*181254a7Smrg 	    if (u.value == one)
55*181254a7Smrg 	      return x/zero;
56*181254a7Smrg 	    else
57*181254a7Smrg 	      return (x-x)/(x-x);
58*181254a7Smrg 	  }
59*181254a7Smrg 	if(ix<0x3fc60000 && (huge+x)>zero)	/* x < 2^-57 */
60*181254a7Smrg 	  {
61*181254a7Smrg 	    math_check_force_underflow (x);
62*181254a7Smrg 	    return x;
63*181254a7Smrg 	  }
64*181254a7Smrg 
65*181254a7Smrg 	if(ix<0x3ffe0000) {		/* x < 0.5 */
66*181254a7Smrg 	    t = u.value+u.value;
67*181254a7Smrg 	    t = 0.5*log1pq(t+t*u.value/(one-u.value));
68*181254a7Smrg 	} else
69*181254a7Smrg 	    t = 0.5*log1pq((u.value+u.value)/(one-u.value));
70*181254a7Smrg 	if(jx & 0x80000000) return -t; else return t;
71*181254a7Smrg }
72