xref: /csrg-svn/old/libm/libm/atanh.c (revision 24337)
121026Smiriam /*
221026Smiriam  * Copyright (c) 1985 Regents of the University of California.
321026Smiriam  *
421026Smiriam  * Use and reproduction of this software are granted  in  accordance  with
521026Smiriam  * the terms and conditions specified in  the  Berkeley  Software  License
621026Smiriam  * Agreement (in particular, this entails acknowledgement of the programs'
721026Smiriam  * source, and inclusion of this notice) with the additional understanding
821026Smiriam  * that  all  recipients  should regard themselves as participants  in  an
921026Smiriam  * ongoing  research  project and hence should  feel  obligated  to report
1021026Smiriam  * their  experiences (good or bad) with these elementary function  codes,
1121026Smiriam  * using "sendbug 4bsd-bugs@BERKELEY", to the authors.
1221026Smiriam  */
1321026Smiriam 
1421026Smiriam #ifndef lint
15*24337Smiriam static char sccsid[] = "@(#)atanh.c	1.2 (Berkeley) 08/21/85";
1621026Smiriam #endif not lint
1721026Smiriam 
1821026Smiriam /* ATANH(X)
1921026Smiriam  * RETURN THE HYPERBOLIC ARC TANGENT OF X
2021026Smiriam  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
2121026Smiriam  * CODED IN C BY K.C. NG, 1/8/85;
22*24337Smiriam  * REVISED BY K.C. NG on 2/7/85, 3/7/85, 8/18/85.
2321026Smiriam  *
2421026Smiriam  * Required kernel function:
25*24337Smiriam  *	log1p(x) 	...return log(1+x)
2621026Smiriam  *
2721026Smiriam  * Method :
2821026Smiriam  *	Return
29*24337Smiriam  *                          1              2x                          x
30*24337Smiriam  *		atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
31*24337Smiriam  *                          2             1 - x                      1 - x
3221026Smiriam  *
3321026Smiriam  * Special cases:
34*24337Smiriam  *	atanh(x) is NaN if |x| > 1 with signal;
35*24337Smiriam  *	atanh(NaN) is that NaN with no signal;
3621026Smiriam  *	atanh(+-1) is +-INF with signal.
3721026Smiriam  *
3821026Smiriam  * Accuracy:
3921026Smiriam  *	atanh(x) returns the exact hyperbolic arc tangent of x nearly rounded.
40*24337Smiriam  *	In a test run with 512,000 random arguments on a VAX, the maximum
41*24337Smiriam  *	observed error was 1.87 ulps (units in the last place) at
42*24337Smiriam  *	x= -3.8962076028810414000e-03.
4321026Smiriam  */
44*24337Smiriam #ifdef VAX
45*24337Smiriam #include <errno.h>
46*24337Smiriam #endif
4721026Smiriam 
atanh(x)4821026Smiriam double atanh(x)
4921026Smiriam double x;
5021026Smiriam {
51*24337Smiriam 	double copysign(),log1p(),z;
52*24337Smiriam 	z = copysign(0.5,x);
53*24337Smiriam 	x = copysign(x,1.0);
54*24337Smiriam #ifdef VAX
55*24337Smiriam 	if (x == 1.0) {
56*24337Smiriam 	    extern double infnan();
57*24337Smiriam 	    return(copysign(1.0,z)*infnan(ERANGE));	/* sign(x)*INF */
58*24337Smiriam 	}
59*24337Smiriam #endif
60*24337Smiriam 	x = x/(1.0-x);
61*24337Smiriam 	return( z*log1p(x+x) );
6221026Smiriam }
63