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