124588Szliu /* 224588Szliu * Copyright (c) 1985 Regents of the University of California. 324588Szliu * 424588Szliu * Use and reproduction of this software are granted in accordance with 524588Szliu * the terms and conditions specified in the Berkeley Software License 624588Szliu * Agreement (in particular, this entails acknowledgement of the programs' 724588Szliu * source, and inclusion of this notice) with the additional understanding 824588Szliu * that all recipients should regard themselves as participants in an 924588Szliu * ongoing research project and hence should feel obligated to report 1024588Szliu * their experiences (good or bad) with these elementary function codes, 1124588Szliu * using "sendbug 4bsd-bugs@BERKELEY", to the authors. 1224588Szliu */ 1324588Szliu 1424588Szliu #ifndef lint 15*24706Selefunt static char sccsid[] = 16*24706Selefunt "@(#)asinh.c 1.2 (Berkeley) 8/21/85; 1.2 (ucb.elefunt) 09/11/85"; 1724588Szliu #endif not lint 1824588Szliu 1924588Szliu /* ASINH(X) 2024588Szliu * RETURN THE INVERSE HYPERBOLIC SINE OF X 2124588Szliu * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 2224588Szliu * CODED IN C BY K.C. NG, 2/16/85; 2324588Szliu * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85. 2424588Szliu * 2524588Szliu * Required system supported functions : 2624588Szliu * copysign(x,y) 2724588Szliu * sqrt(x) 2824588Szliu * 2924588Szliu * Required kernel function: 3024588Szliu * log1p(x) ...return log(1+x) 3124588Szliu * 3224588Szliu * Method : 3324588Szliu * Based on 3424588Szliu * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 3524588Szliu * we have 3624588Szliu * asinh(x) := x if 1+x*x=1, 3724588Szliu * := sign(x)*(log1p(x)+ln2)) if sqrt(1+x*x)=x, else 3824588Szliu * := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) ) 3924588Szliu * 4024588Szliu * Accuracy: 4124588Szliu * asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded. 4224588Szliu * In a test run with 52,000 random arguments on a VAX, the maximum 4324588Szliu * observed error was 1.58 ulps (units in the last place). 4424588Szliu * 4524588Szliu * Constants: 4624588Szliu * The hexadecimal values are the intended ones for the following constants. 4724588Szliu * The decimal values may be used, provided that the compiler will convert 4824588Szliu * from decimal to binary accurately enough to produce the hexadecimal values 4924588Szliu * shown. 5024588Szliu */ 5124588Szliu 5224588Szliu #ifdef VAX /* VAX D format */ 5324588Szliu /* static double */ 5424588Szliu /* ln2hi = 6.9314718055829871446E-1 , Hex 2^ 0 * .B17217F7D00000 */ 5524588Szliu /* ln2lo = 1.6465949582897081279E-12 ; Hex 2^-39 * .E7BCD5E4F1D9CC */ 5624588Szliu static long ln2hix[] = { 0x72174031, 0x0000f7d0}; 5724588Szliu static long ln2lox[] = { 0xbcd52ce7, 0xd9cce4f1}; 5824588Szliu #define ln2hi (*(double*)ln2hix) 5924588Szliu #define ln2lo (*(double*)ln2lox) 6024588Szliu #else /* IEEE double */ 6124588Szliu static double 6224588Szliu ln2hi = 6.9314718036912381649E-1 , /*Hex 2^ -1 * 1.62E42FEE00000 */ 6324588Szliu ln2lo = 1.9082149292705877000E-10 ; /*Hex 2^-33 * 1.A39EF35793C76 */ 6424588Szliu #endif 6524588Szliu 6624588Szliu double asinh(x) 6724588Szliu double x; 6824588Szliu { 6924588Szliu double copysign(),log1p(),sqrt(),t,s; 7024588Szliu static double small=1.0E-10, /* fl(1+small*small) == 1 */ 7124588Szliu big =1.0E20, /* fl(1+big) == big */ 7224588Szliu one =1.0 ; 7324588Szliu 7424588Szliu #ifndef VAX 7524588Szliu if(x!=x) return(x); /* x is NaN */ 7624588Szliu #endif 7724588Szliu if((t=copysign(x,one))>small) 7824588Szliu if(t<big) { 7924588Szliu s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); } 8024588Szliu else /* if |x| > big */ 8124588Szliu {s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));} 8224588Szliu else /* if |x| < small */ 8324588Szliu return(x); 8424588Szliu } 85