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[] = "@(#)asinh.c 5.5 (Berkeley) 06/01/90"; 15 #endif /* not lint */ 16 17 /* ASINH(X) 18 * RETURN THE INVERSE HYPERBOLIC SINE OF X 19 * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 20 * CODED IN C BY K.C. NG, 2/16/85; 21 * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85. 22 * 23 * Required system supported functions : 24 * copysign(x,y) 25 * sqrt(x) 26 * 27 * Required kernel function: 28 * log1p(x) ...return log(1+x) 29 * 30 * Method : 31 * Based on 32 * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 33 * we have 34 * asinh(x) := x if 1+x*x=1, 35 * := sign(x)*(log1p(x)+ln2)) if sqrt(1+x*x)=x, else 36 * := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) ) 37 * 38 * Accuracy: 39 * asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded. 40 * In a test run with 52,000 random arguments on a VAX, the maximum 41 * observed error was 1.58 ulps (units in the last place). 42 * 43 * Constants: 44 * The hexadecimal values are the intended ones for the following constants. 45 * The decimal values may be used, provided that the compiler will convert 46 * from decimal to binary accurately enough to produce the hexadecimal values 47 * shown. 48 */ 49 #include "mathimpl.h" 50 51 vc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000) 52 vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC) 53 54 ic(ln2hi, 6.9314718036912381649E-1, -1, 1.62E42FEE00000) 55 ic(ln2lo, 1.9082149292705877000E-10, -33, 1.A39EF35793C76) 56 57 #ifdef vccast 58 #define ln2hi vccast(ln2hi) 59 #define ln2lo vccast(ln2lo) 60 #endif 61 62 double asinh(x) 63 double x; 64 { 65 double t,s; 66 const static double small=1.0E-10, /* fl(1+small*small) == 1 */ 67 big =1.0E20, /* fl(1+big) == big */ 68 one =1.0 ; 69 70 #if !defined(vax)&&!defined(tahoe) 71 if(x!=x) return(x); /* x is NaN */ 72 #endif /* !defined(vax)&&!defined(tahoe) */ 73 if((t=copysign(x,one))>small) 74 if(t<big) { 75 s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); } 76 else /* if |x| > big */ 77 {s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));} 78 else /* if |x| < small */ 79 return(x); 80 } 81