134124Sbostic /* 2*61283Sbostic * Copyright (c) 1985, 1993 3*61283Sbostic * The Regents of the University of California. All rights reserved. 434124Sbostic * 542655Sbostic * %sccs.include.redist.c% 624586Szliu */ 724586Szliu 824586Szliu #ifndef lint 9*61283Sbostic static char sccsid[] = "@(#)acosh.c 8.1 (Berkeley) 06/04/93"; 1034124Sbostic #endif /* not lint */ 1134124Sbostic 1224586Szliu /* ACOSH(X) 1324586Szliu * RETURN THE INVERSE HYPERBOLIC COSINE OF X 1424586Szliu * DOUBLE PRECISION (VAX D FORMAT 56 BITS, IEEE DOUBLE 53 BITS) 1524586Szliu * CODED IN C BY K.C. NG, 2/16/85; 1624586Szliu * REVISED BY K.C. NG on 3/6/85, 3/24/85, 4/16/85, 8/17/85. 1724586Szliu * 1824586Szliu * Required system supported functions : 1924586Szliu * sqrt(x) 2024586Szliu * 2124586Szliu * Required kernel function: 2224586Szliu * log1p(x) ...return log(1+x) 2324586Szliu * 2424586Szliu * Method : 2524586Szliu * Based on 2624586Szliu * acosh(x) = log [ x + sqrt(x*x-1) ] 2724586Szliu * we have 2824586Szliu * acosh(x) := log1p(x)+ln2, if (x > 1.0E20); else 2924586Szliu * acosh(x) := log1p( sqrt(x-1) * (sqrt(x-1) + sqrt(x+1)) ) . 3024586Szliu * These formulae avoid the over/underflow complication. 3124586Szliu * 3224586Szliu * Special cases: 3324586Szliu * acosh(x) is NaN with signal if x<1. 3424586Szliu * acosh(NaN) is NaN without signal. 3524586Szliu * 3624586Szliu * Accuracy: 3724586Szliu * acosh(x) returns the exact inverse hyperbolic cosine of x nearly 3824586Szliu * rounded. In a test run with 512,000 random arguments on a VAX, the 3924586Szliu * maximum observed error was 3.30 ulps (units of the last place) at 4024586Szliu * x=1.0070493753568216 . 4124586Szliu * 4224586Szliu * Constants: 4324586Szliu * The hexadecimal values are the intended ones for the following constants. 4424586Szliu * The decimal values may be used, provided that the compiler will convert 4524586Szliu * from decimal to binary accurately enough to produce the hexadecimal values 4624586Szliu * shown. 4724586Szliu */ 4824586Szliu 4935679Sbostic #include "mathimpl.h" 5024586Szliu 5135679Sbostic vc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000) 5235679Sbostic vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC) 5335679Sbostic 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 6224586Szliu double acosh(x) 6324586Szliu double x; 6424586Szliu { 6535679Sbostic double t,big=1.E20; /* big+1==big */ 6624586Szliu 6731853Szliu #if !defined(vax)&&!defined(tahoe) 6824586Szliu if(x!=x) return(x); /* x is NaN */ 6931853Szliu #endif /* !defined(vax)&&!defined(tahoe) */ 7024586Szliu 7124586Szliu /* return log1p(x) + log(2) if x is large */ 7224586Szliu if(x>big) {t=log1p(x)+ln2lo; return(t+ln2hi);} 7324586Szliu 7424586Szliu t=sqrt(x-1.0); 7524586Szliu return(log1p(t*(t+sqrt(x+1.0)))); 7624586Szliu } 77