1*34124Sbostic /* 224588Szliu * Copyright (c) 1985 Regents of the University of California. 3*34124Sbostic * All rights reserved. 4*34124Sbostic * 5*34124Sbostic * Redistribution and use in source and binary forms are permitted 6*34124Sbostic * provided that this notice is preserved and that due credit is given 7*34124Sbostic * to the University of California at Berkeley. The name of the University 8*34124Sbostic * may not be used to endorse or promote products derived from this 9*34124Sbostic * software without specific prior written permission. This software 10*34124Sbostic * is provided ``as is'' without express or implied warranty. 11*34124Sbostic * 12*34124Sbostic * All recipients should regard themselves as participants in an ongoing 13*34124Sbostic * research project and hence should feel obligated to report their 14*34124Sbostic * experiences (good or bad) with these elementary function codes, using 15*34124Sbostic * the sendbug(8) program, to the authors. 1624588Szliu */ 1724588Szliu 1824588Szliu #ifndef lint 19*34124Sbostic static char sccsid[] = "@(#)asinh.c 5.2 (Berkeley) 04/29/88"; 20*34124Sbostic #endif /* not lint */ 2124588Szliu 2224588Szliu /* ASINH(X) 2324588Szliu * RETURN THE INVERSE HYPERBOLIC SINE OF X 2424588Szliu * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 2524588Szliu * CODED IN C BY K.C. NG, 2/16/85; 2624588Szliu * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85. 2724588Szliu * 2824588Szliu * Required system supported functions : 2924588Szliu * copysign(x,y) 3024588Szliu * sqrt(x) 3124588Szliu * 3224588Szliu * Required kernel function: 3324588Szliu * log1p(x) ...return log(1+x) 3424588Szliu * 3524588Szliu * Method : 3624588Szliu * Based on 3724588Szliu * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 3824588Szliu * we have 3924588Szliu * asinh(x) := x if 1+x*x=1, 4024588Szliu * := sign(x)*(log1p(x)+ln2)) if sqrt(1+x*x)=x, else 4124588Szliu * := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) ) 4224588Szliu * 4324588Szliu * Accuracy: 4424588Szliu * asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded. 4524588Szliu * In a test run with 52,000 random arguments on a VAX, the maximum 4624588Szliu * observed error was 1.58 ulps (units in the last place). 4724588Szliu * 4824588Szliu * Constants: 4924588Szliu * The hexadecimal values are the intended ones for the following constants. 5024588Szliu * The decimal values may be used, provided that the compiler will convert 5124588Szliu * from decimal to binary accurately enough to produce the hexadecimal values 5224588Szliu * shown. 5324588Szliu */ 5424588Szliu 5531853Szliu #if defined(vax)||defined(tahoe) /* VAX/TAHOE D format */ 5631853Szliu #ifdef vax 5731812Szliu #define _0x(A,B) 0x/**/A/**/B 5831853Szliu #else /* vax */ 5931812Szliu #define _0x(A,B) 0x/**/B/**/A 6031853Szliu #endif /* vax */ 6124588Szliu /* static double */ 6224588Szliu /* ln2hi = 6.9314718055829871446E-1 , Hex 2^ 0 * .B17217F7D00000 */ 6324588Szliu /* ln2lo = 1.6465949582897081279E-12 ; Hex 2^-39 * .E7BCD5E4F1D9CC */ 6431812Szliu static long ln2hix[] = { _0x(7217,4031), _0x(0000,f7d0)}; 6531812Szliu static long ln2lox[] = { _0x(bcd5,2ce7), _0x(d9cc,e4f1)}; 6624588Szliu #define ln2hi (*(double*)ln2hix) 6724588Szliu #define ln2lo (*(double*)ln2lox) 6831853Szliu #else /* defined(vax)||defined(tahoe) */ 6924588Szliu static double 7024588Szliu ln2hi = 6.9314718036912381649E-1 , /*Hex 2^ -1 * 1.62E42FEE00000 */ 7124588Szliu ln2lo = 1.9082149292705877000E-10 ; /*Hex 2^-33 * 1.A39EF35793C76 */ 7231853Szliu #endif /* defined(vax)||defined(tahoe) */ 7324588Szliu 7424588Szliu double asinh(x) 7524588Szliu double x; 7624588Szliu { 7724588Szliu double copysign(),log1p(),sqrt(),t,s; 7824588Szliu static double small=1.0E-10, /* fl(1+small*small) == 1 */ 7924588Szliu big =1.0E20, /* fl(1+big) == big */ 8024588Szliu one =1.0 ; 8124588Szliu 8231853Szliu #if !defined(vax)&&!defined(tahoe) 8324588Szliu if(x!=x) return(x); /* x is NaN */ 8431853Szliu #endif /* !defined(vax)&&!defined(tahoe) */ 8524588Szliu if((t=copysign(x,one))>small) 8624588Szliu if(t<big) { 8724588Szliu s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); } 8824588Szliu else /* if |x| > big */ 8924588Szliu {s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));} 9024588Szliu else /* if |x| < small */ 9124588Szliu return(x); 9224588Szliu } 93