13f708241SDavid Schultz
23a8617a8SJordan K. Hubbard /*
33a8617a8SJordan K. Hubbard * ====================================================
43a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
53a8617a8SJordan K. Hubbard *
63f708241SDavid Schultz * Developed at SunSoft, a Sun Microsystems, Inc. business.
73a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this
83a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice
93a8617a8SJordan K. Hubbard * is preserved.
103a8617a8SJordan K. Hubbard * ====================================================
113f708241SDavid Schultz *
123a8617a8SJordan K. Hubbard */
133a8617a8SJordan K. Hubbard
14*99843eb8SSteve Kargl /* atanh(x)
153a8617a8SJordan K. Hubbard * Method :
163a8617a8SJordan K. Hubbard * 1.Reduced x to positive by atanh(-x) = -atanh(x)
173a8617a8SJordan K. Hubbard * 2.For x>=0.5
183a8617a8SJordan K. Hubbard * 1 2x x
193a8617a8SJordan K. Hubbard * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
203a8617a8SJordan K. Hubbard * 2 1 - x 1 - x
213a8617a8SJordan K. Hubbard *
223a8617a8SJordan K. Hubbard * For x<0.5
233a8617a8SJordan K. Hubbard * atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
243a8617a8SJordan K. Hubbard *
253a8617a8SJordan K. Hubbard * Special cases:
263a8617a8SJordan K. Hubbard * atanh(x) is NaN if |x| > 1 with signal;
273a8617a8SJordan K. Hubbard * atanh(NaN) is that NaN with no signal;
283a8617a8SJordan K. Hubbard * atanh(+-1) is +-INF with signal.
293a8617a8SJordan K. Hubbard *
303a8617a8SJordan K. Hubbard */
313a8617a8SJordan K. Hubbard
32998b640bSDavid Schultz #include <float.h>
33998b640bSDavid Schultz
343a8617a8SJordan K. Hubbard #include "math.h"
353a8617a8SJordan K. Hubbard #include "math_private.h"
363a8617a8SJordan K. Hubbard
373a8617a8SJordan K. Hubbard static const double one = 1.0, huge = 1e300;
383a8617a8SJordan K. Hubbard static const double zero = 0.0;
393a8617a8SJordan K. Hubbard
40a82bbc73SAlfred Perlstein double
atanh(double x)41*99843eb8SSteve Kargl atanh(double x)
423a8617a8SJordan K. Hubbard {
433a8617a8SJordan K. Hubbard double t;
443a8617a8SJordan K. Hubbard int32_t hx,ix;
453a8617a8SJordan K. Hubbard u_int32_t lx;
463a8617a8SJordan K. Hubbard EXTRACT_WORDS(hx,lx,x);
473a8617a8SJordan K. Hubbard ix = hx&0x7fffffff;
483a8617a8SJordan K. Hubbard if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
493a8617a8SJordan K. Hubbard return (x-x)/(x-x);
503a8617a8SJordan K. Hubbard if(ix==0x3ff00000)
513a8617a8SJordan K. Hubbard return x/zero;
523a8617a8SJordan K. Hubbard if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */
533a8617a8SJordan K. Hubbard SET_HIGH_WORD(x,ix);
543a8617a8SJordan K. Hubbard if(ix<0x3fe00000) { /* x < 0.5 */
553a8617a8SJordan K. Hubbard t = x+x;
563a8617a8SJordan K. Hubbard t = 0.5*log1p(t+t*x/(one-x));
573a8617a8SJordan K. Hubbard } else
583a8617a8SJordan K. Hubbard t = 0.5*log1p((x+x)/(one-x));
593a8617a8SJordan K. Hubbard if(hx>=0) return t; else return -t;
603a8617a8SJordan K. Hubbard }
61998b640bSDavid Schultz
62998b640bSDavid Schultz #if LDBL_MANT_DIG == 53
63998b640bSDavid Schultz __weak_reference(atanh, atanhl);
64998b640bSDavid Schultz #endif
65