1 /*
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)atanh.c 8.1 (Berkeley) 06/04/93";
10 #endif /* not lint */
11
12 /* ATANH(X)
13 * RETURN THE HYPERBOLIC ARC TANGENT OF X
14 * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
15 * CODED IN C BY K.C. NG, 1/8/85;
16 * REVISED BY K.C. NG on 2/7/85, 3/7/85, 8/18/85.
17 *
18 * Required kernel function:
19 * log1p(x) ...return log(1+x)
20 *
21 * Method :
22 * Return
23 * 1 2x x
24 * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
25 * 2 1 - x 1 - x
26 *
27 * Special cases:
28 * atanh(x) is NaN if |x| > 1 with signal;
29 * atanh(NaN) is that NaN with no signal;
30 * atanh(+-1) is +-INF with signal.
31 *
32 * Accuracy:
33 * atanh(x) returns the exact hyperbolic arc tangent of x nearly rounded.
34 * In a test run with 512,000 random arguments on a VAX, the maximum
35 * observed error was 1.87 ulps (units in the last place) at
36 * x= -3.8962076028810414000e-03.
37 */
38 #include "mathimpl.h"
39
40 #if defined(vax)||defined(tahoe)
41 #include <errno.h>
42 #endif /* defined(vax)||defined(tahoe) */
43
atanh(x)44 double atanh(x)
45 double x;
46 {
47 double z;
48 z = copysign(0.5,x);
49 x = copysign(x,1.0);
50 #if defined(vax)||defined(tahoe)
51 if (x == 1.0) {
52 return(copysign(1.0,z)*infnan(ERANGE)); /* sign(x)*INF */
53 }
54 #endif /* defined(vax)||defined(tahoe) */
55 x = x/(1.0-x);
56 return( z*log1p(x+x) );
57 }
58