1 /* 2 * Copyright (c) 1985 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * All recipients should regard themselves as participants in an ongoing 18 * research project and hence should feel obligated to report their 19 * experiences (good or bad) with these elementary function codes, using 20 * the sendbug(8) program, to the authors. 21 */ 22 23 #ifndef lint 24 static char sccsid[] = "@(#)acosh.c 5.4 (Berkeley) 09/22/88"; 25 #endif /* not lint */ 26 27 /* ACOSH(X) 28 * RETURN THE INVERSE HYPERBOLIC COSINE OF X 29 * DOUBLE PRECISION (VAX D FORMAT 56 BITS, IEEE DOUBLE 53 BITS) 30 * CODED IN C BY K.C. NG, 2/16/85; 31 * REVISED BY K.C. NG on 3/6/85, 3/24/85, 4/16/85, 8/17/85. 32 * 33 * Required system supported functions : 34 * sqrt(x) 35 * 36 * Required kernel function: 37 * log1p(x) ...return log(1+x) 38 * 39 * Method : 40 * Based on 41 * acosh(x) = log [ x + sqrt(x*x-1) ] 42 * we have 43 * acosh(x) := log1p(x)+ln2, if (x > 1.0E20); else 44 * acosh(x) := log1p( sqrt(x-1) * (sqrt(x-1) + sqrt(x+1)) ) . 45 * These formulae avoid the over/underflow complication. 46 * 47 * Special cases: 48 * acosh(x) is NaN with signal if x<1. 49 * acosh(NaN) is NaN without signal. 50 * 51 * Accuracy: 52 * acosh(x) returns the exact inverse hyperbolic cosine of x nearly 53 * rounded. In a test run with 512,000 random arguments on a VAX, the 54 * maximum observed error was 3.30 ulps (units of the last place) at 55 * x=1.0070493753568216 . 56 * 57 * Constants: 58 * The hexadecimal values are the intended ones for the following constants. 59 * The decimal values may be used, provided that the compiler will convert 60 * from decimal to binary accurately enough to produce the hexadecimal values 61 * shown. 62 */ 63 64 #include "mathimpl.h" 65 66 vc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000) 67 vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC) 68 69 ic(ln2hi, 6.9314718036912381649E-1, -1, 1.62E42FEE00000) 70 ic(ln2lo, 1.9082149292705877000E-10,-33, 1.A39EF35793C76) 71 72 #ifdef vccast 73 #define ln2hi vccast(ln2hi) 74 #define ln2lo vccast(ln2lo) 75 #endif 76 77 double acosh(x) 78 double x; 79 { 80 double t,big=1.E20; /* big+1==big */ 81 82 #if !defined(vax)&&!defined(tahoe) 83 if(x!=x) return(x); /* x is NaN */ 84 #endif /* !defined(vax)&&!defined(tahoe) */ 85 86 /* return log1p(x) + log(2) if x is large */ 87 if(x>big) {t=log1p(x)+ln2lo; return(t+ln2hi);} 88 89 t=sqrt(x-1.0); 90 return(log1p(t*(t+sqrt(x+1.0)))); 91 } 92