e_atanh.c revision 97407
121308Sache/* @(#)e_atanh.c 5.1 93/09/24 */
221308Sache/*
321308Sache * ====================================================
421308Sache * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
521308Sache *
621308Sache * Developed at SunPro, a Sun Microsystems, Inc. business.
721308Sache * Permission to use, copy, modify, and distribute this
821308Sache * software is freely granted, provided that this notice
958310Sache * is preserved.
1021308Sache * ====================================================
1121308Sache */
1221308Sache
1321308Sache#ifndef lint
1421308Sachestatic char rcsid[] = "$FreeBSD: head/lib/msun/src/e_atanh.c 97407 2002-05-28 17:03:12Z alfred $";
1521308Sache#endif
1621308Sache
1721308Sache/* __ieee754_atanh(x)
1821308Sache * Method :
1921308Sache *    1.Reduced x to positive by atanh(-x) = -atanh(x)
2058310Sache *    2.For x>=0.5
2121308Sache *                  1              2x                          x
2221308Sache *	atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
2321308Sache *                  2             1 - x                      1 - x
2421308Sache *
25119610Sache * 	For x<0.5
26119610Sache *	atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
27119610Sache *
28119610Sache * Special cases:
29119610Sache *	atanh(x) is NaN if |x| > 1 with signal;
30119610Sache *	atanh(NaN) is that NaN with no signal;
3158310Sache *	atanh(+-1) is +-INF with signal.
3221308Sache *
3358310Sache */
3458310Sache
3558310Sache#include "math.h"
3621308Sache#include "math_private.h"
3721308Sache
3821308Sachestatic const double one = 1.0, huge = 1e300;
3921308Sachestatic const double zero = 0.0;
4021308Sache
4121308Sachedouble
4221308Sache__ieee754_atanh(double x)
4321308Sache{
4421308Sache	double t;
4521308Sache	int32_t hx,ix;
4621308Sache	u_int32_t lx;
4721308Sache	EXTRACT_WORDS(hx,lx,x);
4821308Sache	ix = hx&0x7fffffff;
4921308Sache	if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
5021308Sache	    return (x-x)/(x-x);
5121308Sache	if(ix==0x3ff00000)
5221308Sache	    return x/zero;
5321308Sache	if(ix<0x3e300000&&(huge+x)>zero) return x;	/* x<2**-28 */
5421308Sache	SET_HIGH_WORD(x,ix);
5521308Sache	if(ix<0x3fe00000) {		/* x < 0.5 */
5621308Sache	    t = x+x;
5721308Sache	    t = 0.5*log1p(t+t*x/(one-x));
5821308Sache	} else
5921308Sache	    t = 0.5*log1p((x+x)/(one-x));
6021308Sache	if(hx>=0) return t; else return -t;
6121308Sache}
6221308Sache