134124Sbostic /* 224586Szliu * Copyright (c) 1985 Regents of the University of California. 334124Sbostic * All rights reserved. 434124Sbostic * 5*42655Sbostic * %sccs.include.redist.c% 634124Sbostic * 734124Sbostic * All recipients should regard themselves as participants in an ongoing 834124Sbostic * research project and hence should feel obligated to report their 934124Sbostic * experiences (good or bad) with these elementary function codes, using 1034124Sbostic * the sendbug(8) program, to the authors. 1124586Szliu */ 1224586Szliu 1324586Szliu #ifndef lint 14*42655Sbostic static char sccsid[] = "@(#)acosh.c 5.5 (Berkeley) 06/01/90"; 1534124Sbostic #endif /* not lint */ 1634124Sbostic 1724586Szliu /* ACOSH(X) 1824586Szliu * RETURN THE INVERSE HYPERBOLIC COSINE OF X 1924586Szliu * DOUBLE PRECISION (VAX D FORMAT 56 BITS, IEEE DOUBLE 53 BITS) 2024586Szliu * CODED IN C BY K.C. NG, 2/16/85; 2124586Szliu * REVISED BY K.C. NG on 3/6/85, 3/24/85, 4/16/85, 8/17/85. 2224586Szliu * 2324586Szliu * Required system supported functions : 2424586Szliu * sqrt(x) 2524586Szliu * 2624586Szliu * Required kernel function: 2724586Szliu * log1p(x) ...return log(1+x) 2824586Szliu * 2924586Szliu * Method : 3024586Szliu * Based on 3124586Szliu * acosh(x) = log [ x + sqrt(x*x-1) ] 3224586Szliu * we have 3324586Szliu * acosh(x) := log1p(x)+ln2, if (x > 1.0E20); else 3424586Szliu * acosh(x) := log1p( sqrt(x-1) * (sqrt(x-1) + sqrt(x+1)) ) . 3524586Szliu * These formulae avoid the over/underflow complication. 3624586Szliu * 3724586Szliu * Special cases: 3824586Szliu * acosh(x) is NaN with signal if x<1. 3924586Szliu * acosh(NaN) is NaN without signal. 4024586Szliu * 4124586Szliu * Accuracy: 4224586Szliu * acosh(x) returns the exact inverse hyperbolic cosine of x nearly 4324586Szliu * rounded. In a test run with 512,000 random arguments on a VAX, the 4424586Szliu * maximum observed error was 3.30 ulps (units of the last place) at 4524586Szliu * x=1.0070493753568216 . 4624586Szliu * 4724586Szliu * Constants: 4824586Szliu * The hexadecimal values are the intended ones for the following constants. 4924586Szliu * The decimal values may be used, provided that the compiler will convert 5024586Szliu * from decimal to binary accurately enough to produce the hexadecimal values 5124586Szliu * shown. 5224586Szliu */ 5324586Szliu 5435679Sbostic #include "mathimpl.h" 5524586Szliu 5635679Sbostic vc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000) 5735679Sbostic vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC) 5835679Sbostic 5935679Sbostic ic(ln2hi, 6.9314718036912381649E-1, -1, 1.62E42FEE00000) 6035679Sbostic ic(ln2lo, 1.9082149292705877000E-10,-33, 1.A39EF35793C76) 6135679Sbostic 6235679Sbostic #ifdef vccast 6335679Sbostic #define ln2hi vccast(ln2hi) 6435679Sbostic #define ln2lo vccast(ln2lo) 6535679Sbostic #endif 6635679Sbostic 6724586Szliu double acosh(x) 6824586Szliu double x; 6924586Szliu { 7035679Sbostic double t,big=1.E20; /* big+1==big */ 7124586Szliu 7231853Szliu #if !defined(vax)&&!defined(tahoe) 7324586Szliu if(x!=x) return(x); /* x is NaN */ 7431853Szliu #endif /* !defined(vax)&&!defined(tahoe) */ 7524586Szliu 7624586Szliu /* return log1p(x) + log(2) if x is large */ 7724586Szliu if(x>big) {t=log1p(x)+ln2lo; return(t+ln2hi);} 7824586Szliu 7924586Szliu t=sqrt(x-1.0); 8024586Szliu return(log1p(t*(t+sqrt(x+1.0)))); 8124586Szliu } 82