134124Sbostic /* 224588Szliu * Copyright (c) 1985 Regents of the University of California. 334124Sbostic * All rights reserved. 434124Sbostic * 534124Sbostic * Redistribution and use in source and binary forms are permitted 634931Sbostic * provided that the above copyright notice and this paragraph are 734931Sbostic * duplicated in all such forms and that any documentation, 834931Sbostic * advertising materials, and other materials related to such 934931Sbostic * distribution and use acknowledge that the software was developed 1034931Sbostic * by the University of California, Berkeley. The name of the 1134931Sbostic * University may not be used to endorse or promote products derived 1234931Sbostic * from this software without specific prior written permission. 1334931Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434931Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534931Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634124Sbostic * 1734124Sbostic * All recipients should regard themselves as participants in an ongoing 1834124Sbostic * research project and hence should feel obligated to report their 1934124Sbostic * experiences (good or bad) with these elementary function codes, using 2034124Sbostic * the sendbug(8) program, to the authors. 2124588Szliu */ 2224588Szliu 2324588Szliu #ifndef lint 24*35679Sbostic static char sccsid[] = "@(#)asinh.c 5.4 (Berkeley) 09/22/88"; 2534124Sbostic #endif /* not lint */ 2624588Szliu 2724588Szliu /* ASINH(X) 2824588Szliu * RETURN THE INVERSE HYPERBOLIC SINE OF X 2924588Szliu * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 3024588Szliu * CODED IN C BY K.C. NG, 2/16/85; 3124588Szliu * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85. 3224588Szliu * 3324588Szliu * Required system supported functions : 3424588Szliu * copysign(x,y) 3524588Szliu * sqrt(x) 3624588Szliu * 3724588Szliu * Required kernel function: 3824588Szliu * log1p(x) ...return log(1+x) 3924588Szliu * 4024588Szliu * Method : 4124588Szliu * Based on 4224588Szliu * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 4324588Szliu * we have 4424588Szliu * asinh(x) := x if 1+x*x=1, 4524588Szliu * := sign(x)*(log1p(x)+ln2)) if sqrt(1+x*x)=x, else 4624588Szliu * := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) ) 4724588Szliu * 4824588Szliu * Accuracy: 4924588Szliu * asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded. 5024588Szliu * In a test run with 52,000 random arguments on a VAX, the maximum 5124588Szliu * observed error was 1.58 ulps (units in the last place). 5224588Szliu * 5324588Szliu * Constants: 5424588Szliu * The hexadecimal values are the intended ones for the following constants. 5524588Szliu * The decimal values may be used, provided that the compiler will convert 5624588Szliu * from decimal to binary accurately enough to produce the hexadecimal values 5724588Szliu * shown. 5824588Szliu */ 59*35679Sbostic #include "mathimpl.h" 6024588Szliu 61*35679Sbostic vc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000) 62*35679Sbostic vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC) 6324588Szliu 64*35679Sbostic ic(ln2hi, 6.9314718036912381649E-1, -1, 1.62E42FEE00000) 65*35679Sbostic ic(ln2lo, 1.9082149292705877000E-10, -33, 1.A39EF35793C76) 66*35679Sbostic 67*35679Sbostic #ifdef vccast 68*35679Sbostic #define ln2hi vccast(ln2hi) 69*35679Sbostic #define ln2lo vccast(ln2lo) 70*35679Sbostic #endif 71*35679Sbostic 7224588Szliu double asinh(x) 7324588Szliu double x; 7424588Szliu { 75*35679Sbostic double t,s; 76*35679Sbostic const static double small=1.0E-10, /* fl(1+small*small) == 1 */ 77*35679Sbostic big =1.0E20, /* fl(1+big) == big */ 78*35679Sbostic one =1.0 ; 7924588Szliu 8031853Szliu #if !defined(vax)&&!defined(tahoe) 8124588Szliu if(x!=x) return(x); /* x is NaN */ 8231853Szliu #endif /* !defined(vax)&&!defined(tahoe) */ 8324588Szliu if((t=copysign(x,one))>small) 8424588Szliu if(t<big) { 8524588Szliu s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); } 8624588Szliu else /* if |x| > big */ 8724588Szliu {s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));} 8824588Szliu else /* if |x| < small */ 8924588Szliu return(x); 9024588Szliu } 91