134124Sbostic /* 224588Szliu * Copyright (c) 1985 Regents of the University of California. 334124Sbostic * All rights reserved. 434124Sbostic * 5*42655Sbostic * %sccs.include.redist.c% 634124Sbostic * 734124Sbostic * All recipients should regard themselves as participants in an ongoing 834124Sbostic * research project and hence should feel obligated to report their 934124Sbostic * experiences (good or bad) with these elementary function codes, using 1034124Sbostic * the sendbug(8) program, to the authors. 1124588Szliu */ 1224588Szliu 1324588Szliu #ifndef lint 14*42655Sbostic static char sccsid[] = "@(#)asinh.c 5.5 (Berkeley) 06/01/90"; 1534124Sbostic #endif /* not lint */ 1624588Szliu 1724588Szliu /* ASINH(X) 1824588Szliu * RETURN THE INVERSE HYPERBOLIC SINE OF X 1924588Szliu * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 2024588Szliu * CODED IN C BY K.C. NG, 2/16/85; 2124588Szliu * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85. 2224588Szliu * 2324588Szliu * Required system supported functions : 2424588Szliu * copysign(x,y) 2524588Szliu * sqrt(x) 2624588Szliu * 2724588Szliu * Required kernel function: 2824588Szliu * log1p(x) ...return log(1+x) 2924588Szliu * 3024588Szliu * Method : 3124588Szliu * Based on 3224588Szliu * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 3324588Szliu * we have 3424588Szliu * asinh(x) := x if 1+x*x=1, 3524588Szliu * := sign(x)*(log1p(x)+ln2)) if sqrt(1+x*x)=x, else 3624588Szliu * := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) ) 3724588Szliu * 3824588Szliu * Accuracy: 3924588Szliu * asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded. 4024588Szliu * In a test run with 52,000 random arguments on a VAX, the maximum 4124588Szliu * observed error was 1.58 ulps (units in the last place). 4224588Szliu * 4324588Szliu * Constants: 4424588Szliu * The hexadecimal values are the intended ones for the following constants. 4524588Szliu * The decimal values may be used, provided that the compiler will convert 4624588Szliu * from decimal to binary accurately enough to produce the hexadecimal values 4724588Szliu * shown. 4824588Szliu */ 4935679Sbostic #include "mathimpl.h" 5024588Szliu 5135679Sbostic vc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000) 5235679Sbostic vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC) 5324588Szliu 5435679Sbostic ic(ln2hi, 6.9314718036912381649E-1, -1, 1.62E42FEE00000) 5535679Sbostic ic(ln2lo, 1.9082149292705877000E-10, -33, 1.A39EF35793C76) 5635679Sbostic 5735679Sbostic #ifdef vccast 5835679Sbostic #define ln2hi vccast(ln2hi) 5935679Sbostic #define ln2lo vccast(ln2lo) 6035679Sbostic #endif 6135679Sbostic 6224588Szliu double asinh(x) 6324588Szliu double x; 6424588Szliu { 6535679Sbostic double t,s; 6635679Sbostic const static double small=1.0E-10, /* fl(1+small*small) == 1 */ 6735679Sbostic big =1.0E20, /* fl(1+big) == big */ 6835679Sbostic one =1.0 ; 6924588Szliu 7031853Szliu #if !defined(vax)&&!defined(tahoe) 7124588Szliu if(x!=x) return(x); /* x is NaN */ 7231853Szliu #endif /* !defined(vax)&&!defined(tahoe) */ 7324588Szliu if((t=copysign(x,one))>small) 7424588Szliu if(t<big) { 7524588Szliu s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); } 7624588Szliu else /* if |x| > big */ 7724588Szliu {s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));} 7824588Szliu else /* if |x| < small */ 7924588Szliu return(x); 8024588Szliu } 81